esubghz_chat_i.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/text_box.h>
  7. #include <gui/modules/text_input.h>
  8. #include <notification/notification_messages.h>
  9. #include <lib/subghz/subghz_tx_rx_worker.h>
  10. #include <toolbox/sha256.h>
  11. #include "crypto_wrapper.h"
  12. #include "scenes/esubghz_chat_scene.h"
  13. #define APPLICATION_NAME "ESubGhzChat"
  14. #define DEFAULT_FREQ 433920000
  15. #define CHAT_LEAVE_DELAY 10
  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. TextBox *chat_box;
  25. FuriString *chat_box_store;
  26. TextInput *text_input;
  27. char text_input_store[TEXT_INPUT_STORE_SIZE + 1];
  28. // for Sub-GHz
  29. uint32_t frequency;
  30. SubGhzTxRxWorker *subghz_worker;
  31. const SubGhzDevice *subghz_device;
  32. // message assembly before TX
  33. FuriString *name_prefix;
  34. FuriString *msg_input;
  35. // encryption
  36. bool encrypted;
  37. ESubGhzChatCryptoCtx *crypto_ctx;
  38. // RX and TX buffers
  39. uint8_t rx_buffer[RX_TX_BUFFER_SIZE];
  40. uint8_t tx_buffer[RX_TX_BUFFER_SIZE];
  41. char rx_str_buffer[RX_TX_BUFFER_SIZE + 1];
  42. volatile uint32_t last_time_rx_data;
  43. // for locking
  44. ViewPortDrawCallback orig_draw_cb;
  45. ViewPortInputCallback orig_input_cb;
  46. bool kbd_locked;
  47. uint32_t kbd_lock_msg_ticks;
  48. uint8_t kbd_lock_count;
  49. bool kbd_ok_input_ongoing;
  50. } ESubGhzChatState;
  51. typedef enum {
  52. ESubGhzChatEvent_FreqEntered,
  53. ESubGhzChatEvent_PassEntered,
  54. ESubGhzChatEvent_MsgEntered
  55. } ESubGhzChatEvent;
  56. typedef enum {
  57. ESubGhzChatView_Input,
  58. ESubGhzChatView_ChatBox,
  59. } ESubGhzChatView;
  60. void tx_msg_input(ESubGhzChatState *state);