瀏覽代碼

Fixed menu. New graph

Vladimir N. Shilov 1 天之前
父節點
當前提交
7deec1eb30
共有 2 個文件被更改,包括 42 次插入109 次删除
  1. 26 92
      src/graph.c
  2. 16 17
      src/main.c

+ 26 - 92
src/graph.c

@@ -1,118 +1,52 @@
-/*
- * https://wiki.ugfx.io/index.php/Graph
- *
- * Copyright (c) 2012, 2013, Joel Bodenmann aka Tectu <joel@unormal.org>
- * Copyright (c) 2012, 2013, Andrew Hannam aka inmarket
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *    * Redistributions of source code must retain the above copyright
- *      notice, this list of conditions and the following disclaimer.
- *    * Redistributions in binary form must reproduce the above copyright
- *      notice, this list of conditions and the following disclaimer in the
- *      documentation and/or other materials provided with the distribution.
- *    * Neither the name of the <organization> nor the
- *      names of its contributors may be used to endorse or promote products
- *      derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
 #include "gfx.h"
-#include "math.h"
 
 // window
-#define WINDOW_X    1
-#define WINDOW_Y    123
-#define WINDOW_W    318
-#define WINDOW_H    218
+#define WINDOW_X    0
+#define WINDOW_Y    120
+#define WINDOW_W    320
+#define WINDOW_H    240
+
+#define COLOUR_BG   HTML2COLOR(0x202020)
+#define COLOUR_1    GFX_BLUE
+#define COLOUR_2    GFX_RED
 
 #define MIN_U       0
 #define MIN_I       0
 #define MAX_U       15000
 #define MAX_I       5000
 
+static gCoord pos_X;
+
 // from Arduino
 static long map(long x, long in_min, long in_max, long out_min, long out_max) {
       return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
 }
 
-// A graph styling
-static GGraphStyle GraphStyle1 = {
-    { GGRAPH_POINT_DOT, 4, GFX_BLUE },          // Point
-    { GGRAPH_LINE_NONE, 2, GFX_GRAY },          // Line
-    { GGRAPH_LINE_NONE, 0, GFX_WHITE },        // X axis
-    { GGRAPH_LINE_NONE, 0, GFX_WHITE },        // Y axis
-    { GGRAPH_LINE_DOT, 5, GFX_GRAY, 25 },      // X grid
-    { GGRAPH_LINE_DOT, 5, GFX_YELLOW, 25 },     // Y grid
-    GWIN_GRAPH_STYLE_ALL_AXIS_ARROWS	// Flags
-};
-
-static GHandle gh;
-static gCoord pos_X, win_H, win_W;
-
 void graph_Init(void) {
-    // Create the graph window
-    {
-        GWindowInit wi;
- 
-        wi.show = gTrue;
-        wi.x = WINDOW_X;
-        wi.y = WINDOW_Y;
-        wi.width = WINDOW_W;
-        wi.height = WINDOW_H;
-        gh = gwinGraphCreate(0, &wi);
-    }
-
-    win_H = gwinGetHeight(gh);
-    win_W = gwinGetWidth(gh);
-
     // clear area
-    gdispFillArea(WINDOW_X, WINDOW_Y, WINDOW_W, WINDOW_H, GFX_BLACK);
-    //gwinFillArea(gh, 0, 0, win_W, win_H);
-
-    // Set the graph origin and style
-    gwinGraphSetOrigin(gh, 0, 0);
-    gwinGraphSetStyle(gh, &GraphStyle1);
-    gwinGraphDrawAxis(gh);
+    gdispFillArea(WINDOW_X, WINDOW_Y, WINDOW_W, (WINDOW_H-WINDOW_Y), COLOUR_BG);
 
     pos_X = 0;
 }
 
 void graph_Draw(uint32_t u_value, uint32_t i_value) {
-    gCoord pos_Y;
-
-    // Modify the style
-    gwinGraphStartSet(gh);
-    GraphStyle1.point.color = GFX_BLUE;
-    gwinGraphSetStyle(gh, &GraphStyle1);
-
-    // Draw voltage point
-    pos_Y = map(u_value, MIN_U, MAX_U, 0, win_H);
-    gwinGraphDrawPoint(gh, pos_X, pos_Y);
-
-    // Modify the style
-    gwinGraphStartSet(gh);
-    GraphStyle1.point.color = GFX_RED;
-    gwinGraphSetStyle(gh, &GraphStyle1);
-
-    // Draw current point
-    pos_Y = map(i_value, MIN_I, MAX_I, 0, win_H);
-    gwinGraphDrawPoint(gh, pos_X, pos_Y);
+    gCoord u = map(u_value, MIN_U, MAX_U, WINDOW_H-1, WINDOW_Y);
+    gCoord i = map(i_value, MIN_I, MAX_I, WINDOW_H-1, WINDOW_Y);
+
+    // cleear col
+    gdispDrawLine(pos_X, WINDOW_H, pos_X, WINDOW_Y, COLOUR_BG);
+
+    // draw new values
+    if (u < i) {
+        gdispDrawLine(pos_X, WINDOW_H-1, pos_X, i, COLOUR_2);
+        gdispDrawLine(pos_X, i+1, pos_X, u, COLOUR_1);
+    } else {
+        gdispDrawLine(pos_X, WINDOW_H-1, pos_X, u, COLOUR_1);
+        gdispDrawLine(pos_X, u+1, pos_X, i, COLOUR_2);
+    }
 
     pos_X ++;
-    if (pos_X >= win_W) {
+    if (pos_X >= WINDOW_W) {
         pos_X = 0;
     }
 }

+ 16 - 17
src/main.c

@@ -29,8 +29,8 @@
 #define INA_SCAN_PERIOS_US    62500
 #define INA_AVG_FACTOR        16
 
-#define CHRGR_PAUSE1_S        300
-#define CHRGR_PAUSE2_S        300
+#define CHRGR_PAUSE1_S        60
+#define CHRGR_PAUSE2_S        60
 
 #define INA_ALL_VALUSE        EVENT_MASK(0)
 #define INA_BUS_VALUES        EVENT_MASK(1)
@@ -431,24 +431,22 @@ int main(void) {
       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);
-      */
+      gdispFillStringBox(0, MENU_LINE_5, MENU_LINE_W, MENU_LINE_H, buf, font2, Red, Gray, gJustifyLeft);
 
       tmp0 = (Capacity_I + 1800) / 3600;
       tmp1 = tmp0 / 1000;
       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);
+      gdispFillStringBox(0, MENU_LINE_6, MENU_LINE_W, MENU_LINE_H, buf, font2, Red, Gray, gJustifyLeft);
 
       tmp0 = (Capacity_P + 1800) / 3600;
       tmp1 = tmp0 / 1000;
       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);
+      gdispFillStringBox(0, MENU_LINE_7, MENU_LINE_W, MENU_LINE_H, buf, font2, Red, Gray, gJustifyLeft);
 
       graph_Draw(Voltage, Current);
 
@@ -505,7 +503,7 @@ int main(void) {
           gwinPrintf(GW1, "No Battery detected / Low voltage...\n");
           charger_State = Stop;
           show_MenuItem(MenuItem_4);
-          gdispFillStringBox(0, MENU_LINE_8, MENU_LINE_W, MENU_LINE_H, "Stop", font2, Red, Silver, gJustifyCenter);
+          gdispFillStringBox(0, MENU_LINE_2, MENU_LINE_W, MENU_LINE_H, "Stop", font2, Red, Silver, gJustifyCenter);
           break;
         }
         oldState = Charge1;
@@ -517,7 +515,7 @@ int main(void) {
         gwinPrintf(GW1, "Begin process: Charge_1\n");
 
         palClearLine(LINE_RELAY1);  // power relay on
-        gdispFillStringBox(0, MENU_LINE_8, MENU_LINE_W, MENU_LINE_H, "Charge 1", font2, Red, Silver, gJustifyCenter);
+        gdispFillStringBox(0, MENU_LINE_2, MENU_LINE_W, MENU_LINE_H, "Charge 1", font2, Red, Silver, gJustifyCenter);
         break;
 
       case Pause1:
@@ -541,7 +539,7 @@ int main(void) {
 
         gwinPrintf(GW1, "Pause after Charge_1\n");
 
-        gdispFillStringBox(0, MENU_LINE_8, MENU_LINE_W, MENU_LINE_H, "Pause 1", font2, Red, Silver, gJustifyCenter);
+        gdispFillStringBox(0, MENU_LINE_2, 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;
 
@@ -555,7 +553,7 @@ int main(void) {
         gwinPrintf(GW1, "Begin process: Decharge\n");
         
         palClearLine(LINE_RELAY2);  // load relay on
-        gdispFillStringBox(0, MENU_LINE_8, MENU_LINE_W, MENU_LINE_H, "Decharge", font2, Red, Silver, gJustifyCenter);
+        gdispFillStringBox(0, MENU_LINE_2, MENU_LINE_W, MENU_LINE_H, "Decharge", font2, Red, Silver, gJustifyCenter);
         break;
 
       case Pause2:
@@ -582,7 +580,7 @@ int main(void) {
         gwinPrintf(GW1, "/%2u.%02u\n", tmp1, tmp2);
 
         gwinPrintf(GW1, "Pause after Decharge\n");
-        gdispFillStringBox(0, MENU_LINE_8, MENU_LINE_W, MENU_LINE_H, "Pause 2", font2, Red, Silver, gJustifyCenter);
+        gdispFillStringBox(0, MENU_LINE_2, 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;
@@ -597,7 +595,7 @@ int main(void) {
         gwinPrintf(GW1, "Begin process: Charge_2\n");
 
         palClearLine(LINE_RELAY1);  // power relay on
-        gdispFillStringBox(0, MENU_LINE_8, MENU_LINE_W, MENU_LINE_H, "Charge 2", font2, Red, Silver, gJustifyCenter);
+        gdispFillStringBox(0, MENU_LINE_2, MENU_LINE_W, MENU_LINE_H, "Charge 2", font2, Red, Silver, gJustifyCenter);
         break;
       
       case Error:
@@ -606,7 +604,7 @@ int main(void) {
         palSetLine(LINE_RELAY1);
         palSetLine(LINE_RELAY2);
         gwinPrintf(GW1, "ERROR\n");
-        gdispFillStringBox(0, MENU_LINE_8, MENU_LINE_W, MENU_LINE_H, "Error", font2, Silver, Red, gJustifyCenter);
+        gdispFillStringBox(0, MENU_LINE_2, MENU_LINE_W, MENU_LINE_H, "Error", font2, Silver, Red, gJustifyCenter);
         break;
 
       default:
@@ -632,14 +630,14 @@ int main(void) {
         palSetLine(LINE_RELAY1);
         palSetLine(LINE_RELAY2);
         gwinPrintf(GW1, "STOP\n");
-        gdispFillStringBox(0, MENU_LINE_8, MENU_LINE_W, MENU_LINE_H, "Stop", font2, Red, Silver, gJustifyCenter);
+        gdispFillStringBox(0, MENU_LINE_2, 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(0, MENU_LINE_7, MENU_LINE_W, MENU_LINE_H, buf, font2, Red, Gray, gJustifyLeft);
+      gdispFillStringBox(0, MENU_LINE_8, MENU_LINE_W, MENU_LINE_H, buf, font2, Red, Gray, gJustifyLeft);
     }
 
     if (events & INSERTED_EVENT) {
@@ -659,7 +657,8 @@ static void prepare_Screen(void) {
   /* Set some fonts */
   font1 = gdispOpenFont("DejaVu Sans Book 12");
   //font2 = gdispOpenFont("DejaVu Sans Book 24");
-  font2 = gdispOpenFont("DejaVuSans10");
+  font2 = font1;
+  //gdispOpenFont("DejaVuSans10");
   gwinSetDefaultFont(font1);
 
   /* draw screen frame */