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. /* 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->signal_info.name);
  15. y += lineheight;
  16. /* Info fields. */
  17. char buf[128];
  18. canvas_set_font(canvas, FontSecondary);
  19. if (app->signal_info.raw[0]) {
  20. snprintf(buf,sizeof(buf),"Raw: %s", app->signal_info.raw);
  21. canvas_draw_str(canvas, 0, y, buf);
  22. y += lineheight;
  23. }
  24. canvas_draw_str(canvas, 0, y, app->signal_info.info1); y += lineheight;
  25. canvas_draw_str(canvas, 0, y, app->signal_info.info2); y += lineheight;
  26. canvas_draw_str(canvas, 0, y, app->signal_info.info3); y += lineheight;
  27. canvas_draw_str(canvas, 0, y, app->signal_info.info4); y += lineheight;
  28. }
  29. /* Render view with save option. */
  30. static void render_subview_save(Canvas *const canvas, ProtoViewApp *app) {
  31. UNUSED(canvas);
  32. UNUSED(app);
  33. }
  34. /* Render the selected subview of this view. */
  35. void render_view_info(Canvas *const canvas, ProtoViewApp *app) {
  36. if (app->signal_decoded == false) {
  37. canvas_set_font(canvas, FontSecondary);
  38. canvas_draw_str(canvas, 30,36,"No signal decoded");
  39. return;
  40. }
  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. }