Przeglądaj źródła

Switch around key input and frequency scenes

twisted_pear 2 lat temu
rodzic
commit
a29177ac94

+ 5 - 3
esubghz_chat.c

@@ -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
@@ -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);
@@ -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 */

+ 6 - 4
scenes/esubghz_chat_freq_input.c

@@ -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);
 }
@@ -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,
@@ -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;
 		}

+ 4 - 6
scenes/esubghz_chat_hex_key_input.c

@@ -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);
@@ -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);
 }
@@ -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;
 		}

+ 6 - 4
scenes/esubghz_chat_key_menu.c

@@ -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);
@@ -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);
@@ -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",
@@ -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;
 

+ 3 - 4
scenes/esubghz_chat_key_read_popup.c

@@ -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);
 	}
@@ -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;
 

+ 3 - 5
scenes/esubghz_chat_pass_input.c

@@ -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);
@@ -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);
 }
@@ -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;
 		}