Kaynağa Gözat

Very simple graph.

Vladimir N. Shilov 3 gün önce
ebeveyn
işleme
57916ab344
3 değiştirilmiş dosya ile 55 ekleme ve 48 silme
  1. 3 4
      Makefile
  2. 19 15
      src/graph.c
  3. 33 29
      src/main.c

+ 3 - 4
Makefile

@@ -55,13 +55,13 @@ endif
 # Stack size to be allocated to the Cortex-M process stack. This stack is
 # the stack used by the main() thread.
 ifeq ($(USE_PROCESS_STACKSIZE),)
-  USE_PROCESS_STACKSIZE = 0x800
+  USE_PROCESS_STACKSIZE = 0x400
 endif
 
 # Stack size to the allocated to the Cortex-M main/exceptions stack. This
 # stack is used for processing interrupts and exceptions.
 ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
-  USE_EXCEPTIONS_STACKSIZE = 0x800
+  USE_EXCEPTIONS_STACKSIZE = 0x400
 endif
 
 # Enables the use of FPU (no, softfp, hard).
@@ -127,7 +127,6 @@ LDSCRIPT= $(STARTUPLD)/STM32F407xG.ld
 # setting.
 CSRC =	$(ALLCSRC) \
 	$(GFXSRC) \
-	$(FATFSSRC) \
 	src/graph.c \
 	src/buttons.c \
 	src/INA3221.c \
@@ -144,7 +143,7 @@ ASMSRC = $(ALLASMSRC)
 ASMXSRC = $(ALLXASMSRC)
 
 # Inclusion directories.
-INCDIR = $(CONFDIR) $(ALLINC) $(GFXINC) $(FATFSINC)
+INCDIR = $(CONFDIR) $(ALLINC) $(GFXINC)
 
 # Define C warning options here.
 CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes

+ 19 - 15
src/graph.c

@@ -36,7 +36,7 @@
 #define WINDOW_X    1
 #define WINDOW_Y    123
 #define WINDOW_W    318
-#define WINDOW_H    118
+#define WINDOW_H    218
 
 #define MIN_U       0
 #define MIN_I       0
@@ -50,17 +50,17 @@ static long map(long x, long in_min, long in_max, long out_min, long out_max) {
 
 // A graph styling
 static GGraphStyle GraphStyle1 = {
-    { GGRAPH_POINT_DOT, 0, GFX_BLUE },          // Point
+    { GGRAPH_POINT_DOT, 4, GFX_BLUE },          // Point
     { GGRAPH_LINE_NONE, 2, GFX_GRAY },          // Line
-    { GGRAPH_LINE_SOLID, 0, GFX_WHITE },        // X axis
-    { GGRAPH_LINE_SOLID, 0, GFX_WHITE },        // Y axis
-    { GGRAPH_LINE_DASH, 5, GFX_GRAY, 50 },      // X grid
-    { GGRAPH_LINE_DOT, 7, GFX_YELLOW, 50 },     // Y grid
-    GWIN_GRAPH_STYLE_POSITIVE_AXIS_ARROWS		// Flags
+    { 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;
+static gCoord pos_X, win_H, win_W;
 
 void graph_Init(void) {
     // Create the graph window
@@ -75,15 +75,19 @@ void graph_Init(void) {
         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, gwinGetWidth(gh)/2, gwinGetHeight(gh)/2);
+    gwinGraphSetOrigin(gh, 0, 0);
     gwinGraphSetStyle(gh, &GraphStyle1);
     gwinGraphDrawAxis(gh);
 
-    pos_X = WINDOW_X;
+    pos_X = 0;
 }
 
 void graph_Draw(uint32_t u_value, uint32_t i_value) {
@@ -91,11 +95,11 @@ void graph_Draw(uint32_t u_value, uint32_t i_value) {
 
     // Modify the style
     gwinGraphStartSet(gh);
-    GraphStyle1.point.color = GFX_GREEN;
+    GraphStyle1.point.color = GFX_BLUE;
     gwinGraphSetStyle(gh, &GraphStyle1);
 
     // Draw voltage point
-    pos_Y = map(u_value, MIN_U, MAX_U, WINDOW_Y, WINDOW_H);
+    pos_Y = map(u_value, MIN_U, MAX_U, 0, win_H);
     gwinGraphDrawPoint(gh, pos_X, pos_Y);
 
     // Modify the style
@@ -104,11 +108,11 @@ void graph_Draw(uint32_t u_value, uint32_t i_value) {
     gwinGraphSetStyle(gh, &GraphStyle1);
 
     // Draw current point
-    pos_Y = map(i_value, MIN_I, MAX_I, WINDOW_Y, WINDOW_H);
+    pos_Y = map(i_value, MIN_I, MAX_I, 0, win_H);
     gwinGraphDrawPoint(gh, pos_X, pos_Y);
 
     pos_X ++;
-    if (pos_X >= WINDOW_W) {
-        pos_X = WINDOW_X;
+    if (pos_X >= win_W) {
+        pos_X = 0;
     }
 }

+ 33 - 29
src/main.c

@@ -687,36 +687,40 @@ static void prepare_Screen(void) {
  * @brief Select next menu item
  */
 static void btn1_handler(button_state_t state) {
-  if (state == BTN_st_Pressed) {
-    switch (menu_Active) {
-    case MenuItem_1:
-      menu_Active = MenuItem_2;
-      show_MenuItem(MenuItem_1);
-      show_MenuItem(MenuItem_2);
-      break;
-    
-    case MenuItem_2:
-      menu_Active = MenuItem_3;
-      show_MenuItem(MenuItem_2);
-      show_MenuItem(MenuItem_3);
-      break;
-    
-    case MenuItem_3:
-      menu_Active = MenuItem_4;
-      show_MenuItem(MenuItem_3);
-      show_MenuItem(MenuItem_4);
-      break;
-    
-    case MenuItem_4:
-      menu_Active = MenuItem_1;
-      show_MenuItem(MenuItem_4);
-      show_MenuItem(MenuItem_1);
-      break;
-    
-    default:
-      menu_Active = MenuItem_1;
-      break;
+  if (charger_State == Stop) {
+    if (state == BTN_st_Pressed) {
+      switch (menu_Active) {
+      case MenuItem_1:
+        menu_Active = MenuItem_2;
+        show_MenuItem(MenuItem_1);
+        show_MenuItem(MenuItem_2);
+        break;
+      
+      case MenuItem_2:
+        menu_Active = MenuItem_3;
+        show_MenuItem(MenuItem_2);
+        show_MenuItem(MenuItem_3);
+        break;
+      
+      case MenuItem_3:
+        menu_Active = MenuItem_4;
+        show_MenuItem(MenuItem_3);
+        show_MenuItem(MenuItem_4);
+        break;
+      
+      case MenuItem_4:
+        menu_Active = MenuItem_1;
+        show_MenuItem(MenuItem_4);
+        show_MenuItem(MenuItem_1);
+        break;
+      
+      default:
+        menu_Active = MenuItem_1;
+        break;
+      }
     }
+  } else {
+    // switch between graph/values
   }
 }