Mercurial > public > ostc4
annotate Discovery/Src/tMenuEditSetpoint.c @ 483:90d1f793dcf2 FixLayout_Header_LogView
Development option only read bottledata:
If the header divisor is set (in my case because of switching between development and main versions) the samples need to be read considering the bottle values, too. Divelogs written by a SW not supporting bottle pressure have the divisor set to 0 => no impact to main SW
Bugfix header memory layout:
The batterygaugeregisters were not used and will be reused for other information. To keep the OSTC3 format up and running the datafield is not filled with "0x00"
author | ideenmodellierer |
---|---|
date | Tue, 26 May 2020 21:12:02 +0200 |
parents | ba229a012ac7 |
children | 4532953ac1a0 |
rev | line source |
---|---|
38 | 1 /////////////////////////////////////////////////////////////////////////////// |
2 /// -*- coding: UTF-8 -*- | |
3 /// | |
4 /// \file Discovery/Src/tMenuEditSetpoint.c | |
5 /// \brief | |
6 /// \author heinrichs weikamp gmbh | |
7 /// \date 19-Dec-2014 | |
8 /// | |
9 /// \details | |
10 /// | |
11 /// $Id$ | |
12 /////////////////////////////////////////////////////////////////////////////// | |
13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh | |
14 /// | |
15 /// This program is free software: you can redistribute it and/or modify | |
16 /// it under the terms of the GNU General Public License as published by | |
17 /// the Free Software Foundation, either version 3 of the License, or | |
18 /// (at your option) any later version. | |
19 /// | |
20 /// This program is distributed in the hope that it will be useful, | |
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 /// GNU General Public License for more details. | |
24 /// | |
25 /// You should have received a copy of the GNU General Public License | |
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
27 ////////////////////////////////////////////////////////////////////////////// | |
28 | |
29 /* Includes ------------------------------------------------------------------*/ | |
30 #include "tMenuEditSetpoint.h" | |
31 | |
32 #include "check_warning.h" | |
33 #include "gfx_fonts.h" | |
34 #include "tMenuEdit.h" | |
35 #include "unit.h" | |
36 | |
37 /* Private types -------------------------------------------------------------*/ | |
38 typedef struct | |
39 { | |
40 uint8_t spID; | |
41 SSetpointLine * pSetpointLine; | |
42 } SEditSetpointPage; | |
43 | |
44 | |
45 /* Private variables ---------------------------------------------------------*/ | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
46 static SEditSetpointPage editSetpointPage; |
38 | 47 |
48 /* Private function prototypes -----------------------------------------------*/ | |
49 | |
50 /* Announced function prototypes -----------------------------------------------*/ | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
51 static uint8_t OnAction_SP_Setpoint (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
52 static uint8_t OnAction_SP_DM_Sensor1 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
53 static uint8_t OnAction_SP_DM_Sensor2 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
54 static uint8_t OnAction_SP_DM_Sensor3 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); |
38 | 55 |
56 /* Exported functions --------------------------------------------------------*/ | |
57 | |
58 void openEdit_Setpoint(uint8_t line) | |
59 { | |
60 uint8_t useSensorSubMenu = 0; | |
61 | |
62 /* dive mode */ | |
63 if(actual_menu_content != MENU_SURFACE) | |
64 { | |
65 uint8_t setpointCbar, actualGasID; | |
130
b7689d9e888a
Minor changes to improved code quality and to eliminate warnings
Ideenmodellierer
parents:
38
diff
changeset
|
66 setpointCbar = 100; |
38 | 67 |
68 // actualGasID | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
69 if(stateUsedWrite->diveSettings.diveMode != DIVEMODE_CCR) |
38 | 70 { |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
71 actualGasID = stateUsedWrite->lifeData.lastDiluent_GasIdInSettings; |
38 | 72 if((actualGasID <= NUM_OFFSET_DILUENT) || (actualGasID > NUM_GASES + NUM_OFFSET_DILUENT)) |
73 actualGasID = NUM_OFFSET_DILUENT + 1; | |
74 } | |
75 else | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
76 actualGasID = stateUsedWrite->lifeData.actualGas.GasIdInSettings; |
38 | 77 |
78 // setpointCbar, CCR_Mode and sensor menu | |
79 if(line < 6) | |
80 { | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
81 setpointCbar = stateUsedWrite->diveSettings.setpoint[line].setpoint_cbar; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
82 stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_FixedSetpoint; |
38 | 83 |
84 // BetterSetpoint warning only once | |
85 if(actualBetterSetpointId() == line) | |
86 { | |
87 uint8_t depth; | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
88 depth = stateUsedWrite->diveSettings.setpoint[line].depth_meter; |
38 | 89 // BetterSetpoint warning only once -> clear active |
90 for(int i=0; i<=NUM_GASES; i++) | |
91 { | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
92 stateUsedWrite->diveSettings.setpoint[i].note.ub.first = 0; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
93 if(stateUsedWrite->diveSettings.setpoint[i].depth_meter <= depth) |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
94 stateUsedWrite->diveSettings.setpoint[i].note.ub.active = 0; |
38 | 95 } |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
96 stateUsedWrite->diveSettings.setpoint[line].note.ub.first = 1; |
38 | 97 } |
98 } | |
99 else | |
100 { | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
101 if(stateUsedWrite->diveSettings.CCR_Mode != CCRMODE_Sensors) |
38 | 102 { |
103 /* setpoint_cbar will be written by updateSetpointStateUsed() in main.c loop */ | |
104 setpointCbar = 255; | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
105 stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_Sensors; |
38 | 106 } |
107 else | |
108 { | |
109 useSensorSubMenu = 1; | |
110 } | |
111 } | |
112 | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
113 setActualGas_DM(&stateUsedWrite->lifeData,actualGasID,setpointCbar); |
38 | 114 |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
115 if(stateUsedWrite->diveSettings.diveMode != DIVEMODE_CCR) |
38 | 116 { |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
117 stateUsedWrite->diveSettings.diveMode = DIVEMODE_CCR; |
38 | 118 unblock_diluent_page(); |
119 } | |
120 | |
121 clear_warning_fallback(); | |
122 | |
123 if(!useSensorSubMenu) | |
124 { | |
125 exitMenuEdit_to_Home(); | |
126 } | |
127 else // entire sub menu during dive to select sensors active | |
128 { | |
129 set_globalState_Menu_Line(line); | |
130 resetMenuEdit(CLUT_MenuPageGasSP); | |
131 | |
132 char text[3]; | |
133 uint8_t sensorActive[3]; | |
134 | |
135 text[0] = '\001'; | |
136 text[1] = TXT_o2Sensors; | |
137 text[2] = 0; | |
138 write_topline(text); | |
139 | |
140 write_label_var( 96, 340, ME_Y_LINE1, &FontT48, "Sensor 1"); | |
141 write_label_var( 96, 340, ME_Y_LINE2, &FontT48, "Sensor 2"); | |
142 write_label_var( 96, 340, ME_Y_LINE3, &FontT48, "Sensor 3"); | |
143 | |
144 sensorActive[0] = 1; | |
145 sensorActive[1] = 1; | |
146 sensorActive[2] = 1; | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
147 if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 1) |
38 | 148 sensorActive[0] = 0; |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
149 if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 2) |
38 | 150 sensorActive[1] = 0; |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
151 if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 4) |
38 | 152 sensorActive[2] = 0; |
153 | |
154 write_field_on_off(StMSP_Sensor1, 30, 95, ME_Y_LINE1, &FontT48, "", sensorActive[0]); | |
155 write_field_on_off(StMSP_Sensor2, 30, 95, ME_Y_LINE2, &FontT48, "", sensorActive[1]); | |
156 write_field_on_off(StMSP_Sensor3, 30, 95, ME_Y_LINE3, &FontT48, "", sensorActive[2]); | |
157 | |
158 setEvent(StMSP_Sensor1, (uint32_t)OnAction_SP_DM_Sensor1); | |
159 setEvent(StMSP_Sensor2, (uint32_t)OnAction_SP_DM_Sensor2); | |
160 setEvent(StMSP_Sensor3, (uint32_t)OnAction_SP_DM_Sensor3); | |
161 } | |
162 return; | |
163 } | |
164 else | |
165 { | |
166 /* surface mode */ | |
167 uint8_t spId, setpoint_cbar, sp_high, depthDeco, first; | |
168 // uint8_t active, | |
166
255eedad4155
cleanup: get rid of some compile warnings
Jan Mulder <jlmulder@xs4all.nl>
parents:
130
diff
changeset
|
169 char text[70]; |
255eedad4155
cleanup: get rid of some compile warnings
Jan Mulder <jlmulder@xs4all.nl>
parents:
130
diff
changeset
|
170 uint8_t textPointer; |
38 | 171 uint16_t y_line; |
172 | |
173 set_globalState_Menu_Line(line); | |
174 | |
175 resetMenuEdit(CLUT_MenuPageGasSP); | |
176 | |
177 spId = line; | |
178 editSetpointPage.spID = spId; | |
179 SSettings *data = settingsGetPointer(); | |
180 editSetpointPage.pSetpointLine = data->setpoint; | |
181 | |
182 setpoint_cbar = editSetpointPage.pSetpointLine[spId].setpoint_cbar; | |
183 depthDeco = editSetpointPage.pSetpointLine[spId].depth_meter; | |
184 //active = editSetpointPage.pSetpointLine[spId].note.ub.active; | |
185 first = editSetpointPage.pSetpointLine[spId].note.ub.first; | |
186 | |
187 sp_high = setpoint_cbar / 100; | |
188 | |
189 strcpy(text, "\001" "Setpoint #0 X"); | |
190 text[11] += spId; | |
191 text[13] = TXT_Setpoint_Edit; | |
192 write_topline(text); | |
193 | |
194 | |
195 y_line = ME_Y_LINE_BASE + (line * ME_Y_LINE_STEP); | |
196 | |
197 textPointer = 0; | |
198 text[textPointer++] = 'S'; | |
199 text[textPointer++] = 'P'; | |
200 text[textPointer++] = '0' + spId; | |
201 text[textPointer++] = ' '; | |
202 text[textPointer++] = ' '; | |
203 | |
204 if(first == 0) | |
205 strcpy(&text[textPointer++],"\177"); | |
206 | |
207 textPointer += snprintf(&text[textPointer], 60,\ | |
208 "* " | |
209 " " | |
210 "\016\016" | |
211 " bar" | |
212 "\017" | |
213 "\034" | |
214 " " | |
215 "\016\016" | |
216 " " | |
217 "\017" | |
218 " " | |
219 "\016\016" | |
220 "meter" | |
221 "\017" | |
222 "\035" | |
223 "\n\r" | |
224 ); | |
225 write_label_var( 20, 800, y_line, &FontT48, text); | |
226 | |
227 write_field_udigit(StMSP_ppo2_setting, 160, 800, y_line, &FontT48, "#.## ###", (uint32_t)sp_high, (uint32_t)(setpoint_cbar - (100 * sp_high)), depthDeco, 0); | |
228 setEvent(StMSP_ppo2_setting, (uint32_t)OnAction_SP_Setpoint); | |
229 startEdit(); | |
230 } | |
231 } | |
232 | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
233 static uint8_t OnAction_SP_Setpoint(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) |
38 | 234 { |
235 int8_t digitContentNew; | |
236 uint32_t new_integer_part, new_fractional_part, new_cbar, newDepth; | |
237 | |
238 if(action == ACTION_BUTTON_ENTER) | |
239 return digitContent; | |
240 | |
241 if(action == ACTION_BUTTON_ENTER_FINAL) | |
242 { | |
243 evaluateNewString(editId, &new_integer_part, &new_fractional_part, &newDepth, 0); | |
244 | |
245 new_cbar = (new_integer_part * 100) + new_fractional_part; | |
246 | |
247 if(new_cbar < 50) | |
248 new_cbar = 50; | |
249 | |
250 if(new_cbar > 160) | |
251 new_cbar = 160; | |
252 | |
253 new_integer_part = new_cbar / 100; | |
254 new_fractional_part = new_cbar - (new_integer_part * 100); | |
255 | |
256 editSetpointPage.pSetpointLine[editSetpointPage.spID].setpoint_cbar = new_cbar; | |
257 | |
258 if(newDepth > 255) | |
259 newDepth = 255; | |
260 | |
261 editSetpointPage.pSetpointLine[editSetpointPage.spID].depth_meter = newDepth; | |
262 | |
263 return UPDATE_AND_EXIT_TO_MENU; | |
264 } | |
265 | |
266 if(action == ACTION_BUTTON_NEXT) | |
267 { | |
268 digitContentNew = digitContent + 1; | |
269 if((blockNumber == 0) && (digitContentNew > '1')) | |
270 digitContentNew = '0'; | |
271 if(digitContentNew > '9') | |
272 digitContentNew = '0'; | |
273 return digitContentNew; | |
274 } | |
275 | |
276 if(action == ACTION_BUTTON_BACK) | |
277 { | |
278 digitContentNew = digitContent - 1; | |
213
d539ed9aa5b8
Bugfix, trivial: do not visit 9 on first digit for setpoint
Jan Mulder <jlmulder@xs4all.nl>
parents:
166
diff
changeset
|
279 if((blockNumber == 0) && (digitContentNew < '0')) |
38 | 280 digitContentNew = '1'; |
281 if(digitContentNew < '0') | |
282 digitContentNew = '9'; | |
283 return digitContentNew; | |
284 } | |
285 | |
286 return EXIT_TO_MENU; | |
287 } | |
288 | |
289 void openEdit_DiveSelectBetterSetpoint(void) | |
290 { | |
291 uint8_t spId; | |
292 uint8_t depth; | |
293 | |
294 spId = actualBetterSetpointId(); | |
295 | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
296 depth = stateUsedWrite->diveSettings.setpoint[spId].depth_meter; |
38 | 297 |
298 // BetterSetpoint warning only once -> clear active | |
299 for(int i=0; i<=NUM_GASES; i++) | |
300 { | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
301 stateUsedWrite->diveSettings.setpoint[i].note.ub.first = 0; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
302 if(stateUsedWrite->diveSettings.setpoint[i].depth_meter <= depth) |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
303 stateUsedWrite->diveSettings.setpoint[i].note.ub.active = 0; |
38 | 304 } |
305 | |
306 // new setpoint | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
307 stateUsedWrite->diveSettings.setpoint[spId].note.ub.first = 1; |
38 | 308 |
309 // change in lifeData | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
310 setActualGas_DM(&stateUsedWrite->lifeData, stateUsedWrite->lifeData.actualGas.GasIdInSettings, stateUsedWrite->diveSettings.setpoint[spId].setpoint_cbar); |
38 | 311 } |
312 | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
313 static uint8_t OnAction_SP_DM_Sensor1 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) |
38 | 314 { |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
315 if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 1) |
38 | 316 { |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
317 stateUsedWrite->diveSettings.ppo2sensors_deactivated &= 4+2; |
38 | 318 tMenuEdit_set_on_off(editId, 1); |
319 } | |
320 else | |
321 { | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
322 stateUsedWrite->diveSettings.ppo2sensors_deactivated |= 1; |
38 | 323 tMenuEdit_set_on_off(editId, 0); |
324 } | |
325 | |
326 return UNSPECIFIC_RETURN; | |
327 } | |
328 | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
329 static uint8_t OnAction_SP_DM_Sensor2 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) |
38 | 330 { |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
331 if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 2) |
38 | 332 { |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
333 stateUsedWrite->diveSettings.ppo2sensors_deactivated &= 4+1; |
38 | 334 tMenuEdit_set_on_off(editId, 1); |
335 } | |
336 else | |
337 { | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
338 stateUsedWrite->diveSettings.ppo2sensors_deactivated |= 2; |
38 | 339 tMenuEdit_set_on_off(editId, 0); |
340 } | |
341 | |
342 return UNSPECIFIC_RETURN; | |
343 } | |
344 | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
345 static uint8_t OnAction_SP_DM_Sensor3 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) |
38 | 346 { |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
347 if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 4) |
38 | 348 { |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
349 stateUsedWrite->diveSettings.ppo2sensors_deactivated &= 2+1; |
38 | 350 tMenuEdit_set_on_off(editId, 1); |
351 } | |
352 else | |
353 { | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
213
diff
changeset
|
354 stateUsedWrite->diveSettings.ppo2sensors_deactivated |= 4; |
38 | 355 tMenuEdit_set_on_off(editId, 0); |
356 } | |
357 return UNSPECIFIC_RETURN; | |
358 } |