comparison Discovery/Src/data_central.c @ 945:aad1a6b9aaec Evo_2_23

Added slow exit graph to t3 view: In the first implementation slow exit was only available in T7 view. To enable it in T3 view the common parts have been extracted into a separate function which is shared between T7 and T3. Only the drawing specific parts remain in the T7 / T3 files.
author Ideenmodellierer
date Thu, 19 Dec 2024 22:16:36 +0100
parents 44599695df41
children c6b858f2e025
comparison
equal deleted inserted replaced
944:44599695df41 945:aad1a6b9aaec
1005 break; 1005 break;
1006 } 1006 }
1007 } 1007 }
1008 } 1008 }
1009 1009
1010 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 }