Summary_view.c 2.5 KB

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