Mercurial > public > ostc4
comparison Discovery/Src/tMenuEditSystem.c @ 1027:158100a84ebd GasConsumption
New profile feature:
In the past the OSTC provide just one instance for settings. If for example a diver switched from OC to CCR configuration several settings had to be modified. To improve this and to be more flexible in adapting the OSTC to differend dive scenarions the usage of up to 4 profiles has beem introduced. The profiles are copies of the common settings but stored in a separate, previously not used, flash section => no impact to existings settings handling. For access to the profiles the existing setting flash functions are reused. To enable this a parameter war introduced which defines the target of the operation (common settings or profiles).
| author | Ideenmodellierer |
|---|---|
| date | Sun, 07 Sep 2025 19:03:44 +0200 |
| parents | 5924a2d1d3ba |
| children | 2af07aa38531 |
comparison
equal
deleted
inserted
replaced
| 1026:5fedf7ba2392 | 1027:158100a84ebd |
|---|---|
| 44 #include "math.h" | 44 #include "math.h" |
| 45 | 45 |
| 46 | 46 |
| 47 /*#define HAVE_DEBUG_VIEW */ | 47 /*#define HAVE_DEBUG_VIEW */ |
| 48 static uint8_t infoPage = 0; | 48 static uint8_t infoPage = 0; |
| 49 static uint32_t profileStartCrc[NUMBER_OF_PROFILES]; | |
| 50 static uint8_t profileActiveStart = 0; | |
| 51 | |
| 49 | 52 |
| 50 /* Private function prototypes -----------------------------------------------*/ | 53 /* Private function prototypes -----------------------------------------------*/ |
| 51 void openEdit_DateTime(void); | 54 void openEdit_DateTime(void); |
| 52 void openEdit_DateFormat(void); | 55 void openEdit_DateFormat(void); |
| 53 void openEdit_Language(void); | 56 void openEdit_Language(void); |
| 54 void openEdit_Design(void); | 57 void openEdit_Design(void); |
| 58 void openEdit_Profile(void); | |
| 55 void openEdit_Information(void); | 59 void openEdit_Information(void); |
| 56 void openEdit_Reset(void); | 60 void openEdit_Reset(void); |
| 57 void openEdit_Maintenance(void); | 61 void openEdit_Maintenance(void); |
| 58 //void openEdit_ShowDebugInfo(void); | 62 //void openEdit_ShowDebugInfo(void); |
| 59 //void openEdit_Salinity(void); | 63 //void openEdit_Salinity(void); |
| 92 //uint8_t OnAction_Design_t3 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | 96 //uint8_t OnAction_Design_t3 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); |
| 93 | 97 |
| 94 uint8_t OnAction_Units (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | 98 uint8_t OnAction_Units (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); |
| 95 uint8_t OnAction_Colorscheme (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | 99 uint8_t OnAction_Colorscheme (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); |
| 96 uint8_t OnAction_DebugInfo (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | 100 uint8_t OnAction_DebugInfo (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); |
| 101 uint8_t OnAction_Profile(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
| 102 uint8_t OnAction_SetProfile(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
| 97 | 103 |
| 98 uint8_t OnAction_Exit (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | 104 uint8_t OnAction_Exit (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); |
| 99 uint8_t OnAction_Confirm (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | 105 uint8_t OnAction_Confirm (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); |
| 100 uint8_t OnAction_Maintenance (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | 106 uint8_t OnAction_Maintenance (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); |
| 101 uint8_t OnAction_RebootRTE (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | 107 uint8_t OnAction_RebootRTE (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); |
| 136 case 1: | 142 case 1: |
| 137 default: | 143 default: |
| 138 openEdit_DateTime(); | 144 openEdit_DateTime(); |
| 139 break; | 145 break; |
| 140 case 2: | 146 case 2: |
| 147 openEdit_Profile(); | |
| 148 break; | |
| 149 case 3: | |
| 141 openEdit_Language(); | 150 openEdit_Language(); |
| 142 break; | 151 break; |
| 143 case 3: | 152 case 4: |
| 144 openEdit_Design(); | 153 openEdit_Design(); |
| 145 break; | 154 break; |
| 146 case 4: | 155 case 5: |
| 147 openEdit_Information(); | 156 openEdit_Information(); |
| 148 break; | 157 break; |
| 149 case 5: | 158 case 6: |
| 150 openEdit_Reset(); | 159 openEdit_Reset(); |
| 151 break; | 160 break; |
| 161 | |
| 152 } | 162 } |
| 153 } | 163 } |
| 154 else | 164 else |
| 155 { | 165 { |
| 156 openEdit_CustomviewDivemodeMenu(line); | 166 openEdit_CustomviewDivemodeMenu(line); |
| 907 #ifdef HAVE_DEBUG_VIEW | 917 #ifdef HAVE_DEBUG_VIEW |
| 908 setEvent(StMSYS3_Debug, (uint32_t)OnAction_DebugInfo); | 918 setEvent(StMSYS3_Debug, (uint32_t)OnAction_DebugInfo); |
| 909 #endif | 919 #endif |
| 910 } | 920 } |
| 911 | 921 |
| 922 void changeActiveProfil(uint8_t newProfile) | |
| 923 { | |
| 924 SSettings *pSettings = settingsGetPointer(); | |
| 925 SSettings* pOldProfile = profileGetPointer(pSettings->activeProfile); | |
| 926 SSettings* pNewProfile = profileGetPointer(newProfile); | |
| 927 uint16_t personalDiveCountBackup; | |
| 928 uint8_t lastDiveLogIdBackup; | |
| 929 uint32_t sampleStartBackup; | |
| 930 char customTextBackup[60]; | |
| 931 | |
| 932 if( newProfile < NUMBER_OF_PROFILES) | |
| 933 { | |
| 934 /* some data needs to be the same in all profiles => make backup before gettings the new profile */ | |
| 935 personalDiveCountBackup = pSettings->personalDiveCount; | |
| 936 lastDiveLogIdBackup = pSettings->lastDiveLogId; | |
| 937 sampleStartBackup = pSettings->logFlashNextSampleStartAddress; | |
| 938 memcpy(customTextBackup, pSettings->customtext, 60); | |
| 939 | |
| 940 | |
| 941 memcpy(pOldProfile,pSettings,sizeof(SSettings)); | |
| 942 memcpy(pSettings,pNewProfile,sizeof(SSettings)); | |
| 943 | |
| 944 set_new_settings_missing_in_ext_flash(EF_PROFILE0 + newProfile); | |
| 945 check_and_correct_settings(EF_PROFILE0 + newProfile); | |
| 946 | |
| 947 pSettings->personalDiveCount = personalDiveCountBackup; | |
| 948 pSettings->lastDiveLogId = lastDiveLogIdBackup; | |
| 949 pSettings->logFlashNextSampleStartAddress = sampleStartBackup; | |
| 950 | |
| 951 pSettings->firmwareVersion[0] = firmware_FirmwareData.versionFirst; | |
| 952 pSettings->firmwareVersion[1] = firmware_FirmwareData.versionSecond; | |
| 953 pSettings->firmwareVersion[2] = firmware_FirmwareData.versionThird; | |
| 954 pSettings->firmwareVersion[3] = firmware_FirmwareData.versionBeta; | |
| 955 | |
| 956 memcpy(pSettings->customtext, customTextBackup, 60); | |
| 957 | |
| 958 if(pOldProfile->tX_colorscheme != pSettings->tX_colorscheme) | |
| 959 { | |
| 960 GFX_use_colorscheme(pSettings->tX_colorscheme); | |
| 961 tHome_init_compass(); | |
| 962 } | |
| 963 } | |
| 964 } | |
| 965 | |
| 966 void exitMenuProfil() | |
| 967 { | |
| 968 uint8_t index = 0; | |
| 969 SSettings* pProfile; | |
| 970 uint8_t writeFlash = 0; | |
| 971 uint32_t profileExitCrc; | |
| 972 | |
| 973 for(index = 0; index < NUMBER_OF_PROFILES; index++) | |
| 974 { | |
| 975 pProfile = profileGetPointer(index); | |
| 976 profileExitCrc = CalcFletcher32((uint32_t)pProfile, (uint32_t)pProfile + sizeof(SSettings)); | |
| 977 | |
| 978 if(profileExitCrc != profileStartCrc[index]) | |
| 979 { | |
| 980 writeFlash = 1; | |
| 981 break; | |
| 982 } | |
| 983 } | |
| 984 if(writeFlash) | |
| 985 { | |
| 986 for(index = EF_PROFILE0; index <= EF_PROFILE3; index++) | |
| 987 ext_flash_write_settings(index,0); | |
| 988 } | |
| 989 if(profileActiveStart != settingsGetPointer()->activeProfile) | |
| 990 { | |
| 991 createDiveSettings(); | |
| 992 } | |
| 993 exitMenuEdit(1); | |
| 994 } | |
| 995 | |
| 996 void openEdit_Profile(void) | |
| 997 { | |
| 998 char text[50]; | |
| 999 uint8_t index = 0; | |
| 1000 SSettings *pSettings = settingsGetPointer(); | |
| 1001 SSettings* pProfile; | |
| 1002 | |
| 1003 setBackMenu((uint32_t)exitMenuProfil,0,0); | |
| 1004 | |
| 1005 profileActiveStart = pSettings->activeProfile; | |
| 1006 | |
| 1007 /* read profiles from flash */ | |
| 1008 for(index = EF_PROFILE0; index <= EF_PROFILE3; index++) | |
| 1009 { | |
| 1010 set_settings_to_Standard(index); /* this is needed because details like header version are used by the read block function */ | |
| 1011 ext_flash_read_settings(index); /* will overwrite standard settings if reading is successfull */ | |
| 1012 pProfile = profileGetPointer(index - EF_PROFILE0); | |
| 1013 profileStartCrc[index - EF_PROFILE0] = CalcFletcher32((uint32_t)pProfile, (uint32_t)pProfile + sizeof(SSettings)); | |
| 1014 set_new_settings_missing_in_ext_flash(index); | |
| 1015 check_and_correct_settings(index); | |
| 1016 } | |
| 1017 | |
| 1018 sprintf(text,"\001%c%c",TXT_2BYTE,TXT2BYTE_Profile); | |
| 1019 write_topline(text); | |
| 1020 | |
| 1021 sprintf(text,"%c %c%c:",TXT_Active,TXT_2BYTE,TXT2BYTE_Profile); | |
| 1022 write_label_var( 30, 300, ME_Y_LINE1, &FontT48, text); | |
| 1023 sprintf(text,"%s",pSettings->profileName[pSettings->activeProfile]); | |
| 1024 write_field_button(StMSYS_Profile, 400, 700, ME_Y_LINE1, &FontT48, text); | |
| 1025 write_field_text(StMSYS_ProfileA, 400, 700, ME_Y_LINE3, &FontT48, "########", pSettings->profileName[0]); | |
| 1026 write_field_text(StMSYS_ProfileB, 400, 700, ME_Y_LINE4, &FontT48, "########", pSettings->profileName[1]); | |
| 1027 write_field_text(StMSYS_ProfileC, 400, 700, ME_Y_LINE5, &FontT48, "########", pSettings->profileName[2]); | |
| 1028 write_field_text(StMSYS_ProfileD, 400, 700, ME_Y_LINE6, &FontT48, "########", pSettings->profileName[3]); | |
| 1029 | |
| 1030 setEvent(StMSYS_Profile, (uint32_t)OnAction_SetProfile); | |
| 1031 setEvent(StMSYS_ProfileA, (uint32_t)OnAction_Profile); | |
| 1032 setEvent(StMSYS_ProfileB, (uint32_t)OnAction_Profile); | |
| 1033 setEvent(StMSYS_ProfileC, (uint32_t)OnAction_Profile); | |
| 1034 setEvent(StMSYS_ProfileD, (uint32_t)OnAction_Profile); | |
| 1035 | |
| 1036 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext); | |
| 1037 } | |
| 1038 | |
| 1039 | |
| 912 | 1040 |
| 913 void refresh_Design(void) | 1041 void refresh_Design(void) |
| 914 { | 1042 { |
| 915 char text[32]; | 1043 char text[32]; |
| 1044 SSettings *pSettings = settingsGetPointer(); | |
| 916 | 1045 |
| 917 // header | 1046 // header |
| 918 text[0] = '\001'; | 1047 text[0] = '\001'; |
| 919 text[1] = TXT_2BYTE; | 1048 text[1] = TXT_2BYTE; |
| 920 text[2] = TXT2BYTE_Layout; | 1049 text[2] = TXT2BYTE_Layout; |
| 925 text[0] = TXT_2BYTE; | 1054 text[0] = TXT_2BYTE; |
| 926 text[1] = TXT2BYTE_Units; | 1055 text[1] = TXT2BYTE_Units; |
| 927 text[2] = 0; | 1056 text[2] = 0; |
| 928 write_label_var( 30, 200, ME_Y_LINE1, &FontT48, text); | 1057 write_label_var( 30, 200, ME_Y_LINE1, &FontT48, text); |
| 929 | 1058 |
| 930 if(settingsGetPointer()->nonMetricalSystem) | 1059 if(pSettings->nonMetricalSystem) |
| 931 { | 1060 { |
| 932 text[1] = TXT2BYTE_Units_feet; | 1061 text[1] = TXT2BYTE_Units_feet; |
| 933 } | 1062 } |
| 934 else | 1063 else |
| 935 { | 1064 { |
| 941 text[0] = TXT_2BYTE; | 1070 text[0] = TXT_2BYTE; |
| 942 text[1] = TXT2BYTE_Farbschema; | 1071 text[1] = TXT2BYTE_Farbschema; |
| 943 text[2] = 0; | 1072 text[2] = 0; |
| 944 write_label_var( 30, 300, ME_Y_LINE2, &FontT48, text); | 1073 write_label_var( 30, 300, ME_Y_LINE2, &FontT48, text); |
| 945 | 1074 |
| 946 text[0] = '0' + settingsGetPointer()->tX_colorscheme; | 1075 text[0] = '0' + pSettings->tX_colorscheme; |
| 947 text[1] = 0; | 1076 text[1] = 0; |
| 948 write_label_var( 400, 700, ME_Y_LINE2, &FontT48, text); | 1077 write_label_var( 400, 700, ME_Y_LINE2, &FontT48, text); |
| 949 | 1078 |
| 1079 #if 0 | |
| 1080 /* profile */ | |
| 1081 sprintf(text,"Profile:"); | |
| 1082 write_label_var( 30, 300, ME_Y_LINE3, &FontT48, text); | |
| 1083 | |
| 1084 memset(text,0, sizeof(text)); | |
| 1085 sprintf(text,"%s",pSettings->profileName[pSettings->activeProfile]); | |
| 1086 tMenuEdit_newInputText(StMSYS_Profile,(uint8_t*)text); | |
| 1087 // write_label_var( 400, 700, ME_Y_LINE3, &FontT48, text); | |
| 1088 #endif | |
| 950 #ifdef HAVE_DEBUG_VIEW | 1089 #ifdef HAVE_DEBUG_VIEW |
| 951 // specials | 1090 // specials |
| 952 text[0] = TXT_2BYTE; | 1091 text[0] = TXT_2BYTE; |
| 953 text[1] = TXT2BYTE_ShowDebug; | 1092 text[1] = TXT2BYTE_ShowDebug; |
| 954 text[2] = 0; | 1093 text[2] = 0; |
| 1002 { | 1141 { |
| 1003 settingsGetPointer()->showDebugInfo = !(settingsGetPointer()->showDebugInfo); | 1142 settingsGetPointer()->showDebugInfo = !(settingsGetPointer()->showDebugInfo); |
| 1004 return UPDATE_DIVESETTINGS; | 1143 return UPDATE_DIVESETTINGS; |
| 1005 } | 1144 } |
| 1006 | 1145 |
| 1007 | 1146 uint8_t OnAction_SetProfile(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) |
| 1147 { | |
| 1148 SSettings *pSettings = settingsGetPointer(); | |
| 1149 | |
| 1150 uint8_t newProfile = pSettings->activeProfile + 1; | |
| 1151 | |
| 1152 if(newProfile == NUMBER_OF_PROFILES) | |
| 1153 { | |
| 1154 newProfile = 0; | |
| 1155 } | |
| 1156 changeActiveProfil(newProfile); | |
| 1157 pSettings->activeProfile = newProfile; | |
| 1158 | |
| 1159 tMenuEdit_newButtonText(editId,(char*)pSettings->profileName[pSettings->activeProfile]); | |
| 1160 return UNSPECIFIC_RETURN; | |
| 1161 } | |
| 1162 uint8_t OnAction_Profile(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
| 1163 { | |
| 1164 SSettings *pSettings = settingsGetPointer(); | |
| 1165 SSettings *pProfile; | |
| 1166 uint8_t digitContentNew; | |
| 1167 uint8_t profilName[9]; | |
| 1168 uint8_t updateProfilIndex = 0; | |
| 1169 uint8_t index = 0; | |
| 1170 | |
| 1171 uint8_t returnValue = UNSPECIFIC_RETURN; | |
| 1172 | |
| 1173 switch (editId) | |
| 1174 { | |
| 1175 default: | |
| 1176 case StMSYS_ProfileA: updateProfilIndex = 0; | |
| 1177 break; | |
| 1178 case StMSYS_ProfileB: updateProfilIndex = 1; | |
| 1179 break; | |
| 1180 case StMSYS_ProfileC: updateProfilIndex = 2; | |
| 1181 break; | |
| 1182 case StMSYS_ProfileD: updateProfilIndex = 3; | |
| 1183 break; | |
| 1184 } | |
| 1185 | |
| 1186 switch (action) | |
| 1187 { | |
| 1188 case ACTION_BUTTON_ENTER: returnValue = digitContent; | |
| 1189 break; | |
| 1190 case ACTION_BUTTON_ENTER_FINAL: | |
| 1191 { | |
| 1192 evaluateNewStringText(editId, profilName); | |
| 1193 tMenuEdit_newInputText(editId, profilName); | |
| 1194 if(pSettings->activeProfile == updateProfilIndex) | |
| 1195 { | |
| 1196 tMenuEdit_newButtonText(StMSYS_Profile, (char*)profilName); | |
| 1197 } | |
| 1198 strcpy((char*)pSettings->profileName[updateProfilIndex],(char*)profilName); | |
| 1199 for (index = 0; index < NUMBER_OF_PROFILES; index++) | |
| 1200 { | |
| 1201 pProfile = profileGetPointer(index); | |
| 1202 strcpy((char*)pProfile->profileName[updateProfilIndex],(char*)profilName); | |
| 1203 } | |
| 1204 } | |
| 1205 | |
| 1206 break; | |
| 1207 case ACTION_BUTTON_NEXT: | |
| 1208 if(digitContent == 'Z') | |
| 1209 { | |
| 1210 digitContentNew = '_'; | |
| 1211 } | |
| 1212 else if (digitContent == '_') | |
| 1213 { | |
| 1214 digitContentNew = 'A'; | |
| 1215 } | |
| 1216 else | |
| 1217 { | |
| 1218 digitContentNew = digitContent + 1; | |
| 1219 } | |
| 1220 returnValue = digitContentNew; | |
| 1221 break; | |
| 1222 case ACTION_BUTTON_BACK: | |
| 1223 if(digitContent == 'A') | |
| 1224 { | |
| 1225 digitContentNew = '_'; | |
| 1226 } | |
| 1227 else if (digitContent == '_') | |
| 1228 { | |
| 1229 digitContentNew = 'Z'; | |
| 1230 } | |
| 1231 else | |
| 1232 { | |
| 1233 digitContentNew = digitContent - 1; | |
| 1234 } | |
| 1235 returnValue = digitContentNew; | |
| 1236 break; | |
| 1237 } | |
| 1238 return returnValue; | |
| 1239 } | |
| 1008 | 1240 |
| 1009 | 1241 |
| 1010 /* | 1242 /* |
| 1011 uint8_t OnAction_Design_t7ft (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | 1243 uint8_t OnAction_Design_t7ft (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) |
| 1012 { | 1244 { |
| 1572 return EXIT_TO_MENU; | 1804 return EXIT_TO_MENU; |
| 1573 } | 1805 } |
| 1574 | 1806 |
| 1575 uint8_t OnAction_ResetAll (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | 1807 uint8_t OnAction_ResetAll (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) |
| 1576 { | 1808 { |
| 1577 set_settings_to_Standard(); | 1809 set_settings_to_Standard(EF_SETTINGS); |
| 1578 check_and_correct_settings(); | 1810 check_and_correct_settings(EF_SETTINGS); |
| 1579 | 1811 |
| 1580 return UPDATE_AND_EXIT_TO_HOME; | 1812 return UPDATE_AND_EXIT_TO_HOME; |
| 1581 } | 1813 } |
| 1582 | 1814 |
| 1583 uint8_t OnAction_ResetLogbook (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | 1815 uint8_t OnAction_ResetLogbook (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) |
