Skip to content

Commit

Permalink
Switch around key input and frequency scenes
Browse files Browse the repository at this point in the history
  • Loading branch information
twisted_pear committed Aug 16, 2023
1 parent 74253f5 commit a29177a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
8 changes: 5 additions & 3 deletions esubghz_chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#define CHAT_LEAVE_DELAY 10
#define TICK_INTERVAL 50
#define MESSAGE_COMPLETION_TIMEOUT 500
#define TIMEOUT_BETWEEN_MESSAGES 500

#define KBD_UNLOCK_CNT 3
#define KBD_UNLOCK_TIMEOUT 1000
Expand Down Expand Up @@ -575,6 +574,9 @@ int32_t esubghz_chat(void)
goto err_alloc_crypto;
}

/* set the default frequency */
state->frequency = DEFAULT_FREQ;

/* set the have_read callback of the Sub-GHz worker */
subghz_tx_rx_worker_set_callback_have_read(state->subghz_worker,
have_read_cb, state);
Expand Down Expand Up @@ -642,8 +644,8 @@ int32_t esubghz_chat(void)
view_dispatcher_attach_to_gui(state->view_dispatcher, gui,
ViewDispatcherTypeFullscreen);

/* switch to the frequency input scene */
scene_manager_next_scene(state->scene_manager, ESubGhzChatScene_FreqInput);
/* switch to the key menu scene */
scene_manager_next_scene(state->scene_manager, ESubGhzChatScene_KeyMenu);

/* run the view dispatcher, this call only returns when we close the
* application */
Expand Down
10 changes: 6 additions & 4 deletions scenes/esubghz_chat_freq_input.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include "../esubghz_chat_i.h"

/* Sends FreqEntered event to scene manager. */
/* Sends FreqEntered event to scene manager and enters the chat. */
static void freq_input_cb(void *context)
{
furi_assert(context);
ESubGhzChatState* state = context;

enter_chat(state);

view_dispatcher_send_custom_event(state->view_dispatcher,
ESubGhzChatEvent_FreqEntered);
}
Expand Down Expand Up @@ -55,7 +57,7 @@ void scene_on_enter_freq_input(void* context)
ESubGhzChatState* state = context;

snprintf(state->text_input_store, TEXT_INPUT_STORE_SIZE, "%lu",
(uint32_t) DEFAULT_FREQ);
state->frequency);
text_input_reset(state->text_input);
text_input_set_result_callback(
state->text_input,
Expand Down Expand Up @@ -88,10 +90,10 @@ bool scene_on_event_freq_input(void* context, SceneManagerEvent event)
switch(event.type) {
case SceneManagerEventTypeCustom:
switch(event.event) {
/* switch to password input scene */
/* switch to message input scene */
case ESubGhzChatEvent_FreqEntered:
scene_manager_next_scene(state->scene_manager,
ESubGhzChatScene_KeyMenu);
ESubGhzChatScene_ChatInput);
consumed = true;
break;
}
Expand Down
10 changes: 4 additions & 6 deletions scenes/esubghz_chat_hex_key_input.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "../esubghz_chat_i.h"

/* Sets the entered bytes as the key, enters the chat and sends a HexKeyEntered
* event to the scene manager. */
/* Sets the entered bytes as the key and sends a HexKeyEntered event to the
* scene manager. */
static void hex_key_input_cb(void* context)
{
furi_assert(context);
Expand All @@ -23,8 +23,6 @@ static void hex_key_input_cb(void* context)

state->encrypted = true;

enter_chat(state);

view_dispatcher_send_custom_event(state->view_dispatcher,
ESubGhzChatEvent_HexKeyEntered);
}
Expand Down Expand Up @@ -61,10 +59,10 @@ bool scene_on_event_hex_key_input(void* context, SceneManagerEvent event)
switch(event.type) {
case SceneManagerEventTypeCustom:
switch(event.event) {
/* switch to message input scene */
/* switch to frequency input scene */
case ESubGhzChatEvent_HexKeyEntered:
scene_manager_next_scene(state->scene_manager,
ESubGhzChatScene_ChatInput);
ESubGhzChatScene_FreqInput);
consumed = true;
break;
}
Expand Down
10 changes: 6 additions & 4 deletions scenes/esubghz_chat_key_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ static void key_menu_cb(void* context, uint32_t index)
switch(index) {
case ESubGhzChatKeyMenuItems_NoEncryption:
state->encrypted = false;
enter_chat(state);

view_dispatcher_send_custom_event(state->view_dispatcher,
ESubGhzChatEvent_KeyMenuNoEncryption);
Expand Down Expand Up @@ -52,7 +51,6 @@ static void key_menu_cb(void* context, uint32_t index)

/* set encrypted flag and enter the chat */
state->encrypted = true;
enter_chat(state);

view_dispatcher_send_custom_event(state->view_dispatcher,
ESubGhzChatEvent_KeyMenuGenKey);
Expand All @@ -78,6 +76,10 @@ void scene_on_enter_key_menu(void* context)

menu_reset(state->menu);

/* clear the crypto CTX in case we got back from password or hex key
* input */
crypto_ctx_clear(state->crypto_ctx);

menu_add_item(
state->menu,
"No encryption",
Expand Down Expand Up @@ -135,11 +137,11 @@ bool scene_on_event_key_menu(void* context, SceneManagerEvent event)
switch(event.type) {
case SceneManagerEventTypeCustom:
switch(event.event) {
/* switch to message input scene */
/* switch to frequency input scene */
case ESubGhzChatEvent_KeyMenuNoEncryption:
case ESubGhzChatEvent_KeyMenuGenKey:
scene_manager_next_scene(state->scene_manager,
ESubGhzChatScene_ChatInput);
ESubGhzChatScene_FreqInput);
consumed = true;
break;

Expand Down
7 changes: 3 additions & 4 deletions scenes/esubghz_chat_key_read_popup.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ static void key_read_popup_timeout_cb(void* context)
if (cur_state == KeyReadPopupState_Fail) {
view_dispatcher_send_custom_event(state->view_dispatcher,
ESubGhzChatEvent_KeyReadPopupFailed);
/* done displaying our success, enter chat */
/* done displaying our success */
} else if (cur_state == KeyReadPopupState_Success) {
enter_chat(state);
view_dispatcher_send_custom_event(state->view_dispatcher,
ESubGhzChatEvent_KeyReadPopupSucceeded);
}
Expand Down Expand Up @@ -247,10 +246,10 @@ bool scene_on_event_key_read_popup(void* context, SceneManagerEvent event)
consumed = true;
break;

/* success, go to chat input */
/* success, go to frequency input */
case ESubGhzChatEvent_KeyReadPopupSucceeded:
scene_manager_next_scene(state->scene_manager,
ESubGhzChatScene_ChatInput);
ESubGhzChatScene_FreqInput);
consumed = true;
break;

Expand Down
8 changes: 3 additions & 5 deletions scenes/esubghz_chat_pass_input.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "../esubghz_chat_i.h"

/* Sends PassEntered event to scene manager and enters the chat. */
/* Sends PassEntered event to scene manager. */
static void pass_input_cb(void *context)
{
furi_assert(context);
Expand All @@ -9,8 +9,6 @@ static void pass_input_cb(void *context)
crypto_explicit_bzero(state->text_input_store,
sizeof(state->text_input_store));

enter_chat(state);

view_dispatcher_send_custom_event(state->view_dispatcher,
ESubGhzChatEvent_PassEntered);
}
Expand Down Expand Up @@ -96,10 +94,10 @@ bool scene_on_event_pass_input(void* context, SceneManagerEvent event)
switch(event.type) {
case SceneManagerEventTypeCustom:
switch(event.event) {
/* switch to message input scene */
/* switch to frequency input scene */
case ESubGhzChatEvent_PassEntered:
scene_manager_next_scene(state->scene_manager,
ESubGhzChatScene_ChatInput);
ESubGhzChatScene_FreqInput);
consumed = true;
break;
}
Expand Down

0 comments on commit a29177a

Please sign in to comment.