main/task_user.c

changeset 30
8b630bf52092
parent 29
106464d4c727
child 32
7717ac1d2f7f
equal deleted inserted replaced
29:106464d4c727 30:8b630bf52092
36 extern int update_running; ///< If update is running 36 extern int update_running; ///< If update is running
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 41 const int TASK_USER_REFRESH = BIT3; ///< Refresh requested
42 42
43 43
44 /** 44 /**
45 * @brief Seconds timer callback. 45 * @brief Seconds timer callback.
46 */ 46 */
342 */ 342 */
343 void screen_main() 343 void screen_main()
344 { 344 {
345 char buf[65]; 345 char buf[65];
346 int i; 346 int i;
347 347 uint32_t temperature = 0, pressure[3];
348 screen_top("CO2 meter %s", app_desc->version);
349 348
350 if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE) { 349 if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE) {
351 350 temperature = units[0].temperature;
352 u8g2_SetFont(&u8g2, u8g2_font_t0_22b_tf);
353 sprintf(buf, "%.1f °C", units[0].temperature / 1000.0);
354 u8g2_uint_t w = u8g2_GetUTF8Width(&u8g2, buf);
355 u8g2_DrawUTF8(&u8g2, (128 - w) / 2,40, buf);
356 u8g2_SetFont(&u8g2, u8g2_font_t0_18b_tf);
357
358 for (i = 0; i < 3; i++) { 351 for (i = 0; i < 3; i++) {
359 sprintf(buf, "%.1f", units[i].pressure / 1000.0); 352 pressure[i] = units[i].pressure;
360 w = u8g2_GetUTF8Width(&u8g2, buf);
361 u8g2_DrawUTF8(&u8g2, ((42 - w) / 2) + i * 43,63, buf);
362 } 353 }
363 xSemaphoreGive(xSemaphoreUnits); 354 xSemaphoreGive(xSemaphoreUnits);
364 } else { 355 } else {
365 ESP_LOGE(TAG, "screen_main() lock error"); 356 ESP_LOGE(TAG, "screen_main() lock error");
366 } 357 }
358
359 screen_top("CO2 meter %s", app_desc->version);
360 u8g2_SetFont(&u8g2, u8g2_font_t0_22b_tf);
361 sprintf(buf, "%.1f °C", temperature / 1000.0);
362 u8g2_uint_t w = u8g2_GetUTF8Width(&u8g2, buf);
363 u8g2_DrawUTF8(&u8g2, (128 - w) / 2,40, buf);
364 u8g2_SetFont(&u8g2, u8g2_font_t0_18b_tf);
365
366 for (i = 0; i < 3; i++) {
367 sprintf(buf, "%.1f", pressure[i] / 1000.0);
368 w = u8g2_GetUTF8Width(&u8g2, buf);
369 u8g2_DrawUTF8(&u8g2, ((42 - w) / 2) + i * 43,63, buf);
370 }
371
367 u8g2_SendBuffer(&u8g2); 372 u8g2_SendBuffer(&u8g2);
368 u8g2_SetPowerSave(&u8g2, 0); // wake up display 373 u8g2_SetPowerSave(&u8g2, 0); // wake up display
369 } 374 }
370 375
371 376
375 * @param no The unit index number. 380 * @param no The unit index number.
376 */ 381 */
377 void screen_unit(int no) 382 void screen_unit(int no)
378 { 383 {
379 char buf[65]; 384 char buf[65];
385 int mode = 0;
386 uint32_t temperature = 0, pressure = 0;
380 387
381 if (xSemaphoreTake(xSemaphoreUnits, 35) == pdTRUE) { 388 if (xSemaphoreTake(xSemaphoreUnits, 35) == pdTRUE) {
382 389 mode = units[no].mode;
383 screen_top("Meter %d %s", no + 1, units[no].mode ? "Aan":"Uit"); 390 temperature = units[no].temperature;
384 391 pressure = units[no].pressure;
385 u8g2_SetFont(&u8g2, u8g2_font_t0_22b_tf);
386 sprintf(buf, "%.1f °C", units[no].temperature / 1000.0);
387 u8g2_uint_t w = u8g2_GetUTF8Width(&u8g2, buf);
388 u8g2_DrawUTF8(&u8g2, (128 - w) / 2,40, buf);
389
390 sprintf(buf, "%.2f bar", units[no].pressure / 1000.0);
391 w = u8g2_GetUTF8Width(&u8g2, buf);
392 u8g2_DrawUTF8(&u8g2, (128 - w) / 2,63, buf);
393 u8g2_SendBuffer(&u8g2);
394
395 xSemaphoreGive(xSemaphoreUnits); 392 xSemaphoreGive(xSemaphoreUnits);
396 } else { 393 } else {
397 ESP_LOGE(TAG, "screen_unit(%d) lock error", no); 394 ESP_LOGE(TAG, "screen_unit(%d) lock error", no);
398 } 395 }
396
397 screen_top("Meter %d %s", no + 1, mode ? "Aan":"Uit");
398
399 u8g2_SetFont(&u8g2, u8g2_font_t0_22b_tf);
400 sprintf(buf, "%.1f °C", temperature / 1000.0);
401 u8g2_uint_t w = u8g2_GetUTF8Width(&u8g2, buf);
402 u8g2_DrawUTF8(&u8g2, (128 - w) / 2,40, buf);
403
404 sprintf(buf, "%.2f bar", pressure / 1000.0);
405 w = u8g2_GetUTF8Width(&u8g2, buf);
406 u8g2_DrawUTF8(&u8g2, (128 - w) / 2,63, buf);
407 u8g2_SendBuffer(&u8g2);
399 } 408 }
400 409
401 410
402 411
403 /** 412 /**
434 443
435 444
436 void screen_wifi() 445 void screen_wifi()
437 { 446 {
438 char buf[65]; 447 char buf[65];
448 int8_t rssi = 0;
449 bool online = false;
439 450
440 if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) { 451 if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
441 screen_top("WiFi Status");
442 snprintf(buf, 65, "SSID %s", wifi_state->STA_ssid); 452 snprintf(buf, 65, "SSID %s", wifi_state->STA_ssid);
443 u8g2_DrawStr(&u8g2, 1, 28, buf); 453 rssi = wifi_state->STA_rssi;
444 snprintf(buf, 65, "RSSI %d", wifi_state->STA_rssi); 454 online = wifi_state->STA_online;
445 u8g2_DrawStr(&u8g2, 1, 43, buf);
446 snprintf(buf, 65, "Verbonden %s", wifi_state->STA_online ? "Ja":"Nee");
447 u8g2_DrawStr(&u8g2, 1, 59, buf);
448 u8g2_SendBuffer(&u8g2);
449 xSemaphoreGive(xSemaphoreWiFi); 455 xSemaphoreGive(xSemaphoreWiFi);
450 } else { 456 } else {
451 ESP_LOGE(TAG, "screen_wifi() lock error"); 457 ESP_LOGE(TAG, "screen_wifi() lock error");
452 } 458 }
459
460 screen_top("WiFi Status");
461 u8g2_DrawStr(&u8g2, 1, 28, buf);
462 snprintf(buf, 65, "RSSI %d", rssi);
463 u8g2_DrawStr(&u8g2, 1, 43, buf);
464 snprintf(buf, 65, "Verbonden %s", online ? "Ja":"Nee");
465 u8g2_DrawStr(&u8g2, 1, 59, buf);
466 u8g2_SendBuffer(&u8g2);
453 } 467 }
454 468
455 469
456 470
457 void screen_wifi_setup(int sub) 471 void screen_wifi_setup(int sub)
466 480
467 481
468 482
469 void screen_network() 483 void screen_network()
470 { 484 {
485 char ip[17], nm[17], gw[17];
486
471 if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) { 487 if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
472 screen_top("Netwerk Status"); 488 strcpy(ip, wifi_state->STA_ip);
473 menu_line(0, 1, 25, "IP %s", wifi_state->STA_ip); 489 strcpy(nm, wifi_state->STA_nm);
474 menu_line(0, 1, 37, "Mask %s", wifi_state->STA_nm); 490 strcpy(gw, wifi_state->STA_gw);
475 menu_line(0, 1, 49, "GW %s", wifi_state->STA_gw);
476 menu_line(0, 1, 61, "Naam %s", config.hostname);
477 u8g2_SendBuffer(&u8g2);
478 xSemaphoreGive(xSemaphoreWiFi); 491 xSemaphoreGive(xSemaphoreWiFi);
479 } else { 492 } else {
480 ESP_LOGE(TAG, "screen_network() lock error"); 493 ESP_LOGE(TAG, "screen_network() lock error");
481 } 494 }
495
496 screen_top("Netwerk Status");
497 menu_line(0, 1, 25, "IP %s", ip);
498 menu_line(0, 1, 37, "Mask %s", nm);
499 menu_line(0, 1, 49, "GW %s", gw);
500 menu_line(0, 1, 61, "Naam %s", config.hostname);
501 u8g2_SendBuffer(&u8g2);
482 } 502 }
483 503
484 504
485 505
486 void screen_network_setup(int sub) 506 void screen_network_setup(int sub)
753 /* 773 /*
754 * Refresh screens that are in focus. Called by the main measurement loop. 774 * Refresh screens that are in focus. Called by the main measurement loop.
755 */ 775 */
756 void user_refresh(void) 776 void user_refresh(void)
757 { 777 {
758 switch (Main_Loop2) { 778 if (UserTimer)
759 case ML2_USER: screen_main(); break; 779 xEventGroupSetBits(xEventGroupUser, TASK_USER_REFRESH);
760 case ML2_UNIT1: screen_unit(0); break;
761 case ML2_UNIT2: screen_unit(1); break;
762 case ML2_UNIT3: screen_unit(2); break;
763 case ML2_WIFI: screen_wifi(); break;
764 }
765 } 780 }
766 781
767 782
768 783
769 void menu_loop(void) 784 void menu_loop(void)
972 SubMenu = 0; 987 SubMenu = 0;
973 988
974 while (UserTimer) { 989 while (UserTimer) {
975 990
976 menu_change(); 991 menu_change();
992
993 if (xEventGroupGetBits(xEventGroupUser) & TASK_USER_REFRESH) {
994 switch (Main_Loop2) {
995 case ML2_USER: screen_main(); break;
996 case ML2_UNIT1: screen_unit(0); break;
997 case ML2_UNIT2: screen_unit(1); break;
998 case ML2_UNIT3: screen_unit(2); break;
999 case ML2_WIFI: screen_wifi(); break;
1000 }
1001 xEventGroupClearBits(xEventGroupUser, TASK_USER_REFRESH);
1002 }
1003
977 if (xQueueReceive(event_queue, &event, 100 / portTICK_PERIOD_MS) == pdTRUE) { 1004 if (xQueueReceive(event_queue, &event, 100 / portTICK_PERIOD_MS) == pdTRUE) {
978 UserTimer = INACTIVITY; 1005 UserTimer = INACTIVITY;
979 menu_rotary(); 1006 menu_rotary();
980 } 1007 }
981 1008

mercurial