master
Felix Pankratz 2 years ago
parent 70e16ee086
commit e79cb8ae0b

@ -58,25 +58,24 @@ static void build_output(char* input, char* output) {
} }
static void text_input_callback(void* ctx) { static void text_input_callback(void* ctx) {
CaesarState* caesar_state = acquire_mutex((ValueMutex*)ctx, 25); CaesarState* caesar_state = acquire_mutex((ValueMutex*)ctx, 25);
FURI_LOG_D("caesar_cipher", "Input text: %s", caesar_state->input); FURI_LOG_D("caesar_cipher", "Input text: %s", caesar_state->input);
// this is where we build the output. // this is where we build the output.
//char upper[TEXT_BUFFER_SIZE]; string_to_uppercase(caesar_state->input);
string_to_uppercase(caesar_state->input); FURI_LOG_D("caesar_cipher", "Upper text: %s", caesar_state->input);
FURI_LOG_D("caesar_cipher", "Upper text: %s", caesar_state->input); build_output(caesar_state->input, caesar_state->output);
build_output(caesar_state->input, caesar_state->output); text_box_set_text(caesar_state->text_box, caesar_state->output);
text_box_set_text(caesar_state->text_box, caesar_state->output); view_dispatcher_switch_to_view(caesar_state->view_dispatcher, 1);
view_dispatcher_switch_to_view(caesar_state->view_dispatcher, 1);
release_mutex((ValueMutex*)ctx, caesar_state);
release_mutex((ValueMutex*)ctx, caesar_state);
} }
static bool back_event_callback(void* ctx) { static bool back_event_callback(void* ctx) {
const CaesarState* caesar_state = acquire_mutex((ValueMutex*)ctx, 25); const CaesarState* caesar_state = acquire_mutex((ValueMutex*)ctx, 25);
view_dispatcher_stop(caesar_state->view_dispatcher); view_dispatcher_stop(caesar_state->view_dispatcher);
release_mutex((ValueMutex*)ctx, caesar_state); release_mutex((ValueMutex*)ctx, caesar_state);
return true; return true;
} }
static void caesar_cipher_state_init(CaesarState* const caesar_state) { static void caesar_cipher_state_init(CaesarState* const caesar_state) {
@ -97,52 +96,51 @@ static void caesar_cipher_state_free(CaesarState* const caesar_state) {
int32_t caesar_cipher_app() { int32_t caesar_cipher_app() {
CaesarState* caesar_state = malloc(sizeof(CaesarState)); CaesarState* caesar_state = malloc(sizeof(CaesarState));
FURI_LOG_D("caesar_cipher", "Running caesar_cipher_state_init"); FURI_LOG_D("caesar_cipher", "Running caesar_cipher_state_init");
caesar_cipher_state_init(caesar_state); caesar_cipher_state_init(caesar_state);
ValueMutex state_mutex; ValueMutex state_mutex;
if(!init_mutex(&state_mutex, caesar_state, sizeof(CaesarState))) { if(!init_mutex(&state_mutex, caesar_state, sizeof(CaesarState))) {
FURI_LOG_E("caesar_cipher", "cannot create mutex\r\n"); FURI_LOG_E("caesar_cipher", "cannot create mutex\r\n");
free(caesar_state); free(caesar_state);
return 255; return 255;
} }
FURI_LOG_D("caesar_cipher", "Assigning text input callback"); FURI_LOG_D("caesar_cipher", "Assigning text input callback");
text_input_set_result_callback( text_input_set_result_callback(
caesar_state->text_input, caesar_state->text_input,
text_input_callback, text_input_callback,
&state_mutex, &state_mutex,
caesar_state->input, caesar_state->input,
TEXT_BUFFER_SIZE, TEXT_BUFFER_SIZE,
//clear default text //clear default text
true true
); );
text_input_set_header_text(caesar_state->text_input, "Input"); text_input_set_header_text(caesar_state->text_input, "Input");
// Open GUI and register view_port // Open GUI and register view_port
Gui* gui = furi_record_open("gui"); Gui* gui = furi_record_open("gui");
//gui_add_view_port(gui, view_port, GuiLayerFullscreen); //gui_add_view_port(gui, view_port, GuiLayerFullscreen);
FURI_LOG_D("caesar_cipher", "Enabling view dispatcher queue"); FURI_LOG_D("caesar_cipher", "Enabling view dispatcher queue");
view_dispatcher_enable_queue(caesar_state->view_dispatcher); view_dispatcher_enable_queue(caesar_state->view_dispatcher);
FURI_LOG_D("caesar_cipher", "Adding text input view to dispatcher"); FURI_LOG_D("caesar_cipher", "Adding text input view to dispatcher");
view_dispatcher_add_view(caesar_state->view_dispatcher, 0, text_input_get_view(caesar_state->text_input)); view_dispatcher_add_view(caesar_state->view_dispatcher, 0, text_input_get_view(caesar_state->text_input));
view_dispatcher_add_view(caesar_state->view_dispatcher, 1, text_box_get_view(caesar_state->text_box)); view_dispatcher_add_view(caesar_state->view_dispatcher, 1, text_box_get_view(caesar_state->text_box));
FURI_LOG_D("caesar_cipher", "Attaching view dispatcher to GUI"); FURI_LOG_D("caesar_cipher", "Attaching view dispatcher to GUI");
view_dispatcher_attach_to_gui(caesar_state->view_dispatcher, gui, ViewDispatcherTypeFullscreen); view_dispatcher_attach_to_gui(caesar_state->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
FURI_LOG_D("ceasar_cipher", "starting view dispatcher"); FURI_LOG_D("ceasar_cipher", "starting view dispatcher");
view_dispatcher_set_navigation_event_callback(caesar_state->view_dispatcher, back_event_callback); view_dispatcher_set_navigation_event_callback(caesar_state->view_dispatcher, back_event_callback);
view_dispatcher_set_event_callback_context(caesar_state->view_dispatcher, &state_mutex); view_dispatcher_set_event_callback_context(caesar_state->view_dispatcher, &state_mutex);
view_dispatcher_switch_to_view(caesar_state->view_dispatcher, 0); view_dispatcher_switch_to_view(caesar_state->view_dispatcher, 0);
view_dispatcher_run(caesar_state->view_dispatcher); view_dispatcher_run(caesar_state->view_dispatcher);
furi_record_close("gui");
furi_record_close("gui"); delete_mutex(&state_mutex);
delete_mutex(&state_mutex); caesar_cipher_state_free(caesar_state);
caesar_cipher_state_free(caesar_state);
return 0;
return 0;
} }

Loading…
Cancel
Save