@@ -21,6 +21,7 @@ typedef struct {
2121} PluginEvent ;
2222
2323typedef struct {
24+ FuriMutex * mutex ;
2425 ViewDispatcher * view_dispatcher ;
2526 TextInput * text_input ;
2627 TextBox * text_box ;
@@ -58,7 +59,10 @@ static void build_output(char* input, char* output) {
5859}
5960
6061static void text_input_callback (void * ctx ) {
61- CaesarState * caesar_state = acquire_mutex ((ValueMutex * )ctx , 25 );
62+ furi_assert (ctx );
63+ CaesarState * caesar_state = ctx ;
64+ furi_mutex_acquire (caesar_state -> mutex , FuriWaitForever );
65+
6266 FURI_LOG_D ("caesar_cipher" , "Input text: %s" , caesar_state -> input );
6367 // this is where we build the output.
6468 string_to_uppercase (caesar_state -> input );
@@ -67,13 +71,14 @@ static void text_input_callback(void* ctx) {
6771 text_box_set_text (caesar_state -> text_box , caesar_state -> output );
6872 view_dispatcher_switch_to_view (caesar_state -> view_dispatcher , 1 );
6973
70- release_mutex (( ValueMutex * ) ctx , caesar_state );
74+ furi_mutex_release ( caesar_state -> mutex );
7175}
7276
7377static bool back_event_callback (void * ctx ) {
74- const CaesarState * caesar_state = acquire_mutex ((ValueMutex * )ctx , 25 );
78+ const CaesarState * caesar_state = ctx ;
79+ furi_mutex_acquire (caesar_state -> mutex , FuriWaitForever );
7580 view_dispatcher_stop (caesar_state -> view_dispatcher );
76- release_mutex (( ValueMutex * ) ctx , caesar_state );
81+ furi_mutex_release ( caesar_state -> mutex );
7782 return true;
7883}
7984
@@ -99,8 +104,8 @@ int32_t caesar_cipher_app() {
99104 FURI_LOG_D ("caesar_cipher" , "Running caesar_cipher_state_init" );
100105 caesar_cipher_state_init (caesar_state );
101106
102- ValueMutex state_mutex ;
103- if (!init_mutex ( & state_mutex , caesar_state , sizeof ( CaesarState )) ) {
107+ caesar_state -> mutex = furi_mutex_alloc ( FuriMutexTypeNormal ) ;
108+ if (!caesar_state -> mutex ) {
104109 FURI_LOG_E ("caesar_cipher" , "cannot create mutex\r\n" );
105110 free (caesar_state );
106111 return 255 ;
@@ -110,7 +115,7 @@ int32_t caesar_cipher_app() {
110115 text_input_set_result_callback (
111116 caesar_state -> text_input ,
112117 text_input_callback ,
113- & state_mutex ,
118+ caesar_state ,
114119 caesar_state -> input ,
115120 TEXT_BUFFER_SIZE ,
116121 //clear default text
@@ -135,12 +140,12 @@ int32_t caesar_cipher_app() {
135140 FURI_LOG_D ("ceasar_cipher" , "starting view dispatcher" );
136141 view_dispatcher_set_navigation_event_callback (
137142 caesar_state -> view_dispatcher , back_event_callback );
138- view_dispatcher_set_event_callback_context (caesar_state -> view_dispatcher , & state_mutex );
143+ view_dispatcher_set_event_callback_context (caesar_state -> view_dispatcher , caesar_state );
139144 view_dispatcher_switch_to_view (caesar_state -> view_dispatcher , 0 );
140145 view_dispatcher_run (caesar_state -> view_dispatcher );
141146
142147 furi_record_close ("gui" );
143- delete_mutex ( & state_mutex );
148+ furi_mutex_free ( caesar_state -> mutex );
144149 caesar_cipher_state_free (caesar_state );
145150
146151 return 0 ;
0 commit comments