esubghz_chat_i.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. #include <furi.h>
  3. #include <gui/view_dispatcher_i.h>
  4. #include <gui/view_port_i.h>
  5. #include <gui/scene_manager.h>
  6. #include <gui/modules/menu.h>
  7. #include <gui/modules/text_box.h>
  8. #include <gui/modules/text_input.h>
  9. #include <notification/notification_messages.h>
  10. #include <lib/subghz/subghz_tx_rx_worker.h>
  11. #include <toolbox/sha256.h>
  12. #include "crypto_wrapper.h"
  13. #include "scenes/esubghz_chat_scene.h"
  14. #define APPLICATION_NAME "ESubGhzChat"
  15. #define DEFAULT_FREQ 433920000
  16. #define RX_TX_BUFFER_SIZE 1024
  17. #define CHAT_BOX_STORE_SIZE 4096
  18. #define TEXT_INPUT_STORE_SIZE 256
  19. typedef struct {
  20. SceneManager *scene_manager;
  21. ViewDispatcher *view_dispatcher;
  22. NotificationApp *notification;
  23. // UI elements
  24. Menu *menu;
  25. TextBox *chat_box;
  26. FuriString *chat_box_store;
  27. TextInput *text_input;
  28. char text_input_store[TEXT_INPUT_STORE_SIZE + 1];
  29. // for Sub-GHz
  30. uint32_t frequency;
  31. SubGhzTxRxWorker *subghz_worker;
  32. const SubGhzDevice *subghz_device;
  33. // message assembly before TX
  34. FuriString *name_prefix;
  35. FuriString *msg_input;
  36. // encryption
  37. bool encrypted;
  38. ESubGhzChatCryptoCtx *crypto_ctx;
  39. // RX and TX buffers
  40. uint8_t rx_buffer[RX_TX_BUFFER_SIZE];
  41. uint8_t tx_buffer[RX_TX_BUFFER_SIZE];
  42. char rx_str_buffer[RX_TX_BUFFER_SIZE + 1];
  43. volatile uint32_t last_time_rx_data;
  44. // for locking
  45. ViewPortDrawCallback orig_draw_cb;
  46. ViewPortInputCallback orig_input_cb;
  47. bool kbd_locked;
  48. uint32_t kbd_lock_msg_ticks;
  49. uint8_t kbd_lock_count;
  50. bool kbd_ok_input_ongoing;
  51. } ESubGhzChatState;
  52. typedef enum {
  53. ESubGhzChatEvent_FreqEntered,
  54. ESubGhzChatEvent_KeyMenuNoEncryption,
  55. ESubGhzChatEvent_KeyMenuPassword,
  56. ESubGhzChatEvent_PassEntered,
  57. ESubGhzChatEvent_MsgEntered
  58. } ESubGhzChatEvent;
  59. typedef enum {
  60. ESubGhzChatView_Menu,
  61. ESubGhzChatView_Input,
  62. ESubGhzChatView_ChatBox,
  63. } ESubGhzChatView;
  64. void tx_msg_input(ESubGhzChatState *state);
  65. void enter_chat(ESubGhzChatState *state);