Skip to content

Commit

Permalink
remove auto gen menu in amiibolink app
Browse files Browse the repository at this point in the history
fixed amiloop mode option incorrect issue
  • Loading branch information
solosky committed Apr 4, 2024
1 parent 56539c3 commit f4f9468
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 74 deletions.
2 changes: 0 additions & 2 deletions docs/en/04-Using-Firmware.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions docs/it/04-Using-Firmware.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
73 changes: 45 additions & 28 deletions fw/application/src/app/amiibolink/scene/amiibolink_scene_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -40,45 +63,45 @@ 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) {
ntag_emu_set_tag(&ntag);
}
}

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");
}

Expand All @@ -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);
}
}

Expand All @@ -109,24 +129,21 @@ 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);
amiibolink_view_set_max_size(app->p_amiibolink_view, MAX_NTAG_INDEX);

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) {
}
}

Expand All @@ -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());
Expand Down Expand Up @@ -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);
}
Expand Down
34 changes: 0 additions & 34 deletions fw/application/src/app/amiibolink/scene/amiibolink_scene_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
}
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions fw/application/src/app/amiibolink/view/amiibolink_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions fw/application/src/mod/ble/ble_amiibolink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion fw/application/src/mod/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f4f9468

Please sign in to comment.