scr-logging.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Copyright (C) 2023 Daniele Lacamera <root@danielinux.net>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <stdint.h>
  18. #include <stddef.h>
  19. #include "ui.h"
  20. #include "button.h"
  21. #include <stdio.h>
  22. #include "ksp-serial.h"
  23. const char logging_name[] = "Logging";
  24. static void logging_draw(void);
  25. static void logging_run(uint32_t ev, void *arg);
  26. static void logging_init(void)
  27. {
  28. }
  29. struct screen logging_screen = {
  30. .draw = logging_draw,
  31. .name = logging_name
  32. };
  33. struct task logging_task = {
  34. .init = logging_init,
  35. .run = logging_run,
  36. .events = EV_BUTTON | EV_HEARTBEAT | EV_VESSELDATA,
  37. .screen = &logging_screen,
  38. .name = logging_name
  39. };
  40. static int button = -1;
  41. static void logging_run(uint32_t event, void *arg)
  42. {
  43. uint32_t potl;
  44. struct sample *s;
  45. int ts;
  46. if (screen_get_focus() != &logging_screen)
  47. return;
  48. if (ui_menu_is_on()) {
  49. if (event & EV_BUTTON)
  50. ui_redraw(EV_BUTTON);
  51. return;
  52. }
  53. ts = input_detect_touch();
  54. if (ts == TS_TOUCH_NONE) {
  55. } else {
  56. event |= EV_BUTTON;
  57. button = 12;
  58. }
  59. if (event & EV_BUTTON) {
  60. if (button < 0)
  61. button = ui_process_button_pressed();
  62. switch(button) {
  63. case BUTTON_DPADU:
  64. break;
  65. case BUTTON_DPADD:
  66. break;
  67. case BUTTON_DPADL:
  68. break;
  69. case BUTTON_DPADR:
  70. break;
  71. case 7:
  72. ui_menu(1);
  73. ui_redraw(EV_NONE);
  74. break;
  75. case 4:
  76. case 12:
  77. break;
  78. case 5:
  79. break;
  80. case 8:
  81. break;
  82. case 9:
  83. break;
  84. case 10:
  85. break;
  86. case 11:
  87. break;
  88. }
  89. clear_event(EV_BUTTON);
  90. } else if (event & EV_VESSELDATA) {
  91. char mtime[40];
  92. ui_fill_area(0, BLACK, 40, 234, 200, 244);
  93. snprintf(mtime, 40, "MTIME: %u", cur_vdata->MissionTime);
  94. ui_text_at(0, CYAN, 40, 234, mtime);
  95. clear_event(EV_VESSELDATA);
  96. }
  97. pot_read(&potl, NULL);
  98. ui_fill_area(0, BLACK, 40, 40, 130, 60);
  99. ui_text_at(0, GREEN, 40, 40, "Roll:");
  100. ui_text_at(0, GREEN, 40, 50, "None");
  101. ui_fill_area(0, BLACK, 105, 40, 135, 60);
  102. ui_text_at(0, YELLOW, 105, 40, "Yaw:");
  103. ui_text_at(0, YELLOW, 105, 50, "None");
  104. ui_fill_area(0, BLACK, 40, 214, 80, 234);
  105. ui_text_at(0, GREEN, 40, 214, "Pitch:");
  106. ui_text_at(0, GREEN, 40, 224, "None");
  107. ui_fill_area(0, BLACK, 85, 214, 120, 234);
  108. ui_text_at(0, YELLOW, 85, 214, "Pow:");
  109. ui_text_at(0, YELLOW, 85, 224, ui_printn((potl * 100) / 4096));
  110. }
  111. static void logging_draw(void)
  112. {
  113. int i;
  114. char btn_str[4] = "";
  115. /* background to foreground */
  116. ui_fill_area(0, DARKRED, 0, 0, xres, yres);
  117. /* Logo & appname */
  118. ui_text_at (0, GREY, 35, 4, "Debug Info");
  119. ui_text_at (0, YELLOW, 160, 40, "Button pressed:");
  120. snprintf(btn_str, 4, "%d", button);
  121. ui_text_at (0, YELLOW, 160, 80, btn_str);
  122. //image_at(0, logo, 5, 4, logox, logoy);
  123. }
  124. void logging_setup(void)
  125. {
  126. register_task(&logging_task);
  127. register_screen(&logging_task, &logging_screen);
  128. }