comparison Discovery/Src/t6_apnea.c @ 202:d328abe2e44e

Merged heinrichsweikamp/ostc4 into default
author Thorsten <ideenmodellierer@o2mail.de>
date Sun, 17 Mar 2019 19:16:59 +0100
parents 8b8074080d7b
children 2bb1db22b5f5
comparison
equal deleted inserted replaced
201:4073b8091224 202:d328abe2e44e
72 /* Private function prototypes -----------------------------------------------*/ 72 /* Private function prototypes -----------------------------------------------*/
73 void t6_refresh_divemode(void); 73 void t6_refresh_divemode(void);
74 void t6_refresh_customview(float depth); 74 void t6_refresh_customview(float depth);
75 75
76 uint8_t t6_test_customview_warnings(void); 76 uint8_t t6_test_customview_warnings(void);
77 void t6_show_customview_warnings(void);
78 void t6_compass(uint16_t ActualHeading, uint16_t UserSetHeading);
79 77
80 /* Exported functions --------------------------------------------------------*/ 78 /* Exported functions --------------------------------------------------------*/
81 79
82 // for tHomeDiveMenuControl() in tHome.c and t6_refresh_customview 80 // for tHomeDiveMenuControl() in tHome.c and t6_refresh_customview
83 uint8_t t6_getCustomView(void) 81 uint8_t t6_getCustomView(void)
329 uint8_t count = 0; 327 uint8_t count = 0;
330 328
331 count = 0; 329 count = 0;
332 return count; 330 return count;
333 } 331 }
334
335 /*
336
337 char text[512];
338 uint16_t textpointer = 0;
339
340
341 // CVIEW_T3_Temperature
342 float temperatureThisCall;
343 float temperature;
344
345
346 // CVIEW_T3_StopWatch
347 SDivetime Stopwatch = {0,0,0,0};
348 float fAverageDepth, fAverageDepthAbsolute;
349 uint16_t tempWinX0;
350 uint16_t tempWinY0;
351
352 switch(t6_selection_customview)
353 {
354 case CVIEW_T3_ApnoeTimes:
355 break;
356
357 case CVIEW_T3_StopWatch:
358 Stopwatch.Total = timer_Stopwatch_GetTime();
359 Stopwatch.Minutes = Stopwatch.Total / 60;
360 Stopwatch.Seconds = Stopwatch.Total - ( Stopwatch.Minutes * 60 );
361 fAverageDepth = timer_Stopwatch_GetAvarageDepth_Meter();
362 fAverageDepthAbsolute = stateUsed->lifeData.average_depth_meter;
363
364 snprintf(text,TEXTSIZE,"\032\f%c",TXT_AvgDepth);
365 GFX_write_string(&FontT42,&t6c1,text,0);
366 snprintf(text,TEXTSIZE,"\030\003\016%01.1f",fAverageDepthAbsolute);
367 GFX_write_string(&FontT105,&t6c1,text,0);
368
369 tempWinX0 = t6c1.WindowX0;
370 tempWinY0 = t6c1.WindowY0;
371 t6c1.WindowX0 = 480;
372 // snprintf(text,TEXTSIZE,"\032\f%c%c - %c",TXT_2BYTE, TXT2BYTE_Clock, TXT_AvgDepth);
373 snprintf(text,TEXTSIZE,"\032\f%c", TXT_Stopwatch);
374 GFX_write_string(&FontT42,&t6c1,text,0);
375 snprintf(text,TEXTSIZE,"\030\016%01.1f",fAverageDepth);
376 GFX_write_string(&FontT105,&t6c1,text,0);
377 t6c1.WindowY0 = 100;
378 snprintf(text,TEXTSIZE,"\030%u:\016\016%02u",Stopwatch.Minutes, Stopwatch.Seconds);
379 GFX_write_string(&FontT105,&t6c1,text,0);
380 t6c1.WindowX0 = tempWinX0;
381 t6c1.WindowY0 = tempWinY0;
382 break;
383
384 case CVIEW_T3_Temperature:
385 snprintf(text,TEXTSIZE,"\032\f%c",TXT_Temperature);
386 GFX_write_string(&FontT42,&t6c1,text,0);
387 // mean value
388 temperatureThisCall = unit_temperature_float(stateUsed->lifeData.temperature_celsius);
389 temperature = (temperatureThisCall + temperatureLastCall[0] + temperatureLastCall[1] + temperatureLastCall[2]) / 4.0f;
390 idTemperatureLastCall++;
391 if(idTemperatureLastCall >= 3)
392 idTemperatureLastCall = 0;
393 temperatureLastCall[idTemperatureLastCall] = temperatureThisCall;
394 textpointer = snprintf(text,TEXTSIZE,"\030\003\016%01.1f \140",temperature); // "\016\016%01.1f `" + C or F
395 if(settingsGetPointer()->nonMetricalSystem == 0)
396 text[textpointer++] = 'C';
397 else
398 text[textpointer++] = 'F';
399 text[textpointer++] = 0;
400 GFX_write_string(&FontT105,&t6c1,text,0);
401 break;
402
403 case CVIEW_Compass:
404 snprintf(text,TEXTSIZE,"\032\f%c%c",TXT_2BYTE, TXT2BYTE_Compass);
405 GFX_write_string(&FontT42,&t6c1,text,0);
406 snprintf(text,100,"\030\003%03i`",(uint16_t)stateUsed->lifeData.compass_heading);
407 GFX_write_string(&FontT105,&t6c1,text,0);
408 t6_compass((uint16_t)stateUsed->lifeData.compass_heading, stateUsed->diveSettings.compassHeading);
409 break;
410
411 case CVIEW_T3_MaxDepth:
412 default:
413 snprintf(text,TEXTSIZE,"\032\f%c",TXT_MaxDepth);
414 GFX_write_string(&FontT42,&t6c1,text,0);
415 snprintf(text,TEXTSIZE,"\020\003\016%01.1f",unit_depth_float(stateUsed->lifeData.max_depth_meter));
416 t3_basics_colorscheme_mod(text);
417 GFX_write_string(&FontT105,&t6c1,text,1);
418 break;
419 }
420 }
421
422
423 void t6_show_customview_warnings(void)
424 {
425 char text[256], textMain[256];
426 uint8_t textpointer, textpointerMain, lineFree, more;
427
428 snprintf(text,TEXTSIZE,"\025\f%c",TXT_Warning);
429 GFX_write_string(&FontT42,&t6c1,text,0);
430
431 lineFree = 1;
432 more = 0;
433
434 textpointerMain = 0;
435 textMain[textpointerMain++] = '\025';
436 textMain[textpointerMain++] = '\003';
437
438 textpointer = 0;
439
440 text[textpointer++] = '\021';
441 text[textpointer++] = TXT_2BYTE;
442 text[textpointer++] = TXT2BYTE_WarnDecoMissed;
443 if(stateUsed->warnings.decoMissed)
444 {
445 text[textpointer - 3] = '\025';
446 if(lineFree)
447 {
448 textMain[textpointerMain++] = TXT_2BYTE;
449 textMain[textpointerMain++] = text[textpointer - 1];
450 textMain[textpointerMain] = 0;
451 lineFree--;
452 }
453 else
454 {
455 more++;
456 }
457 }
458
459 text[textpointer++] = '\t';
460 text[textpointer++] = '\021';
461 text[textpointer++] = TXT_2BYTE;
462 text[textpointer++] = TXT2BYTE_WarnPPO2Low;
463 if(stateUsed->warnings.ppO2Low)
464 {
465 text[textpointer - 3] = '\025';
466 if(lineFree)
467 {
468 textMain[textpointerMain++] = TXT_2BYTE;
469 textMain[textpointerMain++] = text[textpointer - 1];
470 textMain[textpointerMain] = 0;
471 lineFree--;
472 }
473 else
474 {
475 more++;
476 }
477 }
478
479 text[textpointer++] = '\n';
480 text[textpointer++] = '\r';
481 text[textpointer++] = '\021';
482 text[textpointer++] = TXT_2BYTE;
483 text[textpointer++] = TXT2BYTE_WarnPPO2High;
484 if(stateUsed->warnings.ppO2High)
485 {
486 text[textpointer - 3] = '\025';
487 if(lineFree)
488 {
489 textMain[textpointerMain++] = TXT_2BYTE;
490 textMain[textpointerMain++] = text[textpointer - 1];
491 textMain[textpointerMain] = 0;
492 lineFree--;
493 }
494 else
495 {
496 more++;
497 }
498 }
499
500 text[textpointer++] = '\t';
501 text[textpointer++] = '\021';
502 text[textpointer++] = TXT_2BYTE;
503 text[textpointer++] = TXT2BYTE_WarnFallback;
504 if(stateUsed->warnings.fallback)
505 {
506 text[textpointer - 3] = '\025';
507 if(lineFree)
508 {
509 textMain[textpointerMain++] = TXT_2BYTE;
510 textMain[textpointerMain++] = text[textpointer - 1];
511 textMain[textpointerMain] = 0;
512 lineFree--;
513 }
514 else
515 {
516 more++;
517 }
518 }
519
520 text[textpointer++] = '\n';
521 text[textpointer++] = '\r';
522 text[textpointer++] = '\021';
523 text[textpointer++] = TXT_2BYTE;
524 text[textpointer++] = TXT2BYTE_WarnSensorLinkLost;
525 if(stateUsed->warnings.sensorLinkLost)
526 {
527 text[textpointer - 3] = '\025';
528 if(lineFree)
529 {
530 textMain[textpointerMain++] = TXT_2BYTE;
531 textMain[textpointerMain++] = text[textpointer - 1];
532 textMain[textpointerMain] = 0;
533 lineFree--;
534 }
535 else
536 {
537 more++;
538 }
539 }
540
541 text[textpointer] = 0;
542 GFX_write_string(&FontT48,&t6c1,textMain,1);
543 if(more)
544 {
545 GFX_write_string(&FontT48,&t6c2,text,1);
546 }
547 }
548
549
550 void t6_change_customview(void)
551 {
552 const uint8_t *pViews;
553 pViews = t6_customviews;
554
555 while((*pViews != CVIEW_T3_END) && (*pViews != t6_selection_customview))
556 {pViews++;}
557
558 if(*pViews < CVIEW_T3_END)
559 pViews++;
560
561 if(*pViews == CVIEW_T3_END)
562 {
563 t6_selection_customview = t6_customviews[0];
564 }
565 else
566 t6_selection_customview = *pViews;
567 }
568
569
570 void t3_basics_colorscheme_mod(char *text)
571 {
572 if((text[0] == '\020') && !GFX_is_colorschemeDiveStandard())
573 {
574 text[0] = '\027';
575 }
576 }
577
578 point_t t6_compass_circle(uint8_t id, uint16_t degree)
579 {
580 float fCos, fSin;
581 const float piMult = ((2 * 3.14159) / 360);
582 // const int radius[4] = {95,105,115,60};
583 const int radius[4] = {85,95,105,90};
584 const point_t offset = {.x = 600, .y = 116};
585
586 static point_t r[4][360] = { 0 };
587
588 if(r[0][0].y == 0)
589 {
590 for(int i=0;i<360;i++)
591 {
592 fCos = cos(i * piMult);
593 fSin = sin(i * piMult);
594 for(int j=0;j<4;j++)
595 {
596 r[j][i].x = offset.x + (int)(fSin * radius[j]);
597 r[j][i].y = offset.y + (int)(fCos * radius[j]);
598 }
599 }
600 }
601 if(id > 3) id = 0;
602 if(degree > 359) degree = 0;
603 return r[id][degree];
604 }
605
606
607 void t6_compass(uint16_t ActualHeading, uint16_t UserSetHeading)
608 {
609 uint16_t LineHeading;
610 point_t center;
611 static int32_t LastHeading = 0;
612 int32_t newHeading = 0;
613 int32_t diff = 0;
614 int32_t diff2 = 0;
615
616 int32_t diffAbs = 0;
617 int32_t diffAbs2 = 0;
618
619 newHeading = ActualHeading;
620
621 diff = newHeading - LastHeading;
622
623 if(newHeading < LastHeading)
624 diff2 = newHeading + 360 - LastHeading;
625 else
626 diff2 = newHeading - 360 - LastHeading;
627
628 diffAbs = diff;
629 if(diffAbs < 0)
630 diffAbs *= -1;
631
632 diffAbs2 = diff2;
633 if(diffAbs2 < 0)
634 diffAbs2 *= -1;
635
636
637 if(diffAbs <= diffAbs2)
638 newHeading = LastHeading + (diff / 2);
639 else
640 newHeading = LastHeading + (diff2 / 2);
641
642 if(newHeading < 0)
643 newHeading += 360;
644 else
645 if(newHeading >= 360)
646 newHeading -= 360;
647
648 LastHeading = newHeading;
649 ActualHeading = newHeading;
650
651 if (ActualHeading < 90)
652 ActualHeading += 360;
653
654 while(ActualHeading > 359) ActualHeading -= 360;
655
656 LineHeading = 360 - ActualHeading;
657 GFX_draw_thick_line(9,&t6screen, t6_compass_circle(0,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font030); // North
658 LineHeading += 90;
659 if(LineHeading > 359) LineHeading -= 360;
660 GFX_draw_thick_line(9,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031); // Maintick
661 LineHeading += 90;
662 if(LineHeading > 359) LineHeading -= 360;
663 GFX_draw_thick_line(9,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
664 LineHeading += 90;
665 if(LineHeading > 359) LineHeading -= 360;
666 GFX_draw_thick_line(9,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
667
668 LineHeading = 360 - ActualHeading;
669 LineHeading += 45;
670 if(LineHeading > 359) LineHeading -= 360;
671 GFX_draw_thick_line(5,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031); // Subtick
672 LineHeading += 90;
673 if(LineHeading > 359) LineHeading -= 360;
674 GFX_draw_thick_line(5,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
675 LineHeading += 90;
676 if(LineHeading > 359) LineHeading -= 360;
677 GFX_draw_thick_line(5,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
678 LineHeading += 90;
679 if(LineHeading > 359) LineHeading -= 360;
680 GFX_draw_thick_line(5,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
681
682 LineHeading = 360 - ActualHeading;
683 LineHeading += 22;
684 if(LineHeading > 359) LineHeading -= 360;
685 GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031); // Subtick
686 LineHeading += 45;
687 if(LineHeading > 359) LineHeading -= 360;
688 GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
689 LineHeading += 45;
690 if(LineHeading > 359) LineHeading -= 360;
691 GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
692 LineHeading += 45;
693 if(LineHeading > 359) LineHeading -= 360;
694 GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
695 LineHeading += 45;
696 if(LineHeading > 359) LineHeading -= 360;
697 GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031); // Subtick
698 LineHeading += 45;
699 if(LineHeading > 359) LineHeading -= 360;
700 GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
701 LineHeading += 45;
702 if(LineHeading > 359) LineHeading -= 360;
703 GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
704 LineHeading += 45;
705 if(LineHeading > 359) LineHeading -= 360;
706 GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading), t6_compass_circle(2,LineHeading), CLUT_Font031);
707
708 if(UserSetHeading)
709 {
710 LineHeading = UserSetHeading + 360 - ActualHeading;
711 if(LineHeading > 359) LineHeading -= 360;
712 GFX_draw_thick_line(9,&t6screen, t6_compass_circle(3,LineHeading), t6_compass_circle(2,LineHeading), CLUT_CompassUserHeadingTick);
713
714 // R�ckpeilung, User Back Heading
715 LineHeading = UserSetHeading + 360 + 180 - ActualHeading;
716 if(LineHeading > 359) LineHeading -= 360;
717 if(LineHeading > 359) LineHeading -= 360;
718 GFX_draw_thick_line(9,&t6screen, t6_compass_circle(3,LineHeading), t6_compass_circle(2,LineHeading), CLUT_CompassUserBackHeadingTick);
719 }
720
721 center.x = 600;
722 center.y = 116;
723 GFX_draw_circle(&t6screen, center, 106, CLUT_Font030);
724 GFX_draw_circle(&t6screen, center, 107, CLUT_Font030);
725 GFX_draw_circle(&t6screen, center, 108, CLUT_Font030);
726 }
727 */
728