Parcourir la source

Organize lcd output.

Vladimir N. Shilov il y a 1 an
Parent
commit
b0c58cbfdd
2 fichiers modifiés avec 25 ajouts et 18 suppressions
  1. 10 0
      lib/main.h
  2. 15 18
      main.c

+ 10 - 0
lib/main.h

@@ -10,6 +10,16 @@
 #define TOP_INFO_2_X  120
 #define TOP_INFO_2_Y  0
 
+#define LCD_LINE_1  23
+#define LCD_LINE_2  33
+#define LCD_LINE_3  43
+#define LCD_LINE_4  53
+#define LCD_LINE_5  63
+#define LCD_LINE_6  73
+#define LCD_LINE_7  83
+#define LCD_LINE_8  93
+#define LCD_LINE_9  103
+
 /* Private variables */
 
 /*

+ 15 - 18
main.c

@@ -70,7 +70,7 @@ int main(void) {
   /*
    * Creates the blinker thread.
    */
-  //chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
+  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
 
   /*
    * Buttons
@@ -89,30 +89,27 @@ int main(void) {
   /*
    * Normal main() thread activity.
    */
-  ST7735_WriteString(0, 20, "onewireTest...", LiberM_7x10, Blue, Black);
-  onewireTest();
+  ST7735_WriteString(0, LCD_LINE_1, "OneWire search...", LiberM_7x10, Blue, Black);
+  onewireMeasure();
   int32_t t;
   int n = onewireGetDevicesNum();
   chsnprintf(buf, 22, "Found %d device[s]", n);
-  ST7735_WriteString(0, 80, buf, LiberM_7x10, Cyan, Black);
-  if (n != 0) {
-    t = onewireGetTemperature(1);
-    chsnprintf(buf, 22, "    T = %d °C     ", t);
-    ST7735_WriteString(0, 20, buf, LiberM_7x10, Yellow, Black);
-  } else {
-    ST7735_WriteString(0, 20, "DS18B20 not found.", LiberM_7x10, Red, Black);
+  ST7735_WriteString(0, LCD_LINE_1, buf, LiberM_7x10, Cyan, Black);
+  chThdSleepMilliseconds(2000);
+  if (n == 0) {
+    ST7735_WriteString(0, LCD_LINE_1, "DS18B20 not found.", LiberM_7x10, Red, Black);
   }
 
   int a, b;
   while (true) {
-    chThdSleepMilliseconds(1000);
     if (n != 0) {
-      onewireTest();
-      t = onewireGetTemperature(1);
+      onewireMeasure();
+      t = onewireGetTemperature(0);
       a = t / 1000; b = t % 1000;
-      chsnprintf(buf, 22, "T = %d.%03u oC  ", a, b);
-      ST7735_WriteString(0, 40, buf, LiberM_7x10, Yellow, Black);
+      chsnprintf(buf, 22, "T = %d.%03u °C     ", a, b);
+      ST7735_WriteString(0, LCD_LINE_1, buf, LiberM_7x10, Yellow, Black);
     }
+    chThdSleepMilliseconds(1000);
   }
 }
 
@@ -130,9 +127,9 @@ int main(void) {
 static void lcd_MainScreen(void) {
   ST7735_FillScreen(Black);
 
-  ST7735_WriteString(47, 38, "Heater", Font_11x18, Yellow, Black);
-  ST7735_WriteString(52, 58, "Power", Font_11x18, Yellow, Black);
-  ST7735_WriteString(25, 78, "Stabilizer", Font_11x18, Yellow, Black);
+  ST7735_WriteString(47, LCD_LINE_2, "Heater", Font_11x18, Yellow, Black);
+  ST7735_WriteString(52, LCD_LINE_4, "Power", Font_11x18, Yellow, Black);
+  ST7735_WriteString(25, LCD_LINE_6, "Stabilizer", Font_11x18, Yellow, Black);
   chThdSleepMilliseconds(1000);
 
   /* top info line */