esubghz_chat_i.h 3.3 KB

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