view_info.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Copyright (C) 2022-2023 Salvatore Sanfilippo -- All Rights Reserved
  2. * See the LICENSE file for information about the license. */
  3. #include "app.h"
  4. enum {
  5. SubViewInfoMain,
  6. SubViewInfoSave,
  7. SubViewInfoLast, /* Just a sentinel. */
  8. };
  9. /* Render the view with the detected message information. */
  10. static void render_subview_main(Canvas *const canvas, ProtoViewApp *app) {
  11. /* Protocol name as title. */
  12. canvas_set_font(canvas, FontPrimary);
  13. uint8_t y = 8, lineheight = 10;
  14. canvas_draw_str(canvas, 0, y, app->msg_info->name);
  15. y += lineheight;
  16. /* Info fields. */
  17. char buf[128];
  18. canvas_set_font(canvas, FontSecondary);
  19. if (app->msg_info->raw[0]) {
  20. snprintf(buf,sizeof(buf),"Raw: %s", app->msg_info->raw);
  21. canvas_draw_str(canvas, 0, y, buf);
  22. y += lineheight;
  23. }
  24. canvas_draw_str(canvas, 0, y, app->msg_info->info1); y += lineheight;
  25. canvas_draw_str(canvas, 0, y, app->msg_info->info2); y += lineheight;
  26. canvas_draw_str(canvas, 0, y, app->msg_info->info3); y += lineheight;
  27. canvas_draw_str(canvas, 0, y, app->msg_info->info4); y += lineheight;
  28. }
  29. /* Render view with save option. */
  30. static void render_subview_save(Canvas *const canvas, ProtoViewApp *app) {
  31. uint8_t rows = 6;
  32. uint8_t rowheight = 8;
  33. uint8_t bitwidth = 4;
  34. uint8_t bitheight = 5;
  35. uint32_t idx = 0;
  36. bool prevbit = false;
  37. for (uint8_t y = bitheight; y < rows*rowheight; y += rowheight) {
  38. for (uint8_t x = 5; x < 128; x += 4) {
  39. bool bit = bitmap_get(app->msg_info->bits,
  40. app->msg_info->bits_bytes,idx++);
  41. uint8_t prevy = y + prevbit*bitheight - 1;
  42. uint8_t thisy = y + bit*bitheight - 1;
  43. canvas_draw_line(canvas,x,prevy,x,thisy);
  44. canvas_draw_line(canvas,x,thisy,x+bitwidth-1,thisy);
  45. }
  46. }
  47. }
  48. /* Render the selected subview of this view. */
  49. void render_view_info(Canvas *const canvas, ProtoViewApp *app) {
  50. if (app->signal_decoded == false) {
  51. canvas_set_font(canvas, FontSecondary);
  52. canvas_draw_str(canvas, 30,36,"No signal decoded");
  53. return;
  54. }
  55. show_available_subviews(canvas,app,SubViewInfoLast);
  56. switch(app->current_subview[app->current_view]) {
  57. case SubViewInfoMain: render_subview_main(canvas,app); break;
  58. case SubViewInfoSave: render_subview_save(canvas,app); break;
  59. }
  60. }
  61. /* Handle input for the info view. */
  62. void process_input_info(ProtoViewApp *app, InputEvent input) {
  63. if (process_subview_updown(app,input,SubViewInfoLast)) return;
  64. if (input.type == InputTypeShort) {
  65. if (input.key == InputKeyOk) {
  66. /* Reset the current sample to capture the next. */
  67. reset_current_signal(app);
  68. }
  69. }
  70. }