comparison Small_CPU/Src/scheduler.c @ 301:a09b1855d656 cleanup-4

cleanup, RTE: factor out scheduleCheck_pressure_reached_dive_mode_level The detection of the start of dive mode is conceptually simple (when the pressure sensor reaches a certain threshold, we are diving). This said, there are multiple implementations over the entire code base to answer the question: are we diving? This commit factors out scheduleCheck_pressure_reached_dive_mode_level used only in the RTE, in favor of is_ambient_pressure_close_to_surface, which is used in both RTE and CPU1 firmware. I had a little hope that is would fix the 1 second difference between the initial stopwatch and the divetime, but it does not. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Mon, 20 May 2019 10:05:27 +0200
parents 580822b5d3d1
children 95928ef3986f
comparison
equal deleted inserted replaced
300:5ca177d2df5d 301:a09b1855d656
83 void copyDeviceData(void); 83 void copyDeviceData(void);
84 void copyPICdata(void); 84 void copyPICdata(void);
85 static void schedule_update_timer_helper(int8_t thisSeconds); 85 static void schedule_update_timer_helper(int8_t thisSeconds);
86 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow); 86 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow);
87 87
88 _Bool scheduleCheck_pressure_reached_dive_mode_level(void);
89 void scheduleSetDate(SDeviceLine *line); 88 void scheduleSetDate(SDeviceLine *line);
90 89
91 /* Exported functions --------------------------------------------------------*/ 90 /* Exported functions --------------------------------------------------------*/
92 91
93 void initGlobals(void) 92 void initGlobals(void)
769 scheduleUpdateDeviceData(); 768 scheduleUpdateDeviceData();
770 global.lifeData.ascent_rate_meter_per_min = 0; 769 global.lifeData.ascent_rate_meter_per_min = 0;
771 copyPressureData(); 770 copyPressureData();
772 Scheduler.counterPressure100msec++; 771 Scheduler.counterPressure100msec++;
773 772
774 if(scheduleCheck_pressure_reached_dive_mode_level()) 773 if (!is_ambient_pressure_close_to_surface(&global.lifeData))
775 global.mode = MODE_DIVE; 774 global.mode = MODE_DIVE;
776 } 775 }
777 776
778 /* Evaluate compass data at 50 ms, 150 ms, 250 ms,... duration ~5ms */ 777 /* Evaluate compass data at 50 ms, 150 ms, 250 ms,... duration ~5ms */
779 if(ticksdiff >= Scheduler.counterCompass100msec * 100 + 50) 778 if(ticksdiff >= Scheduler.counterCompass100msec * 100 + 50)
1027 global.accidentRemainingSeconds = 0; 1026 global.accidentRemainingSeconds = 0;
1028 global.accidentFlag = 0; 1027 global.accidentFlag = 0;
1029 } 1028 }
1030 } 1029 }
1031 1030
1032 if(scheduleCheck_pressure_reached_dive_mode_level()) 1031 if (!is_ambient_pressure_close_to_surface(&global.lifeData))
1033 global.mode = MODE_BOOT; 1032 global.mode = MODE_BOOT;
1034 1033
1035 scheduleUpdateLifeData(2000); 1034 scheduleUpdateLifeData(2000);
1036 } 1035 }
1037 while(global.mode == MODE_SLEEP); 1036 while(global.mode == MODE_SLEEP);
1043 } 1042 }
1044 1043
1045 1044
1046 1045
1047 /* Private functions ---------------------------------------------------------*/ 1046 /* Private functions ---------------------------------------------------------*/
1048
1049
1050 /**
1051 ******************************************************************************
1052 * @brief scheduleCheck_pressure_reached_dive_mode_level
1053 * @author heinrichs weikamp gmbh
1054 * @version V0.0.1 from inline code
1055 * @date 09-Sept-2015
1056 ******************************************************************************
1057 */
1058 _Bool scheduleCheck_pressure_reached_dive_mode_level(void)
1059 {
1060 if(get_pressure_mbar() > 1160)
1061 return 1;
1062 else
1063 if((global.mode == MODE_SURFACE) && (get_pressure_mbar() > (get_surface_mbar() + 100)) && (get_surface_mbar() > 880))
1064 return 1;
1065 else
1066 return 0;
1067 }
1068
1069 1047
1070 /** 1048 /**
1071 ****************************************************************************** 1049 ******************************************************************************
1072 * @brief scheduleUpdateLifeData / calculates tissues 1050 * @brief scheduleUpdateLifeData / calculates tissues
1073 * @author Peter Ryser 1051 * @author Peter Ryser