app.h 2.6 KB

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