comparison Discovery/Src/tMenuEditHardware.c @ 539:d784f281833a

Added inertia simulation for compass heading: In previous version calculated compass values were directly used for visualization of the compass. This causes a fast changing (jumping) of values. With the inertia introduction the compass behalfs more like an analog compass. The final value is reached slowly and the displayed values are more stable. For configuration a new menu item has been added to the compass menu allowing to switch inertia off (default), small and large inertia simulation
author Ideenmodellierer
date Sat, 10 Oct 2020 16:59:18 +0200
parents 1f557e5f4b5a
children ec76fa85009e
comparison
equal deleted inserted replaced
538:b1eee27cd02b 539:d784f281833a
52 52
53 /* Announced function prototypes -----------------------------------------------*/ 53 /* Announced function prototypes -----------------------------------------------*/
54 uint8_t OnAction_Compass (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); 54 uint8_t OnAction_Compass (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
55 uint8_t OnAction_Bearing (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); 55 uint8_t OnAction_Bearing (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
56 uint8_t OnAction_BearingClear (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); 56 uint8_t OnAction_BearingClear (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
57 uint8_t OnAction_InertiaLevel (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
57 //uint8_t OnAction_ExitHardw (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); 58 //uint8_t OnAction_ExitHardw (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
58 uint8_t OnAction_Sensor1 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); 59 uint8_t OnAction_Sensor1 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
59 uint8_t OnAction_Sensor2 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); 60 uint8_t OnAction_Sensor2 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
60 uint8_t OnAction_Sensor3 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); 61 uint8_t OnAction_Sensor3 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
61 uint8_t OnAction_O2_Fallback (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); 62 uint8_t OnAction_O2_Fallback (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
145 146
146 void refresh_CompassEdit(void) 147 void refresh_CompassEdit(void)
147 { 148 {
148 uint16_t heading; 149 uint16_t heading;
149 char text[32]; 150 char text[32];
151 uint8_t textIndex = 0;
150 152
151 text[0] = '\001'; 153 text[0] = '\001';
152 text[1] = TXT_2BYTE; 154 text[1] = TXT_2BYTE;
153 text[2] = TXT2BYTE_Compass; 155 text[2] = TXT2BYTE_Compass;
154 text[3] = 0; 156 text[3] = 0;
155 write_topline(text); 157 write_topline(text);
156 158
157 heading = (uint16_t)stateUsed->lifeData.compass_heading; 159 if(settingsGetPointer()->compassInertia)
160 {
161 heading = (uint16_t)compass_getCompensated();
162 }
163 else
164 {
165 heading = (uint16_t)stateUsed->lifeData.compass_heading;
166 }
158 snprintf(text,32,"\001%03i`",heading); 167 snprintf(text,32,"\001%03i`",heading);
159 write_label_var( 0, 800, ME_Y_LINE1, &FontT54, text); 168 write_label_var( 0, 800, ME_Y_LINE1, &FontT54, text);
160 169
161 tMenuEdit_refresh_field(StMHARD2_Compass_SetCourse); 170 tMenuEdit_refresh_field(StMHARD2_Compass_SetCourse);
162 tMenuEdit_refresh_field(StMHARD2_Compass_Calibrate); 171 tMenuEdit_refresh_field(StMHARD2_Compass_Calibrate);
163 tMenuEdit_refresh_field(StMHARD2_Compass_ResetCourse); 172 tMenuEdit_refresh_field(StMHARD2_Compass_ResetCourse);
173 text[textIndex++] = TXT_2BYTE;
174 text[textIndex++] = TXT2BYTE_CompassInertia;
175 text[textIndex++] = ':';
176 text[textIndex++] = ' ';
177 text[textIndex++] = '0' + settingsGetPointer()->compassInertia;
178
179 write_label_var(30, 800, ME_Y_LINE5, &FontT48, text);
164 180
165 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext); 181 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
166 } 182 }
167 183
168 184
169 void openEdit_Compass(void) 185 void openEdit_Compass(void)
170 { 186 {
171 char text[4]; 187 char text[10];
172 188 uint8_t textIndex = 0;
173 text[0] = '\001'; 189
174 text[1] = TXT_2BYTE; 190 text[textIndex++] = '\001';
175 text[2] = TXT2BYTE_Compass; 191 text[textIndex++] = TXT_2BYTE;
176 text[3] = 0; 192 text[textIndex++] = TXT2BYTE_Compass;
193 text[textIndex++] = 0;
177 write_topline(text); 194 write_topline(text);
178 195
179 text[0] = TXT_2BYTE; 196 text[0] = TXT_2BYTE;
180 text[2] = 0; 197 text[2] = 0;
181 198
185 text[1] = TXT2BYTE_CompassCalib; 202 text[1] = TXT2BYTE_CompassCalib;
186 write_field_button(StMHARD2_Compass_Calibrate, 30, 800, ME_Y_LINE3, &FontT48, text); 203 write_field_button(StMHARD2_Compass_Calibrate, 30, 800, ME_Y_LINE3, &FontT48, text);
187 204
188 text[1] = TXT2BYTE_ResetBearing; 205 text[1] = TXT2BYTE_ResetBearing;
189 write_field_button(StMHARD2_Compass_ResetCourse, 30, 800, ME_Y_LINE4, &FontT48, text); 206 write_field_button(StMHARD2_Compass_ResetCourse, 30, 800, ME_Y_LINE4, &FontT48, text);
207
208 text[1] = TXT2BYTE_CompassInertia;
209 textIndex = 2;
210 text[textIndex++] = ':';
211 text[textIndex++] = ' ';
212 text[textIndex++] = '0' + settingsGetPointer()->compassInertia;
213
214 write_field_button(StMHARD2_Compass_Inertia, 30, 800, ME_Y_LINE5, &FontT48, text);
190 215
191 setEvent(StMHARD2_Compass_SetCourse, (uint32_t)OnAction_Bearing); 216 setEvent(StMHARD2_Compass_SetCourse, (uint32_t)OnAction_Bearing);
192 setEvent(StMHARD2_Compass_Calibrate, (uint32_t)OnAction_Compass); 217 setEvent(StMHARD2_Compass_Calibrate, (uint32_t)OnAction_Compass);
193 setEvent(StMHARD2_Compass_ResetCourse, (uint32_t)OnAction_BearingClear); 218 setEvent(StMHARD2_Compass_ResetCourse, (uint32_t)OnAction_BearingClear);
219 setEvent(StMHARD2_Compass_Inertia, (uint32_t)OnAction_InertiaLevel);
194 220
195 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext); 221 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
196 } 222 }
197 223
198 224
214 240
215 uint8_t OnAction_BearingClear (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) 241 uint8_t OnAction_BearingClear (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
216 { 242 {
217 settingsGetPointer()->compassBearing = 0; 243 settingsGetPointer()->compassBearing = 0;
218 return UPDATE_AND_EXIT_TO_MENU; 244 return UPDATE_AND_EXIT_TO_MENU;
245 }
246
247
248 uint8_t OnAction_InertiaLevel (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
249 {
250 uint8_t newLevel = 0;
251
252 newLevel = settingsGetPointer()->compassInertia + 1;
253 if(newLevel > MAX_COMPASS_COMP)
254 {
255 newLevel = 0;
256 }
257 settingsGetPointer()->compassInertia = newLevel;
258 return UPDATE_DIVESETTINGS;
219 } 259 }
220 260
221 /* 261 /*
222 uint8_t OnAction_ExitHardw (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) 262 uint8_t OnAction_ExitHardw (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
223 { 263 {