* nfc: st25tb: rework async poller * nfc: st25tb: introduce sync poller * nfc: st25tb: add write support * nfc: st25tb: rewrite poller to use better states * nfc: st25tb: move to mode request state after success * nfc: st25tb: minor bug fixes * type wasn't properly set on ready event * sending NfcCustomEventPollerFailure on St25tbPollerEventTypeFailure caused poller to being freed and ultimately resulted in a thread crash Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
		
			
				
	
	
		
			111 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			111 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
#include "st25tb.h"
 | 
						|
#include "st25tb_render.h"
 | 
						|
 | 
						|
#include <nfc/protocols/st25tb/st25tb_poller.h>
 | 
						|
 | 
						|
#include "nfc/nfc_app_i.h"
 | 
						|
 | 
						|
#include "../nfc_protocol_support_common.h"
 | 
						|
#include "../nfc_protocol_support_gui_common.h"
 | 
						|
 | 
						|
static void nfc_scene_info_on_enter_st25tb(NfcApp* instance) {
 | 
						|
    const NfcDevice* device = instance->nfc_device;
 | 
						|
    const St25tbData* data = nfc_device_get_data(device, NfcProtocolSt25tb);
 | 
						|
 | 
						|
    FuriString* temp_str = furi_string_alloc();
 | 
						|
    furi_string_cat_printf(
 | 
						|
        temp_str, "\e#%s\n", nfc_device_get_name(device, NfcDeviceNameTypeFull));
 | 
						|
    nfc_render_st25tb_info(data, NfcProtocolFormatTypeFull, temp_str);
 | 
						|
 | 
						|
    widget_add_text_scroll_element(
 | 
						|
        instance->widget, 0, 0, 128, 64, furi_string_get_cstr(temp_str));
 | 
						|
 | 
						|
    furi_string_free(temp_str);
 | 
						|
}
 | 
						|
 | 
						|
static NfcCommand nfc_scene_read_poller_callback_st25tb(NfcGenericEvent event, void* context) {
 | 
						|
    furi_assert(event.protocol == NfcProtocolSt25tb);
 | 
						|
 | 
						|
    NfcApp* instance = context;
 | 
						|
    const St25tbPollerEvent* st25tb_event = event.event_data;
 | 
						|
 | 
						|
    if(st25tb_event->type == St25tbPollerEventTypeRequestMode) {
 | 
						|
        st25tb_event->data->mode_request.mode = St25tbPollerModeRead;
 | 
						|
    } else if(st25tb_event->type == St25tbPollerEventTypeSuccess) {
 | 
						|
        nfc_device_set_data(
 | 
						|
            instance->nfc_device, NfcProtocolSt25tb, nfc_poller_get_data(instance->poller));
 | 
						|
        view_dispatcher_send_custom_event(instance->view_dispatcher, NfcCustomEventPollerSuccess);
 | 
						|
        return NfcCommandStop;
 | 
						|
    }
 | 
						|
 | 
						|
    return NfcCommandContinue;
 | 
						|
}
 | 
						|
 | 
						|
static void nfc_scene_read_on_enter_st25tb(NfcApp* instance) {
 | 
						|
    nfc_poller_start(instance->poller, nfc_scene_read_poller_callback_st25tb, instance);
 | 
						|
}
 | 
						|
 | 
						|
static void nfc_scene_read_success_on_enter_st25tb(NfcApp* instance) {
 | 
						|
    const NfcDevice* device = instance->nfc_device;
 | 
						|
    const St25tbData* data = nfc_device_get_data(device, NfcProtocolSt25tb);
 | 
						|
 | 
						|
    FuriString* temp_str = furi_string_alloc();
 | 
						|
    furi_string_cat_printf(
 | 
						|
        temp_str, "\e#%s\n", nfc_device_get_name(device, NfcDeviceNameTypeFull));
 | 
						|
    nfc_render_st25tb_info(data, NfcProtocolFormatTypeShort, temp_str);
 | 
						|
 | 
						|
    widget_add_text_scroll_element(
 | 
						|
        instance->widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str));
 | 
						|
 | 
						|
    furi_string_free(temp_str);
 | 
						|
}
 | 
						|
 | 
						|
static bool nfc_scene_saved_menu_on_event_st25tb(NfcApp* instance, uint32_t event) {
 | 
						|
    if(event == SubmenuIndexCommonEdit) {
 | 
						|
        scene_manager_next_scene(instance->scene_manager, NfcSceneSetUid);
 | 
						|
        return true;
 | 
						|
    }
 | 
						|
 | 
						|
    return false;
 | 
						|
}
 | 
						|
 | 
						|
const NfcProtocolSupportBase nfc_protocol_support_st25tb = {
 | 
						|
    .features = NfcProtocolFeatureNone,
 | 
						|
 | 
						|
    .scene_info =
 | 
						|
        {
 | 
						|
            .on_enter = nfc_scene_info_on_enter_st25tb,
 | 
						|
            .on_event = nfc_protocol_support_common_on_event_empty,
 | 
						|
        },
 | 
						|
    .scene_read =
 | 
						|
        {
 | 
						|
            .on_enter = nfc_scene_read_on_enter_st25tb,
 | 
						|
            .on_event = nfc_protocol_support_common_on_event_empty,
 | 
						|
        },
 | 
						|
    .scene_read_menu =
 | 
						|
        {
 | 
						|
            .on_enter = nfc_protocol_support_common_on_enter_empty,
 | 
						|
            .on_event = nfc_protocol_support_common_on_event_empty,
 | 
						|
        },
 | 
						|
    .scene_read_success =
 | 
						|
        {
 | 
						|
            .on_enter = nfc_scene_read_success_on_enter_st25tb,
 | 
						|
            .on_event = nfc_protocol_support_common_on_event_empty,
 | 
						|
        },
 | 
						|
    .scene_saved_menu =
 | 
						|
        {
 | 
						|
            .on_enter = nfc_protocol_support_common_on_enter_empty,
 | 
						|
            .on_event = nfc_scene_saved_menu_on_event_st25tb,
 | 
						|
        },
 | 
						|
    .scene_save_name =
 | 
						|
        {
 | 
						|
            .on_enter = nfc_protocol_support_common_on_enter_empty,
 | 
						|
            .on_event = nfc_protocol_support_common_on_event_empty,
 | 
						|
        },
 | 
						|
    .scene_emulate =
 | 
						|
        {
 | 
						|
            .on_enter = nfc_protocol_support_common_on_enter_empty,
 | 
						|
            .on_event = nfc_protocol_support_common_on_event_empty,
 | 
						|
        },
 | 
						|
};
 |