From 0846de20a4484da3345045c4089c2ee23c08b24b Mon Sep 17 00:00:00 2001 From: DrZlo13 Date: Sat, 13 Feb 2021 01:44:14 +1000 Subject: [PATCH] IrDA test app^ acquire state only when needed, fix exit, remove delay in main program cycle (#335) --- applications/irda/irda.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/applications/irda/irda.c b/applications/irda/irda.c index 6da6f088..0566d779 100644 --- a/applications/irda/irda.c +++ b/applications/irda/irda.c @@ -294,20 +294,27 @@ void irda(void* p) { AppEvent event; while(1) { osStatus_t event_status = osMessageQueueGet(event_queue, &event, NULL, 500); - State* state = (State*)acquire_mutex_block(&state_mutex); if(event_status == osOK) { if(event.type == EventTypeKey) { + State* state = (State*)acquire_mutex_block(&state_mutex); + // press events if(event.value.input.type == InputTypeShort && event.value.input.key == InputKeyBack) { + api_interrupt_remove(irda_timer_capture_callback, InterruptTypeTimerCapture); + release_mutex(&state_mutex, state); + // remove all view_ports create by app - view_port_enabled_set(view_port, false); gui_remove_view_port(gui, view_port); + view_port_free(view_port); // free decoder free_decoder(decoder); + delete_mutex(&state_mutex); + osMessageQueueDelete(event_queue); + // exit furiac_exit(NULL); } @@ -327,6 +334,10 @@ void irda(void* p) { } modes[state->mode_id].input(&event, state); + + release_mutex(&state_mutex, state); + view_port_update(view_port); + } else if(event.type == EventTypeRX) { IrDADecoderOutputData out; const uint8_t out_data_length = 4; @@ -342,6 +353,8 @@ void irda(void* p) { if(decoded) { // save only if we in packet mode + State* state = (State*)acquire_mutex_block(&state_mutex); + if(state->mode_id == 1) { if(out.protocol == IRDA_NEC) { printf("P=NEC "); @@ -361,9 +374,11 @@ void irda(void* p) { } } + release_mutex(&state_mutex, state); + view_port_update(view_port); + // blink anyway gpio_write(green_led_record, false); - delay(10); gpio_write(green_led_record, true); } } @@ -371,8 +386,5 @@ void irda(void* p) { } else { // event timeout } - - release_mutex(&state_mutex, state); - view_port_update(view_port); } } \ No newline at end of file