esubghz_chat_i.h 3.1 KB

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