Vladimir N. Shilov 2 днів тому
батько
коміт
e57561fc8f
2 змінених файлів з 116 додано та 88 видалено
  1. 35 24
      cfg/gfxconf.h
  2. 81 64
      src/main.c

+ 35 - 24
cfg/gfxconf.h

@@ -31,44 +31,55 @@
 #define _GFXCONF_H
 
 /* The operating system to use. One of these must be defined - preferably in your Makefile */
-#define GFX_USE_OS_CHIBIOS		        GFXON
-    #define GFX_MEM_LT64K		        GFXOFF
-#define GOS_NEED_X_HEAP 		        GFXOFF
-#define GOS_NEED_X_THREADS		        GFXOFF
+#define GFX_USE_OS_CHIBIOS            GFXON
+    #define GFX_MEM_LT64K            GFXOFF
+#define GOS_NEED_X_HEAP             GFXOFF
+#define GOS_NEED_X_THREADS            GFXOFF
 
 /* GFX sub-systems to turn on */
-#define GFX_USE_GDISP			        GFXON
-#define GFX_USE_GWIN			        GFXON
-#define GFX_USE_GMISC			        GFXON
-#define GFX_USE_GTIMER			        GFXON
-#define GFX_USE_GQUEUE			        GFXON
-#define GDISP_NEED_CONTROL		        GFXON
+#define GFX_USE_GDISP              GFXON
+#define GFX_USE_GWIN              GFXON
+#define GFX_USE_GMISC              GFXON
+#define GFX_USE_GTIMER              GFXON
+#define GFX_USE_GQUEUE              GFXON
+#define GDISP_NEED_CONTROL            GFXON
 #define GDISP_DEFAULT_ORIENTATION       gOrientationLandscape
 
 /* Features for the GDISP sub-system. */
-#define GDISP_NEED_VALIDATION	        GFXON
-#define GDISP_NEED_CLIP			        GFXON
-#define GDISP_NEED_MULTITHREAD	        GFXON
-#define GDISP_NEED_TEXT			        GFXON
+#define GDISP_NEED_VALIDATION          GFXON
+#define GDISP_NEED_CLIP              GFXON
+#define GDISP_NEED_MULTITHREAD          GFXON
+#define GDISP_NEED_TEXT              GFXON
 
 /* GDISP fonts to include */
-#define GDISP_INCLUDE_FONT_DEJAVUSANS12 GFXON
-#define GDISP_INCLUDE_FONT_DEJAVUSANS24 GFXON
+#define GDISP_INCLUDE_FONT_UI1               GFXOFF
+#define GDISP_INCLUDE_FONT_UI2               GFXOFF
+#define GDISP_INCLUDE_FONT_LARGENUMBERS      GFXOFF
+#define GDISP_INCLUDE_FONT_DEJAVUSANS10      GFXON
+#define GDISP_INCLUDE_FONT_DEJAVUSANS12      GFXON
+#define GDISP_INCLUDE_FONT_DEJAVUSANS16      GFXOFF
+#define GDISP_INCLUDE_FONT_DEJAVUSANS20      GFXOFF
+#define GDISP_INCLUDE_FONT_DEJAVUSANS24      GFXON
+#define GDISP_INCLUDE_FONT_DEJAVUSANS32      GFXOFF
+#define GDISP_INCLUDE_FONT_DEJAVUSANSBOLD12  GFXOFF
+#define GDISP_INCLUDE_FONT_FIXED_10x20       GFXOFF
+#define GDISP_INCLUDE_FONT_FIXED_7x14        GFXOFF
+#define GDISP_INCLUDE_FONT_FIXED_5x8         GFXON
 
 /* Features for the GWIN subsystem. */
-#define GWIN_NEED_WINDOWMANAGER	        GFXON
-#define GWIN_NEED_CONSOLE		        GFXON
-#define GWIN_CONSOLE_ESCSEQ		        GFXON
-#define GWIN_CONSOLE_USE_HISTORY	    GFXOFF
-//#define GWIN_CONSOLE_HISTORY_AVERAGING	GFXON
-//#define GWIN_CONSOLE_HISTORY_ATCREATE	    GFXON
-#define GWIN_NEED_GRAPH			        GFXON
+#define GWIN_NEED_WINDOWMANAGER         GFXON
+#define GWIN_NEED_CONSOLE               GFXON
+#define GWIN_CONSOLE_ESCSEQ             GFXON
+#define GWIN_CONSOLE_USE_HISTORY        GFXOFF
+//#define GWIN_CONSOLE_HISTORY_AVERAGING  GFXON
+//#define GWIN_CONSOLE_HISTORY_ATCREATE      GFXON
+#define GWIN_NEED_GRAPH                 GFXON
 
 /* Features for the GQUEUE subsystem. */
 #define GQUEUE_NEED_ASYNC               GFXON
 
 /* Features for the GMISC subsystem. */
-#define GMISC_NEED_FASTTRIG		        GFXON
+#define GMISC_NEED_FASTTRIG             GFXON
 #define GMISC_NEED_MATRIXFLOAT2D        GFXOFF
 #define GMISC_NEED_MATRIXFIXED2D        GFXOFF
 

+ 81 - 64
src/main.c

@@ -43,6 +43,26 @@
 #define POLLING_INTERVAL      10
 #define POLLING_DELAY         10
 
+/* screensize */
+#define SCR_WIDTH             320
+#define SCR_HEIGHT            240
+#define SCR_MENU_W            (SCR_WIDTH/4)
+#define SCR_CON_W             (SCR_WIDTH - SCR_MENU_W)
+#define SCR_MENU_H            (SCR_HEIGHT/2)
+#define SCR_CON_H             (SCR_HEIGHT/2)
+#define SCR_GRPH_W            SCR_WIDTH
+#define SCR_GRPH_H            (SCR_HEIGHT/2)
+#define MENU_LINE_W           SCR_MENU_W
+#define MENU_LINE_H           14
+#define MENU_LINE_1           0
+#define MENU_LINE_2           15
+#define MENU_LINE_3           30
+#define MENU_LINE_4           45
+#define MENU_LINE_5           60
+#define MENU_LINE_6           75
+#define MENU_LINE_7           90
+#define MENU_LINE_8           105
+
 /* Type definitions */
 typedef enum chrgr_state {
   Stop = 0,
@@ -401,36 +421,35 @@ int main(void) {
     events = chEvtWaitAny(ALL_EVENTS);
 
     if (events & INA_ALL_VALUSE) {
-      /*
       tmp1 = Voltage / 1000;
       tmp2 = Voltage % 1000;
-      chsnprintf(buf, 11, "U:%2d.%03uV", tmp1, tmp2);
-      gdispFillStringBox(1, 123, 158, 29, buf, font2, Red, Gray, gJustifyLeft);
+      chsnprintf(buf, 11, "U:%2d.%03u V", tmp1, tmp2);
+      gdispFillStringBox(0, MENU_LINE_3, MENU_LINE_W, MENU_LINE_H, buf, font2, Red, Gray, gJustifyLeft);
 
       tmp1 = Current / 1000;
       tmp2 = Current % 1000;
-      chsnprintf(buf, 11, "I:%2d.%03uA", tmp1, tmp2);
-      gdispFillStringBox(1, 153, 158, 29, buf, font2, Red, Gray, gJustifyLeft);
+      chsnprintf(buf, 11, "I:%2d.%03u A", tmp1, tmp2);
+      gdispFillStringBox(0, MENU_LINE_4, MENU_LINE_W, MENU_LINE_H, buf, font2, Red, Gray, gJustifyLeft);
 
+      /*
       tmp1 = Power / 1000;
       tmp2 = Power % 1000;
       chsnprintf(buf, 11, "P:%2d.%03uW", tmp1, tmp2);
       gdispFillStringBox(1, 183, 158, 29, buf, font2, Red, Gray, gJustifyLeft);
+      */
 
       tmp0 = (Capacity_I + 1800) / 3600;
       tmp1 = tmp0 / 1000;
-      tmp2 = tmp0 % 1000;
-      tmp2 /= 100;
-      chsnprintf(buf, 13, "CI:%2d.%1uAH", tmp1, tmp2);
-      gdispFillStringBox(160, 153, 158, 29, buf, font2, Red, Gray, gJustifyLeft);
+      tmp2 = (tmp0 % 1000) / 10;
+      chsnprintf(buf, 13, "CI:%2d.%02u AH", tmp1, tmp2);
+      gdispFillStringBox(0, MENU_LINE_5, MENU_LINE_W, MENU_LINE_H, buf, font2, Red, Gray, gJustifyLeft);
 
       tmp0 = (Capacity_P + 1800) / 3600;
       tmp1 = tmp0 / 1000;
-      tmp2 = tmp0 % 1000;
-      tmp2 /= 100;
-      chsnprintf(buf, 13, "CP:%2d.%1uWH", tmp1, tmp2);
-      gdispFillStringBox(160, 183, 158, 29, buf, font2, Red, Gray, gJustifyLeft);
-      */
+      tmp2 = (tmp0 % 1000) / 100;
+      chsnprintf(buf, 13, "CP:%2d.%1u WH", tmp1, tmp2);
+      gdispFillStringBox(0, MENU_LINE_6, MENU_LINE_W, MENU_LINE_H, buf, font2, Red, Gray, gJustifyLeft);
+
       graph_Draw(Voltage, Current);
 
       /* Check charge/decharge conditions */
@@ -471,14 +490,12 @@ int main(void) {
       }
     }
 
+    /* show bus voltage in STOP mode */
     if (events & INA_BUS_VALUES) {
-      /*
       tmp1 = Voltage / 1000;
-      tmp2 = Voltage % 1000;
-      chsnprintf(buf, 11, "U:%2d.%03uV", tmp1, tmp2);
-      gdispFillStringBox(1, 123, 158, 29, buf, font2, Red, Gray, gJustifyLeft);
-      */
-      /* here should control processes time ? */
+      tmp2 = (Voltage % 1000) / 10;
+      chsnprintf(buf, 11, "U:%2d.%02u V", tmp1, tmp2);
+      gdispFillStringBox(0, MENU_LINE_3, MENU_LINE_W, MENU_LINE_H, buf, font2, Red, Blue, gJustifyCenter);
     }
 
     if (events & CHRGR_ST_CHANGE) {
@@ -487,7 +504,8 @@ int main(void) {
         if (Profile[charger_Profile].VoltageDechMin_mv > Voltage) {
           gwinPrintf(GW1, "No Battery detected / Low voltage...\n");
           charger_State = Stop;
-          //gdispFillStringBox(1, 213, 318, 29, "Stop", font2, Red, Silver, gJustifyCenter);
+          show_MenuItem(MenuItem_4);
+          gdispFillStringBox(0, MENU_LINE_8, MENU_LINE_W, MENU_LINE_H, "Stop", font2, Red, Silver, gJustifyCenter);
           break;
         }
         oldState = Charge1;
@@ -499,7 +517,7 @@ int main(void) {
         gwinPrintf(GW1, "Begin process: Charge_1\n");
 
         palClearLine(LINE_RELAY1);  // power relay on
-        //gdispFillStringBox(1, 213, 318, 29, "Charge 1", font2, Red, Silver, gJustifyCenter);
+        gdispFillStringBox(0, MENU_LINE_8, MENU_LINE_W, MENU_LINE_H, "Charge 1", font2, Red, Silver, gJustifyCenter);
         break;
 
       case Pause1:
@@ -523,7 +541,7 @@ int main(void) {
 
         gwinPrintf(GW1, "Pause after Charge_1\n");
 
-        //gdispFillStringBox(1, 213, 318, 29, "Pause 1", font2, Red, Silver, gJustifyCenter);
+        gdispFillStringBox(0, MENU_LINE_8, MENU_LINE_W, MENU_LINE_H, "Pause 1", font2, Red, Silver, gJustifyCenter);
         chVTSet(&mode_vt, TIME_S2I(CHRGR_PAUSE1_S), mode_vt_cb, (void *)Decharge);
         break;
 
@@ -537,7 +555,7 @@ int main(void) {
         gwinPrintf(GW1, "Begin process: Decharge\n");
         
         palClearLine(LINE_RELAY2);  // load relay on
-        //gdispFillStringBox(1, 213, 318, 29, "Decharge", font2, Red, Silver, gJustifyCenter);
+        gdispFillStringBox(0, MENU_LINE_8, MENU_LINE_W, MENU_LINE_H, "Decharge", font2, Red, Silver, gJustifyCenter);
         break;
 
       case Pause2:
@@ -564,7 +582,7 @@ int main(void) {
         gwinPrintf(GW1, "/%2u.%02u\n", tmp1, tmp2);
 
         gwinPrintf(GW1, "Pause after Decharge\n");
-        //gdispFillStringBox(1, 213, 318, 29, "Pause 2", font2, Red, Silver, gJustifyCenter);
+        gdispFillStringBox(0, MENU_LINE_8, MENU_LINE_W, MENU_LINE_H, "Pause 2", font2, Red, Silver, gJustifyCenter);
 
         chVTSet(&mode_vt, TIME_S2I(CHRGR_PAUSE2_S), mode_vt_cb, (void *)Charge2);
         break;
@@ -579,7 +597,7 @@ int main(void) {
         gwinPrintf(GW1, "Begin process: Charge_2\n");
 
         palClearLine(LINE_RELAY1);  // power relay on
-        //gdispFillStringBox(1, 213, 318, 29, "Charge 2", font2, Red, Silver, gJustifyCenter);
+        gdispFillStringBox(0, MENU_LINE_8, MENU_LINE_W, MENU_LINE_H, "Charge 2", font2, Red, Silver, gJustifyCenter);
         break;
       
       case Error:
@@ -588,7 +606,7 @@ int main(void) {
         palSetLine(LINE_RELAY1);
         palSetLine(LINE_RELAY2);
         gwinPrintf(GW1, "ERROR\n");
-        //gdispFillStringBox(1, 213, 318, 29, "Error", font2, Silver, Red, gJustifyCenter);
+        gdispFillStringBox(0, MENU_LINE_8, MENU_LINE_W, MENU_LINE_H, "Error", font2, Silver, Red, gJustifyCenter);
         break;
 
       default:
@@ -614,14 +632,14 @@ int main(void) {
         palSetLine(LINE_RELAY1);
         palSetLine(LINE_RELAY2);
         gwinPrintf(GW1, "STOP\n");
-        //gdispFillStringBox(1, 213, 318, 29, "Stop", font2, Red, Silver, gJustifyCenter);
+        gdispFillStringBox(0, MENU_LINE_8, MENU_LINE_W, MENU_LINE_H, "Stop", font2, Red, Silver, gJustifyCenter);
         break;
       }
     }
 
     if (events & TIME_CHANGE) {
-      //chsnprintf(buf, 12, "T:%02u:%02u:%02u", Timer.hh, Timer.mm, Timer.ss);
-      //gdispFillStringBox(160, 123, 158, 29, buf, font2, Red, Gray, gJustifyLeft);
+      chsnprintf(buf, 12, "T: %02u:%02u:%02u", Timer.hh, Timer.mm, Timer.ss);
+      gdispFillStringBox(0, MENU_LINE_7, MENU_LINE_W, MENU_LINE_H, buf, font2, Red, Gray, gJustifyLeft);
     }
 
     if (events & INSERTED_EVENT) {
@@ -635,32 +653,32 @@ int main(void) {
 }
 
 /**
- * @brief Prepare screen for inforation presentation.
+ * @brief Prepare screen for information presentation.
  */
 static void prepare_Screen(void) {
   /* Set some fonts */
   font1 = gdispOpenFont("DejaVu Sans Book 12");
-  font2 = gdispOpenFont("DejaVu Sans Book 24");
+  //font2 = gdispOpenFont("DejaVu Sans Book 24");
+  font2 = gdispOpenFont("DejaVuSans10");
   gwinSetDefaultFont(font1);
 
   /* draw screen frame */
-  const coord_t width = 320;
-  const coord_t height = 240;
-
-  gdispDrawBox(0, 0, width-1, height-1, Green); // all screen
-  gdispDrawLine(0, 122, width-1, 122, Green); // h line
-  gdispDrawLine(79, 0, 79, 122, Green); // v line, text | console
-  gdispFillArea(1, 1, 78, 121, Blue); // menu area
+  //gdispDrawLine(0, (SCR_HEIGHT/2), SCR_WIDTH, (SCR_HEIGHT/2), Green); // h line
+  //gdispDrawLine(SCR_MENU_W-1, 0, SCR_MENU_W, (SCR_HEIGHT/2), Green); // v line, text | console
 
+  gdispFillArea(0, 0, SCR_MENU_W, (SCR_HEIGHT/2), Blue); // menu area
   /* print menu to top-left area */
   show_MenuItem(MenuItem_1);
-  show_MenuItem(MenuItem_2);
-  show_MenuItem(MenuItem_3);
-  show_MenuItem(MenuItem_4);
+//  show_MenuItem(MenuItem_2);
+//  show_MenuItem(MenuItem_3);
+//  show_MenuItem(MenuItem_4);
+
+  /* clear bootom area */
+  gdispFillArea(0, SCR_HEIGHT/2, SCR_WIDTH, SCR_HEIGHT, Black); // graphic area
 
-  /* clear bootom area. 1,123-319,239 - measure area. 1,213-310,239 - status line */
-  gdispFillStringBox(1, 123, 318, 115, " ", font2, Red, Gray, gJustifyLeft);
-  gdispFillStringBox(1, 213, 318, 29, "Stop", font2, Red, Silver, gJustifyCenter);
+  /*. 0,123-319,239 - measure area. 0,213-310,239 - status line */
+  //gdispFillStringBox(0, 120, SCR_WIDTH-1, 115, " ", font2, Red, Gray, gJustifyLeft);
+  //gdispFillStringBox(0, 213, SCR_WIDTH-1, 29, "Stop", font2, Red, Silver, gJustifyCenter);
 
   /* create the console window */
   {
@@ -668,7 +686,7 @@ static void prepare_Screen(void) {
 
     gwinClearInit(&wi);
     wi.show = gTrue;
-    wi.x = 82; wi.y = 2; wi.width = 239; wi.height = 120;
+    wi.x = SCR_MENU_W; wi.y = 0; wi.width = SCR_CON_W; wi.height = SCR_CON_H;
     GW1 = gwinConsoleCreate(0, &wi);
   }
 
@@ -829,11 +847,13 @@ static void show_MenuItem(const int item) {
   char buf1[16] = {0};
   char buf2[16] = {0};
   int tmp;
-  coord_t y1=0, y2=0;
-  static const coord_t x=1, cx=78, cy=15;
+//  coord_t y1=0, y2=0;
+  static const coord_t x=0, cx=MENU_LINE_W, cy=MENU_LINE_H;
   static const justify_t j1 = gJustifyLeft;
-  justify_t j2 = gJustifyLeft;
+  static const justify_t j2 = gJustifyCenter;
   color_t fgc, bgc;
+  static const coord_t y1 = MENU_LINE_1;
+  static const coord_t y2 = MENU_LINE_2;
 
   if (item == menu_Active) {
     fgc = menu_Colors.activeFG;
@@ -849,26 +869,24 @@ static void show_MenuItem(const int item) {
     chsnprintf(buf1, 10, "[1] ch.%u", tmp);
     chsnprintf(buf2, 12, "%2uA", charger_Channels[charger_Channel].max_current/1000);
 
-    y1 = 1;
-    y2 = 16;
-    j2 = gJustifyCenter;
+//    y1 = MENU_LINE_1;
+//    y2 = MENU_LINE_2;
     break;
   
   case MenuItem_2:
     chsnprintf(buf1, 10, "[2] %s", Profile[charger_Profile].Chemistry);
     tmp = Profile[charger_Profile].Capacity_mAh / 1000;
-    chsnprintf(buf2, 12, "%s/%uAh", Profile[charger_Profile].VoltageNominal, tmp);
+    chsnprintf(buf2, 12, "%s/%uAH", Profile[charger_Profile].VoltageNominal, tmp);
 
-    y1 = 31;
-    y2 = 46;
-    j2 = gJustifyCenter;
+//    y1 = MENU_LINE_3;
+//    y2 = MENU_LINE_4;
     break;
 
   case MenuItem_3:
-    chsnprintf(buf1, 12, "[3] show ch");
-    chsnprintf(buf2, 12, "dech results");
-    y1 = 61;
-    y2 = 76;
+    chsnprintf(buf1, 12, "[3] show");
+    chsnprintf(buf2, 12, "results");
+//    y1 = MENU_LINE_5;
+//    y2 = MENU_LINE_6;
     break;
 
   case MenuItem_4:
@@ -877,9 +895,9 @@ static void show_MenuItem(const int item) {
     } else {
       chsnprintf(buf1, 12, "[4] Stop");
     }
-    //chsnprintf(buf2, 12, "          ");
-    y1 = 91;
-    y2 = 106;
+//    chsnprintf(buf2, 12, "[ - / - / - ]");
+//    y1 = MENU_LINE_7;
+//    y2 = MENU_LINE_8;
     break;
 
   default:
@@ -887,7 +905,6 @@ static void show_MenuItem(const int item) {
   }
 
   gdispFillStringBox(x, y1, cx, cy, buf1, font1, fgc, bgc, j1);
-//  gdispFillStringBox(x, y2, cx, cy, buf2, font1, fgc, bgc, j2);
   gdispFillStringBox(x, y2, cx, cy, buf2, font1, menu_Colors.inactiveFG, menu_Colors.inactiveBG, j2);
 }