app.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* Copyright (C) 2022-2023 Salvatore Sanfilippo -- All Rights Reserved
  2. * See the LICENSE file for information about the license. */
  3. #pragma once
  4. #include <furi.h>
  5. #include <furi_hal.h>
  6. #include <input/input.h>
  7. #include <gui/gui.h>
  8. #include <stdlib.h>
  9. #include <gui/gui.h>
  10. #include <gui/view_dispatcher.h>
  11. #include <gui/scene_manager.h>
  12. #include <gui/modules/submenu.h>
  13. #include <gui/modules/variable_item_list.h>
  14. #include <gui/modules/widget.h>
  15. #include <notification/notification_messages.h>
  16. #include <lib/subghz/subghz_setting.h>
  17. #include <lib/subghz/subghz_worker.h>
  18. #include <lib/subghz/receiver.h>
  19. #include <lib/subghz/transmitter.h>
  20. #include <lib/subghz/registry.h>
  21. #include "app_buffer.h"
  22. #define TAG "ProtoView"
  23. typedef struct ProtoViewApp ProtoViewApp;
  24. /* Subghz system state */
  25. typedef enum {
  26. TxRxStateIDLE,
  27. TxRxStateRx,
  28. TxRxStateSleep,
  29. } TxRxState;
  30. /* Currently active view. */
  31. typedef enum {
  32. ViewRawPulses,
  33. ViewFrequencySettings,
  34. ViewModulationSettings,
  35. ViewLast, /* Just a sentinel to wrap around. */
  36. } ProtoViewCurrentView;
  37. typedef struct {
  38. const char *name;
  39. FuriHalSubGhzPreset preset;
  40. } ProtoViewModulation;
  41. extern ProtoViewModulation ProtoViewModulations[]; /* In app_subghz.c */
  42. /* This is the context of our subghz worker and associated thread.
  43. * It receives data and we get our protocol "feed" callback called
  44. * with the level (1 or 0) and duration. */
  45. struct ProtoViewTxRx {
  46. SubGhzWorker* worker; /* Our background worker. */
  47. SubGhzEnvironment* environment;
  48. SubGhzReceiver* receiver;
  49. TxRxState txrx_state; /* Receiving, idle or sleeping? */
  50. };
  51. typedef struct ProtoViewTxRx ProtoViewTxRx;
  52. struct ProtoViewApp {
  53. /* GUI */
  54. Gui *gui;
  55. ViewPort *view_port; /* We just use a raw viewport and we render
  56. everything into the low level canvas. */
  57. ProtoViewCurrentView current_view; /* Active view ID. */
  58. FuriMessageQueue *event_queue; /* Keypress events go here. */
  59. /* Radio related. */
  60. ProtoViewTxRx *txrx; /* Radio state. */
  61. SubGhzSetting *setting; /* A list of valid frequencies. */
  62. /* Generic app state. */
  63. int running; /* Once false exists the app. */
  64. uint32_t signal_bestlen; /* Longest coherent signal observed so far. */
  65. /* Raw view apps state. */
  66. uint32_t us_scale; /* microseconds per pixel. */
  67. uint32_t signal_offset; /* Long press left/right panning in raw view. */
  68. /* Configuration view app state. */
  69. uint32_t frequency; /* Current frequency. */
  70. uint8_t modulation; /* Current modulation ID, array index in the
  71. ProtoViewModulations table. */
  72. };
  73. extern RawSamplesBuffer *RawSamples, *DetectedSamples;
  74. /* app_radio.c */
  75. void radio_begin(ProtoViewApp* app);
  76. uint32_t radio_rx(ProtoViewApp* app);
  77. void radio_idle(ProtoViewApp* app);
  78. void radio_rx_end(ProtoViewApp* app);
  79. void radio_sleep(ProtoViewApp* app);
  80. /* signal.c */
  81. uint32_t duration_delta(uint32_t a, uint32_t b);
  82. void scan_for_signal(ProtoViewApp *app);
  83. /* view_*.c */
  84. void render_view_raw_pulses(Canvas *const canvas, ProtoViewApp *app);
  85. void process_input_raw_pulses(ProtoViewApp *app, InputEvent input);
  86. void render_view_settings(Canvas *const canvas, ProtoViewApp *app);
  87. void process_input_settings(ProtoViewApp *app, InputEvent input);
  88. /* ui.c */
  89. void canvas_draw_str_with_border(Canvas* canvas, uint8_t x, uint8_t y, const char* str, Color text_color, Color border_color);