comparison Discovery/Src/show_logbook.c @ 662:1b995079c045 Betatest

PSCR Mode
author heinrichs weikamp
date Tue, 14 Dec 2021 15:36:10 +0100
parents 269e57ac4e56
children aa6006975e76
comparison
equal deleted inserted replaced
661:87bee7cc77b3 662:1b995079c045
33 #include "gfx_fonts.h" 33 #include "gfx_fonts.h"
34 #include "show_logbook.h" 34 #include "show_logbook.h"
35 #include "unit.h" 35 #include "unit.h"
36 #include "configuration.h" 36 #include "configuration.h"
37 #include "logbook_miniLive.h" 37 #include "logbook_miniLive.h"
38 #include "text_multilanguage.h"
38 39
39 #include <stdint.h> 40 #include <stdint.h>
40 #include <stdio.h> 41 #include <stdio.h>
41 #include <stdlib.h> // for abs() 42 #include <stdlib.h> // for abs()
42 43
513 514
514 //Print Dive Mode (OC/CCR/...) 515 //Print Dive Mode (OC/CCR/...)
515 switch(logbookHeader.diveMode) 516 switch(logbookHeader.diveMode)
516 { 517 {
517 case DIVEMODE_OC: 518 case DIVEMODE_OC:
518 snprintf(text,20,"open circuit"); 519 snprintf(text,20,"%c",TXT_OpenCircuit);
519 break; 520 break;
520 case DIVEMODE_CCR: 521 case DIVEMODE_CCR:
521 snprintf(text,20,"closed circuit"); 522 snprintf(text,20,"%c",TXT_ClosedCircuit);
522 break; 523 break;
523 case DIVEMODE_Gauge: 524 case DIVEMODE_Gauge:
524 snprintf(text,20,"Gauge"); 525 snprintf(text,20,"%c",TXT_Gauge);
525 break; 526 break;
526 case DIVEMODE_Apnea: 527 case DIVEMODE_Apnea:
527 snprintf(text,20,"Apnea"); 528 snprintf(text,20,"%c",TXT_Apnoe);
529 break;
530 case DIVEMODE_PSCR:
531 snprintf(text,20,"%c",TXT_PSClosedCircuit);
528 break; 532 break;
529 } 533 }
530 Gfx_write_label_var(hgfx, 30, 250,60, &FontT42,CLUT_GasSensor4,text); 534 Gfx_write_label_var(hgfx, 30, 250,60, &FontT42,CLUT_GasSensor4,text);
531 535
532 // Decomodel 536 // Decomodel
884 888
885 static void show_logbook_logbook_show_log_page3(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards) 889 static void show_logbook_logbook_show_log_page3(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards)
886 { 890 {
887 SWindowGimpStyle wintemp; 891 SWindowGimpStyle wintemp;
888 SWindowGimpStyle winsmal; 892 SWindowGimpStyle winsmal;
893 uint8_t gasWasUsed[NUM_GASES * 2];
894 int16_t index = 0;
895 uint8_t loopMode = 0;
896
889 wintemp.left = 50; 897 wintemp.left = 50;
890 wintemp.right = 799 - wintemp.left; 898 wintemp.right = 799 - wintemp.left;
891 wintemp.top = 50; 899 wintemp.top = 50;
892 wintemp.bottom = 479 - 40; 900 wintemp.bottom = 479 - 40;
893 901
897 uint16_t dataLength = 0; 905 uint16_t dataLength = 0;
898 uint16_t depthdata[1000]; 906 uint16_t depthdata[1000];
899 uint8_t gasdata[1000]; 907 uint8_t gasdata[1000];
900 dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 908 dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
901 909
910 char msg[15];
911 char gas_name[15];
912 int j = 0;
913
914 loopMode = isLoopMode(logbookHeader.diveMode);
915
916 /* check if gas was used, independent from its active state */
917 for(index = 0; index < NUM_GASES * 2; index++)
918 {
919 gasWasUsed[index] = 0;
920 }
921 for(index = 0; index < dataLength; index++)
922 {
923 if(loopMode)
924 {
925 if(gasdata[index] < NUM_GASES) /* the log entry starts with a ID in range 1..4 independend if diluent is used at start */
926 {
927 gasdata[index] += NUM_GASES;
928 }
929 else
930 {
931 loopMode = 0; /* after the first gas change, no matter if diluent or bailout, the correct ID will be stored */
932 }
933 }
934 if(gasdata[index] > 0)
935 {
936 gasWasUsed[gasdata[index]-1] = 1; /* The ID stored in the samples is starting with 1 (array[0] = gasID1) */
937 }
938 else
939 {
940 gasWasUsed[0] = 1;
941 }
942 }
943
902 //--- print coordinate system & depth graph with gaschanges --- 944 //--- print coordinate system & depth graph with gaschanges ---
903 show_logbook_draw_depth_graph(hgfx, StepBackwards, &wintemp, 1, dataLength, depthdata, gasdata, NULL); 945 show_logbook_draw_depth_graph(hgfx, StepBackwards, &wintemp, 1, dataLength, depthdata, gasdata, NULL);
904 946
905 //--- print gas list --- 947 //--- print gas list ---
906 winsmal.left = wintemp.right - 190; 948 winsmal.left = wintemp.right - 190;
907 winsmal.right = winsmal.left + 150; 949 winsmal.right = winsmal.left + 150;
908 950
909 char msg[15]; 951 loopMode = isLoopMode(logbookHeader.diveMode);
910 char gas_name[15]; 952 for(index = (2 * NUM_GASES) -1; index >= 0; index--)
911 int j = 0; 953 {
912 for(int i = 4;i >= 0;i--) 954 if(gasWasUsed[index])
913 {
914 if(logbookHeader.gasordil[i].note.ub.active > 0)
915 { 955 {
916 j++; 956 j++;
957 if(j > 5) /* limit number of gases displayed to 5 */
958 {
959 break;
960 }
917 winsmal.top = wintemp.bottom - 5 - j * 26 ; 961 winsmal.top = wintemp.bottom - 5 - j * 26 ;
918 winsmal.bottom = winsmal.top + 21 ; 962 winsmal.bottom = winsmal.top + 21 ;
919 uint8_t color = get_colour(i); 963 uint8_t color = get_colour(index);
920 964
921 print_gas_name(gas_name,15,logbookHeader.gasordil[i].oxygen_percentage,logbookHeader.gasordil[i].helium_percentage); 965 if(loopMode)
922 snprintf(msg,15,"G%i: %s",i + 1, gas_name); 966 {
923 //msg[10] = 0; 967 if(index < NUM_GASES) /* Switch to Bailout is not covered by log gas list */
968 {
969 snprintf(gas_name,15,"Bailout");
970 snprintf(msg,15,"G%d: %s",index +1, gas_name);
971 }
972 else
973 {
974 print_gas_name(gas_name,15,logbookHeader.gasordil[index-NUM_GASES].oxygen_percentage,logbookHeader.gasordil[index-NUM_GASES].helium_percentage);
975 snprintf(msg,15,"D%d: %s",index +1 - NUM_GASES, gas_name);
976 }
977 }
978 else
979 {
980 print_gas_name(gas_name,15,logbookHeader.gasordil[index].oxygen_percentage,logbookHeader.gasordil[index].helium_percentage);
981 snprintf(msg,15,"G%d: %s",index +1, gas_name);
982 }
924 Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,color,msg); 983 Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,color,msg);
925 } 984 }
926 } 985 }
927 986
928 //--- define buttons --- 987 //--- define buttons ---
929 /*if(*ghost_char_logfile_oxydata) 988 /*if(*ghost_char_logfile_oxydata)
930 button_start_single_action(surf1_menu_logbook_current_page, surf1_menu_logbook_show_log_page4, surf1_menu_logbook_show_log_next); 989 button_start_single_action(surf1_menu_logbook_current_page, surf1_menu_logbook_show_log_page4, surf1_menu_logbook_show_log_next);
931 else 990 else
932 button_start_single_action(surf1_menu_logbook_current_page, surf1_menu_logbook_show_log_page1, surf1_menu_logbook_show_log_next); 991 button_start_single_action(surf1_menu_logbook_current_page, surf1_menu_logbook_show_log_page1, surf1_menu_logbook_show_log_next);
933 */ 992 */
993 }
994
995 static uint8_t check_data_array_empty(uint16_t* pdata)
996 {
997 uint8_t ret = 0;
998 uint8_t index = 0;
999 uint8_t emptyCnt = 0;
1000
1001 for (index=0; index < 10; index++) /* read the first 10 data points. If all are 0 then the array is rated as empty */
1002 {
1003 if(*(pdata+index) == 0)
1004 {
1005 emptyCnt++;
1006 }
1007 }
1008 if(emptyCnt == 10)
1009 {
1010 ret = 1;
1011 }
1012 return ret;
934 } 1013 }
935 1014
936 static void show_logbook_logbook_show_log_page4(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards) 1015 static void show_logbook_logbook_show_log_page4(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards)
937 { SWindowGimpStyle wintemp; 1016 { SWindowGimpStyle wintemp;
938 SWindowGimpStyle winsmal; 1017 SWindowGimpStyle winsmal;
948 uint16_t depthdata[1000]; 1027 uint16_t depthdata[1000];
949 uint8_t gasdata[1000]; 1028 uint8_t gasdata[1000];
950 uint16_t ppO2data[1000]; 1029 uint16_t ppO2data[1000];
951 uint16_t sensor2[1000]; 1030 uint16_t sensor2[1000];
952 uint16_t sensor3[1000]; 1031 uint16_t sensor3[1000];
953 uint16_t *setpoint = ppO2data; 1032 uint16_t *setpoint = ppO2data;
954 uint16_t *sensor1 = ppO2data; 1033 uint16_t *sensor1 = ppO2data;
955 1034 uint8_t sensorDataAvailable[] = {0,0,0};
956 1035
957 if(logbookHeader.diveMode != DIVEMODE_CCR) 1036
1037 if(!isLoopMode(logbookHeader.diveMode))
958 dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, ppO2data, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 1038 dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, ppO2data, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
959 else 1039 else
960 { 1040 {
961 if(logbookHeader.CCRmode == CCRMODE_FixedSetpoint) 1041 switch(logbookHeader.CCRmode)
962 dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata, gasdata, NULL, NULL, setpoint, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 1042 {
963 else 1043 case CCRMODE_FixedSetpoint:
964 dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata, gasdata, NULL, NULL, NULL, sensor1, sensor2, sensor3, NULL, NULL, NULL, NULL, NULL); 1044 default: dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata, gasdata, NULL, NULL, setpoint, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1045 break;
1046 case CCRMODE_Sensors: dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata, gasdata, NULL, NULL, NULL, sensor1, sensor2, sensor3, NULL, NULL, NULL, NULL, NULL);
1047 if(!check_data_array_empty(sensor1))
1048 {
1049 sensorDataAvailable[0] = 1;
1050 }
1051 if(!check_data_array_empty(sensor2))
1052 {
1053 sensorDataAvailable[1] = 1;
1054 }
1055 if(!check_data_array_empty(sensor3))
1056 {
1057 sensorDataAvailable[2] = 1;
1058 }
1059 if((logbookHeader.diveMode == DIVEMODE_PSCR) && (sensorDataAvailable[0] + sensorDataAvailable[1] + sensorDataAvailable[2] != 3)) /*insert sim data if not all three sensors are in use*/
1060 {
1061 if(sensorDataAvailable[0] == 0)
1062 {
1063 logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, sensor1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1064 sensorDataAvailable[0] = 1;
1065 }
1066 else if(sensorDataAvailable[1] == 0)
1067 {
1068 logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, sensor2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1069 sensorDataAvailable[1] = 1;
1070 }
1071 else if(sensorDataAvailable[2] == 0)
1072 {
1073 logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, sensor3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1074 sensorDataAvailable[2] = 1;
1075 }
1076 }
1077 break;
1078 case CCRMODE_Simulation: dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, ppO2data, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1079 break;
1080 }
965 } 1081 }
966 1082
967 1083
968 //--- print coordinate system & depth graph with bailout--- 1084 //--- print coordinate system & depth graph with bailout---
969 show_logbook_draw_depth_graph(hgfx, StepBackwards, &wintemp, 0, dataLength, depthdata, gasdata, NULL); 1085 show_logbook_draw_depth_graph(hgfx, StepBackwards, &wintemp, 0, dataLength, depthdata, gasdata, NULL);
997 1113
998 } 1114 }
999 winsmal.left = 799 - 67;//wintemp.right -67; 1115 winsmal.left = 799 - 67;//wintemp.right -67;
1000 winsmal.right = winsmal.left;// + 45; 1116 winsmal.right = winsmal.left;// + 45;
1001 1117
1002 color = CLUT_LogbookTemperature;//LOGBOOK_GRAPH_DEPTH; 1118 color = CLUT_LogbookTemperature;
1003 if(logbookHeader.diveMode != DIVEMODE_CCR) 1119
1120 if(!isLoopMode(logbookHeader.diveMode))
1121 {
1004 Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,color,"\002PP O2"); 1122 Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,color,"\002PP O2");
1005 else 1123 }
1006 if(logbookHeader.CCRmode != CCRMODE_Sensors) 1124 else
1007 Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,color,"\002SETPOINT"); 1125 {
1008 else 1126 switch(logbookHeader.CCRmode)
1009 Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,color,"\002SENSORS"); 1127 {
1128 case CCRMODE_FixedSetpoint:
1129 default: Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,color,"\002SETPOINT");
1130 break;
1131 case CCRMODE_Sensors: Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,color,"\002SENSORS");
1132 break;
1133 case CCRMODE_Simulation: Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,color,"\002SIM PPO2");
1134 break;
1135 }
1136 }
1010 1137
1011 //*** PP O2 **************************************************** 1138 //*** PP O2 ****************************************************
1012 //calc lines and labels 1139 //calc lines and labels
1013 int datamax = 0; 1140 int datamax = 0;
1014 int datamin = 10000; 1141 int datamin = 10000;
1017 if(ppO2data[i]>datamax) 1144 if(ppO2data[i]>datamax)
1018 datamax = ppO2data[i]; 1145 datamax = ppO2data[i];
1019 if(ppO2data[i]<datamin) 1146 if(ppO2data[i]<datamin)
1020 datamin = ppO2data[i]; 1147 datamin = ppO2data[i];
1021 } 1148 }
1022 if((logbookHeader.diveMode == DIVEMODE_CCR) && (logbookHeader.CCRmode == CCRMODE_Sensors)) 1149 if(isLoopMode(logbookHeader.diveMode) && (logbookHeader.CCRmode == CCRMODE_Sensors))
1023 { 1150 {
1024 for(int i=1;i<dataLength;i++) 1151 for(int i=1;i<dataLength;i++)
1025 { 1152 {
1026 if(sensor2[i]>datamax) 1153 if(sensor2[i]>datamax)
1027 datamax = sensor2[i]; 1154 datamax = sensor2[i];
1075 if((ftmp - (int)ftmp) >= 0.5f) 1202 if((ftmp - (int)ftmp) >= 0.5f)
1076 wintemp.top++; 1203 wintemp.top++;
1077 wintemp.top = MaxU32LOG(wintemp.top ,0); 1204 wintemp.top = MaxU32LOG(wintemp.top ,0);
1078 if(wintemp.top < wintemp.bottom) 1205 if(wintemp.top < wintemp.bottom)
1079 { 1206 {
1080 if((logbookHeader.diveMode == DIVEMODE_CCR) && (logbookHeader.CCRmode == CCRMODE_Sensors)) 1207 if(isLoopMode(logbookHeader.diveMode) && (logbookHeader.CCRmode == CCRMODE_Sensors))
1081 { 1208 {
1082 GFX_graph_print(hgfx,&wintemp,0,1,datamax,datamin, ppO2data,dataLength,CLUT_LogbookTemperature, NULL); 1209 if(sensorDataAvailable[0])
1083 GFX_graph_print(hgfx,&wintemp,0,1,datamax,datamin, sensor2,dataLength,CLUT_LogbookTemperature, NULL); 1210 {
1084 GFX_graph_print(hgfx,&wintemp,0,1,datamax,datamin, sensor3,dataLength,CLUT_LogbookTemperature, NULL); 1211 GFX_graph_print(hgfx,&wintemp,0,1,datamax,datamin, ppO2data,dataLength,CLUT_GasSensor2, NULL);
1212 }
1213 if(sensorDataAvailable[1])
1214 {
1215 GFX_graph_print(hgfx,&wintemp,0,1,datamax,datamin, sensor2,dataLength,CLUT_GasSensor3, NULL);
1216 }
1217 if(sensorDataAvailable[2])
1218 {
1219 GFX_graph_print(hgfx,&wintemp,0,1,datamax,datamin, sensor3,dataLength,CLUT_GasSensor4, NULL);
1220 }
1085 } 1221 }
1086 else 1222 else
1087 GFX_graph_print(hgfx,&wintemp,0,1,datamax,datamin, ppO2data,dataLength,CLUT_LogbookTemperature, NULL); 1223 GFX_graph_print(hgfx,&wintemp,0,1,datamax,datamin, ppO2data,dataLength,CLUT_LogbookTemperature, NULL);
1088 } 1224 }
1089 else 1225 else