comparison Discovery/Src/tMenuEditHardware.c @ 562:ec76fa85009e

Added ADC sensor interface to O2 sensore menu structure: Based on the availability of an external ADC (Old / new HW) the interface to the O2 sensors may now be choosen between classic optical and the new analog. Depending on the selection HUB Battery or a button for sensor calibration will be shown.
author Ideenmodellierer
date Sun, 15 Nov 2020 19:58:14 +0100
parents d784f281833a
children 830de438e0b0
comparison
equal deleted inserted replaced
561:e581425c7e3e 562:ec76fa85009e
36 #include "tMenuEdit.h" 36 #include "tMenuEdit.h"
37 #include "tHome.h" 37 #include "tHome.h"
38 #include "tInfo.h" 38 #include "tInfo.h"
39 #include "tInfoLog.h" 39 #include "tInfoLog.h"
40 #include "tComm.h" 40 #include "tComm.h"
41 #include "data_exchange_main.h"
41 42
42 extern void tM_build_pages(void); 43 extern void tM_build_pages(void);
43 44
44 /* Private function prototypes -----------------------------------------------*/ 45 /* Private function prototypes -----------------------------------------------*/
45 void openEdit_Bluetooth(void); 46 void openEdit_Bluetooth(void);
58 //uint8_t OnAction_ExitHardw (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); 59 //uint8_t OnAction_ExitHardw (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
59 uint8_t OnAction_Sensor1 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); 60 uint8_t OnAction_Sensor1 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
60 uint8_t OnAction_Sensor2 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); 61 uint8_t OnAction_Sensor2 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
61 uint8_t OnAction_Sensor3 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); 62 uint8_t OnAction_Sensor3 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
62 uint8_t OnAction_O2_Fallback (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); 63 uint8_t OnAction_O2_Fallback (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
64 uint8_t OnAction_O2_Calibrate (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
65 uint8_t OnAction_O2_Source (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
63 uint8_t OnAction_Button (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); 66 uint8_t OnAction_Button (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
64 uint8_t OnAction_ButtonBalance (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); 67 uint8_t OnAction_ButtonBalance (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
65 // nicht notwending uint8_t OnAction_Bluetooth (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); 68 // nicht notwending uint8_t OnAction_Bluetooth (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
66 69
67 /* Exported functions --------------------------------------------------------*/ 70 /* Exported functions --------------------------------------------------------*/
71
72
73 #define O2_CALIB_FRACTION_AIR (0.209F)
74
68 75
69 void openEdit_Hardware(uint8_t line) 76 void openEdit_Hardware(uint8_t line)
70 { 77 {
71 set_globalState_Menu_Line(line); 78 set_globalState_Menu_Line(line);
72 resetMenuEdit(CLUT_MenuPageHardware); 79 resetMenuEdit(CLUT_MenuPageHardware);
265 } 272 }
266 */ 273 */
267 274
268 void refresh_O2Sensors(void) 275 void refresh_O2Sensors(void)
269 { 276 {
270 char text[16]; 277 char text[32];
271 uint16_t y_line; 278 uint16_t y_line;
279
280 const SDiveState *pStateReal = stateRealGetPointer();
272 281
273 text[0] = '\001'; 282 text[0] = '\001';
274 text[1] = TXT_o2Sensors; 283 text[1] = TXT_o2Sensors;
275 text[2] = 0; 284 text[2] = 0;
276 write_topline(text); 285 write_topline(text);
285 text[3] = '2'; 294 text[3] = '2';
286 write_label_var( 96, 340, ME_Y_LINE2, &FontT48, text); 295 write_label_var( 96, 340, ME_Y_LINE2, &FontT48, text);
287 text[3] = '3'; 296 text[3] = '3';
288 write_label_var( 96, 340, ME_Y_LINE3, &FontT48, text); 297 write_label_var( 96, 340, ME_Y_LINE3, &FontT48, text);
289 298
290 text[0] = TXT_2BYTE; 299 if(settingsGetPointer()->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC)
291 text[1] = TXT2BYTE_HUDbattery; 300 {
292 text[2] = 0; 301 text[0] = TXT_2BYTE;
293 write_label_var( 30, 340, ME_Y_LINE4, &FontT48, text); 302 text[1] = TXT2BYTE_HUDbattery;
294 // write_label_var( 30, 340, ME_Y_LINE4, &FontT48, "HUD Battery"); 303 text[2] = 0;
295 304 write_label_var( 30, 340, ME_Y_LINE4, &FontT48, text);
296 for(int i=0;i<3;i++) 305
297 { 306
298 snprintf(text, 20,"%01.2f, %01.1fmV",get_ppO2Sensor_bar(i),get_sensorVoltage_mV(i)); 307 snprintf(text, 20,"%01.3fV", get_HUD_battery_voltage_V());
299 y_line = ME_Y_LINE1 + (i * ME_Y_LINE_STEP); 308 write_label_var( 400, 800, ME_Y_LINE4, &FontT48, text);
300 write_label_var( 400, 800, y_line, &FontT48, text); 309 }
301 } 310 else
302 311 {
303 snprintf(text, 20,"%01.3fV", get_HUD_battery_voltage_V()); 312 text[0] = TXT_2BYTE;
304 write_label_var( 400, 800, ME_Y_LINE4, &FontT48, text); 313 text[1] = TXT2BYTE_O2CalibAir;
305 314 text[2] = 0;
315 write_label_var( 30, 340, ME_Y_LINE4, &FontT48, text);
316 }
317
318 for(int i=0;i<3;i++)
319 {
320 snprintf(text, 20,"%01.2f, %01.1fmV", pStateReal->lifeData.ppO2Sensor_bar[i], pStateReal->lifeData.sensorVoltage_mV[i]);
321 y_line = ME_Y_LINE1 + (i * ME_Y_LINE_STEP);
322 write_label_var( 400, 800, y_line, &FontT48, text);
323 }
324
325 if(DataEX_external_ADC_Present())
326 {
327 text[0] = TXT_2BYTE;
328 text[1] = TXT2BYTE_O2Interface;
329 text[2] = 0;
330 write_label_var( 30, 340, ME_Y_LINE6, &FontT48, text);
331 text[0] = TXT_2BYTE;
332 switch(settingsGetPointer()->ppo2sensors_source)
333 {
334 default:
335 case O2_SENSOR_SOURCE_OPTIC: text[1] = TXT2BYTE_O2IFOptic;
336 break;
337 case O2_SENSOR_SOURCE_ANALOG: text[1] = TXT2BYTE_O2IFAnalog;
338 }
339 text[2] = 0;
340 write_label_var( 400, 800, ME_Y_LINE6, &FontT48, text);
341 }
306 tMenuEdit_refresh_field(StMHARD3_O2_Sensor1); 342 tMenuEdit_refresh_field(StMHARD3_O2_Sensor1);
307 tMenuEdit_refresh_field(StMHARD3_O2_Sensor2); 343 tMenuEdit_refresh_field(StMHARD3_O2_Sensor2);
308 tMenuEdit_refresh_field(StMHARD3_O2_Sensor3); 344 tMenuEdit_refresh_field(StMHARD3_O2_Sensor3);
309 tMenuEdit_refresh_field(StMHARD3_O2_Fallback); 345 tMenuEdit_refresh_field(StMHARD3_O2_Fallback);
310 346
329 365
330 write_field_on_off(StMHARD3_O2_Sensor1, 30, 95, ME_Y_LINE1, &FontT48, "", sensorActive[0]); 366 write_field_on_off(StMHARD3_O2_Sensor1, 30, 95, ME_Y_LINE1, &FontT48, "", sensorActive[0]);
331 write_field_on_off(StMHARD3_O2_Sensor2, 30, 95, ME_Y_LINE2, &FontT48, "", sensorActive[1]); 367 write_field_on_off(StMHARD3_O2_Sensor2, 30, 95, ME_Y_LINE2, &FontT48, "", sensorActive[1]);
332 write_field_on_off(StMHARD3_O2_Sensor3, 30, 95, ME_Y_LINE3, &FontT48, "", sensorActive[2]); 368 write_field_on_off(StMHARD3_O2_Sensor3, 30, 95, ME_Y_LINE3, &FontT48, "", sensorActive[2]);
333 369
370 if(settingsGetPointer()->ppo2sensors_source == O2_SENSOR_SOURCE_ANALOG)
371 {
372 write_field_button(StMHARD3_O2_Calibrate, 30, 800, ME_Y_LINE4, &FontT48, "");
373 }
374
334 text[0] = TXT_Fallback; 375 text[0] = TXT_Fallback;
335 text[1] = 1; 376 text[1] = 1;
377
336 write_field_on_off(StMHARD3_O2_Fallback, 30, 500, ME_Y_LINE5, &FontT48, text, settingsGetPointer()->fallbackToFixedSetpoint); 378 write_field_on_off(StMHARD3_O2_Fallback, 30, 500, ME_Y_LINE5, &FontT48, text, settingsGetPointer()->fallbackToFixedSetpoint);
379
380 if(DataEX_external_ADC_Present())
381 {
382 write_field_button(StMHARD3_O2_Source, 30, 800, ME_Y_LINE6, &FontT48, "");
383 }
337 384
338 setEvent(StMHARD3_O2_Sensor1, (uint32_t)OnAction_Sensor1); 385 setEvent(StMHARD3_O2_Sensor1, (uint32_t)OnAction_Sensor1);
339 setEvent(StMHARD3_O2_Sensor2, (uint32_t)OnAction_Sensor2); 386 setEvent(StMHARD3_O2_Sensor2, (uint32_t)OnAction_Sensor2);
340 setEvent(StMHARD3_O2_Sensor3, (uint32_t)OnAction_Sensor3); 387 setEvent(StMHARD3_O2_Sensor3, (uint32_t)OnAction_Sensor3);
388 if(settingsGetPointer()->ppo2sensors_source == O2_SENSOR_SOURCE_ANALOG)
389 {
390 setEvent(StMHARD3_O2_Calibrate, (uint32_t)OnAction_O2_Calibrate);
391 }
341 setEvent(StMHARD3_O2_Fallback, (uint32_t)OnAction_O2_Fallback); 392 setEvent(StMHARD3_O2_Fallback, (uint32_t)OnAction_O2_Fallback);
393 if(DataEX_external_ADC_Present())
394 {
395 setEvent(StMHARD3_O2_Source, (uint32_t)OnAction_O2_Source);
396 }
342 397
343 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext); 398 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
344 } 399 }
345 400
346 401
406 461
407 settingsGetPointer()->fallbackToFixedSetpoint = fallback; 462 settingsGetPointer()->fallbackToFixedSetpoint = fallback;
408 tMenuEdit_set_on_off(editId, fallback); 463 tMenuEdit_set_on_off(editId, fallback);
409 return UPDATE_DIVESETTINGS; 464 return UPDATE_DIVESETTINGS;
410 } 465 }
411 466 uint8_t OnAction_O2_Calibrate (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
467 {
468 uint8_t loop;
469 const SDiveState *pStateReal = stateRealGetPointer();
470 SSettings* pSettings = settingsGetPointer();
471
472 for(loop=0;loop<3;loop++)
473 {
474 if((pSettings->ppo2sensors_deactivated & (0x1 << loop)) == 0)
475 {
476 if(pStateReal->lifeData.sensorVoltage_mV[loop] > 0.0001) /* sensor connected ?*/
477 {
478 pSettings->ppo2sensors_calibCoeff[loop] = O2_CALIB_FRACTION_AIR / pStateReal->lifeData.sensorVoltage_mV[loop];
479 }
480 else
481 {
482 pSettings->ppo2sensors_calibCoeff[loop] = 0.0;
483 settingsGetPointer()->ppo2sensors_deactivated |= 0x1 << loop;
484 tMenuEdit_set_on_off(editId, 0);
485 }
486 }
487 }
488
489 return UPDATE_DIVESETTINGS;
490 }
491 uint8_t OnAction_O2_Source (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
492 {
493 uint8_t source = settingsGetPointer()->ppo2sensors_source;
494
495 if(source == O2_SENSOR_SOURCE_OPTIC)
496 {
497 source = O2_SENSOR_SOURCE_ANALOG;
498 }
499 else
500 {
501 source = O2_SENSOR_SOURCE_OPTIC;
502 }
503
504 settingsGetPointer()->ppo2sensors_source = source;
505
506 resetMenuEdit(CLUT_MenuPageHardware); /* rebuild menu structure (Hide HUD <=> Show Calibrate) */
507 openEdit_O2Sensors();
508 return UPDATE_DIVESETTINGS;
509 }
412 510
413 void openEdit_Brightness(void) 511 void openEdit_Brightness(void)
414 { 512 {
415 uint8_t actualBrightness; 513 uint8_t actualBrightness;
416 SSettings *pSettings = settingsGetPointer(); 514 SSettings *pSettings = settingsGetPointer();