16 int New_Loop2 = ML2_INIT; ///< New menu |
16 int New_Loop2 = ML2_INIT; ///< New menu |
17 int SubMenu = 0; ///< Submenu number |
17 int SubMenu = 0; ///< Submenu number |
18 int SubOffset = 0; ///< Submenu offset |
18 int SubOffset = 0; ///< Submenu offset |
19 u8g2_t u8g2; ///< A structure which will contain all the data for one display |
19 u8g2_t u8g2; ///< A structure which will contain all the data for one display |
20 rotary_encoder_info_t rinfo = { 0 }; ///< Rotary encoder record |
20 rotary_encoder_info_t rinfo = { 0 }; ///< Rotary encoder record |
21 rotary_encoder_event_t event = { 0 }; |
21 rotary_encoder_event_t event = { 0 }; ///< Rotary encoder events |
22 QueueHandle_t event_queue; |
22 QueueHandle_t event_queue; ///< Events queue |
23 static xQueueHandle gpio_evt_queue = NULL; ///< Rotary pushbutton queue |
23 static xQueueHandle gpio_evt_queue = NULL; ///< Rotary pushbutton queue |
24 static int PushDuration = 0; ///< Duration of the pushed button |
24 static int PushDuration = 0; ///< Duration of the pushed button |
25 struct strStations APs[10]; ///< List of APs we know |
25 struct strStations APs[10]; ///< List of APs we know |
26 int edit_ssid = 0; ///< SSID being edited |
26 int edit_ssid = 0; ///< SSID being edited |
27 int num_ssids = 0; ///< Number of SSIDs we know |
27 int num_ssids = 0; ///< Number of SSIDs we know |
28 struct strStations editAP; ///< Data of station to edit |
28 struct strStations editAP; ///< Data of station to edit |
29 char sensors[DS18B20_MAX][17]; ///< Sensors to select |
29 char sensors[DS18B20_MAX][17]; ///< Sensors to select |
30 |
30 |
31 extern const esp_app_desc_t *app_desc; |
31 extern const esp_app_desc_t *app_desc; ///< App description |
32 extern unit_t units[3]; ///< Pressure test units |
32 extern unit_t units[3]; ///< Pressure test units |
33 extern SemaphoreHandle_t xSemaphoreUnits; ///< Units lock semaphore |
33 extern SemaphoreHandle_t xSemaphoreUnits; ///< Units lock semaphore |
34 extern DS18B20_State *ds18b20_state; ///< DS18B20 state |
34 extern DS18B20_State *ds18b20_state; ///< DS18B20 state |
35 extern SemaphoreHandle_t xSemaphoreDS18B20; ///< DS18B20 lock semaphore |
35 extern SemaphoreHandle_t xSemaphoreDS18B20; ///< DS18B20 lock semaphore |
36 extern ADC_State *adc_state; ///< ADC state |
36 extern ADC_State *adc_state; ///< ADC state |
421 u8g2_SendBuffer(&u8g2); |
421 u8g2_SendBuffer(&u8g2); |
422 } |
422 } |
423 |
423 |
424 |
424 |
425 |
425 |
|
426 /** |
|
427 * @brief The list of detected DS18B20 sensors. |
|
428 * @param no The unit index number. |
|
429 * @param sub The submenu index number. |
|
430 * @param offset The offset in the list. |
|
431 */ |
|
432 |
426 void screen_list_sensors(int no, int sub, int offset) |
433 void screen_list_sensors(int no, int sub, int offset) |
427 { |
434 { |
428 int i; |
435 int i; |
429 |
436 |
430 if (xSemaphoreTake(xSemaphoreDS18B20, 10) == pdTRUE) { |
437 if (xSemaphoreTake(xSemaphoreDS18B20, 10) == pdTRUE) { |
495 u8g2_SendBuffer(&u8g2); |
505 u8g2_SendBuffer(&u8g2); |
496 } |
506 } |
497 |
507 |
498 |
508 |
499 |
509 |
|
510 /** |
|
511 * @brief The WiFi setup menu. |
|
512 * @param sub The submenu entry to hilite. |
|
513 */ |
500 void screen_wifi_setup(int sub) |
514 void screen_wifi_setup(int sub) |
501 { |
515 { |
502 screen_top("WiFi AP setup"); |
516 screen_top("WiFi AP setup"); |
503 menu_line(sub == 0, 1, 25, "Lijst AP"); |
517 menu_line(sub == 0, 1, 25, "Lijst AP"); |
504 menu_line(sub == 1, 1, 37, "Nieuw AP"); |
518 menu_line(sub == 1, 1, 37, "Nieuw AP"); |
506 u8g2_SendBuffer(&u8g2); |
520 u8g2_SendBuffer(&u8g2); |
507 } |
521 } |
508 |
522 |
509 |
523 |
510 |
524 |
|
525 /** |
|
526 * @brief Show the list if WiFi Access Points. |
|
527 * @param sub The sub entry line. |
|
528 * @param offset The offset in the list. |
|
529 */ |
511 void screen_list_aps(int sub, int offset) |
530 void screen_list_aps(int sub, int offset) |
512 { |
531 { |
513 int i; |
532 int i; |
514 struct strStations ap; |
533 struct strStations ap; |
515 uint8_t *dst = (uint8_t *)≈ |
534 uint8_t *dst = (uint8_t *)≈ |
529 memcpy(APs[num_ssids].SSID, ap.SSID, 32); |
548 memcpy(APs[num_ssids].SSID, ap.SSID, 32); |
530 memcpy(APs[num_ssids].Password, ap.Password, 64); |
549 memcpy(APs[num_ssids].Password, ap.Password, 64); |
531 num_ssids++; |
550 num_ssids++; |
532 } |
551 } |
533 } |
552 } |
534 //printf("loaded %d SSIDs sub %d offset %d\n", num_ssids, sub, offset); |
|
535 |
553 |
536 screen_top("WiFi AP lijst"); |
554 screen_top("WiFi AP lijst"); |
537 if (num_ssids == 0) { |
555 if (num_ssids == 0) { |
538 menu_line(0, 1, 25, "Geen AP's"); |
556 menu_line(0, 1, 25, "Geen AP's"); |
539 } else { |
557 } else { |
548 u8g2_SendBuffer(&u8g2); |
566 u8g2_SendBuffer(&u8g2); |
549 } |
567 } |
550 |
568 |
551 |
569 |
552 |
570 |
|
571 /** |
|
572 * @brief Edit WiFi AP menu. |
|
573 * @param sub The menu entry to hilite. |
|
574 */ |
553 void screen_edit_ap(int sub) |
575 void screen_edit_ap(int sub) |
554 { |
576 { |
555 screen_top("WiFi wijzig AP"); |
577 screen_top("WiFi wijzig AP"); |
556 menu_line(sub == 0, 1, 25, "SSID %s", editAP.SSID); |
578 menu_line(sub == 0, 1, 25, "SSID %s", editAP.SSID); |
557 menu_line(sub == 1, 1, 37, "PSK %s", editAP.Password); |
579 menu_line(sub == 1, 1, 37, "PSK %s", editAP.Password); |
562 u8g2_SendBuffer(&u8g2); |
584 u8g2_SendBuffer(&u8g2); |
563 } |
585 } |
564 |
586 |
565 |
587 |
566 |
588 |
|
589 /** |
|
590 * @brief The network status screen. |
|
591 */ |
567 void screen_network() |
592 void screen_network() |
568 { |
593 { |
569 char ip[17], nm[17], gw[17]; |
594 char ip[17], nm[17], gw[17]; |
570 |
595 |
571 if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) { |
596 if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) { |
585 u8g2_SendBuffer(&u8g2); |
610 u8g2_SendBuffer(&u8g2); |
586 } |
611 } |
587 |
612 |
588 |
613 |
589 |
614 |
|
615 /** |
|
616 * @brief The network setup menu. |
|
617 * @param sub The menu entry to hilite. |
|
618 */ |
590 void screen_network_setup(int sub) |
619 void screen_network_setup(int sub) |
591 { |
620 { |
592 screen_top("Netwerk setup"); |
621 screen_top("Netwerk setup"); |
593 menu_line(sub == 0, 1, 25, "Naam %s", config.hostname); |
622 menu_line(sub == 0, 1, 25, "Naam %s", config.hostname); |
594 menu_line(sub == 1, 1, 37, "NTP %s", config.ntp_server); |
623 menu_line(sub == 1, 1, 37, "NTP %s", config.ntp_server); |
596 u8g2_SendBuffer(&u8g2); |
625 u8g2_SendBuffer(&u8g2); |
597 } |
626 } |
598 |
627 |
599 |
628 |
600 |
629 |
|
630 /** |
|
631 * @brief MQTT status |
|
632 */ |
601 void screen_mqtt() |
633 void screen_mqtt() |
602 { |
634 { |
603 screen_top("MQTT Status"); |
635 screen_top("MQTT Status"); |
604 menu_line(0, 1, 25, "serv %s", config.mqtt_server); |
636 menu_line(0, 1, 25, "serv %s", config.mqtt_server); |
605 menu_line(0, 1, 37, "port %d", config.mqtt_port); |
637 menu_line(0, 1, 37, "port %d", config.mqtt_port); |
607 u8g2_SendBuffer(&u8g2); |
639 u8g2_SendBuffer(&u8g2); |
608 } |
640 } |
609 |
641 |
610 |
642 |
611 |
643 |
|
644 /** |
|
645 * @brief MQTT setup menu. |
|
646 * @param sub The submenu entry to hilite. |
|
647 */ |
612 void screen_mqtt_setup(int sub) |
648 void screen_mqtt_setup(int sub) |
613 { |
649 { |
614 screen_top("MQTT Setup"); |
650 screen_top("MQTT Setup"); |
615 menu_line(sub == 0, 1, 25, "serv %s", config.mqtt_server); |
651 menu_line(sub == 0, 1, 25, "serv %s", config.mqtt_server); |
616 menu_line(sub == 1, 1, 37, "port %d", config.mqtt_port); |
652 menu_line(sub == 1, 1, 37, "port %d", config.mqtt_port); |
619 u8g2_SendBuffer(&u8g2); |
655 u8g2_SendBuffer(&u8g2); |
620 } |
656 } |
621 |
657 |
622 |
658 |
623 |
659 |
|
660 /** |
|
661 * @brief The OTA update menu. |
|
662 */ |
624 void screen_update() |
663 void screen_update() |
625 { |
664 { |
626 screen_top("Update software"); |
665 screen_top("Update software"); |
627 menu_line(0, 1, 43, "Druk voor update"); |
666 menu_line(0, 1, 43, "Druk voor update"); |
628 u8g2_SendBuffer(&u8g2); |
667 u8g2_SendBuffer(&u8g2); |
629 } |
668 } |
630 |
669 |
631 |
670 |
632 |
671 |
|
672 /** |
|
673 * @brief The update status screen. |
|
674 * @param m1 The first message line or NULL. |
|
675 * @param m2 The second message line or NULL. |
|
676 */ |
633 void screen_updating(char *m1, char *m2) |
677 void screen_updating(char *m1, char *m2) |
634 { |
678 { |
635 screen_top("Bijwerken ..."); |
679 screen_top("Bijwerken ..."); |
636 u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols); |
680 u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols); |
637 if (m1) { |
681 if (m1) { |
766 ESP_LOGI(TAG, "Loop user: Init"); |
813 ESP_LOGI(TAG, "Loop user: Init"); |
767 New_Loop2 = ML2_USER; |
814 New_Loop2 = ML2_USER; |
768 break; |
815 break; |
769 |
816 |
770 case ML2_USER: |
817 case ML2_USER: |
771 ESP_LOGI(TAG, "Loop user: User mainmenu"); |
|
772 screen_main(); |
818 screen_main(); |
773 break; |
819 break; |
774 |
820 |
775 case ML2_UNIT1: |
821 case ML2_UNIT1: |
776 case ML2_UNIT2: |
822 case ML2_UNIT2: |
777 case ML2_UNIT3: |
823 case ML2_UNIT3: |
778 ESP_LOGI(TAG, "Loop user: Unit %d", Main_Loop2 - ML2_UNIT1); |
|
779 screen_unit(Main_Loop2 - ML2_UNIT1); |
824 screen_unit(Main_Loop2 - ML2_UNIT1); |
780 break; |
825 break; |
781 |
826 |
782 case ML2_WIFI: |
827 case ML2_WIFI: |
783 ESP_LOGI(TAG, "Loop user: WiFi"); |
|
784 screen_wifi(); |
828 screen_wifi(); |
785 break; |
829 break; |
786 |
830 |
787 case ML2_SETUP_WIFI: |
831 case ML2_SETUP_WIFI: |
788 ESP_LOGI(TAG, "Loop user: WiFi setup"); |
832 ESP_LOGI(TAG, "Loop user: WiFi setup"); |
799 ESP_LOGI(TAG, "Loop user: WiFi edit AP"); |
843 ESP_LOGI(TAG, "Loop user: WiFi edit AP"); |
800 screen_edit_ap(0); |
844 screen_edit_ap(0); |
801 break; |
845 break; |
802 |
846 |
803 case ML2_NETWORK: |
847 case ML2_NETWORK: |
804 ESP_LOGI(TAG, "Loop user: Network"); |
|
805 screen_network(); |
848 screen_network(); |
806 break; |
849 break; |
807 |
850 |
808 case ML2_SETUP_NETWORK: |
851 case ML2_SETUP_NETWORK: |
809 ESP_LOGI(TAG, "Loop user: Network setup"); |
852 ESP_LOGI(TAG, "Loop user: Network setup"); |
810 screen_network_setup(SubMenu); |
853 screen_network_setup(SubMenu); |
811 break; |
854 break; |
812 |
855 |
813 case ML2_MQTT: |
856 case ML2_MQTT: |
814 ESP_LOGI(TAG, "Loop user: MQTT"); |
|
815 screen_mqtt(); |
857 screen_mqtt(); |
816 break; |
858 break; |
817 |
859 |
818 case ML2_SETUP_MQTT: |
860 case ML2_SETUP_MQTT: |
819 ESP_LOGI(TAG, "Loop user: MQTT setup"); |
861 ESP_LOGI(TAG, "Loop user: MQTT setup"); |
820 screen_mqtt_setup(SubMenu); |
862 screen_mqtt_setup(SubMenu); |
821 break; |
863 break; |
822 |
864 |
823 case ML2_UPDATE: |
865 case ML2_UPDATE: |
824 ESP_LOGI(TAG, "Loop user: Update"); |
|
825 screen_update(); |
866 screen_update(); |
826 break; |
867 break; |
827 |
868 |
828 case ML2_SETUP_UNIT1: |
869 case ML2_SETUP_UNIT1: |
829 case ML2_SETUP_UNIT2: |
870 case ML2_SETUP_UNIT2: |
861 } |
902 } |
862 } |
903 } |
863 |
904 |
864 |
905 |
865 |
906 |
|
907 /** |
|
908 * @brief Handle rotary switch for menu navigation. |
|
909 */ |
866 void menu_rotary(void) |
910 void menu_rotary(void) |
867 { |
911 { |
868 switch (Main_Loop2) { |
912 switch (Main_Loop2) { |
869 case ML2_USER: rotate_to_menu(event.state.position, ML2_UNIT1, ML2_USER); break; |
913 case ML2_USER: rotate_to_menu(event.state.position, ML2_UNIT1, ML2_USER); break; |
870 case ML2_UNIT1: rotate_to_menu(event.state.position, ML2_UNIT2, ML2_USER); break; |
914 case ML2_UNIT1: rotate_to_menu(event.state.position, ML2_UNIT2, ML2_USER); break; |