Added code comments.

Fri, 01 Nov 2019 14:23:48 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 01 Nov 2019 14:23:48 +0100
changeset 19
4fb9ed228a23
parent 18
d969e0fe05dc
child 20
7c1dacafed03

Added code comments.

main/co2meter.c file | annotate | diff | comparison | revisions
--- a/main/co2meter.c	Fri Nov 01 13:13:14 2019 +0100
+++ b/main/co2meter.c	Fri Nov 01 14:23:48 2019 +0100
@@ -93,6 +93,9 @@
 
 
 
+/**
+ * @brief The splash screen shown during cold boot or user wakeup.
+ */
 void screen_splash()
 {
     screen_top("CO2 meter %s", app_desc->version);
@@ -107,6 +110,9 @@
 
 
 
+/**
+ * @brief The main overview screen.
+ */
 void screen_main()
 {
     char	buf[65];
@@ -135,6 +141,10 @@
 
 
 
+/**
+ * @brief The unit display screen.
+ * @param no The unit index number.
+ */
 void screen_unit(int no)
 {
     char        buf[65];
@@ -160,19 +170,29 @@
 
 
 
+/**
+ * @brief The unit zero setup screen.
+ * @param no The unit index number.
+ * @param sub The submenu index number.
+ */
 void screen_unit_zero(int no, int sub)
 {
     screen_top("Unit %d zero mV", 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);
 }
 
 
 
+/**
+ * @brief The unit setup screen.
+ * @param no The unit index number.
+ * @param sub The submenu index number.
+ */
 void screen_unit_setup(int no, int sub)
 {
     screen_top("Unit %d setup", no + 1);
@@ -180,13 +200,17 @@
     menu_line(sub == 1, 2, 37, "Zero mV %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);
 }
 
 
 
+/**
+ * @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);
@@ -198,8 +222,8 @@
 
 
 
-/*
- * Interrupt service routine for the rotary pushbutton.
+/**
+ * @brief Interrupt service routine for the rotary pushbutton.
  */
 static void IRAM_ATTR gpio_isr_handler(void* arg)
 {
@@ -209,8 +233,8 @@
 
 
 
-/*
- * GPIO queue task. See if there is a rotary pushbutton event in the queue.
+/**
+ * @brief GPIO queue task. See if there is a rotary pushbutton event on the queue.
  */
 static void gpio_task(void* arg)
 {
@@ -237,9 +261,11 @@
 
 
 
-/*
- * Select new menu number on a postitive or negative rotary position.
- * Then reset the rotary position.
+/**
+ * @brief Select new menu number on a postitive or negative rotary position.
+ * @param pos The new position, positive, negative or zero.
+ * @param next_menu The selected menu if rotated clockwise.
+ * @param prev_menu The selected menu if rotated counter-clockwise.
  */
 static void rotate_to_menu(rotary_encoder_position_t pos, int next_menu, int prev_menu)
 {
@@ -252,9 +278,18 @@
 
 
 
-int rotate_to_sub(rotary_encoder_position_t pos, int min, int max, int cursub)
+/**
+ * @brief Rotate subscreens numbers.
+ * @param pos The new position, positive, negative or zero.
+ * @param min The lowest number. If already at the lowest, select the highest.
+ * @param max The highest number. If already at the highest, select the lowest.
+ * @param cursub The subscreen number by reference. This is updated with the new number.
+ * @return Returns true if a new number is selected, false if nothing changed.
+ */
+bool rotate_to_sub(rotary_encoder_position_t pos, int min, int max, int *cursub)
 {
-   int	sub = cursub;
+   int	sub = *cursub;
+   bool	rc = false;
 
    if (pos > 0) {
 	if (sub < max)
@@ -262,17 +297,22 @@
 	else
 	    sub = min;
 	ESP_ERROR_CHECK(rotary_encoder_reset(&rinfo));
+	rc = true;
     } else if (pos < 0) {
 	if (sub > min)
 	    sub--;
 	else
 	    sub = max;
 	ESP_ERROR_CHECK(rotary_encoder_reset(&rinfo));
+	rc = true;
     }
-    return sub;
+
+    *cursub = sub;
+    return rc;
 }
 
 
+
 void app_main()
 {
     struct timeval	now;
@@ -640,7 +680,7 @@
 	    }
 
 	    /*
-	     * Main user processing. Handle the rotary encoder and pushbutton.
+	     * Handle rotationg the rotary encoder.
 	     */
 	    if (Main_Loop2 < ML2_INACTIVE) {
 		// If not configured, start configure
@@ -672,13 +712,13 @@
 		    	case ML2_UPDATE:	rotate_to_menu(event.state.position, ML2_UPDATE, ML2_SET_MQTT); break;
 			case ML2_SETUP_UNIT1:
 			case ML2_SETUP_UNIT2:
-			case ML2_SETUP_UNIT3:	sub = rotate_to_sub(event.state.position, 0, 3, sub);
-						screen_unit_setup(Main_Loop2 - ML2_SETUP_UNIT1, sub);
+			case ML2_SETUP_UNIT3:	if (rotate_to_sub(event.state.position, 0, 3, &sub))
+						    screen_unit_setup(Main_Loop2 - ML2_SETUP_UNIT1, sub);
 						break;
 			case ML2_ZERO_UNIT1:
 			case ML2_ZERO_UNIT2:
-			case ML2_ZERO_UNIT3:	sub = rotate_to_sub(event.state.position, 0, 1, sub);
-						screen_unit_zero(Main_Loop2 - ML2_ZERO_UNIT1, sub);
+			case ML2_ZERO_UNIT3:	if (rotate_to_sub(event.state.position, 0, 1, &sub))
+						    screen_unit_zero(Main_Loop2 - ML2_ZERO_UNIT1, sub);
 						break;
 			default:
 		    				ESP_LOGI(TAG, "Event: position %d, direction %s", event.state.position,

mercurial