comparison Discovery/Src/t7.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 6d8ae8fbccf5
children c6b858f2e025
comparison
equal deleted inserted replaced
944:44599695df41 945:aad1a6b9aaec
124 }; 124 };
125 125
126 126
127 /* Private types -------------------------------------------------------------*/ 127 /* Private types -------------------------------------------------------------*/
128 128
129 typedef enum
130 {
131 SE_INIT = 0,
132 SE_REINIT,
133 SE_ACTIVE,
134 SE_END
135 } SSlowExitState;
136 129
137 const uint8_t customviewsSurfaceStandard[] = 130 const uint8_t customviewsSurfaceStandard[] =
138 { 131 {
139 // CVIEW_CompassDebug, 132 // CVIEW_CompassDebug,
140 CVIEW_Hello, 133 CVIEW_Hello,
2880 if(nextstopDepthMeter) 2873 if(nextstopDepthMeter)
2881 { 2874 {
2882 snprintf(TextR2,TEXTSIZE,"\032\f\002%c",TXT_Decostop); 2875 snprintf(TextR2,TEXTSIZE,"\032\f\002%c",TXT_Decostop);
2883 GFX_write_string(&FontT42,&t7r2,TextR2,0); 2876 GFX_write_string(&FontT42,&t7r2,TextR2,0);
2884 2877
2885 if((pSettings->VPM_conservatism.ub.alternative) && (fabs(stateUsed->lifeData.depth_meter - nextstopDepthMeter)) < 1.5) 2878 if((stateUsed->diveSettings.deco_type.ub.standard == VPM_MODE) && (pSettings->VPM_conservatism.ub.alternative)
2879 && (fabs(stateUsed->lifeData.depth_meter - nextstopDepthMeter)) < 1.5)
2886 { 2880 {
2887 TextR2[0] = '\026'; 2881 TextR2[0] = '\026';
2888 textlength = 1; 2882 textlength = 1;
2889 } 2883 }
2890 else 2884 else
4818 #define ASCENT_GRAPH_YPIXEL 110 4812 #define ASCENT_GRAPH_YPIXEL 110
4819 4813
4820 4814
4821 uint8_t t7_drawSlowExitGraph() /* this function is only called if diver is below last last stop depth */ 4815 uint8_t t7_drawSlowExitGraph() /* this function is only called if diver is below last last stop depth */
4822 { 4816 {
4823 static SSlowExitState slowExitState = SE_END;
4824 static uint16_t countDownSec = 0; 4817 static uint16_t countDownSec = 0;
4825 static uint8_t drawingMeterStep; 4818 uint8_t drawingMeterStep;
4826 static float exitDepthMeter = 0.0; 4819 static float exitDepthMeter = 0.0;
4827 static uint32_t exitSecTick = 0;
4828 static uint32_t lastSecTick = 0;
4829 4820
4830 uint8_t index = 0; 4821 uint8_t index = 0;
4831 static uint8_t color = 0; 4822 uint8_t color = 0;
4832 point_t start, stop; 4823 point_t start, stop;
4833 4824
4834 SSettings* pSettings; 4825 SSettings* pSettings;
4835 pSettings = settingsGetPointer(); 4826 pSettings = settingsGetPointer();
4836 4827
4837 if((stateUsed->lifeData.max_depth_meter < pSettings->last_stop_depth_meter) /* start of dive => reinit timer */ 4828
4838 || (slowExitState == SE_REINIT)) 4829 if(calculateSlowExit(&countDownSec, &exitDepthMeter, &color)) /* graph to be drawn? */
4839 { 4830 {
4840 if(slowExitState != SE_INIT) 4831 if(!pSettings->FlipDisplay)
4841 { 4832 {
4842 countDownSec = pSettings->slowExitTime * 60; 4833 start.y = t7l1.WindowY0 - 1;
4843 drawingMeterStep = ASCENT_GRAPH_YPIXEL / pSettings->last_stop_depth_meter; /* based on 120 / 4 = 30 of standard ascent graph */
4844 slowExitState = SE_INIT;
4845 exitDepthMeter = pSettings->last_stop_depth_meter;
4846 color = 0;
4847 } 4834 }
4848 } 4835 else
4849 else
4850 {
4851 if(slowExitState != SE_END)
4852 { 4836 {
4853 if((slowExitState == SE_INIT) && (stateUsed->lifeData.dive_time_seconds > 900)) /* min 15min divetime */ 4837 start.y = t7l3.WindowY0 - 25;
4854 {
4855 slowExitState = SE_ACTIVE;
4856 exitSecTick = HAL_GetTick();
4857 lastSecTick = exitSecTick;
4858 }
4859 else if(slowExitState == SE_ACTIVE)
4860 {
4861 if(time_elapsed_ms(lastSecTick, HAL_GetTick()) > 60000) /* restart timer if diver go below exit zone */
4862 {
4863 slowExitState = SE_REINIT;
4864 }
4865 else if(time_elapsed_ms(exitSecTick, HAL_GetTick()) > 1000)
4866 {
4867 exitSecTick = HAL_GetTick();
4868 lastSecTick = exitSecTick;
4869 /* select depth digit color */
4870 if(fabsf(stateUsed->lifeData.depth_meter - exitDepthMeter) < 0.5 )
4871 {
4872 color = CLUT_NiceGreen;
4873 }
4874 else if(fabsf(stateUsed->lifeData.depth_meter - exitDepthMeter) <= 1.5)
4875 {
4876 color = CLUT_WarningYellow;
4877 }
4878 else if(stateUsed->lifeData.depth_meter - exitDepthMeter < -1.5 )
4879 {
4880 color = CLUT_WarningRed;
4881 }
4882 else
4883 {
4884 color = 0;
4885 }
4886
4887 if((fabsf(stateUsed->lifeData.depth_meter - exitDepthMeter) <= 1.6 ) /* only decrease counter if diver is close to target depth */
4888 || (color == CLUT_WarningRed)) /* or if diver is far ahead */
4889 {
4890 countDownSec--;
4891 if(countDownSec == 0)
4892 {
4893 slowExitState = SE_END;
4894 color = 0;
4895 exitDepthMeter = 0;
4896 }
4897 else
4898 {
4899 exitDepthMeter -= (pSettings->last_stop_depth_meter / (float)(pSettings->slowExitTime * 60));
4900 }
4901 }
4902 }
4903 if(!pSettings->FlipDisplay)
4904 {
4905 start.y = t7l1.WindowY0 - 1;
4906 }
4907 else
4908 {
4909 start.y = t7l3.WindowY0 - 25;
4910 }
4911
4912 for(index = 0; index < pSettings->last_stop_depth_meter; index++) /* draw meter indicators */
4913 {
4914 start.y += drawingMeterStep;
4915 stop.y = start.y;
4916 start.x = CUSTOMBOX_LINE_LEFT - 1;
4917 stop.x = start.x - 38;
4918 GFX_draw_line(&t7screen, start, stop, 0);
4919 }
4920
4921 start.x = CUSTOMBOX_LINE_LEFT - CUSTOMBOX_OUTSIDE_OFFSET - 20;
4922 stop.x = start.x;
4923 if(!pSettings->FlipDisplay)
4924 {
4925 start.y = t7l1.WindowY0 + ASCENT_GRAPH_YPIXEL + 5;
4926 }
4927 else
4928 {
4929 start.y = t7l3.WindowY0 - 25 + ASCENT_GRAPH_YPIXEL + 5;
4930 }
4931 stop.y = start.y - countDownSec * (ASCENT_GRAPH_YPIXEL / (float)(pSettings->slowExitTime * 60.0));
4932 if(stop.y >= 470)
4933 stop.y = 470;
4934
4935 if(!pSettings->FlipDisplay)
4936 {
4937 stop.y += 5;
4938 }
4939 GFX_draw_thick_line(15,&t7screen, start, stop, 3);
4940 /* mark diver depth */
4941 start.x = CUSTOMBOX_LINE_LEFT - CUSTOMBOX_OUTSIDE_OFFSET - 30;
4942 stop.x = start.x + 24;
4943
4944 start.y = start.y - (stateUsed->lifeData.depth_meter * (ASCENT_GRAPH_YPIXEL) / pSettings->last_stop_depth_meter);
4945 stop.y = start.y;
4946 GFX_draw_thick_line(10,&t7screen, start, stop, 9);
4947 }
4948 } 4838 }
4839 drawingMeterStep = ASCENT_GRAPH_YPIXEL / pSettings->last_stop_depth_meter; /* based on 120 / 4 = 30 of standard ascent graph */
4840 for(index = 0; index < pSettings->last_stop_depth_meter; index++) /* draw meter indicators */
4841 {
4842 start.y += drawingMeterStep;
4843 stop.y = start.y;
4844 start.x = CUSTOMBOX_LINE_LEFT - 1;
4845 stop.x = start.x - 38;
4846 GFX_draw_line(&t7screen, start, stop, 0);
4847 }
4848
4849 start.x = CUSTOMBOX_LINE_LEFT - CUSTOMBOX_OUTSIDE_OFFSET - 20;
4850 stop.x = start.x;
4851 if(!pSettings->FlipDisplay)
4852 {
4853 start.y = t7l1.WindowY0 + ASCENT_GRAPH_YPIXEL + 5;
4854 }
4855 else
4856 {
4857 start.y = t7l3.WindowY0 - 25 + ASCENT_GRAPH_YPIXEL + 5;
4858 }
4859 stop.y = start.y - countDownSec * (ASCENT_GRAPH_YPIXEL / (float)(pSettings->slowExitTime * 60.0));
4860 if(stop.y >= 470) stop.y = 470;
4861 if(!pSettings->FlipDisplay)
4862 {
4863 stop.y += 5;
4864 }
4865 GFX_draw_thick_line(15,&t7screen, start, stop, 3);
4866 /* mark diver depth */
4867 start.x = CUSTOMBOX_LINE_LEFT - CUSTOMBOX_OUTSIDE_OFFSET - 30;
4868 stop.x = start.x + 24;
4869
4870 start.y = start.y - (stateUsed->lifeData.depth_meter * (ASCENT_GRAPH_YPIXEL) / pSettings->last_stop_depth_meter);
4871 stop.y = start.y;
4872 GFX_draw_thick_line(10,&t7screen, start, stop, 9);
4949 } 4873 }
4950 return color; 4874 return color;
4951 } 4875 }
4952 void t7_tick(void) 4876 void t7_tick(void)
4953 { 4877 {