@@ -58,25 +58,24 @@ static void build_output(char* input, char* output) {
58
58
}
59
59
60
60
static void text_input_callback (void * ctx ) {
61
- CaesarState * caesar_state = acquire_mutex ((ValueMutex * )ctx , 25 );
62
- FURI_LOG_D ("caesar_cipher" , "Input text: %s" , caesar_state -> input );
63
- // this is where we build the output.
64
- //char upper[TEXT_BUFFER_SIZE];
65
- string_to_uppercase (caesar_state -> input );
66
- FURI_LOG_D ("caesar_cipher" , "Upper text: %s" , caesar_state -> input );
67
- build_output (caesar_state -> input , caesar_state -> output );
68
- text_box_set_text (caesar_state -> text_box , caesar_state -> output );
69
- view_dispatcher_switch_to_view (caesar_state -> view_dispatcher , 1 );
70
-
71
- release_mutex ((ValueMutex * )ctx , caesar_state );
61
+ CaesarState * caesar_state = acquire_mutex ((ValueMutex * )ctx , 25 );
62
+ FURI_LOG_D ("caesar_cipher" , "Input text: %s" , caesar_state -> input );
63
+ // this is where we build the output.
64
+ string_to_uppercase (caesar_state -> input );
65
+ FURI_LOG_D ("caesar_cipher" , "Upper text: %s" , caesar_state -> input );
66
+ build_output (caesar_state -> input , caesar_state -> output );
67
+ text_box_set_text (caesar_state -> text_box , caesar_state -> output );
68
+ view_dispatcher_switch_to_view (caesar_state -> view_dispatcher , 1 );
69
+
70
+ release_mutex ((ValueMutex * )ctx , caesar_state );
72
71
}
73
72
74
73
75
74
static bool back_event_callback (void * ctx ) {
76
- const CaesarState * caesar_state = acquire_mutex ((ValueMutex * )ctx , 25 );
77
- view_dispatcher_stop (caesar_state -> view_dispatcher );
78
- release_mutex ((ValueMutex * )ctx , caesar_state );
79
- return true;
75
+ const CaesarState * caesar_state = acquire_mutex ((ValueMutex * )ctx , 25 );
76
+ view_dispatcher_stop (caesar_state -> view_dispatcher );
77
+ release_mutex ((ValueMutex * )ctx , caesar_state );
78
+ return true;
80
79
}
81
80
82
81
static void caesar_cipher_state_init (CaesarState * const caesar_state ) {
@@ -97,52 +96,51 @@ static void caesar_cipher_state_free(CaesarState* const caesar_state) {
97
96
98
97
int32_t caesar_cipher_app () {
99
98
100
- CaesarState * caesar_state = malloc (sizeof (CaesarState ));
101
-
102
- FURI_LOG_D ("caesar_cipher" , "Running caesar_cipher_state_init" );
103
- caesar_cipher_state_init (caesar_state );
99
+ CaesarState * caesar_state = malloc (sizeof (CaesarState ));
100
+
101
+ FURI_LOG_D ("caesar_cipher" , "Running caesar_cipher_state_init" );
102
+ caesar_cipher_state_init (caesar_state );
104
103
105
- ValueMutex state_mutex ;
106
- if (!init_mutex (& state_mutex , caesar_state , sizeof (CaesarState ))) {
107
- FURI_LOG_E ("caesar_cipher" , "cannot create mutex\r\n" );
108
- free (caesar_state );
109
- return 255 ;
110
- }
104
+ ValueMutex state_mutex ;
105
+ if (!init_mutex (& state_mutex , caesar_state , sizeof (CaesarState ))) {
106
+ FURI_LOG_E ("caesar_cipher" , "cannot create mutex\r\n" );
107
+ free (caesar_state );
108
+ return 255 ;
109
+ }
111
110
112
- FURI_LOG_D ("caesar_cipher" , "Assigning text input callback" );
113
- text_input_set_result_callback (
114
- caesar_state -> text_input ,
115
- text_input_callback ,
116
- & state_mutex ,
117
- caesar_state -> input ,
118
- TEXT_BUFFER_SIZE ,
119
- //clear default text
120
- true
121
- );
122
- text_input_set_header_text (caesar_state -> text_input , "Input" );
123
-
124
- // Open GUI and register view_port
125
- Gui * gui = furi_record_open ("gui" );
126
- //gui_add_view_port(gui, view_port, GuiLayerFullscreen);
127
-
128
- FURI_LOG_D ("caesar_cipher" , "Enabling view dispatcher queue" );
129
- view_dispatcher_enable_queue (caesar_state -> view_dispatcher );
130
-
131
- FURI_LOG_D ("caesar_cipher" , "Adding text input view to dispatcher" );
132
- view_dispatcher_add_view (caesar_state -> view_dispatcher , 0 , text_input_get_view (caesar_state -> text_input ));
133
- view_dispatcher_add_view (caesar_state -> view_dispatcher , 1 , text_box_get_view (caesar_state -> text_box ));
134
- FURI_LOG_D ("caesar_cipher" , "Attaching view dispatcher to GUI" );
135
- view_dispatcher_attach_to_gui (caesar_state -> view_dispatcher , gui , ViewDispatcherTypeFullscreen );
136
- FURI_LOG_D ("ceasar_cipher" , "starting view dispatcher" );
137
- view_dispatcher_set_navigation_event_callback (caesar_state -> view_dispatcher , back_event_callback );
138
- view_dispatcher_set_event_callback_context (caesar_state -> view_dispatcher , & state_mutex );
139
- view_dispatcher_switch_to_view (caesar_state -> view_dispatcher , 0 );
140
- view_dispatcher_run (caesar_state -> view_dispatcher );
141
-
142
-
143
- furi_record_close ("gui" );
144
- delete_mutex (& state_mutex );
145
- caesar_cipher_state_free (caesar_state );
146
-
147
- return 0 ;
111
+ FURI_LOG_D ("caesar_cipher" , "Assigning text input callback" );
112
+ text_input_set_result_callback (
113
+ caesar_state -> text_input ,
114
+ text_input_callback ,
115
+ & state_mutex ,
116
+ caesar_state -> input ,
117
+ TEXT_BUFFER_SIZE ,
118
+ //clear default text
119
+ true
120
+ );
121
+ text_input_set_header_text (caesar_state -> text_input , "Input" );
122
+
123
+ // Open GUI and register view_port
124
+ Gui * gui = furi_record_open ("gui" );
125
+ //gui_add_view_port(gui, view_port, GuiLayerFullscreen);
126
+
127
+ FURI_LOG_D ("caesar_cipher" , "Enabling view dispatcher queue" );
128
+ view_dispatcher_enable_queue (caesar_state -> view_dispatcher );
129
+
130
+ FURI_LOG_D ("caesar_cipher" , "Adding text input view to dispatcher" );
131
+ view_dispatcher_add_view (caesar_state -> view_dispatcher , 0 , text_input_get_view (caesar_state -> text_input ));
132
+ view_dispatcher_add_view (caesar_state -> view_dispatcher , 1 , text_box_get_view (caesar_state -> text_box ));
133
+ FURI_LOG_D ("caesar_cipher" , "Attaching view dispatcher to GUI" );
134
+ view_dispatcher_attach_to_gui (caesar_state -> view_dispatcher , gui , ViewDispatcherTypeFullscreen );
135
+ FURI_LOG_D ("ceasar_cipher" , "starting view dispatcher" );
136
+ view_dispatcher_set_navigation_event_callback (caesar_state -> view_dispatcher , back_event_callback );
137
+ view_dispatcher_set_event_callback_context (caesar_state -> view_dispatcher , & state_mutex );
138
+ view_dispatcher_switch_to_view (caesar_state -> view_dispatcher , 0 );
139
+ view_dispatcher_run (caesar_state -> view_dispatcher );
140
+
141
+ furi_record_close ("gui" );
142
+ delete_mutex (& state_mutex );
143
+ caesar_cipher_state_free (caesar_state );
144
+
145
+ return 0 ;
148
146
}
0 commit comments