view_info.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. if (app->signal_decoded == false) {
  12. canvas_set_font(canvas, FontSecondary);
  13. canvas_draw_str(canvas, 30,36,"No signal decoded");
  14. return;
  15. }
  16. /* Protocol name as title. */
  17. canvas_set_font(canvas, FontPrimary);
  18. uint8_t y = 8, lineheight = 10;
  19. canvas_draw_str(canvas, 0, y, app->signal_info.name);
  20. y += lineheight;
  21. /* Info fields. */
  22. char buf[128];
  23. canvas_set_font(canvas, FontSecondary);
  24. if (app->signal_info.raw[0]) {
  25. snprintf(buf,sizeof(buf),"Raw: %s", app->signal_info.raw);
  26. canvas_draw_str(canvas, 0, y, buf);
  27. y += lineheight;
  28. }
  29. canvas_draw_str(canvas, 0, y, app->signal_info.info1); y += lineheight;
  30. canvas_draw_str(canvas, 0, y, app->signal_info.info2); y += lineheight;
  31. canvas_draw_str(canvas, 0, y, app->signal_info.info3); y += lineheight;
  32. canvas_draw_str(canvas, 0, y, app->signal_info.info4); y += lineheight;
  33. }
  34. /* Render view with save option. */
  35. static void render_subview_save(Canvas *const canvas, ProtoViewApp *app) {
  36. UNUSED(canvas);
  37. UNUSED(app);
  38. }
  39. /* Render the selected subview of this view. */
  40. void render_view_info(Canvas *const canvas, ProtoViewApp *app) {
  41. show_available_subviews(canvas,app,SubViewInfoLast);
  42. switch(app->current_subview[app->current_view]) {
  43. case SubViewInfoMain: render_subview_main(canvas,app); break;
  44. case SubViewInfoSave: render_subview_save(canvas,app); break;
  45. }
  46. }
  47. /* Handle input for the info view. */
  48. void process_input_info(ProtoViewApp *app, InputEvent input) {
  49. if (process_subview_updown(app,input,SubViewInfoLast)) return;
  50. if (input.type == InputTypeShort) {
  51. if (input.key == InputKeyOk) {
  52. /* Reset the current sample to capture the next. */
  53. reset_current_signal(app);
  54. }
  55. }
  56. }