esubghz_chat_i.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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/byte_input.h>
  7. #include <gui/modules/dialog_ex.h>
  8. #include <gui/modules/menu.h>
  9. #include <gui/modules/text_box.h>
  10. #include <gui/modules/text_input.h>
  11. #include <notification/notification_messages.h>
  12. #include <lib/subghz/subghz_tx_rx_worker.h>
  13. #include <toolbox/sha256.h>
  14. #include "crypto_wrapper.h"
  15. #include "scenes/esubghz_chat_scene.h"
  16. #define APPLICATION_NAME "ESubGhzChat"
  17. #define DEFAULT_FREQ 433920000
  18. #define RX_TX_BUFFER_SIZE 1024
  19. #define CHAT_BOX_STORE_SIZE 4096
  20. #define TEXT_INPUT_STORE_SIZE 256
  21. #define KEY_HEX_STR_SIZE ((KEY_BITS / 8) * 3)
  22. typedef struct {
  23. SceneManager *scene_manager;
  24. ViewDispatcher *view_dispatcher;
  25. NotificationApp *notification;
  26. // UI elements
  27. Menu *menu;
  28. TextBox *chat_box;
  29. FuriString *chat_box_store;
  30. TextInput *text_input;
  31. char text_input_store[TEXT_INPUT_STORE_SIZE + 1];
  32. ByteInput *hex_key_input;
  33. uint8_t hex_key_input_store[KEY_BITS / 8];
  34. DialogEx *key_display;
  35. char key_hex_str[KEY_HEX_STR_SIZE + 1];
  36. // for Sub-GHz
  37. uint32_t frequency;
  38. SubGhzTxRxWorker *subghz_worker;
  39. const SubGhzDevice *subghz_device;
  40. // message assembly before TX
  41. FuriString *name_prefix;
  42. FuriString *msg_input;
  43. // encryption
  44. bool encrypted;
  45. ESubGhzChatCryptoCtx *crypto_ctx;
  46. // RX and TX buffers
  47. uint8_t rx_buffer[RX_TX_BUFFER_SIZE];
  48. uint8_t tx_buffer[RX_TX_BUFFER_SIZE];
  49. char rx_str_buffer[RX_TX_BUFFER_SIZE + 1];
  50. volatile uint32_t last_time_rx_data;
  51. // for locking
  52. ViewPortDrawCallback orig_draw_cb;
  53. ViewPortInputCallback orig_input_cb;
  54. bool kbd_locked;
  55. uint32_t kbd_lock_msg_ticks;
  56. uint8_t kbd_lock_count;
  57. // for ongoing inputs
  58. bool kbd_ok_input_ongoing;
  59. bool kbd_left_input_ongoing;
  60. bool kbd_right_input_ongoing;
  61. } ESubGhzChatState;
  62. typedef enum {
  63. ESubGhzChatEvent_FreqEntered,
  64. ESubGhzChatEvent_KeyMenuNoEncryption,
  65. ESubGhzChatEvent_KeyMenuPassword,
  66. ESubGhzChatEvent_KeyMenuHexKey,
  67. ESubGhzChatEvent_PassEntered,
  68. ESubGhzChatEvent_HexKeyEntered,
  69. ESubGhzChatEvent_MsgEntered,
  70. ESubGhzChatEvent_GotoMsgInput,
  71. ESubGhzChatEvent_GotoKeyDisplay,
  72. ESubGhzChatEvent_KeyDisplayBack
  73. } ESubGhzChatEvent;
  74. typedef enum {
  75. ESubGhzChatView_Menu,
  76. ESubGhzChatView_Input,
  77. ESubGhzChatView_HexKeyInput,
  78. ESubGhzChatView_ChatBox,
  79. ESubGhzChatView_KeyDisplay,
  80. } ESubGhzChatView;
  81. void tx_msg_input(ESubGhzChatState *state);
  82. void enter_chat(ESubGhzChatState *state);