comparison Discovery/Src/data_central.c @ 981:c6c781a2e85b default

Merge into default
author heinrichsweikamp
date Tue, 11 Feb 2025 18:12:00 +0100
parents 9b418e63dbc2
children 65d35e66efb9
comparison
equal deleted inserted replaced
871:f7318457df4d 981:c6c781a2e85b
70 #include "data_exchange_main.h" 70 #include "data_exchange_main.h"
71 #include "ostc.h" // for button adjust on hw testboard 1 71 #include "ostc.h" // for button adjust on hw testboard 1
72 #include "tCCR.h" 72 #include "tCCR.h"
73 #include "crcmodel.h" 73 #include "crcmodel.h"
74 #include "configuration.h" 74 #include "configuration.h"
75 #include "tHome.h"
76 #include "t3.h"
75 77
76 static SDiveState stateReal = { 0 }; 78 static SDiveState stateReal = { 0 };
77 SDiveState stateSim = { 0 }; 79 SDiveState stateSim = { 0 };
78 SDiveState stateDeco = { 0 }; 80 SDiveState stateDeco = { 0 };
79 81
343 stateReal.diveSettings.gf_high = pSettings->GF_high; 345 stateReal.diveSettings.gf_high = pSettings->GF_high;
344 stateReal.diveSettings.gf_low = pSettings->GF_low; 346 stateReal.diveSettings.gf_low = pSettings->GF_low;
345 stateReal.diveSettings.input_next_stop_increment_depth_bar = ((float)pSettings->stop_increment_depth_meter) / 10.0f; 347 stateReal.diveSettings.input_next_stop_increment_depth_bar = ((float)pSettings->stop_increment_depth_meter) / 10.0f;
346 stateReal.diveSettings.last_stop_depth_bar = ((float)pSettings->last_stop_depth_meter) / 10.0f; 348 stateReal.diveSettings.last_stop_depth_bar = ((float)pSettings->last_stop_depth_meter) / 10.0f;
347 stateReal.diveSettings.vpm_conservatism = pSettings->VPM_conservatism.ub.standard; 349 stateReal.diveSettings.vpm_conservatism = pSettings->VPM_conservatism.ub.standard;
350 stateReal.diveSettings.vpm_tableMode = pSettings->VPM_conservatism.ub.alternative;
348 stateReal.diveSettings.deco_type.uw = pSettings->deco_type.uw; 351 stateReal.diveSettings.deco_type.uw = pSettings->deco_type.uw;
349 stateReal.diveSettings.fallbackOption = pSettings->fallbackToFixedSetpoint; 352 stateReal.diveSettings.fallbackOption = pSettings->fallbackToFixedSetpoint;
350 stateReal.diveSettings.ppo2sensors_deactivated = pSettings->ppo2sensors_deactivated; 353 stateReal.diveSettings.ppo2sensors_deactivated = pSettings->ppo2sensors_deactivated;
351 stateReal.diveSettings.future_TTS_minutes = pSettings->future_TTS; 354 stateReal.diveSettings.future_TTS_minutes = pSettings->future_TTS;
352 355
372 if(stateReal.diveSettings.input_next_stop_increment_depth_bar * i > stateReal.diveSettings.last_stop_depth_bar) 375 if(stateReal.diveSettings.input_next_stop_increment_depth_bar * i > stateReal.diveSettings.last_stop_depth_bar)
373 { 376 {
374 stateReal.diveSettings.input_second_to_last_stop_depth_bar = stateReal.diveSettings.input_next_stop_increment_depth_bar * i; 377 stateReal.diveSettings.input_second_to_last_stop_depth_bar = stateReal.diveSettings.input_next_stop_increment_depth_bar * i;
375 break; 378 break;
376 } 379 }
380 }
381 /* generate Bitfield of active T3 views */
382 stateReal.diveSettings.activeAFViews = 0;
383 if(t3_customview_disabled(CVIEW_T3_Navigation) == 0)
384 {
385 stateReal.diveSettings.activeAFViews |= (1 << CVIEW_T3_Navigation);
386 }
387 if(t3_customview_disabled(CVIEW_T3_GasList) == 0)
388 {
389 stateReal.diveSettings.activeAFViews |= (1 << CVIEW_T3_GasList);
390 }
391 if(t3_customview_disabled(CVIEW_T3_DecoTTS) == 0)
392 {
393 stateReal.diveSettings.activeAFViews |= (1 << CVIEW_T3_DecoTTS);
377 } 394 }
378 } 395 }
379 396
380 397
381 void copyDiveSettingsToSim(void) 398 void copyDiveSettingsToSim(void)
873 bool isCompassCalibrated(void) 890 bool isCompassCalibrated(void)
874 { 891 {
875 return stateUsed->lifeData.compass_heading != -1; 892 return stateUsed->lifeData.compass_heading != -1;
876 } 893 }
877 894
895 static void internalLogCompassHeading(uint16_t heading, bool applyHeading, bool clearHeading)
896 {
897 uint16_t compassHeading = 0;
898 if (clearHeading) {
899 compassHeading |= 0x8000;
900 } else {
901 compassHeading = heading & 0x1FF;
902 }
903 if (applyHeading) {
904 compassHeading |= 0x4000;
905 }
906
907 stateUsedWrite->events.compassHeadingUpdate = 1;
908 stateUsedWrite->events.info_compassHeadingUpdate = compassHeading;
909 }
910
911 void logCompassHeading(uint16_t heading) {
912 internalLogCompassHeading(heading, false, false);
913 }
914
915 void clearCompassHeading(void) {
916 uint16_t clearHeading = 0;
917 stateUsedWrite->diveSettings.compassHeading = clearHeading;
918
919 internalLogCompassHeading(clearHeading, true, true);
920 }
878 921
879 void setCompassHeading(uint16_t heading) 922 void setCompassHeading(uint16_t heading)
880 { 923 {
881 924 stateUsedWrite->diveSettings.compassHeading = ((heading - 360) % 360) + 360;
882 // if heading == 0 set compassHeading to 360, because compassHeading == 0 means 'off' 925
883 926 internalLogCompassHeading(heading, true, false);
884 stateUsedWrite->diveSettings.compassHeading = ((heading - 360) % 360) + 360;
885 } 927 }
886 928
887 929
888 const SDecoinfo *getDecoInfo(void) 930 const SDecoinfo *getDecoInfo(void)
889 { 931 {
900 942
901 void disableTimer(void) 943 void disableTimer(void)
902 { 944 {
903 stateUsedWrite->timerState = TIMER_STATE_OFF; 945 stateUsedWrite->timerState = TIMER_STATE_OFF;
904 } 946 }
947
948 #define SPEED_SLOW (5.1f)
949 #define SPEED_MEDIUM (10.1f)
950 #define SPEED_HIGH (15.1f)
951 #define SPEED_HYSTERESE (1.0f)
952
953 uint8_t drawingColor_from_ascentspeed(float speed)
954 {
955 static uint8_t lastColor = 0;
956
957 uint8_t color = CLUT_Font020;
958
959 if((speed >= SPEED_HIGH) || ((lastColor == CLUT_WarningRed) && (speed >= SPEED_HIGH - SPEED_HYSTERESE)))
960 {
961 color = CLUT_WarningRed;
962 }
963 else if((speed >= SPEED_MEDIUM) || ((lastColor == CLUT_WarningYellow) && (speed >= SPEED_MEDIUM - SPEED_HYSTERESE)))
964 {
965 color = CLUT_WarningYellow;
966 }
967 else if((speed >= SPEED_SLOW) || ((lastColor == CLUT_NiceGreen) && (speed >= SPEED_SLOW - SPEED_HYSTERESE)))
968 {
969 color = CLUT_NiceGreen;
970 }
971 lastColor = color;
972 return color;
973 }
974
975 /* returns the date in the order defined by the settings DDMMYY => X */
976 void convertStringOfDate_DDMMYY(char* pString, uint8_t strLen, uint8_t day, uint8_t month, uint8_t year)
977 {
978 if(strLen > 10)
979 {
980 switch(settingsGetPointer()->date_format)
981 {
982 default:
983 case DDMMYY: snprintf(pString,strLen,"%02d.%02d.%02d",day,month,year);
984 break;
985 case MMDDYY: snprintf(pString,strLen,"%02d.%02d.%02d",month,day,year);
986 break;
987 case YYMMDD: snprintf(pString,strLen,"%02d.%02d.%02d",year,month,day);
988 break;
989 }
990 }
991 }
992 /* returns the format in the order defined by the settings DDMMYY => X */
993 void getStringOfFormat_DDMMYY(char* pString, uint8_t strLen)
994 {
995 if(strLen > 10)
996 {
997 switch(settingsGetPointer()->date_format)
998 {
999 default:
1000 case DDMMYY: snprintf(pString,strLen,"%c%c",TXT_2BYTE,TXT2BYTE_DDMMYY);
1001 break;
1002 case MMDDYY: snprintf(pString,strLen,"%c%c",TXT_2BYTE,TXT2BYTE_MMDDYY);
1003 break;
1004 case YYMMDD: snprintf(pString,strLen,"%c%c",TXT_2BYTE,TXT2BYTE_YYMMDD);
1005 break;
1006 }
1007 }
1008 }
1009
1010 uint8_t calculateSlowExit(uint16_t* pCountDownSec, float* pExitDepthMeter, uint8_t* pColor) /* this function is only called if diver is below last last stop depth */
1011 {
1012 static SSlowExitState slowExitState = SE_END;
1013 static uint16_t countDownSec = 0;
1014 static float exitDepthMeter = 0.0;
1015 static uint32_t exitSecTick = 0;
1016 static uint32_t lastSecTick = 0;
1017 static uint8_t color = 0;
1018 static uint8_t drawingActive = 0;
1019
1020 SSettings* pSettings;
1021 pSettings = settingsGetPointer();
1022
1023 if((stateUsed->lifeData.max_depth_meter < pSettings->last_stop_depth_meter) /* start of dive => reinit timer */
1024 || (slowExitState == SE_REINIT))
1025 {
1026 if(slowExitState != SE_INIT)
1027 {
1028 countDownSec = pSettings->slowExitTime * 60;
1029 slowExitState = SE_INIT;
1030 exitDepthMeter = pSettings->last_stop_depth_meter;
1031 color = 0;
1032 drawingActive = 0;
1033 }
1034 }
1035 else
1036 {
1037 if(slowExitState != SE_END)
1038 {
1039 if((slowExitState == SE_INIT) && (stateUsed->lifeData.dive_time_seconds > 900)) /* min 15min divetime */
1040 {
1041 slowExitState = SE_ACTIVE;
1042 exitSecTick = HAL_GetTick();
1043 lastSecTick = exitSecTick;
1044 }
1045 else if(slowExitState == SE_ACTIVE)
1046 {
1047 if(time_elapsed_ms(lastSecTick, HAL_GetTick()) > 60000) /* restart timer if diver go below exit zone */
1048 {
1049 slowExitState = SE_REINIT;
1050 }
1051 else if(time_elapsed_ms(exitSecTick, HAL_GetTick()) > 1000)
1052 {
1053 exitSecTick = HAL_GetTick();
1054 lastSecTick = exitSecTick;
1055 /* select depth digit color */
1056 if(fabsf(stateUsed->lifeData.depth_meter - exitDepthMeter) < 0.5 )
1057 {
1058 color = CLUT_NiceGreen;
1059 }
1060 else if(fabsf(stateUsed->lifeData.depth_meter - exitDepthMeter) <= 1.5)
1061 {
1062 color = CLUT_WarningYellow;
1063 }
1064 else if(stateUsed->lifeData.depth_meter - exitDepthMeter < -1.5 )
1065 {
1066 color = CLUT_WarningRed;
1067 }
1068 else
1069 {
1070 color = 0;
1071 }
1072
1073 if((fabsf(stateUsed->lifeData.depth_meter - exitDepthMeter) <= 1.6 ) /* only decrease counter if diver is close to target depth */
1074 || (color == CLUT_WarningRed)) /* or if diver is far ahead */
1075 {
1076 countDownSec--;
1077 if(countDownSec == 0)
1078 {
1079 slowExitState = SE_END;
1080 color = 0;
1081 exitDepthMeter = 0;
1082 }
1083 else
1084 {
1085 exitDepthMeter -= (pSettings->last_stop_depth_meter / (float)(pSettings->slowExitTime * 60));
1086 }
1087 }
1088 drawingActive = 1;
1089 }
1090 }
1091 }
1092 }
1093 *pCountDownSec = countDownSec;
1094 *pExitDepthMeter = exitDepthMeter;
1095 *pColor = color;
1096 return drawingActive;
1097 }
1098
1099 void convertUTCToLocal(uint8_t utcHours, uint8_t utcMinutes, uint8_t* pLocalHours, uint8_t* pLocalMinutes)
1100 {
1101 int8_t localHours = 0;
1102 int8_t localMinutes = 0;
1103 SSettings* pSettings = settingsGetPointer();
1104
1105 localHours = utcHours + pSettings->timeZone.hours;
1106 if(localHours < 0)
1107 {
1108 localHours += 24;
1109 }
1110 if(localHours > 24)
1111 {
1112 localHours -= 24;
1113 }
1114 localMinutes = utcMinutes + pSettings->timeZone.minutes;
1115 if(localMinutes < 0)
1116 {
1117 localMinutes += 60;
1118 }
1119 if(localMinutes > 60)
1120 {
1121 localMinutes -= 60;
1122 }
1123 *pLocalHours = localHours;
1124 *pLocalMinutes = localMinutes;
1125 }