diff --git a/docs/en/04-Using-Firmware.md b/docs/en/04-Using-Firmware.md index 9dc44299..908d2105 100644 --- a/docs/en/04-Using-Firmware.md +++ b/docs/en/04-Using-Firmware.md @@ -238,8 +238,6 @@ The device use a "special" amiibo slot where only an amiibo can be used, the ami Changing the mode preserve the current selected amiibo, with exception of «Read-write mode». -## Auto Random. [] -When this option is turn ON a new random UUID for the current amiibo is generated after each time a game read it. Allowing to use the same amiibo multiple times on games with restrictions. You cannot change the active amiibo on this mode. Cannot be turned OFF for «Randomize (Auto)» mode, cannot be turned ON for «Randomize (Manual)»mode; ## Compati. Mode [] Shows the emulation firmware mode, the supported values are V1, V2 and AmiLoop, there are several APPs each one designed for a AmiiboLink firmware version or to the AmiLoop protocol. Using this setting you can match the emulation with the protocol needed by the APP you use on your phone. ## Tag Details diff --git a/docs/it/04-Using-Firmware.md b/docs/it/04-Using-Firmware.md index 658d99d9..79980b0b 100644 --- a/docs/it/04-Using-Firmware.md +++ b/docs/it/04-Using-Firmware.md @@ -237,10 +237,6 @@ Il dispositivo utilizza uno slot amiibo "speciale" dove può essere utilizzato s Cambiando la modalità si conserva l'amiibo selezionato corrente, con l'eccezione della modalità «Lettura-scrittura». -## Auto Rand. [] -Quando questa opzione è attiva, viene generato un nuovo UUID casuale per l'amiibo corrente ogni volta che un gioco lo legge, -consentendo di utilizzare lo stesso amiibo più volte su giochi con restrizioni. Non puoi cambiare l'amiibo attivo in questa modalità. - ### Modalità Compati. [] Mostra la modalità di emulazione del firmware, i valori supportati sono V1, V2 e AmiLoop, ci sono diverse APP, ognuna progettata per una versione del firmware AmiiboLink o per il protocollo AmiLoop. Utilizzando questa impostazione puoi far corrispondere l'emulazione con il protocollo necessario per l'APP che usi sul tuo telefono. diff --git a/fw/application/src/app/amiibolink/scene/amiibolink_scene_main.c b/fw/application/src/app/amiibolink/scene/amiibolink_scene_main.c index 5baa69d8..8c1cc434 100644 --- a/fw/application/src/app/amiibolink/scene/amiibolink_scene_main.c +++ b/fw/application/src/app/amiibolink/scene/amiibolink_scene_main.c @@ -25,7 +25,30 @@ APP_TIMER_DEF(m_amiibo_gen_delay_timer); -static void ntag_generate_cb() { +static void amiibolink_scene_amiibo_detail_menu_msg_box_no_key_cb(mui_msg_box_event_t event, mui_msg_box_t *p_msg_box) { + app_amiibolink_t *app = p_msg_box->user_data; + if (event == MUI_MSG_BOX_EVENT_SELECT_CENTER) { + mui_view_dispatcher_switch_to_view(app->p_view_dispatcher, AMIIBOLINK_VIEW_ID_MAIN); + } +} + +static void amiibolink_scene_amiibo_detail_no_key_msg(app_amiibolink_t *app) { + mui_msg_box_set_header(app->p_msg_box, getLangString(_L_AMIIBO_KEY_UNLOADED)); + mui_msg_box_set_message(app->p_msg_box, getLangString(_L_UPLOAD_KEY_RETAIL_BIN)); + mui_msg_box_set_btn_text(app->p_msg_box, NULL, getLangString(_L_KNOW), NULL); + mui_msg_box_set_btn_focus(app->p_msg_box, 1); + mui_msg_box_set_event_cb(app->p_msg_box, amiibolink_scene_amiibo_detail_menu_msg_box_no_key_cb); + + mui_view_dispatcher_switch_to_view(app->p_view_dispatcher, AMIIBOLINK_VIEW_ID_MSG_BOX); +} + +static void ntag_generate_cb(void* ctx) { + app_amiibolink_t *app = ctx; + if (!amiibo_helper_is_key_loaded()) { + amiibolink_scene_amiibo_detail_no_key_msg(app); + return; + } + ret_code_t err_code = amiibo_helper_rand_amiibo_uuid(ntag_emu_get_current_tag()); NRF_LOG_INFO("ntag generate: %d", err_code); if (err_code == NRF_SUCCESS) { @@ -40,7 +63,7 @@ static void ntag_update(app_amiibolink_t *app, uint8_t index, ntag_t *p_ntag) { NRF_LOG_INFO("ntag_update: index=%d, err_code=%d", index, err_code); } -static void ntag_reload(app_amiibolink_t *app, uint8_t index){ +static void ntag_reload(app_amiibolink_t *app, uint8_t index) { ntag_t ntag; ret_code_t err_code = ntag_store_read(app->p_amiibolink_view->index, &ntag); if (err_code == NRF_SUCCESS) { @@ -48,37 +71,37 @@ static void ntag_reload(app_amiibolink_t *app, uint8_t index){ } } -static void ntag_init(){ } +static void ntag_init() {} #else static void ntag_update(app_amiibolink_t *app, uint8_t index, ntag_t *p_ntag) { char path[VFS_MAX_PATH_LEN] = {0}; sprintf(path, "/amiibolink/%02d.bin", index); - vfs_driver_t * p_driver = vfs_get_driver(VFS_DRIVE_EXT); + vfs_driver_t *p_driver = vfs_get_driver(VFS_DRIVE_EXT); int32_t err_code = p_driver->write_file_data(path, p_ntag->data, NTAG_DATA_SIZE); NRF_LOG_INFO("ntag_update: index=%d, err_code=%d", index, err_code); } -static void ntag_reload(app_amiibolink_t *app, uint8_t index){ +static void ntag_reload(app_amiibolink_t *app, uint8_t index) { ntag_t ntag = {0}; char path[VFS_MAX_PATH_LEN] = {0}; memset(&ntag, 0, sizeof(ntag_t)); memset(path, 0, sizeof(path)); sprintf(path, "/amiibolink/%02d.bin", index); - vfs_driver_t * p_driver = vfs_get_driver(VFS_DRIVE_EXT); + vfs_driver_t *p_driver = vfs_get_driver(VFS_DRIVE_EXT); int32_t err_code = p_driver->read_file_data(path, ntag.data, NTAG_DATA_SIZE); if (err_code >= NTAG_DATA_SIZE) { ntag_emu_set_tag(&ntag); - }else{ + } else { NRF_LOG_INFO("ntag_reload: ntag_load_failed. index=%d, err_code=%d", index, err_code); ntag_store_new_rand(&ntag); ntag_emu_set_tag(&ntag); } } -static void ntag_init(){ - vfs_driver_t * p_driver = vfs_get_driver(VFS_DRIVE_EXT); +static void ntag_init() { + vfs_driver_t *p_driver = vfs_get_driver(VFS_DRIVE_EXT); p_driver->create_dir("/amiibolink"); } @@ -91,12 +114,9 @@ static void ntag_update_cb(ntag_event_type_t type, void *context, ntag_t *p_ntag if (type == NTAG_EVENT_TYPE_WRITTEN && app->amiibolink_mode != BLE_AMIIBOLINK_MODE_RANDOM) { ntag_update(app, app->p_amiibolink_view->index, p_ntag); mui_update(mui()); - } else if (type == NTAG_EVENT_TYPE_READ) { - settings_data_t* p_settings = settings_get_data(); - if (p_settings->auto_gen_amiibolink) { - app_timer_stop(m_amiibo_gen_delay_timer); - app_timer_start(m_amiibo_gen_delay_timer, APP_TIMER_TICKS(1000), app); - } + } else if (type == NTAG_EVENT_TYPE_READ && app->amiibolink_mode == BLE_AMIIBOLINK_MODE_RANDOM_AUTO_GEN) { + app_timer_stop(m_amiibo_gen_delay_timer); + app_timer_start(m_amiibo_gen_delay_timer, APP_TIMER_TICKS(1000), app); } } @@ -109,7 +129,8 @@ static void amiibolink_scene_main_event_cb(amiibolink_view_event_t event, amiibo } } -static void amiibolink_scene_switch_mode(app_amiibolink_t *app, ble_amiibolink_mode_t mode, uint8_t initial_index){ +static void amiibolink_scene_switch_mode(app_amiibolink_t *app, ble_amiibolink_mode_t mode, uint8_t initial_index) { + NRF_LOG_INFO("new mode: %d", mode); app->amiibolink_mode = mode; amiibolink_view_set_amiibolink_mode(app->p_amiibolink_view, mode); amiibolink_view_set_index(app->p_amiibolink_view, initial_index); @@ -117,16 +138,12 @@ static void amiibolink_scene_switch_mode(app_amiibolink_t *app, ble_amiibolink_m ble_amiibolink_set_mode(mode); - if(mode == BLE_AMIIBOLINK_MODE_NTAG){ + if (mode == BLE_AMIIBOLINK_MODE_NTAG) { ntag_reload(app, DEFAULT_NTAG_INDEX); - }else if(mode == BLE_AMIIBOLINK_MODE_CYCLE){ + } else if (mode == BLE_AMIIBOLINK_MODE_CYCLE) { ntag_reload(app, initial_index); - }else if(mode == BLE_AMIIBOLINK_MODE_RANDOM_AUTO_GEN){ - settings_data_t* p_settings = settings_get_data(); - p_settings->auto_gen_amiibolink = true; - }else if(mode == BLE_AMIIBOLINK_MODE_RANDOM){ - settings_data_t* p_settings = settings_get_data(); - p_settings->auto_gen_amiibolink = false; + } else if (mode == BLE_AMIIBOLINK_MODE_RANDOM_AUTO_GEN) { + } else if (mode == BLE_AMIIBOLINK_MODE_RANDOM) { } } @@ -138,15 +155,15 @@ static void amiibolink_scene_ble_event_handler(void *ctx, ble_amiibolink_event_t if (app->amiibolink_mode == BLE_AMIIBOLINK_MODE_CYCLE) { // save ntag - ntag_update(app, p_view->index, (ntag_t *) data); + ntag_update(app, p_view->index, (ntag_t *)data); if (p_view->index < p_view->max_size - 1) { p_view->index++; } else { p_view->index = 0; } ntag_reload(app, p_view->index); - }else if(app->amiibolink_mode == BLE_AMIIBOLINK_MODE_NTAG){ - ntag_update(app, DEFAULT_NTAG_INDEX, (ntag_t *) data); + } else if (app->amiibolink_mode == BLE_AMIIBOLINK_MODE_NTAG) { + ntag_update(app, DEFAULT_NTAG_INDEX, (ntag_t *)data); } mui_update(mui()); @@ -189,7 +206,7 @@ void amiibolink_scene_main_on_enter(void *user_data) { int32_t err_code = app_timer_create(&m_amiibo_gen_delay_timer, APP_TIMER_MODE_SINGLE_SHOT, ntag_generate_cb); APP_ERROR_CHECK(err_code); - amiibolink_scene_switch_mode(app,app->amiibolink_mode, amiibolink_view_get_index(app->p_amiibolink_view)); + amiibolink_scene_switch_mode(app, app->amiibolink_mode, amiibolink_view_get_index(app->p_amiibolink_view)); amiibolink_view_set_event_cb(app->p_amiibolink_view, amiibolink_scene_main_event_cb); mui_view_dispatcher_switch_to_view(app->p_view_dispatcher, AMIIBOLINK_VIEW_ID_MAIN); } diff --git a/fw/application/src/app/amiibolink/scene/amiibolink_scene_menu.c b/fw/application/src/app/amiibolink/scene/amiibolink_scene_menu.c index 88211644..dc07cb7f 100644 --- a/fw/application/src/app/amiibolink/scene/amiibolink_scene_menu.c +++ b/fw/application/src/app/amiibolink/scene/amiibolink_scene_menu.c @@ -24,23 +24,6 @@ #define AMIIBOLINK_MENU_VER 3 #define AMIIBOLINK_MENU_AUTO_GENERATE 4 -static void amiibolink_scene_amiibo_detail_menu_msg_box_no_key_cb(mui_msg_box_event_t event, mui_msg_box_t *p_msg_box) { - app_amiibolink_t *app = p_msg_box->user_data; - if (event == MUI_MSG_BOX_EVENT_SELECT_CENTER) { - mui_view_dispatcher_switch_to_view(app->p_view_dispatcher, AMIIBOLINK_VIEW_ID_LIST); - } -} - -static void amiibolink_scene_amiibo_detail_no_key_msg(app_amiibolink_t *app) { - mui_msg_box_set_header(app->p_msg_box, getLangString(_L_AMIIBO_KEY_UNLOADED)); - mui_msg_box_set_message(app->p_msg_box, getLangString(_L_UPLOAD_KEY_RETAIL_BIN)); - mui_msg_box_set_btn_text(app->p_msg_box, NULL, getLangString(_L_KNOW), NULL); - mui_msg_box_set_btn_focus(app->p_msg_box, 1); - mui_msg_box_set_event_cb(app->p_msg_box, amiibolink_scene_amiibo_detail_menu_msg_box_no_key_cb); - - mui_view_dispatcher_switch_to_view(app->p_view_dispatcher, AMIIBOLINK_VIEW_ID_MSG_BOX); -} - void amiibolink_scene_menu_on_event(mui_list_view_event_t event, mui_list_view_t *p_list_view, mui_list_item_t *p_item) { app_amiibolink_t *app = p_list_view->user_data; @@ -55,20 +38,6 @@ void amiibolink_scene_menu_on_event(mui_list_view_event_t event, mui_list_view_t mui_scene_dispatcher_next_scene(app->p_scene_dispatcher, AMIIBOLINK_SCENE_MENU_VER); } else if (menu_code == AMIIBOLINK_MENU_BACK_EXIT) { mini_app_launcher_kill(mini_app_launcher(), MINI_APP_ID_AMIIBOLINK); - } else if (menu_code == AMIIBOLINK_MENU_AUTO_GENERATE) { - settings_data_t *p_settings = settings_get_data(); - - if (!amiibo_helper_is_key_loaded() && !p_settings->auto_gen_amiibolink) { - amiibolink_scene_amiibo_detail_no_key_msg(app); - return; - } - - p_settings->auto_gen_amiibolink = !p_settings->auto_gen_amiibolink; - NRF_LOG_INFO("auto_generate: %d", p_settings->auto_gen_amiibolink); - sprintf(txt, "[%s]", p_settings->auto_gen_amiibolink ? getLangString(_L_ON) : getLangString(_L_OFF)); - settings_save(); - - string_set_str(p_item->sub_text, txt); } } } @@ -94,9 +63,6 @@ void amiibolink_scene_menu_on_enter(void *user_data) { mui_list_view_add_item_ext(app->p_list_view, ICON_MODE, getLangString(_L_MODE), txt, (void *)AMIIBOLINK_MENU_MODE); settings_data_t *p_settings = settings_get_data(); - sprintf(txt, "[%s]", p_settings->auto_gen_amiibolink ? getLangString(_L_ON) : getLangString(_L_OFF)); - mui_list_view_add_item_ext(app->p_list_view, ICON_AUTO, getLangString(_L_AUTO_RANDOM), txt, - (void *)AMIIBOLINK_MENU_AUTO_GENERATE); sprintf(txt, "[%s]", p_settings->amiibo_link_ver == BLE_AMIIBOLINK_VER_V2 diff --git a/fw/application/src/app/amiibolink/view/amiibolink_view.c b/fw/application/src/app/amiibolink/view/amiibolink_view.c index a00d53b7..b4328bee 100644 --- a/fw/application/src/app/amiibolink/view/amiibolink_view.c +++ b/fw/application/src/app/amiibolink/view/amiibolink_view.c @@ -9,6 +9,7 @@ #include "db_header.h" #define ICON_RANDOM 0xe20d +#define ICON_AUTO 0xe1b2 #define ICON_NTAG 0xe1cf #define ICON_LEFT 0xe1ac #define ICON_RIGHT 0xe1aa @@ -28,10 +29,12 @@ static void amiibolink_view_on_draw(mui_view_t *p_view, mui_canvas_t *p_canvas) mui_canvas_set_draw_color(p_canvas, 0); // draw mode icon - if (p_amiibolink_view->amiibolink_mode == BLE_AMIIBOLINK_MODE_RANDOM || - p_amiibolink_view->amiibolink_mode ==BLE_AMIIBOLINK_MODE_RANDOM_AUTO_GEN) { + if (p_amiibolink_view->amiibolink_mode == BLE_AMIIBOLINK_MODE_RANDOM){ mui_canvas_set_font(p_canvas, u8g2_font_siji_t_6x10); mui_canvas_draw_glyph(p_canvas, 10, y + 10, ICON_RANDOM); + }else if(p_amiibolink_view->amiibolink_mode ==BLE_AMIIBOLINK_MODE_RANDOM_AUTO_GEN) { + mui_canvas_set_font(p_canvas, u8g2_font_siji_t_6x10); + mui_canvas_draw_glyph(p_canvas, 10, y + 10, ICON_AUTO); } else if (p_amiibolink_view->amiibolink_mode == BLE_AMIIBOLINK_MODE_CYCLE) { if (p_amiibolink_view->index > 0) { diff --git a/fw/application/src/mod/ble/ble_amiibolink.c b/fw/application/src/mod/ble/ble_amiibolink.c index 6f9b1a88..00d9123a 100644 --- a/fw/application/src/mod/ble/ble_amiibolink.c +++ b/fw/application/src/mod/ble/ble_amiibolink.c @@ -357,11 +357,12 @@ void ble_amiloop_received_data(const uint8_t *m_data, size_t length) { // 0x01 顺序模式 // 0x02 读写模式 uint8_t mode = buff_get_u8(&buffer); + NRF_LOG_INFO("amiloop mode: %d", mode); ble_amiibolink_mode_t link_mode; switch (mode) { case 0x00: - link_mode = BLE_AMIIBOLINK_MODE_RANDOM_AUTO_GEN; + link_mode = BLE_AMIIBOLINK_MODE_RANDOM; NRF_LOG_INFO("amiloop mode: random"); break; @@ -371,8 +372,8 @@ void ble_amiloop_received_data(const uint8_t *m_data, size_t length) { break; case 0x02: - link_mode = BLE_AMIIBOLINK_MODE_NTAG; - NRF_LOG_INFO("amiloop mode: ntag"); + link_mode = BLE_AMIIBOLINK_MODE_RANDOM_AUTO_GEN; + NRF_LOG_INFO("amiloop mode: random auto gen"); break; default: diff --git a/fw/application/src/mod/settings.h b/fw/application/src/mod/settings.h index de93d5b4..d53b7ad0 100644 --- a/fw/application/src/mod/settings.h +++ b/fw/application/src/mod/settings.h @@ -12,7 +12,7 @@ typedef struct { uint8_t sleep_timeout_sec; bool dirty; bool auto_gen_amiibo; - bool auto_gen_amiibolink; + bool auto_gen_amiibolink; //deprecated, keep for capability issue bool skip_driver_select; bool bat_mode; ble_amiibolink_ver_t amiibo_link_ver;