comparison Discovery/Src/t6_apnea.c @ 38:5f11787b4f42

include in ostc4 repository
author heinrichsweikamp
date Sat, 28 Apr 2018 11:52:34 +0200
parents
children cc9c18075e00
comparison
equal deleted inserted replaced
37:ccc45c0e1ea2 38:5f11787b4f42
1 ///////////////////////////////////////////////////////////////////////////////
2 /// -*- coding: UTF-8 -*-
3 ///
4 /// \file Discovery/Src/t6_apnea.c
5 /// \brief dive screen for Gauge mode
6 /// \author Heinrichs Weikamp gmbh
7 /// \date 1-Feb-2017
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 "t6_apnea.h"
31
32 #include "data_exchange_main.h"
33 #include "decom.h"
34 #include "gfx_fonts.h"
35 #include "math.h"
36 #include "tHome.h"
37 #include "simulation.h"
38 #include "timer.h"
39 #include "unit.h"
40
41 /* Private variables ---------------------------------------------------------*/
42 GFX_DrawCfgScreen t6screen;
43 GFX_DrawCfgWindow t6l1;
44 GFX_DrawCfgWindow t6r1;
45 GFX_DrawCfgWindow t6c1;
46 GFX_DrawCfgWindow t6c2;
47 GFX_DrawCfgWindow t6c3; // for menu text
48
49 extern float depthLastCall[9];
50 extern uint8_t idDepthLastCall;
51 extern float temperatureLastCall[3];
52 extern uint8_t idTemperatureLastCall;
53
54 uint8_t t6_selection_customview = 0;
55
56 /* Importend function prototypes ---------------------------------------------*/
57 extern uint8_t write_gas(char *text, uint8_t oxygen, uint8_t helium);
58
59 /* Private types -------------------------------------------------------------*/
60
61 #define CUSTOMBOX_LINE_LEFT (250)
62 #define CUSTOMBOX_LINE_RIGHT (549)
63 #define CUSTOMBOX_INSIDE_OFFSET (2)
64 #define CUSTOMBOX_OUTSIDE_OFFSET (2)
65
66 #define TEXTSIZE 16
67
68 const uint8_t t6_customviewsStandard[] =
69 {
70 CVIEW_noneOrDebug,
71 CVIEW_T3_Temperature,
72 CVIEW_T3_END
73 };
74
75 const uint8_t *t6_customviews = t6_customviewsStandard;
76 const uint8_t t6_customviewSurfaceMode = CVIEW_T3_ApnoeSurfaceInfo;
77
78 /* Private function prototypes -----------------------------------------------*/
79 void t6_refresh_divemode(void);
80 void t6_refresh_customview(float depth);
81
82 uint8_t t6_test_customview_warnings(void);
83 void t6_show_customview_warnings(void);
84 void t6_compass(uint16_t ActualHeading, uint16_t UserSetHeading);
85
86 /* Exported functions --------------------------------------------------------*/
87
88 // for tHomeDiveMenuControl() in tHome.c and t6_refresh_customview
89 uint8_t t6_getCustomView(void)
90 {
91 if(stateUsed->lifeData.counterSecondsShallowDepth)
92 return t6_customviewSurfaceMode;
93 else
94 return t6_selection_customview;
95 }
96
97 void t6_init(void)
98 {
99 t6_selection_customview = t6_customviewsStandard[0];
100
101 t6screen.FBStartAdress = 0;
102 t6screen.ImageHeight = 480;
103 t6screen.ImageWidth = 800;
104 t6screen.LayerIndex = 1;
105
106 t6l1.Image = &t6screen;
107 t6l1.WindowNumberOfTextLines = 2;
108 t6l1.WindowLineSpacing = 19; // Abstand von Y0
109 t6l1.WindowTab = 100;
110 t6l1.WindowX0 = 0;
111 t6l1.WindowX1 = BigFontSeperationLeftRight - 5;
112 t6l1.WindowY0 = BigFontSeperationTopBottom + 5;
113 t6l1.WindowY1 = 479;
114
115 t6r1.Image = &t6screen;
116 t6r1.WindowNumberOfTextLines = t6l1.WindowNumberOfTextLines;
117 t6r1.WindowLineSpacing = t6l1.WindowLineSpacing;
118 t6r1.WindowTab = t6l1.WindowTab;
119 t6r1.WindowX0 = BigFontSeperationLeftRight + 5;
120 t6r1.WindowX1 = 799;
121 t6r1.WindowY0 = t6l1.WindowY0;
122 t6r1.WindowY1 = t6l1.WindowY1;
123
124 t6c1.Image = &t6screen;
125 t6c1.WindowNumberOfTextLines = 2;
126 t6c1.WindowLineSpacing = t6l1.WindowLineSpacing;
127 t6c1.WindowX0 = 0;
128 t6c1.WindowX1 = 799;
129 t6c1.WindowY0 = 0;
130 t6c1.WindowY1 = BigFontSeperationTopBottom - 5;
131
132 t6c2.Image = &t6screen;
133 t6c2.WindowNumberOfTextLines = 3;
134 t6c2.WindowLineSpacing = 58;
135 t6c2.WindowX0 = 370;
136 t6c2.WindowX1 = 799;
137 t6c2.WindowY0 = 0;
138 t6c2.WindowY1 = BigFontSeperationTopBottom - 5;
139 t6c2.WindowTab = 600;
140
141 t6c3.Image = &t6screen;
142 t6c3.WindowNumberOfTextLines = 1;
143 t6c3.WindowLineSpacing = 0; // Abstand von Y0
144 t6c3.WindowTab = 100;
145 t6c3.WindowX0 = CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET;
146 t6c3.WindowX1 = CUSTOMBOX_LINE_RIGHT - CUSTOMBOX_INSIDE_OFFSET;
147 t6c3.WindowY0 = 0;
148 t6c3.WindowY1 = 69;
149 }
150
151
152 void t6_refresh(void)
153 {
154 static uint8_t last_mode = MODE_SURFACE;
155
156 SStateList status;
157 get_globalStateList(&status);
158
159 if(stateUsed->mode != MODE_DIVE)
160 {
161 last_mode = MODE_SURFACE;
162 settingsGetPointer()->design = 7;
163 if(t6screen.FBStartAdress)
164 {
165 releaseFrame(24,t6screen.FBStartAdress);
166 t6screen.FBStartAdress = 0;
167 }
168 return;
169 }
170
171 if(status.base != BaseHome)
172 return;
173
174 t6screen.FBStartAdress = getFrame(24);
175
176 if(last_mode != MODE_DIVE)
177 {
178 last_mode = MODE_DIVE;
179 t6_selection_customview = *t6_customviews;
180 }
181
182 if(status.page == PageSurface)
183 set_globalState(StD);
184
185 t6_refresh_divemode();
186 GFX_SetFramesTopBottom(t6screen.FBStartAdress, NULL,480);
187 releaseAllFramesExcept(24,t6screen.FBStartAdress);
188 }
189
190 /* Private functions ---------------------------------------------------------*/
191
192 void t6_refresh_divemode(void)
193 {
194 char text[512];
195 uint8_t customview_warnings = 0;
196 float depth_meter = 0.0;
197
198 // everything like lines, depth, ascent graph and divetime or counterSecondsShallowDepth
199 depth_meter = t3_basics_lines_depth_and_divetime(&t6screen, &t6l1, &t6r1, DIVEMODE_Apnea);
200
201
202 // customview
203 if(stateUsed->warnings.numWarnings)
204 customview_warnings = t6_test_customview_warnings();
205
206 if(customview_warnings && warning_count_high_time)
207 t3_basics_show_customview_warnings(&t6c1);
208 else
209 t6_refresh_customview(depth_meter);
210
211 if(stateUsed->warnings.lowBattery)
212 t3_basics_battery_low_customview_extra(&t6c1);
213
214
215 /* Menu Selection (and gas mix) */
216 if(get_globalState() == StDBEAR)
217 {
218 snprintf(text,TEXTSIZE,"\a\001%c%c", TXT_2BYTE, TXT2BYTE_DiveBearingQ);
219 GFX_write_string_color(&FontT48,&t6c3,text,0,CLUT_WarningYellow);
220 }
221 else if(get_globalState() == StDRAVG)
222 {
223 snprintf(text,TEXTSIZE,"\a\001%c%c", TXT_2BYTE, TXT2BYTE_DiveResetAvgQ);
224 GFX_write_string_color(&FontT48,&t6c3,text,0,CLUT_WarningYellow);
225 }
226 else if(get_globalState() == StDQUIT)
227 {
228 snprintf(text,TEXTSIZE,"\a\001%c%c", TXT_2BYTE, TXT2BYTE_DiveQuitQ);
229 GFX_write_string_color(&FontT48,&t6c3,text,0,CLUT_WarningYellow);
230 }
231 else if(get_globalState() == StDSIM1)
232 {
233 snprintf(text,TEXTSIZE,"\a\001%c%c", TXT_2BYTE, TXT2BYTE_DiveQuitQ);
234 GFX_write_string_color(&FontT48,&t6c3,text,0,CLUT_WarningYellow);
235 }
236 else if(get_globalState() == StDSIM2)
237 {
238 if(settingsGetPointer()->nonMetricalSystem)
239 snprintf(text,TEXTSIZE,"\a\001" " Sim:-3.33ft ");
240 else
241 snprintf(text,TEXTSIZE,"\a\001" " Sim:-1m ");
242 GFX_write_string_color(&FontT48,&t6c3,text,0,CLUT_WarningYellow);
243 snprintf(text,TEXTSIZE,"\a\f %u %c%c"
244 , unit_depth_integer(simulation_get_aim_depth())
245 , unit_depth_char1()
246 , unit_depth_char2()
247 );
248 GFX_write_string_color(&FontT42,&t6l1,text,0,CLUT_WarningYellow);
249
250 }
251 else if(get_globalState() == StDSIM3)
252 {
253 if(settingsGetPointer()->nonMetricalSystem)
254 snprintf(text,TEXTSIZE,"\a\001" " Sim:+3.33ft ");
255 else
256 snprintf(text,TEXTSIZE,"\a\001" " Sim:+1m ");
257 GFX_write_string_color(&FontT48,&t6c3,text,0,CLUT_WarningYellow);
258 snprintf(text,TEXTSIZE,"\a\f %u %c%c"
259 , unit_depth_integer(simulation_get_aim_depth())
260 , unit_depth_char1()
261 , unit_depth_char2()
262 );
263 GFX_write_string_color(&FontT42,&t6l1,text,0,CLUT_WarningYellow);
264 }
265 else if(get_globalState() == StDSIM4)
266 {
267 snprintf(text,TEXTSIZE,"\a\001" " Sim:+5' ");
268 GFX_write_string_color(&FontT48,&t6c3,text,0,CLUT_WarningYellow);
269 snprintf(text,TEXTSIZE,"\a\f %u %c%c"
270 , unit_depth_integer(simulation_get_aim_depth())
271 , unit_depth_char1()
272 , unit_depth_char2()
273 );
274 GFX_write_string_color(&FontT42,&t6l1,text,0,CLUT_WarningYellow);
275 }
276 else
277 {
278 // keep empty
279 }
280 }
281
282
283 void t6_battery_low_customview_extra(void)
284 {
285 char TextC1[256];
286
287 TextC1[0] = '\002';
288 TextC1[1] = '\f';
289 TextC1[2] = '\025';
290 TextC1[3] = '3';
291 TextC1[4] = '1';
292 TextC1[5] = '1';
293 TextC1[6] = '1';
294 TextC1[7] = '1';
295 TextC1[8] = '1';
296 TextC1[9] = '1';
297 TextC1[10] = '1';
298 TextC1[11] = '1';
299 TextC1[12] = '1';
300 TextC1[13] = '1';
301 TextC1[14] = '0';
302 TextC1[15] = 0;
303
304 if(!warning_count_high_time)
305 TextC1[4] = '2';
306
307 GFX_write_string(&Batt24,&t6c1,TextC1,0);
308 }
309
310
311 void t6_battery_scooter_customview_extra(void)
312 {
313 char TextC1[256];
314
315 TextC1[0] = '\001';
316 TextC1[1] = '\f';
317 TextC1[2] = '\032';
318 TextC1[3] = '3';
319 TextC1[4] = '1';
320 TextC1[5] = '1';
321 TextC1[6] = '1';
322 TextC1[7] = '1';
323 TextC1[8] = '1';
324 TextC1[9] = '1';
325 TextC1[10] = '1';
326 TextC1[11] = '1';
327 TextC1[12] = '1';
328 TextC1[13] = '1';
329 TextC1[14] = '0';
330 TextC1[15] = 0;
331
332 for(int i=1;i<=10;i++)
333 {
334 if( stateUsed_scooterRemainingBattCapacity() > (9 * i))
335 TextC1[i+3] += 1;
336 }
337
338 if(stateUsed_scooterRemainingBattCapacity() < 10)
339 TextC1[2] = '\025';
340
341 if(!warning_count_high_time)
342 TextC1[4] = '2';
343
344 if(stateUsed->lifeData.scooterAgeInMilliSeconds > 1500)
345 TextC1[2] = '\031';
346
347 GFX_write_string(&Batt24,&t6c1,TextC1,0);
348 }
349
350
351 void t6_change_customview(void)
352 {
353 t3_basics_change_customview(&t6_selection_customview, t6_customviews);
354 }
355
356
357 void t6_refresh_customview(float depth)
358 {
359 uint8_t customViewLeftSide = CVIEW_T3_MaxDepth;
360
361 if((t6_selection_customview == CVIEW_sensors) &&(stateUsed->diveSettings.ccrOption == 0))
362 t6_change_customview();
363
364 if(t6_getCustomView() == CVIEW_T3_ApnoeSurfaceInfo)
365 customViewLeftSide = CVIEW_T3_ApnoeSurfaceInfo;
366
367 t3_basics_refresh_customview(depth, customViewLeftSide, &t6screen, &t6c1, &t6c2, DIVEMODE_Apnea);
368 t3_basics_refresh_apnoeRight(depth, t6_getCustomView(), &t6screen, &t6c1, &t6c2, DIVEMODE_Apnea);
369 }
370
371
372 uint8_t t6_test_customview_warnings(void)
373 {
374 uint8_t count = 0;
375
376 count = 0;
377 return count;
378 }
379
380 /*
381
382 char text[512];
383 uint16_t textpointer = 0;
384
385
386 // CVIEW_T3_Temperature
387 float temperatureThisCall;
388 float temperature;
389
390
391 // CVIEW_T3_StopWatch
392 SDivetime Stopwatch = {0,0,0,0};
393 float fAverageDepth, fAverageDepthAbsolute;
394 uint16_t tempWinX0;
395 uint16_t tempWinY0;
396
397 switch(t6_selection_customview)
398 {
399 case CVIEW_T3_ApnoeTimes:
400 break;
401
402 case CVIEW_T3_StopWatch:
403 Stopwatch.Total = timer_Stopwatch_GetTime();
404 Stopwatch.Minutes = Stopwatch.Total / 60;
405 Stopwatch.Seconds = Stopwatch.Total - ( Stopwatch.Minutes * 60 );
406 fAverageDepth = timer_Stopwatch_GetAvarageDepth_Meter();
407 fAverageDepthAbsolute = stateUsed->lifeData.average_depth_meter;
408
409 snprintf(text,TEXTSIZE,"\032\f%c",TXT_AvgDepth);
410 GFX_write_string(&FontT42,&t6c1,text,0);
411 snprintf(text,TEXTSIZE,"\030\003\016%01.1f",fAverageDepthAbsolute);
412 GFX_write_string(&FontT105,&t6c1,text,0);
413
414 tempWinX0 = t6c1.WindowX0;
415 tempWinY0 = t6c1.WindowY0;
416 t6c1.WindowX0 = 480;
417 // snprintf(text,TEXTSIZE,"\032\f%c%c - %c",TXT_2BYTE, TXT2BYTE_Clock, TXT_AvgDepth);
418 snprintf(text,TEXTSIZE,"\032\f%c", TXT_Stopwatch);
419 GFX_write_string(&FontT42,&t6c1,text,0);
420 snprintf(text,TEXTSIZE,"\030\016%01.1f",fAverageDepth);
421 GFX_write_string(&FontT105,&t6c1,text,0);
422 t6c1.WindowY0 = 100;
423 snprintf(text,TEXTSIZE,"\030%u:\016\016%02u",Stopwatch.Minutes, Stopwatch.Seconds);
424 GFX_write_string(&FontT105,&t6c1,text,0);
425 t6c1.WindowX0 = tempWinX0;
426 t6c1.WindowY0 = tempWinY0;
427 break;
428
429 case CVIEW_T3_Temperature:
430 snprintf(text,TEXTSIZE,"\032\f%c",TXT_Temperature);
431 GFX_write_string(&FontT42,&t6c1,text,0);
432 // mean value
433 temperatureThisCall = unit_temperature_float(stateUsed->lifeData.temperature_celsius);
434 temperature = (temperatureThisCall + temperatureLastCall[0] + temperatureLastCall[1] + temperatureLastCall[2]) / 4.0f;
435 idTemperatureLastCall++;
436 if(idTemperatureLastCall >= 3)
437 idTemperatureLastCall = 0;
438 temperatureLastCall[idTemperatureLastCall] = temperatureThisCall;
439 textpointer = snprintf(text,TEXTSIZE,"\030\003\016%01.1f \140",temperature); // "\016\016%01.1f `" + C or F
440 if(settingsGetPointer()->nonMetricalSystem == 0)
441 text[textpointer++] = 'C';
442 else
443 text[textpointer++] = 'F';
444 text[textpointer++] = 0;
445 GFX_write_string(&FontT105,&t6c1,text,0);
446 break;
447
448 case CVIEW_Compass:
449 snprintf(text,TEXTSIZE,"\032\f%c%c",TXT_2BYTE, TXT2BYTE_Compass);
450 GFX_write_string(&FontT42,&t6c1,text,0);
451 snprintf(text,100,"\030\003%03i`",(uint16_t)stateUsed->lifeData.compass_heading);
452 GFX_write_string(&FontT105,&t6c1,text,0);
453 t6_compass((uint16_t)stateUsed->lifeData.compass_heading, stateUsed->diveSettings.compassHeading);
454 break;
455
456 case CVIEW_T3_MaxDepth:
457 default:
458 snprintf(text,TEXTSIZE,"\032\f%c",TXT_MaxDepth);
459 GFX_write_string(&FontT42,&t6c1,text,0);
460 snprintf(text,TEXTSIZE,"\020\003\016%01.1f",unit_depth_float(stateUsed->lifeData.max_depth_meter));
461 t3_basics_colorscheme_mod(text);
462 GFX_write_string(&FontT105,&t6c1,text,1);
463 break;
464 }
465 }
466
467
468 void t6_show_customview_warnings(void)
469 {
470 char text[256], textMain[256];
471 uint8_t textpointer, textpointerMain, lineFree, more;
472
473 snprintf(text,TEXTSIZE,"\025\f%c",TXT_Warning);
474 GFX_write_string(&FontT42,&t6c1,text,0);
475
476 lineFree = 1;
477 more = 0;
478
479 textpointerMain = 0;
480 textMain[textpointerMain++] = '\025';
481 textMain[textpointerMain++] = '\003';
482
483 textpointer = 0;
484
485 text[textpointer++] = '\021';
486 text[textpointer++] = TXT_2BYTE;
487 text[textpointer++] = TXT2BYTE_WarnDecoMissed;
488 if(stateUsed->warnings.decoMissed)
489 {
490 text[textpointer - 3] = '\025';
491 if(lineFree)
492 {
493 textMain[textpointerMain++] = TXT_2BYTE;
494 textMain[textpointerMain++] = text[textpointer - 1];
495 textMain[textpointerMain] = 0;
496 lineFree--;
497 }
498 else
499 {
500 more++;
501 }
502 }
503
504 text[textpointer++] = '\t';
505 text[textpointer++] = '\021';
506 text[textpointer++] = TXT_2BYTE;
507 text[textpointer++] = TXT2BYTE_WarnPPO2Low;
508 if(stateUsed->warnings.ppO2Low)
509 {
510 text[textpointer - 3] = '\025';
511 if(lineFree)
512 {
513 textMain[textpointerMain++] = TXT_2BYTE;
514 textMain[textpointerMain++] = text[textpointer - 1];
515 textMain[textpointerMain] = 0;
516 lineFree--;
517 }
518 else
519 {
520 more++;
521 }
522 }
523
524 text[textpointer++] = '\n';
525 text[textpointer++] = '\r';
526 text[textpointer++] = '\021';
527 text[textpointer++] = TXT_2BYTE;
528 text[textpointer++] = TXT2BYTE_WarnPPO2High;
529 if(stateUsed->warnings.ppO2High)
530 {
531 text[textpointer - 3] = '\025';
532 if(lineFree)
533 {
534 textMain[textpointerMain++] = TXT_2BYTE;
535 textMain[textpointerMain++] = text[textpointer - 1];
536 textMain[textpointerMain] = 0;
537 lineFree--;
538 }
539 else
540 {
541 more++;
542 }
543 }
544
545 text[textpointer++] = '\t';
546 text[textpointer++] = '\021';
547 text[textpointer++] = TXT_2BYTE;
548 text[textpointer++] = TXT2BYTE_WarnFallback;
549 if(stateUsed->warnings.fallback)
550 {
551 text[textpointer - 3] = '\025';
552 if(lineFree)
553 {
554 textMain[textpointerMain++] = TXT_2BYTE;
555 textMain[textpointerMain++] = text[textpointer - 1];
556 textMain[textpointerMain] = 0;
557 lineFree--;
558 }
559 else
560 {
561 more++;
562 }
563 }
564
565 text[textpointer++] = '\n';
566 text[textpointer++] = '\r';
567 text[textpointer++] = '\021';
568 text[textpointer++] = TXT_2BYTE;
569 text[textpointer++] = TXT2BYTE_WarnSensorLinkLost;
570 if(stateUsed->warnings.sensorLinkLost)
571 {
572 text[textpointer - 3] = '\025';
573 if(lineFree)
574 {
575 textMain[textpointerMain++] = TXT_2BYTE;
576 textMain[textpointerMain++] = text[textpointer - 1];
577 textMain[textpointerMain] = 0;
578 lineFree--;
579 }
580 else
581 {
582 more++;
583 }
584 }
585
586 text[textpointer] = 0;
587 GFX_write_string(&FontT48,&t6c1,textMain,1);
588 if(more)
589 {
590 GFX_write_string(&FontT48,&t6c2,text,1);
591 }
592 }
593
594
595 void t6_change_customview(void)
596 {
597 const uint8_t *pViews;
598 pViews = t6_customviews;
599
600 while((*pViews != CVIEW_T3_END) && (*pViews != t6_selection_customview))
601 {pViews++;}
602
603 if(*pViews < CVIEW_T3_END)
604 pViews++;
605
606 if(*pViews == CVIEW_T3_END)
607 {
608 t6_selection_customview = t6_customviews[0];
609 }
610 else
611 t6_selection_customview = *pViews;
612 }
613
614
615 void t3_basics_colorscheme_mod(char *text)
616 {
617 if((text[0] == '\020') && !GFX_is_colorschemeDiveStandard())
618 {
619 text[0] = '\027';
620 }
621 }
622
623 point_t t6_compass_circle(uint8_t id, uint16_t degree)
624 {
625 float fCos, fSin;
626 const float piMult = ((2 * 3.14159) / 360);
627 // const int radius[4] = {95,105,115,60};
628 const int radius[4] = {85,95,105,90};
629 const point_t offset = {.x = 600, .y = 116};
630
631 static point_t r[4][360] = { 0 };
632
633 if(r[0][0].y == 0)
634 {
635 for(int i=0;i<360;i++)
636 {
637 fCos = cos(i * piMult);
638 fSin = sin(i * piMult);
639 for(int j=0;j<4;j++)
640 {
641 r[j][i].x = offset.x + (int)(fSin * radius[j]);
642 r[j][i].y = offset.y + (int)(fCos * radius[j]);
643 }
644 }
645 }
646 if(id > 3) id = 0;
647 if(degree > 359) degree = 0;
648 return r[id][degree];
649 }
650
651
652 void t6_compass(uint16_t ActualHeading, uint16_t UserSetHeading)
653 {
654 uint16_t LineHeading;
655 point_t center;
656 static int32_t LastHeading = 0;
657 int32_t newHeading = 0;
658 int32_t diff = 0;
659 int32_t diff2 = 0;
660
661 int32_t diffAbs = 0;
662 int32_t diffAbs2 = 0;
663
664 newHeading = ActualHeading;
665
666 diff = newHeading - LastHeading;
667
668 if(newHeading < LastHeading)
669 diff2 = newHeading + 360 - LastHeading;
670 else
671 diff2 = newHeading - 360 - LastHeading;
672
673 diffAbs = diff;
674 if(diffAbs < 0)
675 diffAbs *= -1;
676
677 diffAbs2 = diff2;
678 if(diffAbs2 < 0)
679 diffAbs2 *= -1;
680
681
682 if(diffAbs <= diffAbs2)
683 newHeading = LastHeading + (diff / 2);
684 else
685 newHeading = LastHeading + (diff2 / 2);
686
687 if(newHeading < 0)
688 newHeading += 360;
689 else
690 if(newHeading >= 360)
691 newHeading -= 360;
692
693 LastHeading = newHeading;
694 ActualHeading = newHeading;
695
696 if (ActualHeading < 90)
697 ActualHeading += 360;
698
699 while(ActualHeading > 359) ActualHeading -= 360;
700
701 LineHeading = 360 - ActualHeading;
702 GFX_draw_thick_line(9,&t6screen, t6_compass_circle(0,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font030); // North
703 LineHeading += 90;
704 if(LineHeading > 359) LineHeading -= 360;
705 GFX_draw_thick_line(9,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031); // Maintick
706 LineHeading += 90;
707 if(LineHeading > 359) LineHeading -= 360;
708 GFX_draw_thick_line(9,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
709 LineHeading += 90;
710 if(LineHeading > 359) LineHeading -= 360;
711 GFX_draw_thick_line(9,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
712
713 LineHeading = 360 - ActualHeading;
714 LineHeading += 45;
715 if(LineHeading > 359) LineHeading -= 360;
716 GFX_draw_thick_line(5,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031); // Subtick
717 LineHeading += 90;
718 if(LineHeading > 359) LineHeading -= 360;
719 GFX_draw_thick_line(5,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
720 LineHeading += 90;
721 if(LineHeading > 359) LineHeading -= 360;
722 GFX_draw_thick_line(5,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
723 LineHeading += 90;
724 if(LineHeading > 359) LineHeading -= 360;
725 GFX_draw_thick_line(5,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
726
727 LineHeading = 360 - ActualHeading;
728 LineHeading += 22;
729 if(LineHeading > 359) LineHeading -= 360;
730 GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031); // Subtick
731 LineHeading += 45;
732 if(LineHeading > 359) LineHeading -= 360;
733 GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
734 LineHeading += 45;
735 if(LineHeading > 359) LineHeading -= 360;
736 GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
737 LineHeading += 45;
738 if(LineHeading > 359) LineHeading -= 360;
739 GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
740 LineHeading += 45;
741 if(LineHeading > 359) LineHeading -= 360;
742 GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031); // Subtick
743 LineHeading += 45;
744 if(LineHeading > 359) LineHeading -= 360;
745 GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
746 LineHeading += 45;
747 if(LineHeading > 359) LineHeading -= 360;
748 GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
749 LineHeading += 45;
750 if(LineHeading > 359) LineHeading -= 360;
751 GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
752
753 if(UserSetHeading)
754 {
755 LineHeading = UserSetHeading + 360 - ActualHeading;
756 if(LineHeading > 359) LineHeading -= 360;
757 GFX_draw_thick_line(9,&t6screen, t6_compass_circle(3,LineHeading), t6_compass_circle(2,LineHeading), CLUT_CompassUserHeadingTick);
758
759 // R�ckpeilung, User Back Heading
760 LineHeading = UserSetHeading + 360 + 180 - ActualHeading;
761 if(LineHeading > 359) LineHeading -= 360;
762 if(LineHeading > 359) LineHeading -= 360;
763 GFX_draw_thick_line(9,&t6screen, t6_compass_circle(3,LineHeading), t6_compass_circle(2,LineHeading), CLUT_CompassUserBackHeadingTick);
764 }
765
766 center.x = 600;
767 center.y = 116;
768 GFX_draw_circle(&t6screen, center, 106, CLUT_Font030);
769 GFX_draw_circle(&t6screen, center, 107, CLUT_Font030);
770 GFX_draw_circle(&t6screen, center, 108, CLUT_Font030);
771 }
772 */
773