comparison Small_CPU/Src/externalInterface.c @ 786:19ab6f3ed52a

Cleanup sensor data interface: In a very early implementation of the multiplexer the address of the mux was 0 followed by the sensors. As a resul the ID of the channels was shifted by one. To avoid confusion and because the mux address is meanwhile changed to the last address, it makes sense to return to the indexing where only the three visible sensor slots are used as reference (0,1,2).
author Ideenmodellierer
date Sun, 04 Jun 2023 21:54:24 +0200
parents 95af969fe0ae
children bb37d4f3e50e
comparison
equal deleted inserted replaced
785:3c0b16473af4 786:19ab6f3ed52a
410 410
411 411
412 uint8_t externalInterface_GetSensorData(uint8_t sensorId, uint8_t* pDataStruct) 412 uint8_t externalInterface_GetSensorData(uint8_t sensorId, uint8_t* pDataStruct)
413 { 413 {
414 uint8_t localId = sensorId; 414 uint8_t localId = sensorId;
415 if(localId == 0) 415 if(localId == 0xFF)
416 { 416 {
417 localId = lastSensorDataId; 417 localId = lastSensorDataId;
418 } 418 }
419 419
420 if((pDataStruct != NULL) && (localId > 0) && (localId <= MAX_ADC_CHANNEL)) 420 if((pDataStruct != NULL) && (localId <= MAX_ADC_CHANNEL))
421 { 421 {
422 memcpy(pDataStruct, &sensorDataDiveO2[localId-1], sizeof(SSensorDataDiveO2)); 422 memcpy(pDataStruct, &sensorDataDiveO2[localId], sizeof(SSensorDataDiveO2));
423 }
424 else
425 {
426 localId = 0xFF;
423 } 427 }
424 return localId; 428 return localId;
425 } 429 }
426 430
427 void externalInterface_SetSensorData(uint8_t dataId, uint8_t* pDataStruct) 431 void externalInterface_SetSensorData(uint8_t sensorId, uint8_t* pDataStruct)
428 { 432 {
429 if(pDataStruct != NULL) 433 if(pDataStruct != NULL)
430 { 434 {
431 if((dataId != 0) && (dataId <= MAX_ADC_CHANNEL)) 435 if((sensorId != 0xFF) && (sensorId < MAX_ADC_CHANNEL))
432 { 436 {
433 memcpy(&sensorDataDiveO2[dataId-1], pDataStruct, sizeof(SSensorDataDiveO2)); 437 memcpy(&sensorDataDiveO2[sensorId], pDataStruct, sizeof(SSensorDataDiveO2));
438 lastSensorDataId = sensorId;
434 } 439 }
435 else 440 else
436 { 441 {
437 memset(&sensorDataDiveO2,0,sizeof(sensorDataDiveO2)); 442 memset(&sensorDataDiveO2,0,sizeof(sensorDataDiveO2));
438 } 443 lastSensorDataId = 0xFF;
439 lastSensorDataId = dataId; 444 }
440 } 445 }
441 } 446 }
442 447
443 void externalInface_SetSensorMap(uint8_t* pMap) 448 void externalInface_SetSensorMap(uint8_t* pMap)
444 { 449 {
640 UART_MapDigO2_Channel(tmpMuxMapping[index], index); 645 UART_MapDigO2_Channel(tmpMuxMapping[index], index);
641 } 646 }
642 647
643 externalAutoDetect = DETECTION_OFF; 648 externalAutoDetect = DETECTION_OFF;
644 externalInterface_SwitchUART(0); 649 externalInterface_SwitchUART(0);
645 UART_SetDigO2_Channel(0); 650
651
652 for(index = 0; index < MAX_ADC_CHANNEL; index++)
653 {
654 if(tmpSensorMap[index] == SENSOR_DIGO2) /* set Channel to first valid entry */
655 {
656 UART_SetDigO2_Channel(index);
657 break;
658 }
659 }
646 for(index = 0; index < MAX_ADC_CHANNEL; index++) 660 for(index = 0; index < MAX_ADC_CHANNEL; index++)
647 { 661 {
648 if(tmpSensorMap[index] != SENSOR_NONE) 662 if(tmpSensorMap[index] != SENSOR_NONE)
649 { 663 {
650 break; 664 break;