comparison Discovery/Src/show_logbook.c @ 186:f11f0bf6ef2d cleanup-2

cleanup: remove obsolete code, make static, etc. Some rather trivial cleanup things like putting demo code into ifdefs, making functions static where possible, and against my normal policy of hard removing unused code, commenting it out at this point in time. Somehow, I think that this commented code might be useful in the near future as a new pressure sensor is coming. And finally, fixed some typo's in comment. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Fri, 15 Mar 2019 12:39:28 +0100
parents 255eedad4155
children 5a633dece17a
comparison
equal deleted inserted replaced
185:1bb24fd3fc92 186:f11f0bf6ef2d
38 #include <stdio.h> 38 #include <stdio.h>
39 #include <stdlib.h> // for abs() 39 #include <stdlib.h> // for abs()
40 40
41 /* Private variables ---------------------------------------------------------*/ 41 /* Private variables ---------------------------------------------------------*/
42 42
43 GFX_DrawCfgScreen tLOGscreen; 43 static GFX_DrawCfgScreen tLOGscreen;
44 GFX_DrawCfgScreen tLOGbackground; 44 static GFX_DrawCfgScreen tLOGbackground;
45 45
46 46
47 void print_gas_name(char* output,uint8_t lengh,uint8_t oxygen,uint8_t helium); 47 static void print_gas_name(char* output,uint8_t lengh,uint8_t oxygen,uint8_t helium);
48 int16_t get_colour(int16_t color); 48 static int16_t get_colour(int16_t color);
49 49
50 /* Overview */ 50 /* Overview */
51 void show_logbook_logbook_show_log_page1(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards); 51 static void show_logbook_logbook_show_log_page1(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards);
52 /* Temperature */ 52 /* Temperature */
53 void show_logbook_logbook_show_log_page2(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards); 53 static void show_logbook_logbook_show_log_page2(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards);
54 /* Gas List */ 54 /* Gas List */
55 void show_logbook_logbook_show_log_page3(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards); 55 static void show_logbook_logbook_show_log_page3(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards);
56 /* ppO2 */ 56 /* ppO2 */
57 void show_logbook_logbook_show_log_page4(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards); 57 static void show_logbook_logbook_show_log_page4(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards);
58 58
59 59 static inline uint32_t MaxU32LOG(uint32_t a, uint32_t b)
60 inline uint32_t MinU32LOG(uint32_t a, uint32_t b)
61 {
62 return ((a<b)?a:b);
63 }
64
65 uint32_t MaxU32LOG(uint32_t a, uint32_t b)
66 { 60 {
67 return((a>b)?a:b); 61 return((a>b)?a:b);
68 } 62 }
69
70 void write_label_(GFX_DrawCfgScreen *screenInput, SWindowGimpStyle win, const tFont *Font, uint8_t color, const char *text)
71 {
72 GFX_DrawCfgWindow hgfx;
73
74 if( win.right > 799)
75 win.right = 799;
76
77 if(win.top > 479)
78 win.top = 479;
79 hgfx.Image = screenInput;
80 hgfx.WindowNumberOfTextLines = 1;
81 hgfx.WindowLineSpacing = 0;
82 hgfx.WindowTab = 0;
83 hgfx.WindowX0 = win.left;
84 hgfx.WindowX1 = win.right;
85 hgfx.WindowY1 = 479 - win.top;
86 if(hgfx.WindowY1 < Font->height)
87 hgfx.WindowY0 = 0;
88 else
89 hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
90
91 GFX_write_label(Font, &hgfx, text, color);
92 }
93
94 63
95 /** 64 /**
96 ****************************************************************************** 65 ******************************************************************************
97 * @brief GFX write label. / print coordinate system & depth graph 66 * @brief GFX write label. / print coordinate system & depth graph
98 * @author Peter Ryser 67 * @author Peter Ryser
106 * @param dataLength: 75 * @param dataLength:
107 * @param depthdata: 76 * @param depthdata:
108 * @param colordata: 1 77 * @param colordata: 1
109 * @retval None 78 * @retval None
110 */ 79 */
111 void show_logbook_draw_depth_graph(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards, SWindowGimpStyle* window, short mode, uint16_t dataLength, uint16_t* depthdata, uint8_t * colordata, uint16_t * decostopdata) 80 static void show_logbook_draw_depth_graph(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards, SWindowGimpStyle* window, short mode, uint16_t dataLength, uint16_t* depthdata, uint8_t * colordata, uint16_t * decostopdata)
112 { 81 {
113 SLogbookHeader logbookHeader; 82 SLogbookHeader logbookHeader;
114 SWindowGimpStyle wintemp = *window; 83 SWindowGimpStyle wintemp = *window;
115 SWindowGimpStyle winsmal; 84 SWindowGimpStyle winsmal;
116 logbook_getHeader(StepBackwards, &logbookHeader); 85 logbook_getHeader(StepBackwards, &logbookHeader);
283 * @retval *OutputStepOfScale, *OutputMaxValueOnScale, *OutputTop, *OutputBottom 252 * @retval *OutputStepOfScale, *OutputMaxValueOnScale, *OutputTop, *OutputBottom
284 253
285 * fit to multiples of 1�C (data format is 1/10�C) 254 * fit to multiples of 1�C (data format is 1/10�C)
286 */ 255 */
287 256
288 void scaleAdapt( int InputTop, int InputBottom, 257 static void scaleAdapt( int InputTop, int InputBottom,
289 int16_t *OutputMinValue, int16_t *OutputMaxValue, int *OutputTop, int *OutputBottom, 258 int16_t *OutputMinValue, int16_t *OutputMaxValue, int *OutputTop, int *OutputBottom,
290 uint16_t *OutputStepOfScale, int16_t *OutputMaxValueOnScale) 259 uint16_t *OutputStepOfScale, int16_t *OutputMaxValueOnScale)
291 { 260 {
292 // uint16_t oldScale; 261 // uint16_t oldScale;
293 uint16_t newScale; 262 uint16_t newScale;
385 * pixel 390 gesamt h�he 354 * pixel 390 gesamt h�he
386 355
387 * for temperature, input is �C * 10 356 * for temperature, input is �C * 10
388 */ 357 */
389 358
390 void scaleHelper( uint16_t InputDataLength, int16_t *InputDataArray, int InputTop, int InputBottom, 359 static void scaleHelper( uint16_t InputDataLength, int16_t *InputDataArray, int InputTop, int InputBottom,
391 int16_t *OutputMinValue, int16_t *OutputMaxValue, int *OutputTop, int *OutputBottom, 360 int16_t *OutputMinValue, int16_t *OutputMaxValue, int *OutputTop, int *OutputBottom,
392 uint16_t *OutputStepOfScale, int16_t *OutputMaxValueOnScale) 361 uint16_t *OutputStepOfScale, int16_t *OutputMaxValueOnScale)
393 { 362 {
394 int32_t datamin = INT16_MAX; // 32 bit for delta calculation ( delta is unsigned -> value can be 2x INT16_MAX) 363 int32_t datamin = INT16_MAX; // 32 bit for delta calculation ( delta is unsigned -> value can be 2x INT16_MAX)
395 int32_t datamax = INT16_MIN; 364 int32_t datamax = INT16_MIN;
439 ****************************************************************************** 408 ******************************************************************************
440 * 409 *
441 * @param hgfx: 410 * @param hgfx:
442 * @retval None 411 * @retval None
443 */ 412 */
444 void show_logbook_logbook_show_log_page1(GFX_DrawCfgScreen *hgfx,uint8_t StepBackwards) 413 static void show_logbook_logbook_show_log_page1(GFX_DrawCfgScreen *hgfx,uint8_t StepBackwards)
445 { 414 {
446 SWindowGimpStyle wintemp; 415 SWindowGimpStyle wintemp;
447 SWindowGimpStyle winsmal; 416 SWindowGimpStyle winsmal;
448 wintemp.left = 50; 417 wintemp.left = 50;
449 wintemp.right = 799 - wintemp.left; 418 wintemp.right = 799 - wintemp.left;
659 628
660 show_logbook_draw_depth_graph(hgfx, StepBackwards, &wintemp, 1, dataLength, depthdata, gasdata, NULL); 629 show_logbook_draw_depth_graph(hgfx, StepBackwards, &wintemp, 1, dataLength, depthdata, gasdata, NULL);
661 } 630 }
662 631
663 632
664 void show_logbook_logbook_show_log_page2(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards) 633 static void show_logbook_logbook_show_log_page2(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards)
665 { 634 {
666 //*** Page2: Depth and Temperature **** 635 //*** Page2: Depth and Temperature ****
667 636
668 SWindowGimpStyle wintemp; 637 SWindowGimpStyle wintemp;
669 SWindowGimpStyle winsmal; 638 SWindowGimpStyle winsmal;
749 wintemp.top = newTop; 718 wintemp.top = newTop;
750 GFX_graph_print(hgfx,&wintemp,0,1,maxVal,minVal, (uint16_t *)tempdata,dataLength,CLUT_LogbookTemperature, NULL); 719 GFX_graph_print(hgfx,&wintemp,0,1,maxVal,minVal, (uint16_t *)tempdata,dataLength,CLUT_LogbookTemperature, NULL);
751 } 720 }
752 721
753 722
754 void show_logbook_logbook_show_log_page2_original(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards) 723 static void build_logbook_test(uint8_t page, uint8_t StepBackwards)
755 {
756 //*** Page2: Depth and Temperature ****
757
758 SWindowGimpStyle wintemp;
759 SWindowGimpStyle winsmal;
760 wintemp.left = 50;
761 wintemp.right = 799 - wintemp.left;
762 wintemp.top = 50;
763 wintemp.bottom = 479 - 40;
764
765 SLogbookHeader logbookHeader;
766
767 logbook_getHeader(StepBackwards,&logbookHeader);
768 uint16_t dataLength = 0;
769 uint16_t depthdata[1000];
770 uint8_t gasdata[1000];
771 int16_t tempdata[1000];
772 uint16_t decoDepthdata[1000];
773 uint16_t *pDecoDepthData = 0;
774
775 dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, tempdata, NULL, NULL, NULL, NULL, NULL, NULL, NULL, decoDepthdata);
776
777 /* test
778 for(int i = 0; i<dataLength/2; i++)
779 decoDepthdata[i] = 300;
780
781 for(int i = dataLength/2; i<dataLength; i++)
782 decoDepthdata[i] = 1200;
783 */
784 for(int i = 0; i<dataLength; i++)
785 {
786 if(decoDepthdata[i] >= 300)
787 {
788 pDecoDepthData = decoDepthdata;
789 break;
790 }
791 }
792 //--- print coordinate system & depth graph ---
793 show_logbook_draw_depth_graph(hgfx, StepBackwards, &wintemp, 0, dataLength, depthdata, gasdata, pDecoDepthData);
794
795 //*** Temperature *************************************************
796
797
798 int16_t datamax = -1000; // �C * 10
799 int16_t datamin = +1000;
800 for(int i = 0; i < dataLength;i++)
801 {
802 if(tempdata[i]>datamax)
803 datamax = tempdata[i];
804 if(tempdata[i]< datamin)
805 datamin = tempdata[i];
806 }
807 float maxTmp = ((float)datamax) /10.f;
808 float minTmp = ((float)datamin) /10.f;
809 int deltaTmp = maxTmp - minTmp;
810 int tmpstep = 2;
811
812 // 5 different scales: 1�C, 2�C, 4�C, 5�C, 10�C
813 // with 6 lines == 5 steps
814 if((deltaTmp) <=5)
815 {
816 tmpstep = 1;
817 }
818 else
819 if(deltaTmp <= (5*2))
820 {
821 tmpstep = 2;
822 }
823 else
824 if(deltaTmp <= (5 * 4))
825 {
826 tmpstep = 4;
827 }
828 else
829 if(deltaTmp <= (5 * 5))
830 {
831 tmpstep = 5;
832 }
833 else
834 {
835 tmpstep = 10;
836 }
837 // int steps = deltaTmp/tmpstep;
838
839
840 // int steps = deltaTmp/5;
841 // int tmpstep = 5;
842 // if(steps > 4)
843 // tmpstep = 10;
844
845 int maxtmpline = 0;
846 int mintmpline = 0;
847 if(minTmp < 0)
848 {
849 if(minTmp >= -5)
850 {
851 mintmpline = -5;
852
853 }
854 else if(minTmp >= -10)
855 {
856 mintmpline = -10;
857 }
858 else
859 mintmpline = -15;
860 }
861
862 if(maxTmp > 0)
863 {
864 while(maxtmpline < maxTmp)
865 maxtmpline += tmpstep;
866 }
867
868 if(tmpstep < 5)
869 maxtmpline = MaxU32LOG(maxtmpline, 10);
870 else if(tmpstep == 5)
871 maxtmpline = MaxU32LOG(maxtmpline, 25);
872 else
873 maxtmpline = 50;
874
875 maxtmpline += mintmpline;
876
877 //--- print temperature labels ---
878 // input maxtmpline, tmpstep, deltaline
879
880 winsmal.left = wintemp.right +6;
881 winsmal.top = wintemp.top - 3;
882 winsmal.right = wintemp.right + 30;
883 winsmal.bottom = winsmal.top + 16;
884
885 write_label_(hgfx, winsmal,&FontT24,CLUT_LogbookTemperature,"[C]");
886
887 int deltaline = (wintemp.bottom - wintemp.top)/5;
888 char msg[3];
889 int tmp = maxtmpline;
890 for(int i = 1; i<=5; i++)
891 {
892 tmp -= tmpstep;
893 //if(tmp < 0)
894 //break;
895 winsmal.top = wintemp.top + deltaline * i - 14;
896 winsmal.bottom = winsmal.top + 16;
897 snprintf(msg,3,"%2i",tmp);
898 write_label_(hgfx, winsmal,&FontT24,CLUT_LogbookTemperature,msg);
899 }
900
901
902 //--- print temperature graph ---
903 // input tempdata[i], maxtmpline, mintmpline, maxTmp, minTmp, deltaline, wintemp.top, dataLength, datamax,
904
905 //adapt window
906 float ftmp =((maxtmpline - minTmp) * deltaline) /tmpstep + wintemp.top;
907 wintemp.bottom = ftmp;
908 if((ftmp - (int)ftmp) >= 0.5f)
909 wintemp.bottom++;
910
911 ftmp = ((maxtmpline - maxTmp) * deltaline) /tmpstep + wintemp.top;
912 wintemp.top = ftmp;
913 if((ftmp - (int)ftmp) >= 0.5f)
914 wintemp.top++;
915
916 if(wintemp.top <= wintemp.bottom)
917 {
918 for(int i = 0; i < dataLength;i++)
919 {
920 tempdata[i] -= mintmpline;
921 }
922 datamax -= mintmpline;
923 // hw 160518
924 // es wird nur das Fenster (wintemp.top, wintemp.bottom) verwendet in dem Daten sind
925 // daher muss datamin angegeben werden
926 // der Gesamtbereich ist uninteressant
927 // Bsp Temperatur von 8�C bis 5�C
928 // Y-Achse ist 10�C (oben) bis 0�C (unten)
929 // aber wintemp.top ist 127
930 // und wintemp.bottom ist 243
931 GFX_graph_print(hgfx,&wintemp,0,1,datamax,datamin, (uint16_t *)tempdata,dataLength,CLUT_LogbookTemperature, NULL);
932 }
933 }
934
935
936 void build_logbook_test(uint8_t page, uint8_t StepBackwards)
937 { 724 {
938 uint32_t lastScreen,lastBackground; 725 uint32_t lastScreen,lastBackground;
939 726
940 lastScreen = tLOGscreen.FBStartAdress; 727 lastScreen = tLOGscreen.FBStartAdress;
941 lastBackground = tLOGbackground.FBStartAdress; 728 lastBackground = tLOGbackground.FBStartAdress;
998 releaseFrame(16,tLOGscreen.FBStartAdress); 785 releaseFrame(16,tLOGscreen.FBStartAdress);
999 releaseFrame(17,tLOGbackground.FBStartAdress); 786 releaseFrame(17,tLOGbackground.FBStartAdress);
1000 } 787 }
1001 788
1002 789
1003 void show_logbook_logbook_show_log_page3(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards) 790 static void show_logbook_logbook_show_log_page3(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards)
1004 { 791 {
1005 SWindowGimpStyle wintemp; 792 SWindowGimpStyle wintemp;
1006 SWindowGimpStyle winsmal; 793 SWindowGimpStyle winsmal;
1007 wintemp.left = 50; 794 wintemp.left = 50;
1008 wintemp.right = 799 - wintemp.left; 795 wintemp.right = 799 - wintemp.left;
1049 else 836 else
1050 button_start_single_action(surf1_menu_logbook_current_page, surf1_menu_logbook_show_log_page1, surf1_menu_logbook_show_log_next); 837 button_start_single_action(surf1_menu_logbook_current_page, surf1_menu_logbook_show_log_page1, surf1_menu_logbook_show_log_next);
1051 */ 838 */
1052 } 839 }
1053 840
1054 void show_logbook_logbook_show_log_page4(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards) 841 static void show_logbook_logbook_show_log_page4(GFX_DrawCfgScreen *hgfx, uint8_t StepBackwards)
1055 { SWindowGimpStyle wintemp; 842 { SWindowGimpStyle wintemp;
1056 SWindowGimpStyle winsmal; 843 SWindowGimpStyle winsmal;
1057 wintemp.left = 50; 844 wintemp.left = 50;
1058 wintemp.right = 799 - wintemp.left; 845 wintemp.right = 799 - wintemp.left;
1059 wintemp.top = 50; 846 wintemp.top = 50;
1215 1002
1216 //--- define buttons --- 1003 //--- define buttons ---
1217 //button_start_single_action(surf1_menu_logbook_current_page, surf1_menu_logbook_show_log_page1, surf1_menu_logbook_show_log_next); 1004 //button_start_single_action(surf1_menu_logbook_current_page, surf1_menu_logbook_show_log_page1, surf1_menu_logbook_show_log_next);
1218 } 1005 }
1219 1006
1220 void print_gas_name(char* output,uint8_t length,uint8_t oxygen,uint8_t helium) 1007 static void print_gas_name(char* output,uint8_t length,uint8_t oxygen,uint8_t helium)
1221 { 1008 {
1222 if(helium == 0) 1009 if(helium == 0)
1223 { 1010 {
1224 if(oxygen == 21) 1011 if(oxygen == 21)
1225 snprintf(output, length, "Air"); 1012 snprintf(output, length, "Air");
1236 snprintf(output, length, "TMX%i/%i", oxygen, helium); 1023 snprintf(output, length, "TMX%i/%i", oxygen, helium);
1237 } 1024 }
1238 1025
1239 } 1026 }
1240 1027
1241 int16_t get_colour(int16_t color) 1028 static int16_t get_colour(int16_t color)
1242 { 1029 {
1243 return CLUT_GasSensor1 + color; 1030 return CLUT_GasSensor1 + color;
1244 } 1031 }