Skip to content

Commit

Permalink
Merge pull request #6 from jamisonderek/jamisonderek/chat
Browse files Browse the repository at this point in the history
Implement "Start Chatting"
  • Loading branch information
d4rks1d33 authored Oct 9, 2024
2 parents df8db2f + 793078e commit 33f773f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions scenes/gemini_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ ADD_SCENE(gemini, main_menu, MainMenu)
ADD_SCENE(gemini, receive_serial, ReceiveSerial)
ADD_SCENE(gemini, set_name, SetName)
ADD_SCENE(gemini, send_known_aps, SendKnownAps)
ADD_SCENE(gemini, start_chatting, StartChatting)
ADD_SCENE(gemini, missing_api_key, MissingApiKey)
ADD_SCENE(gemini, under_construction, UnderConstruction)
3 changes: 1 addition & 2 deletions scenes/gemini_scene_main_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ bool gemini_scene_main_menu_on_event(void* context, SceneManagerEvent event) {
consumed = true;
break;
case GeminiSceneMainMenuEventStartChatting:
// TODO: Replace with correct scene
scene_manager_next_scene(app->scene_manager, GeminiSceneUnderConstruction);
scene_manager_next_scene(app->scene_manager, GeminiSceneStartChatting);
consumed = true;
break;
case GeminiSceneMainMenuEventHelp:
Expand Down
2 changes: 1 addition & 1 deletion scenes/gemini_scene_set_name.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "../gemini_app_i.h"

#define TEXT_BUFFER_SIZE 64
char text_buffer[TEXT_BUFFER_SIZE];
static char text_buffer[TEXT_BUFFER_SIZE];

enum {
GeminiSceneSetNameEventOk,
Expand Down
49 changes: 49 additions & 0 deletions scenes/gemini_scene_start_chatting.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "../gemini_app_i.h"

#define TEXT_BUFFER_SIZE 128
static char text_buffer[TEXT_BUFFER_SIZE];

enum {
GeminiSceneStartChattingEventOk,
} GeminiSceneStartChattingEvent;

static void gemini_scene_start_chatting_text_input_callback(void* context) {
GeminiApp* app = context;
scene_manager_handle_custom_event(app->scene_manager, GeminiSceneStartChattingEventOk);
}

void gemini_scene_start_chatting_on_enter(void* context) {
GeminiApp* app = context;
text_input_set_header_text(app->text_input, "Enter message");
text_input_set_minimum_length(app->text_input, 0);
text_buffer[0] = '\0';
text_input_set_result_callback(app->text_input, gemini_scene_start_chatting_text_input_callback, app, text_buffer, TEXT_BUFFER_SIZE, true);
view_dispatcher_switch_to_view(app->view_dispatcher, GeminiViewTextInput);
}

bool gemini_scene_start_chatting_on_event(void* context, SceneManagerEvent event) {
GeminiApp* app = context;
bool consumed = false;
if (event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case GeminiSceneStartChattingEventOk:
if (strlen(text_buffer) > 0) {
uart_helper_send(app->uart_helper, text_buffer, 0);
// We want BACK to go back to the start chatting scene.
gemini_scene_receive_serial_set_next(app, GeminiSceneStartChatting);
scene_manager_search_and_switch_to_another_scene(app->scene_manager, GeminiSceneReceiveSerial);
consumed = true;
} else {
scene_manager_previous_scene(app->scene_manager);
consumed = true;
}
break;
}
}

return consumed;
}

void gemini_scene_start_chatting_on_exit(void* context) {
UNUSED(context);
}

0 comments on commit 33f773f

Please sign in to comment.