Better update of the user screens. Added more internal documentation.

Thu, 07 Nov 2019 11:47:15 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 07 Nov 2019 11:47:15 +0100
changeset 22
cceb36fd3a2a
parent 21
043ae27633f8
child 23
58a328e91881

Better update of the user screens. Added more internal documentation.

main/co2meter.c file | annotate | diff | comparison | revisions
main/task_user.c file | annotate | diff | comparison | revisions
main/task_user.h file | annotate | diff | comparison | revisions
--- a/main/co2meter.c	Tue Nov 05 11:31:59 2019 +0100
+++ b/main/co2meter.c	Thu Nov 07 11:47:15 2019 +0100
@@ -186,8 +186,7 @@
 		case ML1_CONNECT:
                     if (ready_WiFi()) {
                         Main_Loop1 = ML1_MQTT_CONNECT;
-//			if (Main_Loop2 == ML2_WIFI)
-//			    screen_wifi();
+			user_refresh();
 		    }
                     break;
 
@@ -239,12 +238,6 @@
 			    write_units();
 			    xSemaphoreGive(xSemaphoreUnits);
 			    user_refresh();
-//			    switch (Main_Loop2) {
-//				case ML2_USER:	screen_main(); break;
-//				case ML2_UNIT1:	screen_unit(0); break;
-//				case ML2_UNIT2: screen_unit(1); break;
-//				case ML2_UNIT3: screen_unit(2); break;
-//			    }
 			}
 		    }
 		    break;
@@ -285,8 +278,7 @@
 		    if (! ready_WiFi()) {
 			ESP_LOGI(TAG, "Loop timer: Done %s", user_busy() ? "true":"false");
 			Main_Loop1 = ML1_DONE;
-//			if (Main_Loop2 == ML2_WIFI)
-//			    screen_wifi();
+			user_refresh();
 		    }
 		    break;
 
--- a/main/task_user.c	Tue Nov 05 11:31:59 2019 +0100
+++ b/main/task_user.c	Thu Nov 07 11:47:15 2019 +0100
@@ -38,7 +38,6 @@
 const int TASK_USER_COLD = BIT0;					///< System cold start
 const int TASK_USER_WAKEUP = BIT1;					///< System wakeup from deepsleep
 const int TASK_USER_BUSY = BIT2;					///< User interface is busy doing something.
-const int TASK_USER_REFRESH = BIT3;					///< Refresh measurement results
 
 
 
@@ -86,13 +85,6 @@
 
 
 
-void user_refresh()
-{
-    xEventGroupSetBits(xEventGroupUser, TASK_USER_REFRESH);
-}
-
-
-
 bool user_busy(void)
 {
     if (xEventGroupGetBits(xEventGroupUser) & TASK_USER_BUSY)
@@ -338,7 +330,6 @@
 	xSemaphoreGive(xSemaphoreUnits);
     }
     u8g2_SendBuffer(&u8g2);
-    u8g2_SetPowerSave(&u8g2, 0); // wake up display
 }
 
 
@@ -350,13 +341,11 @@
  */
 void screen_unit_zero(int no, int sub)
 {
-    screen_top("Unit %d zero mV", no + 1);
+    screen_top("Unit %d zeroset", no + 1);
     menu_line(       0, 2, 25, "Current   %d", units[no].pressure_zero);
     menu_line(sub == 0, 2, 37, "New value %d", units[no].pressure_voltage / (adc_state->Batt_voltage / 1000));
     menu_line(sub == 1, 2, 49, "Return");
-printf("current %d  p_voltage %d  batt %d\n", units[no].pressure_zero, units[no].pressure_voltage, adc_state->Batt_voltage);
     u8g2_SendBuffer(&u8g2);
-    u8g2_SetPowerSave(&u8g2, 0);
 }
 
 
@@ -370,11 +359,10 @@
 {
     screen_top("Unit %d setup", no + 1);
     menu_line(sub == 0, 2, 25, "Mode    %s", units[no].mode ? "ON":"OFF");
-    menu_line(sub == 1, 2, 37, "Zero mV %d", units[no].pressure_zero);
+    menu_line(sub == 1, 2, 37, "Zero    %d", units[no].pressure_zero);
     menu_line(sub == 2, 2, 49, "DS18B20 %s", units[no].temperature_rom_code);
     menu_line(sub == 3, 2, 61, "Return");
     u8g2_SendBuffer(&u8g2);
-    u8g2_SetPowerSave(&u8g2, 0);
 }
 
 
@@ -386,12 +374,11 @@
     screen_top("WiFi Status");
     snprintf(buf, 65, "SSID %s", wifi_state->STA_ssid);
     u8g2_DrawStr(&u8g2, 1, 28, buf);
-    snprintf(buf, 65, "Online %s", wifi_state->STA_online ? "Yes":"No");
+    snprintf(buf, 65, "RSSI %d", wifi_state->STA_rssi);
     u8g2_DrawStr(&u8g2, 1, 43, buf);
-    snprintf(buf, 65, "RSSI %d", wifi_state->STA_rssi);
+    snprintf(buf, 65, "Online %s", wifi_state->STA_online ? "Yes":"No");
     u8g2_DrawStr(&u8g2, 1, 59, buf);
     u8g2_SendBuffer(&u8g2);
-    u8g2_SetPowerSave(&u8g2, 0);
 }
 
 
@@ -404,7 +391,6 @@
     menu_line(sub == 2, 2, 49, "Delete");
     menu_line(sub == 3, 2, 61, "Return");
     u8g2_SendBuffer(&u8g2);
-    u8g2_SetPowerSave(&u8g2, 0);
 }
 
 
@@ -417,7 +403,6 @@
     menu_line(0, 1, 49, "GW   %s", wifi_state->STA_gw);
     menu_line(0, 1, 61, "Name %s", config.hostname);
     u8g2_SendBuffer(&u8g2);
-    u8g2_SetPowerSave(&u8g2, 0);
 }
 
 
@@ -429,7 +414,6 @@
     menu_line(0, 1, 37, "port %d", config.mqtt_port);
     menu_line(0, 1, 49, "user %s", config.mqtt_user);
     u8g2_SendBuffer(&u8g2);
-    u8g2_SetPowerSave(&u8g2, 0);
 }
 
 
@@ -439,23 +423,6 @@
     screen_top("Update firmware");
     menu_line(0, 1, 43, "Push to update");
     u8g2_SendBuffer(&u8g2);
-    u8g2_SetPowerSave(&u8g2, 0);
-}
-
-
-
-/**
- * @brief Fatal messages on the screen.
- * @param e1 The first line.
- * @param e2 The second line.
- */
-void screen_fatal(char *e1, char *e2)
-{
-    u8g2_SetFont(&u8g2, u8g2_font_t0_15_tr);
-    u8g2_DrawStr(&u8g2,2,12,e1);
-    u8g2_DrawStr(&u8g2,2,24,e2);
-    u8g2_SendBuffer(&u8g2);
-    u8g2_SetPowerSave(&u8g2, 0);
 }
 
 
@@ -663,6 +630,22 @@
 
 
 
+/*
+ * Refresh screens that are in focus. Called by the main measurement loop.
+ */
+void user_refresh(void)
+{
+    switch (Main_Loop2) {
+	case ML2_USER:  screen_main(); break;
+	case ML2_UNIT1: screen_unit(0); break;
+	case ML2_UNIT2: screen_unit(1); break;
+	case ML2_UNIT3: screen_unit(2); break;
+	case ML2_WIFI: screen_wifi(); break;
+    }
+}
+
+
+
 void menu_loop(void)
 {
     int idx = 0;
@@ -711,6 +694,7 @@
 			write_units();
 			xSemaphoreGive(xSemaphoreADC);
 			xSemaphoreGive(xSemaphoreUnits);
+			ESP_LOGI(TAG, "Zero set unit %d, %d mV set %d", idx, adc_state->Pressure[idx].voltage, units[idx].pressure_zero);
 			screen_unit_zero(idx, SubMenu);
 			if (Main_Loop1 == ML1_DONE)
 			    Main_Loop1 = ML1_INIT;
@@ -792,7 +776,6 @@
     assert(ret == ESP_OK);
 
     EventBits_t uxBits;
-    ESP_LOGI(TAG, "User task loop enter");
 
     /*
      * Task loop forever.
@@ -811,7 +794,6 @@
 	if (uxBits & TASK_USER_WAKEUP) {
 	    ESP_LOGI(TAG, "User task wakeup");
 	    xEventGroupSetBits(xEventGroupUser, TASK_USER_BUSY);
-	    xEventGroupClearBits(xEventGroupUser, TASK_USER_REFRESH);
 	    screen_main();
 	    UserTimer = INACTIVITY;
 	    New_Loop2 = ML2_INIT;
@@ -821,7 +803,7 @@
 	    while (UserTimer) {
 
 		menu_change();
-		if (xQueueReceive(event_queue, &event, 250 / portTICK_PERIOD_MS) == pdTRUE) {
+		if (xQueueReceive(event_queue, &event, 100 / portTICK_PERIOD_MS) == pdTRUE) {
 		    UserTimer = INACTIVITY;
 		    menu_rotary();
 		}
@@ -830,24 +812,10 @@
 		    PushDuration = 0;
 		    menu_loop();
 		}
-
-		if (xEventGroupGetBits(xEventGroupUser) & TASK_USER_REFRESH) {
-		    ESP_LOGI(TAG, "User task refresh");
-		    switch (Main_Loop2) {
-			case ML2_USER:  screen_main(); break;
-			case ML2_UNIT1: screen_unit(0); break;
-			case ML2_UNIT2: screen_unit(1); break;
-			case ML2_UNIT3: screen_unit(2); break;
-		    }
-		    xEventGroupClearBits(xEventGroupUser, TASK_USER_REFRESH);
-		}
-
-		vTaskDelay(10 / portTICK_PERIOD_MS);
 	    }
 
 	    xEventGroupClearBits(xEventGroupUser, TASK_USER_WAKEUP);
 	}
-	vTaskDelay(10 / portTICK_PERIOD_MS);
     }
 
 // If not configured, start configure
--- a/main/task_user.h	Tue Nov 05 11:31:59 2019 +0100
+++ b/main/task_user.h	Thu Nov 07 11:47:15 2019 +0100
@@ -1,6 +1,6 @@
 /**
  * @file task_user.h
- * @brief The FreeRTOS task to maintain MQTT connections.
+ * @brief The FreeRTOS task to run the user interface.
  */
 
 #ifndef	_TASK_USER_H
@@ -20,9 +20,28 @@
 
 
 
+/**
+ * @brief Called after a power on or hard reset.
+ */
 void user_cold(void);
+
+
+/**
+ * @brief Called after wakeup by the user.
+ */
 void user_wakeup(void);
+
+
+/**
+ * @brief Refresh screens that are in focus.
+ */
 void user_refresh(void);
+
+
+/**
+ * @brief Test is user interface is busy and active
+ * @return Returns true if the user interface is active, false otherwise.
+ */
 bool user_busy(void);
 
 

mercurial