|
|
@@ -21,6 +21,7 @@ typedef struct {
|
|
|
} PluginEvent;
|
|
|
|
|
|
typedef struct {
|
|
|
+ FuriMutex* mutex;
|
|
|
ViewDispatcher* view_dispatcher;
|
|
|
TextInput* text_input;
|
|
|
TextBox* text_box;
|
|
|
@@ -58,7 +59,9 @@ static void build_output(char* input, char* output) {
|
|
|
}
|
|
|
|
|
|
static void text_input_callback(void* ctx) {
|
|
|
- CaesarState* caesar_state = acquire_mutex((ValueMutex*)ctx, 25);
|
|
|
+ furi_assert(ctx);
|
|
|
+ CaesarState* caesar_state = ctx;
|
|
|
+ furi_mutex_acquire(caesar_state->mutex, FuriWaitForever);
|
|
|
FURI_LOG_D("caesar_cipher", "Input text: %s", caesar_state->input);
|
|
|
// this is where we build the output.
|
|
|
string_to_uppercase(caesar_state->input);
|
|
|
@@ -67,14 +70,15 @@ static void text_input_callback(void* ctx) {
|
|
|
text_box_set_text(caesar_state->text_box, caesar_state->output);
|
|
|
view_dispatcher_switch_to_view(caesar_state->view_dispatcher, 1);
|
|
|
|
|
|
- release_mutex((ValueMutex*)ctx, caesar_state);
|
|
|
+ furi_mutex_release(caesar_state->mutex);
|
|
|
}
|
|
|
|
|
|
|
|
|
static bool back_event_callback(void* ctx) {
|
|
|
- const CaesarState* caesar_state = acquire_mutex((ValueMutex*)ctx, 25);
|
|
|
+ const CaesarState* caesar_state = ctx;
|
|
|
+ furi_mutex_acquire(caesar_state->mutex, FuriWaitForever);
|
|
|
view_dispatcher_stop(caesar_state->view_dispatcher);
|
|
|
- release_mutex((ValueMutex*)ctx, caesar_state);
|
|
|
+ furi_mutex_release(caesar_state->mutex);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -101,8 +105,8 @@ int32_t caesar_cipher_app() {
|
|
|
FURI_LOG_D("caesar_cipher", "Running caesar_cipher_state_init");
|
|
|
caesar_cipher_state_init(caesar_state);
|
|
|
|
|
|
- ValueMutex state_mutex;
|
|
|
- if(!init_mutex(&state_mutex, caesar_state, sizeof(CaesarState))) {
|
|
|
+ caesar_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
|
|
+ if(!caesar_state->mutex) {
|
|
|
FURI_LOG_E("caesar_cipher", "cannot create mutex\r\n");
|
|
|
free(caesar_state);
|
|
|
return 255;
|
|
|
@@ -112,7 +116,7 @@ int32_t caesar_cipher_app() {
|
|
|
text_input_set_result_callback(
|
|
|
caesar_state->text_input,
|
|
|
text_input_callback,
|
|
|
- &state_mutex,
|
|
|
+ caesar_state,
|
|
|
caesar_state->input,
|
|
|
TEXT_BUFFER_SIZE,
|
|
|
//clear default text
|
|
|
@@ -139,7 +143,7 @@ int32_t caesar_cipher_app() {
|
|
|
view_dispatcher_run(caesar_state->view_dispatcher);
|
|
|
|
|
|
furi_record_close("gui");
|
|
|
- delete_mutex(&state_mutex);
|
|
|
+ furi_mutex_free(caesar_state->mutex);
|
|
|
caesar_cipher_state_free(caesar_state);
|
|
|
|
|
|
return 0;
|