Summary_view.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "UnitempViews.h"
  2. static View* view;
  3. static void _draw_callback(Canvas* canvas, void* _model) {
  4. UNUSED(_model);
  5. app->sensors_ready = true;
  6. //Рисование бара
  7. canvas_draw_box(canvas, 0, 0, 128, 14);
  8. canvas_set_color(canvas, ColorWhite);
  9. canvas_set_font(canvas, FontPrimary);
  10. canvas_draw_str_aligned(canvas, 64, 7, AlignCenter, AlignCenter, "Unitemp");
  11. canvas_set_color(canvas, ColorBlack);
  12. if(app->sensors_count > 0) {
  13. for(uint8_t i = 0; i < app->sensors_count; i++) {
  14. canvas_set_font(canvas, FontPrimary);
  15. canvas_draw_str(canvas, 0, 24 + 10 * i, app->sensors[i]->name);
  16. canvas_set_font(canvas, FontSecondary);
  17. if(app->sensors[i]->status != UT_OK && app->sensors[i]->status != UT_EARLYPOOL &&
  18. app->sensors[i]->status != UT_POLLING) {
  19. if(app->sensors[i]->status == UT_BADCRC) {
  20. canvas_draw_str(canvas, 96, 24 + 10 * i, "bad CRC");
  21. } else {
  22. canvas_draw_str(canvas, 96, 24 + 10 * i, "timeout");
  23. }
  24. } else {
  25. char buff[20];
  26. snprintf(
  27. buff,
  28. sizeof(buff),
  29. "%2.1f*%c/%d%%",
  30. (double)app->sensors[i]->temp,
  31. app->settings.unit == CELSIUS ? 'C' : 'F',
  32. (int8_t)app->sensors[i]->hum);
  33. canvas_draw_str(canvas, 64, 24 + 10 * i, buff);
  34. }
  35. }
  36. } else {
  37. canvas_set_font(canvas, FontSecondary);
  38. if(app->sensors_count == 0) canvas_draw_str(canvas, 0, 24, "Sensors not found");
  39. }
  40. }
  41. static bool _input_callback(InputEvent* event, void* context) {
  42. Unitemp* app = context;
  43. //Выход по короткому нажатию "назад"
  44. if(event->key == InputKeyBack && event->type == InputTypeShort) {
  45. app->processing = false;
  46. }
  47. //Вход в главное меню по короткому нажатию "Ок"
  48. if(event->key == InputKeyOk && event->type == InputTypeShort) {
  49. app->sensors_ready = false;
  50. unitemp_MainMenu_switch();
  51. }
  52. return true;
  53. }
  54. void unitemp_Summary_alloc(void) {
  55. view = view_alloc();
  56. view_set_context(view, app);
  57. view_set_draw_callback(view, _draw_callback);
  58. view_set_input_callback(view, _input_callback);
  59. view_dispatcher_add_view(app->view_dispatcher, SUMMARY_VIEW, view);
  60. }
  61. void unitemp_Summary_switch(void) {
  62. app->sensors_ready = true;
  63. view_dispatcher_switch_to_view(app->view_dispatcher, SUMMARY_VIEW);
  64. }
  65. void unitemp_Summary_free(void) {
  66. view_free(view);
  67. }