19 int SubOffset = 0; ///< Submenu offset |
19 int SubOffset = 0; ///< Submenu offset |
20 u8g2_t u8g2; ///< A structure which will contain all the data for one display |
20 u8g2_t u8g2; ///< A structure which will contain all the data for one display |
21 rotary_encoder_info_t rinfo = { 0 }; ///< Rotary encoder record |
21 rotary_encoder_info_t rinfo = { 0 }; ///< Rotary encoder record |
22 rotary_encoder_event_t event = { 0 }; ///< Rotary encoder events |
22 rotary_encoder_event_t event = { 0 }; ///< Rotary encoder events |
23 QueueHandle_t event_queue; ///< Events queue |
23 QueueHandle_t event_queue; ///< Events queue |
24 static xQueueHandle gpio_evt_queue = NULL; ///< Rotary pushbutton queue |
24 QueueHandle_t gpio_evt_queue = NULL; ///< Rotary pushbutton queue |
25 static int PushDuration = 0; ///< Duration of the pushed button |
25 static int PushDuration = 0; ///< Duration of the pushed button |
26 struct strStations APs[10]; ///< List of APs we know |
26 wifiStation_t APs[10]; ///< List of APs we know |
27 int edit_ssid = 0; ///< SSID being edited |
27 int edit_ssid = 0; ///< SSID being edited |
28 int num_ssids = 0; ///< Number of SSIDs we know |
28 int num_ssids = 0; ///< Number of SSIDs we know |
29 struct strStations editAP; ///< Data of station to edit |
29 wifiStation_t editAP; ///< Data of station to edit |
30 char sensors[DS18B20_MAX][17]; ///< Sensors to select |
30 char sensors[DS18B20_MAX][17]; ///< Sensors to select |
31 uint32_t err_connect = 0; ///< Connect error count |
31 uint32_t err_connect = 0; ///< Connect error count |
32 uint32_t err_alarm = 0; ///< Alarm watchdog error count |
32 uint32_t err_alarm = 0; ///< Alarm watchdog error count |
33 uint32_t err_temp = 0; ///< DS18B20 read errors |
33 uint32_t err_temp = 0; ///< DS18B20 read errors |
34 |
34 |
43 extern SemaphoreHandle_t xSemaphoreWiFi; ///< WiFi lock semaphore |
43 extern SemaphoreHandle_t xSemaphoreWiFi; ///< WiFi lock semaphore |
44 extern int count_pub; ///< Published MQTT messages in transit |
44 extern int count_pub; ///< Published MQTT messages in transit |
45 extern int Main_Loop1; ///< Main measure loop |
45 extern int Main_Loop1; ///< Main measure loop |
46 extern int update_running; ///< If update is running |
46 extern int update_running; ///< If update is running |
47 extern int num_sensors; ///< Detected DS18B20 sensors |
47 extern int num_sensors; ///< Detected DS18B20 sensors |
|
48 extern strConfig_t config; |
|
49 extern wifiStation_t wifiStation; |
48 |
50 |
49 const int TASK_USER_COLD = BIT0; ///< System cold start |
51 const int TASK_USER_COLD = BIT0; ///< System cold start |
50 const int TASK_USER_WAKEUP = BIT1; ///< System wakeup from deepsleep |
52 const int TASK_USER_WAKEUP = BIT1; ///< System wakeup from deepsleep |
51 const int TASK_USER_BUSY = BIT2; ///< User interface is busy doing something. |
53 const int TASK_USER_BUSY = BIT2; ///< User interface is busy doing something. |
52 const int TASK_USER_REFRESH = BIT3; ///< Refresh requested |
54 const int TASK_USER_REFRESH = BIT3; ///< Refresh requested |
548 * @param offset The offset in the list. |
550 * @param offset The offset in the list. |
549 */ |
551 */ |
550 void screen_list_aps(int sub, int offset) |
552 void screen_list_aps(int sub, int offset) |
551 { |
553 { |
552 int i; |
554 int i; |
553 struct strStations ap; |
555 wifiStation_t ap; |
554 uint8_t *dst = (uint8_t *)≈ |
556 uint8_t *dst = (uint8_t *)≈ |
555 FILE *f; |
557 FILE *f; |
556 size_t bytes; |
558 size_t bytes; |
557 |
559 |
558 num_ssids = 0; |
560 num_ssids = 0; |
559 memset(dst, 0, sizeof(ap)); |
561 memset(dst, 0, sizeof(ap)); |
560 f = fopen("/spiffs/etc/stations.conf", "r+"); |
562 f = fopen("/spiffs/stations.conf", "r"); |
561 if (f) { |
563 if (f) { |
562 while (1) { |
564 while (1) { |
563 bytes = fread(dst, 1, sizeof(ap), f); |
565 bytes = fread(dst, 1, sizeof(ap), f); |
564 if (bytes < sizeof(ap)) { |
566 if (bytes < sizeof(ap)) { |
565 fclose(f); |
567 fclose(f); |
715 void screen_counters() |
717 void screen_counters() |
716 { |
718 { |
717 char buf[65]; |
719 char buf[65]; |
718 |
720 |
719 screen_top("Software fouten"); |
721 screen_top("Software fouten"); |
720 snprintf(buf, 64, "Network %4d", err_connect); |
722 snprintf(buf, 64, "Network %4lu", err_connect); |
721 u8g2_DrawStr(&u8g2, 1, 28, buf); |
723 u8g2_DrawStr(&u8g2, 1, 28, buf); |
722 snprintf(buf, 64, "Watchdog %4d", err_alarm); |
724 snprintf(buf, 64, "Watchdog %4lu", err_alarm); |
723 u8g2_DrawStr(&u8g2, 1, 43, buf); |
725 u8g2_DrawStr(&u8g2, 1, 43, buf); |
724 snprintf(buf, 64, "DS18B20 %4d", err_temp); |
726 snprintf(buf, 64, "DS18B20 %4lu", err_temp); |
725 u8g2_DrawStr(&u8g2, 1, 59, buf); |
727 u8g2_DrawStr(&u8g2, 1, 59, buf); |
726 u8g2_SendBuffer(&u8g2); |
728 u8g2_SendBuffer(&u8g2); |
727 } |
729 } |
728 |
730 |
729 |
731 |
759 if (! user_busy()) { |
761 if (! user_busy()) { |
760 xEventGroupSetBits(xEventGroupUser, TASK_USER_WAKEUP); |
762 xEventGroupSetBits(xEventGroupUser, TASK_USER_WAKEUP); |
761 } |
763 } |
762 } |
764 } |
763 } else { |
765 } else { |
764 ESP_LOGE(TAG, "GPIO[%d] unknown intr, val: %d", io_num, gpio_get_level(io_num)); |
766 ESP_LOGE(TAG, "GPIO[%lu] unknown intr, val: %d", io_num, gpio_get_level(io_num)); |
765 } |
767 } |
766 UserTimer = INACTIVITY; |
768 UserTimer = INACTIVITY; |
767 } |
769 } |
768 } |
770 } |
769 } |
771 } |
1008 break; |
1010 break; |
1009 case ML2_SETUP_NETWORK: if (rotate_to_sub(event.state.position, 2, &SubMenu, &SubOffset)) |
1011 case ML2_SETUP_NETWORK: if (rotate_to_sub(event.state.position, 2, &SubMenu, &SubOffset)) |
1010 screen_network_setup(SubMenu); |
1012 screen_network_setup(SubMenu); |
1011 break; |
1013 break; |
1012 default: |
1014 default: |
1013 ESP_LOGI(TAG, "Event: position %d, direction %s", event.state.position, |
1015 ESP_LOGI(TAG, "Event: position %ld, direction %s", event.state.position, |
1014 event.state.direction ? (event.state.direction == ROTARY_ENCODER_DIRECTION_CLOCKWISE ? "CW":"CCW"):"NOT_SET"); |
1016 event.state.direction ? (event.state.direction == ROTARY_ENCODER_DIRECTION_CLOCKWISE ? "CW":"CCW"):"NOT_SET"); |
1015 } |
1017 } |
1016 } |
1018 } |
1017 |
1019 |
1018 |
1020 |
1077 if (SubMenu == 0) { |
1079 if (SubMenu == 0) { |
1078 if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE && xSemaphoreTake(xSemaphoreADC, 10) == pdTRUE) { |
1080 if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE && xSemaphoreTake(xSemaphoreADC, 10) == pdTRUE) { |
1079 if (adc_state->Pressure[idx].voltage > 165 && adc_state->Pressure[idx].voltage < 660) { |
1081 if (adc_state->Pressure[idx].voltage > 165 && adc_state->Pressure[idx].voltage < 660) { |
1080 units[idx].pressure_zero = adc_state->Pressure[idx].voltage / (adc_state->Batt_voltage / 1000); |
1082 units[idx].pressure_zero = adc_state->Pressure[idx].voltage / (adc_state->Batt_voltage / 1000); |
1081 write_units(); |
1083 write_units(); |
1082 ESP_LOGI(TAG, "Zero set unit %d, %d mV set %d", idx, adc_state->Pressure[idx].voltage, units[idx].pressure_zero); |
1084 ESP_LOGI(TAG, "Zero set unit %d, %lu mV set %lu", idx, adc_state->Pressure[idx].voltage, units[idx].pressure_zero); |
1083 } |
1085 } |
1084 xSemaphoreGive(xSemaphoreADC); |
1086 xSemaphoreGive(xSemaphoreADC); |
1085 xSemaphoreGive(xSemaphoreUnits); |
1087 xSemaphoreGive(xSemaphoreUnits); |
1086 screen_unit_zero(idx, SubMenu); |
1088 screen_unit_zero(idx, SubMenu); |
1087 if (Main_Loop1 == ML1_DONE) |
1089 if (Main_Loop1 == ML1_DONE) |
1148 SubMenu = SubOffset = 0; |
1150 SubMenu = SubOffset = 0; |
1149 } |
1151 } |
1150 break; |
1152 break; |
1151 |
1153 |
1152 case ML2_EDIT_AP: |
1154 case ML2_EDIT_AP: |
|
1155 ESP_LOGI(TAG, " ML2_EDIT_AP: SubMenu %d edit_ssid %d", SubMenu, edit_ssid); |
1153 if (SubMenu == 0) { |
1156 if (SubMenu == 0) { |
1154 rotary_editer("SSID", editAP.SSID, "", 16, EDIT_TYPE_TEXT); |
1157 rotary_editer("SSID", editAP.SSID, "", 16, EDIT_TYPE_TEXT); |
1155 screen_edit_ap(SubMenu); |
1158 screen_edit_ap(SubMenu); |
1156 } else if (SubMenu == 1) { |
1159 } else if (SubMenu == 1) { |
1157 rotary_editer("PSK", editAP.Password, "", 16, EDIT_TYPE_TEXT); |
1160 rotary_editer("PSK", editAP.Password, "", 16, EDIT_TYPE_TEXT); |
1158 screen_edit_ap(SubMenu); |
1161 screen_edit_ap(SubMenu); |
1159 } else if (SubMenu == 2 || SubMenu == 3) { |
1162 } else if (SubMenu == 2 || SubMenu == 3) { |
1160 update_running = 1; // Block measurements |
1163 update_running = 1; // Block measurements |
1161 int timeout = 600; |
|
1162 if (edit_ssid < 0) |
1164 if (edit_ssid < 0) |
1163 New_Loop2 = ML2_SETUP_WIFI; |
1165 New_Loop2 = ML2_SETUP_WIFI; |
1164 else |
1166 else |
1165 New_Loop2 = ML2_LIST_APS; |
1167 New_Loop2 = ML2_LIST_APS; |
1166 |
1168 |
1167 for (;;) { |
|
1168 vTaskDelay(100 / portTICK_PERIOD_MS); |
|
1169 if (Main_Loop1 == ML1_DONE) |
|
1170 break; |
|
1171 if (timeout) |
|
1172 timeout--; |
|
1173 else { |
|
1174 ESP_LOGE(TAG, "Timout request stop"); |
|
1175 goto saveerr; |
|
1176 } |
|
1177 } |
|
1178 if (edit_ssid >= 0) { |
1169 if (edit_ssid >= 0) { |
1179 ESP_LOGI(TAG, "Remove %s", APs[edit_ssid].SSID); |
1170 ESP_LOGI(TAG, "Remove %s", APs[edit_ssid].SSID); |
1180 remove_station((uint8_t *)APs[edit_ssid].SSID); |
1171 remove_station((uint8_t *)APs[edit_ssid].SSID); |
1181 } |
1172 } |
1182 if (SubMenu == 2) { |
1173 if (SubMenu == 2) { |
1183 ESP_LOGI(TAG, "Add %s %s", editAP.SSID, editAP.Password); |
1174 ESP_LOGI(TAG, "Add %s %s", editAP.SSID, editAP.Password); |
1184 add_station((uint8_t *)editAP.SSID, (uint8_t *)editAP.Password); |
1175 add_station((uint8_t *)editAP.SSID, (uint8_t *)editAP.Password); |
1185 } |
1176 } |
1186 } |
1177 } |
1187 saveerr: |
|
1188 update_running = 0; |
1178 update_running = 0; |
1189 break; |
1179 break; |
1190 |
1180 |
1191 case ML2_NETWORK: |
1181 case ML2_NETWORK: |
1192 New_Loop2 = ML2_SETUP_NETWORK; |
1182 New_Loop2 = ML2_SETUP_NETWORK; |
1270 ESP_ERROR_CHECK(gpio_install_isr_service(0)); |
1260 ESP_ERROR_CHECK(gpio_install_isr_service(0)); |
1271 ESP_ERROR_CHECK(rotary_encoder_init(&rinfo, ROT_ENC_A_GPIO, ROT_ENC_B_GPIO)); |
1261 ESP_ERROR_CHECK(rotary_encoder_init(&rinfo, ROT_ENC_A_GPIO, ROT_ENC_B_GPIO)); |
1272 ESP_ERROR_CHECK(rotary_encoder_enable_half_steps(&rinfo, false)); |
1262 ESP_ERROR_CHECK(rotary_encoder_enable_half_steps(&rinfo, false)); |
1273 |
1263 |
1274 gpio_config_t io_conf; |
1264 gpio_config_t io_conf; |
1275 io_conf.intr_type = GPIO_PIN_INTR_ANYEDGE; |
1265 io_conf.intr_type = GPIO_INTR_ANYEDGE; |
1276 io_conf.pin_bit_mask = (1ULL << ROT_ENC_SW_GPIO); |
1266 io_conf.pin_bit_mask = (1ULL << ROT_ENC_SW_GPIO); |
1277 io_conf.mode = GPIO_MODE_INPUT; |
1267 io_conf.mode = GPIO_MODE_INPUT; |
1278 gpio_config(&io_conf); |
1268 gpio_config(&io_conf); |
1279 |
1269 |
1280 gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t)); |
1270 gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t)); |