36 |
36 |
37 |
37 |
38 const int TASK_USER_COLD = BIT0; ///< System cold start |
38 const int TASK_USER_COLD = BIT0; ///< System cold start |
39 const int TASK_USER_WAKEUP = BIT1; ///< System wakeup from deepsleep |
39 const int TASK_USER_WAKEUP = BIT1; ///< System wakeup from deepsleep |
40 const int TASK_USER_BUSY = BIT2; ///< User interface is busy doing something. |
40 const int TASK_USER_BUSY = BIT2; ///< User interface is busy doing something. |
41 const int TASK_USER_REFRESH = BIT3; ///< Refresh measurement results |
|
42 |
41 |
43 |
42 |
44 |
43 |
45 /** |
44 /** |
46 * @brief Seconds timer callback. |
45 * @brief Seconds timer callback. |
348 * @param no The unit index number. |
339 * @param no The unit index number. |
349 * @param sub The submenu index number. |
340 * @param sub The submenu index number. |
350 */ |
341 */ |
351 void screen_unit_zero(int no, int sub) |
342 void screen_unit_zero(int no, int sub) |
352 { |
343 { |
353 screen_top("Unit %d zero mV", no + 1); |
344 screen_top("Unit %d zeroset", no + 1); |
354 menu_line( 0, 2, 25, "Current %d", units[no].pressure_zero); |
345 menu_line( 0, 2, 25, "Current %d", units[no].pressure_zero); |
355 menu_line(sub == 0, 2, 37, "New value %d", units[no].pressure_voltage / (adc_state->Batt_voltage / 1000)); |
346 menu_line(sub == 0, 2, 37, "New value %d", units[no].pressure_voltage / (adc_state->Batt_voltage / 1000)); |
356 menu_line(sub == 1, 2, 49, "Return"); |
347 menu_line(sub == 1, 2, 49, "Return"); |
357 printf("current %d p_voltage %d batt %d\n", units[no].pressure_zero, units[no].pressure_voltage, adc_state->Batt_voltage); |
348 u8g2_SendBuffer(&u8g2); |
358 u8g2_SendBuffer(&u8g2); |
|
359 u8g2_SetPowerSave(&u8g2, 0); |
|
360 } |
349 } |
361 |
350 |
362 |
351 |
363 |
352 |
364 /** |
353 /** |
368 */ |
357 */ |
369 void screen_unit_setup(int no, int sub) |
358 void screen_unit_setup(int no, int sub) |
370 { |
359 { |
371 screen_top("Unit %d setup", no + 1); |
360 screen_top("Unit %d setup", no + 1); |
372 menu_line(sub == 0, 2, 25, "Mode %s", units[no].mode ? "ON":"OFF"); |
361 menu_line(sub == 0, 2, 25, "Mode %s", units[no].mode ? "ON":"OFF"); |
373 menu_line(sub == 1, 2, 37, "Zero mV %d", units[no].pressure_zero); |
362 menu_line(sub == 1, 2, 37, "Zero %d", units[no].pressure_zero); |
374 menu_line(sub == 2, 2, 49, "DS18B20 %s", units[no].temperature_rom_code); |
363 menu_line(sub == 2, 2, 49, "DS18B20 %s", units[no].temperature_rom_code); |
375 menu_line(sub == 3, 2, 61, "Return"); |
364 menu_line(sub == 3, 2, 61, "Return"); |
376 u8g2_SendBuffer(&u8g2); |
365 u8g2_SendBuffer(&u8g2); |
377 u8g2_SetPowerSave(&u8g2, 0); |
|
378 } |
366 } |
379 |
367 |
380 |
368 |
381 |
369 |
382 void screen_wifi() |
370 void screen_wifi() |
384 char buf[65]; |
372 char buf[65]; |
385 |
373 |
386 screen_top("WiFi Status"); |
374 screen_top("WiFi Status"); |
387 snprintf(buf, 65, "SSID %s", wifi_state->STA_ssid); |
375 snprintf(buf, 65, "SSID %s", wifi_state->STA_ssid); |
388 u8g2_DrawStr(&u8g2, 1, 28, buf); |
376 u8g2_DrawStr(&u8g2, 1, 28, buf); |
|
377 snprintf(buf, 65, "RSSI %d", wifi_state->STA_rssi); |
|
378 u8g2_DrawStr(&u8g2, 1, 43, buf); |
389 snprintf(buf, 65, "Online %s", wifi_state->STA_online ? "Yes":"No"); |
379 snprintf(buf, 65, "Online %s", wifi_state->STA_online ? "Yes":"No"); |
390 u8g2_DrawStr(&u8g2, 1, 43, buf); |
|
391 snprintf(buf, 65, "RSSI %d", wifi_state->STA_rssi); |
|
392 u8g2_DrawStr(&u8g2, 1, 59, buf); |
380 u8g2_DrawStr(&u8g2, 1, 59, buf); |
393 u8g2_SendBuffer(&u8g2); |
381 u8g2_SendBuffer(&u8g2); |
394 u8g2_SetPowerSave(&u8g2, 0); |
|
395 } |
382 } |
396 |
383 |
397 |
384 |
398 |
385 |
399 void screen_wifi_setup(int sub) |
386 void screen_wifi_setup(int sub) |
402 menu_line(sub == 0, 2, 25, "Connect"); |
389 menu_line(sub == 0, 2, 25, "Connect"); |
403 menu_line(sub == 1, 2, 37, "New"); |
390 menu_line(sub == 1, 2, 37, "New"); |
404 menu_line(sub == 2, 2, 49, "Delete"); |
391 menu_line(sub == 2, 2, 49, "Delete"); |
405 menu_line(sub == 3, 2, 61, "Return"); |
392 menu_line(sub == 3, 2, 61, "Return"); |
406 u8g2_SendBuffer(&u8g2); |
393 u8g2_SendBuffer(&u8g2); |
407 u8g2_SetPowerSave(&u8g2, 0); |
|
408 } |
394 } |
409 |
395 |
410 |
396 |
411 |
397 |
412 void screen_network() |
398 void screen_network() |
415 menu_line(0, 1, 25, "IP %s", wifi_state->STA_ip); |
401 menu_line(0, 1, 25, "IP %s", wifi_state->STA_ip); |
416 menu_line(0, 1, 37, "Mask %s", wifi_state->STA_nm); |
402 menu_line(0, 1, 37, "Mask %s", wifi_state->STA_nm); |
417 menu_line(0, 1, 49, "GW %s", wifi_state->STA_gw); |
403 menu_line(0, 1, 49, "GW %s", wifi_state->STA_gw); |
418 menu_line(0, 1, 61, "Name %s", config.hostname); |
404 menu_line(0, 1, 61, "Name %s", config.hostname); |
419 u8g2_SendBuffer(&u8g2); |
405 u8g2_SendBuffer(&u8g2); |
420 u8g2_SetPowerSave(&u8g2, 0); |
|
421 } |
406 } |
422 |
407 |
423 |
408 |
424 |
409 |
425 void screen_mqtt() |
410 void screen_mqtt() |
427 screen_top("MQTT Status"); |
412 screen_top("MQTT Status"); |
428 menu_line(0, 1, 25, "serv %s", config.mqtt_server); |
413 menu_line(0, 1, 25, "serv %s", config.mqtt_server); |
429 menu_line(0, 1, 37, "port %d", config.mqtt_port); |
414 menu_line(0, 1, 37, "port %d", config.mqtt_port); |
430 menu_line(0, 1, 49, "user %s", config.mqtt_user); |
415 menu_line(0, 1, 49, "user %s", config.mqtt_user); |
431 u8g2_SendBuffer(&u8g2); |
416 u8g2_SendBuffer(&u8g2); |
432 u8g2_SetPowerSave(&u8g2, 0); |
|
433 } |
417 } |
434 |
418 |
435 |
419 |
436 |
420 |
437 void screen_update() |
421 void screen_update() |
438 { |
422 { |
439 screen_top("Update firmware"); |
423 screen_top("Update firmware"); |
440 menu_line(0, 1, 43, "Push to update"); |
424 menu_line(0, 1, 43, "Push to update"); |
441 u8g2_SendBuffer(&u8g2); |
425 u8g2_SendBuffer(&u8g2); |
442 u8g2_SetPowerSave(&u8g2, 0); |
|
443 } |
|
444 |
|
445 |
|
446 |
|
447 /** |
|
448 * @brief Fatal messages on the screen. |
|
449 * @param e1 The first line. |
|
450 * @param e2 The second line. |
|
451 */ |
|
452 void screen_fatal(char *e1, char *e2) |
|
453 { |
|
454 u8g2_SetFont(&u8g2, u8g2_font_t0_15_tr); |
|
455 u8g2_DrawStr(&u8g2,2,12,e1); |
|
456 u8g2_DrawStr(&u8g2,2,24,e2); |
|
457 u8g2_SendBuffer(&u8g2); |
|
458 u8g2_SetPowerSave(&u8g2, 0); |
|
459 } |
426 } |
460 |
427 |
461 |
428 |
462 |
429 |
463 /** |
430 /** |
656 screen_unit_zero(Main_Loop2 - ML2_ZERO_UNIT1, SubMenu); |
623 screen_unit_zero(Main_Loop2 - ML2_ZERO_UNIT1, SubMenu); |
657 break; |
624 break; |
658 default: |
625 default: |
659 ESP_LOGI(TAG, "Event: position %d, direction %s", event.state.position, |
626 ESP_LOGI(TAG, "Event: position %d, direction %s", event.state.position, |
660 event.state.direction ? (event.state.direction == ROTARY_ENCODER_DIRECTION_CLOCKWISE ? "CW":"CCW"):"NOT_SET"); |
627 event.state.direction ? (event.state.direction == ROTARY_ENCODER_DIRECTION_CLOCKWISE ? "CW":"CCW"):"NOT_SET"); |
|
628 } |
|
629 } |
|
630 |
|
631 |
|
632 |
|
633 /* |
|
634 * Refresh screens that are in focus. Called by the main measurement loop. |
|
635 */ |
|
636 void user_refresh(void) |
|
637 { |
|
638 switch (Main_Loop2) { |
|
639 case ML2_USER: screen_main(); break; |
|
640 case ML2_UNIT1: screen_unit(0); break; |
|
641 case ML2_UNIT2: screen_unit(1); break; |
|
642 case ML2_UNIT3: screen_unit(2); break; |
|
643 case ML2_WIFI: screen_wifi(); break; |
661 } |
644 } |
662 } |
645 } |
663 |
646 |
664 |
647 |
665 |
648 |
709 adc_state->Pressure[idx].voltage < 660) { |
692 adc_state->Pressure[idx].voltage < 660) { |
710 units[idx].pressure_zero = adc_state->Pressure[idx].voltage / (adc_state->Batt_voltage / 1000); |
693 units[idx].pressure_zero = adc_state->Pressure[idx].voltage / (adc_state->Batt_voltage / 1000); |
711 write_units(); |
694 write_units(); |
712 xSemaphoreGive(xSemaphoreADC); |
695 xSemaphoreGive(xSemaphoreADC); |
713 xSemaphoreGive(xSemaphoreUnits); |
696 xSemaphoreGive(xSemaphoreUnits); |
|
697 ESP_LOGI(TAG, "Zero set unit %d, %d mV set %d", idx, adc_state->Pressure[idx].voltage, units[idx].pressure_zero); |
714 screen_unit_zero(idx, SubMenu); |
698 screen_unit_zero(idx, SubMenu); |
715 if (Main_Loop1 == ML1_DONE) |
699 if (Main_Loop1 == ML1_DONE) |
716 Main_Loop1 = ML1_INIT; |
700 Main_Loop1 = ML1_INIT; |
717 } |
701 } |
718 } |
702 } |
809 } |
792 } |
810 |
793 |
811 if (uxBits & TASK_USER_WAKEUP) { |
794 if (uxBits & TASK_USER_WAKEUP) { |
812 ESP_LOGI(TAG, "User task wakeup"); |
795 ESP_LOGI(TAG, "User task wakeup"); |
813 xEventGroupSetBits(xEventGroupUser, TASK_USER_BUSY); |
796 xEventGroupSetBits(xEventGroupUser, TASK_USER_BUSY); |
814 xEventGroupClearBits(xEventGroupUser, TASK_USER_REFRESH); |
|
815 screen_main(); |
797 screen_main(); |
816 UserTimer = INACTIVITY; |
798 UserTimer = INACTIVITY; |
817 New_Loop2 = ML2_INIT; |
799 New_Loop2 = ML2_INIT; |
818 Main_Loop2 = -1; |
800 Main_Loop2 = -1; |
819 SubMenu = 0; |
801 SubMenu = 0; |
820 |
802 |
821 while (UserTimer) { |
803 while (UserTimer) { |
822 |
804 |
823 menu_change(); |
805 menu_change(); |
824 if (xQueueReceive(event_queue, &event, 250 / portTICK_PERIOD_MS) == pdTRUE) { |
806 if (xQueueReceive(event_queue, &event, 100 / portTICK_PERIOD_MS) == pdTRUE) { |
825 UserTimer = INACTIVITY; |
807 UserTimer = INACTIVITY; |
826 menu_rotary(); |
808 menu_rotary(); |
827 } |
809 } |
828 |
810 |
829 if (PushDuration) { |
811 if (PushDuration) { |
830 PushDuration = 0; |
812 PushDuration = 0; |
831 menu_loop(); |
813 menu_loop(); |
832 } |
814 } |
833 |
|
834 if (xEventGroupGetBits(xEventGroupUser) & TASK_USER_REFRESH) { |
|
835 ESP_LOGI(TAG, "User task refresh"); |
|
836 switch (Main_Loop2) { |
|
837 case ML2_USER: screen_main(); break; |
|
838 case ML2_UNIT1: screen_unit(0); break; |
|
839 case ML2_UNIT2: screen_unit(1); break; |
|
840 case ML2_UNIT3: screen_unit(2); break; |
|
841 } |
|
842 xEventGroupClearBits(xEventGroupUser, TASK_USER_REFRESH); |
|
843 } |
|
844 |
|
845 vTaskDelay(10 / portTICK_PERIOD_MS); |
|
846 } |
815 } |
847 |
816 |
848 xEventGroupClearBits(xEventGroupUser, TASK_USER_WAKEUP); |
817 xEventGroupClearBits(xEventGroupUser, TASK_USER_WAKEUP); |
849 } |
818 } |
850 vTaskDelay(10 / portTICK_PERIOD_MS); |
|
851 } |
819 } |
852 |
820 |
853 // If not configured, start configure |
821 // If not configured, start configure |
854 // If configured select first unit |
822 // If configured select first unit |
855 // Handle screen (first is show measured values) |
823 // Handle screen (first is show measured values) |