view_build.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. extern ProtoViewDecoder *Decoders[]; // Defined in signal.c.
  5. /* Our view private data. */
  6. typedef struct {
  7. ProtoViewDecoder *decoder; // Decoder we are using to create a message.
  8. uint32_t cur_decoder; // Decoder index when we are yet selecting
  9. // a decoder. Used when decoder is NULL.
  10. ProtoViewFieldSet *fieldset; // The fields to populate.
  11. uint32_t cur_field; // Field we are editing right now. This
  12. // is the index inside the 'fieldset'
  13. // fields.
  14. } BuildViewPrivData;
  15. /* Render the view to select the decoder, among the ones that
  16. * support message building. */
  17. static void render_view_select_decoder(Canvas *const canvas, ProtoViewApp *app) {
  18. canvas_set_font(canvas, FontPrimary);
  19. canvas_draw_str(canvas, 0, 9, "Signal builder");
  20. canvas_set_font(canvas, FontSecondary);
  21. canvas_draw_str(canvas, 0, 19, "up/down: select, ok: choose");
  22. UNUSED(app); // XXX
  23. }
  24. /* Render the view that allows the user to populate the fields needed
  25. * for the selected decoder to build a message. */
  26. static void render_view_set_fields(Canvas *const canvas, ProtoViewApp *app) {
  27. BuildViewPrivData *privdata = app->view_privdata;
  28. char buf[32];
  29. snprintf(buf,sizeof(buf), "%s field %d/%d",
  30. privdata->decoder->name, (int)privdata->cur_field,
  31. (int)privdata->fieldset->numfields);
  32. canvas_set_font(canvas, FontPrimary);
  33. canvas_draw_str(canvas, 0, 9, buf);
  34. canvas_set_font(canvas, FontSecondary);
  35. canvas_draw_str(canvas, 0, 19, "up/down: next field, ok: edit");
  36. }
  37. /* Render the build message view. */
  38. void render_view_build_message(Canvas *const canvas, ProtoViewApp *app) {
  39. BuildViewPrivData *privdata = app->view_privdata;
  40. if (privdata->decoder == NULL)
  41. render_view_select_decoder(canvas,app);
  42. else
  43. render_view_set_fields(canvas,app);
  44. }
  45. /* Handle input for the build message view. */
  46. void process_input_build_message(ProtoViewApp *app, InputEvent input) {
  47. UNUSED(app);
  48. if (input.type == InputTypeShort) {
  49. if (input.key == InputKeyOk) {
  50. } else if (input.key == InputKeyDown) {
  51. } else if (input.key == InputKeyUp) {
  52. }
  53. }
  54. }
  55. /* Called on exit for cleanup. */
  56. void view_exit_build_message(ProtoViewApp *app) {
  57. BuildViewPrivData *privdata = app->view_privdata;
  58. if (privdata->fieldset) fieldset_free(privdata->fieldset);
  59. }