app.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #include <gui/gui.h>
  3. #include <gui/view_dispatcher.h>
  4. #include <gui/scene_manager.h>
  5. #include <gui/modules/submenu.h>
  6. #include <gui/modules/variable_item_list.h>
  7. #include <gui/modules/widget.h>
  8. #include <notification/notification_messages.h>
  9. #include <lib/subghz/subghz_setting.h>
  10. #include <lib/subghz/subghz_worker.h>
  11. #include <lib/subghz/receiver.h>
  12. #include <lib/subghz/transmitter.h>
  13. #include <lib/subghz/registry.h>
  14. #define TAG "ProtoView"
  15. typedef struct ProtoViewApp ProtoViewApp;
  16. /* Subghz system state */
  17. typedef enum {
  18. TxRxStateIDLE,
  19. TxRxStateRx,
  20. TxRxStateSleep,
  21. } TxRxState;
  22. /* Currently active view. */
  23. typedef enum {
  24. ViewRawPulses,
  25. ViewFrequencySettings,
  26. ViewModulationSettings,
  27. ViewLast, /* Just a sentinel to wrap around. */
  28. } ProtoViewCurrentView;
  29. typedef struct {
  30. const char *name;
  31. FuriHalSubGhzPreset preset;
  32. } ProtoViewModulation;
  33. extern ProtoViewModulation ProtoViewModulations[]; /* In app_subghz.c */
  34. /* This is the context of our subghz worker and associated thread.
  35. * It receives data and we get our protocol "feed" callback called
  36. * with the level (1 or 0) and duration. */
  37. struct ProtoViewTxRx {
  38. SubGhzWorker* worker; /* Our background worker. */
  39. SubGhzEnvironment* environment;
  40. SubGhzReceiver* receiver;
  41. TxRxState txrx_state; /* Receiving, idle or sleeping? */
  42. };
  43. typedef struct ProtoViewTxRx ProtoViewTxRx;
  44. struct ProtoViewApp {
  45. /* GUI */
  46. Gui *gui;
  47. ViewPort *view_port; /* We just use a raw viewport and we render
  48. everything into the low level canvas. */
  49. ProtoViewCurrentView current_view; /* Active view ID. */
  50. FuriMessageQueue *event_queue; /* Keypress events go here. */
  51. /* Radio related. */
  52. ProtoViewTxRx *txrx; /* Radio state. */
  53. SubGhzSetting *setting; /* A list of valid frequencies. */
  54. /* Application state and config. */
  55. int running; /* Once false exists the app. */
  56. uint32_t signal_bestlen; /* Longest coherent signal observed so far. */
  57. uint32_t us_scale; /* microseconds per pixel. */
  58. uint32_t frequency; /* Current frequency. */
  59. uint8_t modulation; /* Current modulation ID, array index in the
  60. ProtoViewModulations table. */
  61. };
  62. void radio_begin(ProtoViewApp* app);
  63. uint32_t radio_rx(ProtoViewApp* app);
  64. void radio_idle(ProtoViewApp* app);
  65. void radio_rx_end(ProtoViewApp* app);
  66. void radio_sleep(ProtoViewApp* app);