Mercurial > public > ostc4
comparison Discovery/Src/t3.c @ 841:70092f552f5a Evo_2_23
Added autofocus for T3_DecoTTS view:
a switch to the DecoTTS view will now be triggered in case a new deco stop depth is added, a deco stopp has been missed or if a new 10 minutes TTS is passed.
author | Ideenmodellierer |
---|---|
date | Sun, 07 Jan 2024 21:25:34 +0100 |
parents | aed39d19269c |
children | ba1aebc6d5af |
comparison
equal
deleted
inserted
replaced
840:7e714662b93f | 841:70092f552f5a |
---|---|
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | 26 /// along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 ////////////////////////////////////////////////////////////////////////////// | 27 ////////////////////////////////////////////////////////////////////////////// |
28 | 28 |
29 /* Includes ------------------------------------------------------------------*/ | 29 /* Includes ------------------------------------------------------------------*/ |
30 #include <stdbool.h> | 30 #include <stdbool.h> |
31 #include <stdlib.h> | |
31 | 32 |
32 #include "t3.h" | 33 #include "t3.h" |
33 | 34 |
34 #include "data_exchange_main.h" | 35 #include "data_exchange_main.h" |
35 #include "decom.h" | 36 #include "decom.h" |
60 GFX_DrawCfgWindow t3c1; | 61 GFX_DrawCfgWindow t3c1; |
61 GFX_DrawCfgWindow t3c2; | 62 GFX_DrawCfgWindow t3c2; |
62 | 63 |
63 uint8_t t3_selection_customview = CVIEW_noneOrDebug; | 64 uint8_t t3_selection_customview = CVIEW_noneOrDebug; |
64 | 65 |
66 static uint8_t AF_lastDecoDepth = 0; | |
67 static uint16_t AF_lastTTS = 0; | |
68 | |
69 | |
65 /* TEM HAS TO MOVE TO GLOBAL--------------------------------------------------*/ | 70 /* TEM HAS TO MOVE TO GLOBAL--------------------------------------------------*/ |
66 | 71 |
67 /* Private types -------------------------------------------------------------*/ | 72 /* Private types -------------------------------------------------------------*/ |
68 #define TEXTSIZE 16 | 73 #define TEXTSIZE 16 |
74 | |
75 /* defines for autofocus of compass */ | |
76 #define AF_COMPASS_ACTIVATION_ANGLE (10.0f) /* angle for pitch and roll. Compass gets activated in case the value is smaller (OSTC4 hold in horitontal position */ | |
77 #define AF_COMPASS_DEBOUNCE (10u) /* debouncing value to avoid compass activation during normal movement */ | |
78 | |
69 | 79 |
70 /* Private function prototypes -----------------------------------------------*/ | 80 /* Private function prototypes -----------------------------------------------*/ |
71 void t3_refresh_divemode(void); | 81 void t3_refresh_divemode(void); |
72 | 82 |
73 uint8_t t3_test_customview_warnings(void); | 83 uint8_t t3_test_customview_warnings(void); |
74 void t3_refresh_customview(float depth); | 84 void t3_refresh_customview(float depth); |
75 void t3_basics_compass(GFX_DrawCfgScreen *tXscreen, point_t center, uint16_t ActualHeading, uint16_t UserSetHeading); | 85 void t3_basics_compass(GFX_DrawCfgScreen *tXscreen, point_t center, uint16_t ActualHeading, uint16_t UserSetHeading); |
86 uint8_t t3_EvaluateAFCondition(uint8_t T3CView); | |
76 | 87 |
77 /* Exported functions --------------------------------------------------------*/ | 88 /* Exported functions --------------------------------------------------------*/ |
78 | 89 |
79 void t3_init(void) | 90 void t3_init(void) |
80 { | 91 { |
150 t3c2.WindowX0 = 370; | 161 t3c2.WindowX0 = 370; |
151 t3c2.WindowX1 = 799; | 162 t3c2.WindowX1 = 799; |
152 t3c2.WindowY0 = t3c1.WindowY0; | 163 t3c2.WindowY0 = t3c1.WindowY0; |
153 t3c2.WindowY1 = t3c1.WindowY1; | 164 t3c2.WindowY1 = t3c1.WindowY1; |
154 t3c2.WindowTab = 600; | 165 t3c2.WindowTab = 600; |
166 | |
167 t3_EvaluateAFCondition(CVIEW_T3_END); /* reset debounce counters */ | |
155 } | 168 } |
156 | 169 |
157 void t3_select_customview(uint8_t selectedCustomview) | 170 void t3_select_customview(uint8_t selectedCustomview) |
158 { | 171 { |
159 if(selectedCustomview < CVIEW_T3_END) | 172 if(selectedCustomview < CVIEW_T3_END) |
1967 } else { | 1980 } else { |
1968 return snprintf(text, size, "%c%u\016\016%%\017", colour, currentTimerMinutes * 100 / settingsGetPointer()->scrubberData[settings->scubberActiveId].TimerMax); | 1981 return snprintf(text, size, "%c%u\016\016%%\017", colour, currentTimerMinutes * 100 / settingsGetPointer()->scrubberData[settings->scubberActiveId].TimerMax); |
1969 } | 1982 } |
1970 } | 1983 } |
1971 | 1984 |
1972 uint8_t t3_HandleAFGaslist() | 1985 void t3_AF_updateBorderConditions() |
1973 { | 1986 { |
1974 static uint8_t debounce = 0; | 1987 uint16_t nextstopLengthSeconds = 0; |
1975 static uint8_t lastState = AF_VIEW_NOCHANGE; | 1988 uint8_t nextstopDepthMeter = 0; |
1989 | |
1990 tHome_findNextStop(getDecoInfo()->output_stop_length_seconds, &nextstopDepthMeter, &nextstopLengthSeconds); | |
1991 AF_lastDecoDepth = nextstopDepthMeter; | |
1992 AF_lastTTS = (getDecoInfo()->output_time_to_surface_seconds / 60) / 10; | |
1993 } | |
1994 | |
1995 uint8_t t3_CheckAfCondition(uint8_t T3CView) | |
1996 { | |
1997 uint8_t retVal = 0; | |
1998 | |
1999 float pitch = stateRealGetPointer()->lifeData.compass_pitch; | |
2000 float roll = stateRealGetPointer()->lifeData.compass_roll; | |
2001 | |
2002 uint16_t nextstopLengthSeconds = 0; | |
2003 uint8_t nextstopDepthMeter = 0; | |
2004 | |
2005 switch (T3CView) | |
2006 { | |
2007 case CVIEW_T3_GasList: retVal = (stateUsed->warnings.betterGas) /* switch if better gas is available or depending on ppo2 if in OC mode */ | |
2008 || ((stateUsed->diveSettings.diveMode == DIVEMODE_OC) && ((stateUsed->warnings.ppO2Low) || (stateUsed->warnings.ppO2High))); | |
2009 | |
2010 break; | |
2011 case CVIEW_T3_Navigation: retVal = (pitch > -AF_COMPASS_ACTIVATION_ANGLE) && (pitch < AF_COMPASS_ACTIVATION_ANGLE) | |
2012 && (roll > -AF_COMPASS_ACTIVATION_ANGLE) && (roll < AF_COMPASS_ACTIVATION_ANGLE); | |
2013 | |
2014 break; | |
2015 case CVIEW_T3_DecoTTS: tHome_findNextStop(getDecoInfo()->output_stop_length_seconds, &nextstopDepthMeter, &nextstopLengthSeconds); | |
2016 /* A new deco step is added to the plan */ | |
2017 if(nextstopDepthMeter > AF_lastDecoDepth) | |
2018 { | |
2019 retVal = 1; | |
2020 } | |
2021 | |
2022 /* Close to the next deco step or missed deco step */ | |
2023 if((abs(stateUsed->lifeData.depth_meter - nextstopDepthMeter) < 2) || (stateUsed->warnings.decoMissed)) | |
2024 { | |
2025 retVal = 1; | |
2026 } | |
2027 /* Another 10 minutes to surface */ | |
2028 if((getDecoInfo()->output_time_to_surface_seconds) && ((uint16_t)((getDecoInfo()->output_time_to_surface_seconds / 60) / 10) > AF_lastTTS)) | |
2029 { | |
2030 retVal = 1; | |
2031 } | |
2032 break; | |
2033 default: break; | |
2034 } | |
2035 | |
2036 return retVal; | |
2037 } | |
2038 | |
2039 uint8_t t3_EvaluateAFCondition(uint8_t T3CView) | |
2040 { | |
2041 static uint8_t debounce[CVIEW_T3_END]; | |
2042 static uint8_t lastState[CVIEW_T3_END]; | |
1976 uint8_t detectionState = AF_VIEW_NOCHANGE; | 2043 uint8_t detectionState = AF_VIEW_NOCHANGE; |
1977 | 2044 uint8_t cnt = 0; |
1978 if((stateUsed->warnings.betterGas) /* switch if better gas is available or depending on ppo2 if in OC mode */ | 2045 |
1979 || ((stateUsed->diveSettings.diveMode == DIVEMODE_OC) && ((stateUsed->warnings.ppO2Low) || (stateUsed->warnings.ppO2High)))) | 2046 if(T3CView <= CVIEW_T3_END) |
1980 { | 2047 { |
1981 if(debounce < 10) | 2048 if(T3CView == CVIEW_T3_END) |
1982 { | 2049 { |
1983 debounce++; | 2050 for(cnt = 0; cnt < CVIEW_T3_END; cnt++) |
2051 { | |
2052 debounce[cnt] = 0; | |
2053 lastState[cnt] = AF_VIEW_NOCHANGE; | |
2054 } | |
2055 } | |
2056 if(t3_CheckAfCondition(T3CView)) | |
2057 { | |
2058 if(debounce[T3CView] < 10) | |
2059 { | |
2060 debounce[T3CView]++; | |
2061 } | |
2062 else | |
2063 { | |
2064 detectionState = AF_VIEW_ACTIVATED; | |
2065 } | |
1984 } | 2066 } |
1985 else | 2067 else |
1986 { | 2068 { |
1987 detectionState = AF_VIEW_ACTIVATED; | 2069 if(debounce[T3CView] > 0) |
2070 { | |
2071 debounce[T3CView]--; | |
2072 } | |
2073 else | |
2074 { | |
2075 detectionState = AF_VIEW_DEACTIVATED; | |
2076 } | |
2077 } | |
2078 if(detectionState) /* no state change => return 0 */ | |
2079 { | |
2080 if((detectionState == lastState[T3CView])) | |
2081 { | |
2082 detectionState = AF_VIEW_NOCHANGE; | |
2083 } | |
2084 else | |
2085 { | |
2086 lastState[T3CView] = detectionState; | |
2087 } | |
1988 } | 2088 } |
1989 } | 2089 } |
1990 else | 2090 return detectionState; |
2091 } | |
2092 | |
2093 void t3_handleAutofocus(void) | |
2094 { | |
2095 static uint8_t returnView = CVIEW_T3_END; | |
2096 | |
2097 uint8_t runningT3CView = 0; | |
2098 | |
2099 for (runningT3CView = 0; runningT3CView < CVIEW_T3_END; runningT3CView++) | |
1991 { | 2100 { |
1992 if(debounce > 0) | 2101 if(stateUsed->diveSettings.activeAFViews & (1 << runningT3CView)) |
1993 { | 2102 { |
1994 debounce--; | 2103 switch(t3_EvaluateAFCondition(runningT3CView)) |
1995 } | 2104 { |
1996 else | 2105 case AF_VIEW_ACTIVATED: returnView = t3_selection_customview; |
1997 { | 2106 t3_select_customview(runningT3CView); |
1998 detectionState = AF_VIEW_DEACTIVATED; | 2107 t3_AF_updateBorderConditions(); |
2108 break; | |
2109 case AF_VIEW_DEACTIVATED: if((returnView != CVIEW_T3_END) && (t3_selection_customview == runningT3CView)) | |
2110 { | |
2111 if(runningT3CView != CVIEW_T3_DecoTTS) /* some view does not switch back */ | |
2112 { | |
2113 t3_select_customview(returnView); | |
2114 } | |
2115 returnView = CVIEW_T3_END; | |
2116 } | |
2117 break; | |
2118 default: | |
2119 break; | |
2120 } | |
1999 } | 2121 } |
2000 } | 2122 } |
2001 if(detectionState) /* no state change => return 0 */ | 2123 } |
2002 { | |
2003 if((detectionState == lastState)) | |
2004 { | |
2005 detectionState = AF_VIEW_NOCHANGE; | |
2006 } | |
2007 else | |
2008 { | |
2009 lastState = detectionState; | |
2010 } | |
2011 } | |
2012 | |
2013 return detectionState; | |
2014 } | |
2015 | |
2016 void t3_handleAutofocus(void) | |
2017 { | |
2018 static uint8_t returnView = CVIEW_T3_END; | |
2019 | |
2020 if(stateUsed->diveSettings.activeAFViews & (1 << CVIEW_T3_Navigation)) | |
2021 { | |
2022 switch(HandleAFCompass()) | |
2023 { | |
2024 case AF_VIEW_ACTIVATED: returnView = t3_selection_customview; | |
2025 t3_select_customview(CVIEW_T3_Navigation); | |
2026 | |
2027 break; | |
2028 case AF_VIEW_DEACTIVATED: if((returnView != CVIEW_T3_END) && (t3_selection_customview == CVIEW_T3_Navigation)) | |
2029 { | |
2030 t3_select_customview(returnView); | |
2031 returnView = CVIEW_T3_END; | |
2032 } | |
2033 break; | |
2034 default: | |
2035 break; | |
2036 } | |
2037 } | |
2038 if(stateUsed->diveSettings.activeAFViews & (1 << CVIEW_T3_GasList)) | |
2039 { | |
2040 switch(t3_HandleAFGaslist()) | |
2041 { | |
2042 case AF_VIEW_ACTIVATED: returnView = t3_selection_customview; | |
2043 t3_select_customview(CVIEW_T3_GasList); | |
2044 | |
2045 break; | |
2046 case AF_VIEW_DEACTIVATED: if((returnView != CVIEW_T3_END) && (t3_selection_customview == CVIEW_T3_GasList)) | |
2047 { | |
2048 t3_select_customview(returnView); | |
2049 returnView = CVIEW_T3_END; | |
2050 } | |
2051 break; | |
2052 default: | |
2053 break; | |
2054 } | |
2055 } | |
2056 } |