Skip to content

Commit

Permalink
Merge pull request #142 from solosky/revert-141-revert-137-feature/qr…
Browse files Browse the repository at this point in the history
…code

Re-merge to develop
  • Loading branch information
solosky authored Nov 17, 2023
2 parents d73782c + 5d3a13c commit f441f4f
Show file tree
Hide file tree
Showing 48 changed files with 5,359 additions and 1,223 deletions.
3 changes: 3 additions & 0 deletions fw/application/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ SRC_FILES += \
$(PROJ_DIR)/utils.c \
$(PROJ_DIR)/version2.c \
$(PROJ_DIR)/amiibo_helper.c \
$(PROJ_DIR)/mui_qrcode_helper.c \
$(PROJ_DIR)/app_error_handler.c \
$(PROJ_DIR)/libc_nano_stubs.c \
$(PROJ_DIR)/hal/hal_spi_bus.c \
Expand Down Expand Up @@ -300,6 +301,7 @@ SRC_FILES += \
$(COMP_DIR)/littlefs/lfs.c \
$(COMP_DIR)/littlefs/lfs_util.c \
$(COMP_DIR)/cwalk/src/cwalk.c \
$(COMP_DIR)/qrcode/c/qrcodegen.c \
$(U8G2_ROOT)/u8g2_bitmap.c \
$(U8G2_ROOT)/u8g2_box.c \
$(U8G2_ROOT)/u8g2_buffer.c \
Expand Down Expand Up @@ -522,6 +524,7 @@ INC_FOLDERS += \
$(COMP_DIR)/littlefs \
$(COMP_DIR)/tlsf \
$(COMP_DIR)/cwalk/include \
$(COMP_DIR)/qrcode/c \
$(SDK_ROOT)/components/libraries/bsp

# Libraries common to all targets
Expand Down
58 changes: 30 additions & 28 deletions fw/application/src/app/amiibo/view/amiibo_detail_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,37 @@ static void amiibo_detail_view_on_draw(mui_view_t *p_view, mui_canvas_t *p_canva

static void amiibo_detail_view_on_input(mui_view_t *p_view, mui_input_event_t *event) {
amiibo_detail_view_t *p_amiibo_detail_view = p_view->user_data;
switch (event->key) {
case INPUT_KEY_LEFT:
if (p_amiibo_detail_view->focus > 0) {
p_amiibo_detail_view->focus--;
} else {
p_amiibo_detail_view->focus = p_amiibo_detail_view->max_ntags - 1;
if (event->type == INPUT_TYPE_SHORT || event->type == INPUT_TYPE_REPEAT || event->type == INPUT_TYPE_LONG) {
switch (event->key) {
case INPUT_KEY_LEFT:
if (p_amiibo_detail_view->focus > 0) {
p_amiibo_detail_view->focus--;
} else {
p_amiibo_detail_view->focus = p_amiibo_detail_view->max_ntags - 1;
}

if (p_amiibo_detail_view->event_cb) {
p_amiibo_detail_view->event_cb(AMIIBO_DETAIL_VIEW_EVENT_UPDATE, p_amiibo_detail_view);
}
break;
case INPUT_KEY_RIGHT:
if (p_amiibo_detail_view->focus < p_amiibo_detail_view->max_ntags - 1) {
p_amiibo_detail_view->focus++;
} else {
p_amiibo_detail_view->focus = 0;
}

if (p_amiibo_detail_view->event_cb) {
p_amiibo_detail_view->event_cb(AMIIBO_DETAIL_VIEW_EVENT_UPDATE, p_amiibo_detail_view);
}
break;
case INPUT_KEY_CENTER:

if (p_amiibo_detail_view->event_cb) {
p_amiibo_detail_view->event_cb(AMIIBO_DETAIL_VIEW_EVENT_MENU, p_amiibo_detail_view);
}
break;
}

if (p_amiibo_detail_view->event_cb) {
p_amiibo_detail_view->event_cb(AMIIBO_DETAIL_VIEW_EVENT_UPDATE, p_amiibo_detail_view);
}
break;
case INPUT_KEY_RIGHT:
if (p_amiibo_detail_view->focus < p_amiibo_detail_view->max_ntags - 1) {
p_amiibo_detail_view->focus++;
} else {
p_amiibo_detail_view->focus = 0;
}

if (p_amiibo_detail_view->event_cb) {
p_amiibo_detail_view->event_cb(AMIIBO_DETAIL_VIEW_EVENT_UPDATE, p_amiibo_detail_view);
}
break;
case INPUT_KEY_CENTER:

if (p_amiibo_detail_view->event_cb) {
p_amiibo_detail_view->event_cb(AMIIBO_DETAIL_VIEW_EVENT_MENU, p_amiibo_detail_view);
}
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
static enum amiidb_detail_menu_t {
AMIIDB_DETAIL_MENU_RAND_UID,
AMIIDB_DETAIL_MENU_AUTO_RAND_UID,
AMIIDB_DETAIL_MENU_SHOW_QRCODE,
AMIIDB_DETAIL_MENU_FAVORITE,
AMIIDB_DETAIL_MENU_SAVE_AS,
AMIIDB_DETAIL_MENU_BACK_AMIIBO_DETAIL,
Expand Down Expand Up @@ -103,6 +104,19 @@ static void amiidb_scene_amiibo_detail_menu_on_selected(mui_list_view_event_t ev
mui_scene_dispatcher_previous_scene(app->p_scene_dispatcher);
} break;

case AMIIDB_DETAIL_MENU_SHOW_QRCODE: {
char txt[32];
settings_data_t *p_settings = settings_get_data();
p_settings->qrcode_enabled = !p_settings->qrcode_enabled;
snprintf(txt, sizeof(txt), "%s [%s]", getLangString(_L_SHOW_QRCODE),
p_settings->qrcode_enabled ? getLangString(_L_ON) : getLangString(_L_OFF));
settings_save();

string_set_str(p_item->text, txt);

mui_scene_dispatcher_previous_scene(app->p_scene_dispatcher);
} break;

case AMIIDB_DETAIL_MENU_FAVORITE: {
mui_scene_dispatcher_next_scene(app->p_scene_dispatcher, AMIIDB_SCENE_FAV_SELECT);
} break;
Expand All @@ -129,6 +143,9 @@ void amiidb_scene_amiibo_detail_menu_on_enter(void *user_data) {
snprintf(txt, sizeof(txt), "%s [%s]", getLangString(_L_AUTO_RANDOM_GENERATION),
p_settings->auto_gen_amiibo ? getLangString(_L_ON) : getLangString(_L_OFF));
mui_list_view_add_item(app->p_list_view, 0xe1c6, txt, (void *)AMIIDB_DETAIL_MENU_AUTO_RAND_UID);
snprintf(txt, sizeof(txt), "%s [%s]", getLangString(_L_SHOW_QRCODE),
p_settings->qrcode_enabled ? getLangString(_L_ON) : getLangString(_L_OFF));
mui_list_view_add_item(app->p_list_view, 0xe006, txt, (void *)AMIIDB_DETAIL_MENU_SHOW_QRCODE);
mui_list_view_add_item(app->p_list_view, ICON_FAVORITE, getLangString(_L_APP_AMIIDB_DETAIL_FAVORITE), (void *)AMIIDB_DETAIL_MENU_FAVORITE);
mui_list_view_add_item(app->p_list_view, ICON_DATA, getLangString(_L_APP_AMIIDB_DETAIL_SAVE_AS), (void *)AMIIDB_DETAIL_MENU_SAVE_AS);
mui_list_view_add_item(app->p_list_view, 0xe068, getLangString(_L_APP_AMIIDB_DETAIL_BACK_DETAIL), (void *)AMIIDB_DETAIL_MENU_BACK_AMIIBO_DETAIL);
Expand Down
103 changes: 78 additions & 25 deletions fw/application/src/app/amiidb/view/amiibo_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "db_header.h"
#include "i18n/language.h"
#include "mui_element.h"
#include "mui_qrcode_helper.h"
#include "settings.h"

#define ICON_LEFT 0xe1ac
#define ICON_RIGHT 0xe1aa
Expand Down Expand Up @@ -33,7 +35,7 @@ static void amiibo_view_on_draw(mui_view_t *p_view, mui_canvas_t *p_canvas) {
mui_canvas_set_draw_color(p_canvas, 1);
mui_canvas_set_font(p_canvas, u8g2_font_wqy12_t_gb2312a);

y += 12;
y += 11;

uint32_t head = to_little_endian_int32(&ntag->data[84]);
uint32_t tail = to_little_endian_int32(&ntag->data[88]);
Expand All @@ -42,57 +44,108 @@ static void amiibo_view_on_draw(mui_view_t *p_view, mui_canvas_t *p_canvas) {
if (amd != NULL) {
const char *name =(getLanguage() == LANGUAGE_ZH_TW || getLanguage() == LANGUAGE_ZH_HANS) ? amd->name_cn : amd->name_en;
mui_canvas_draw_utf8(p_canvas, 0, y += 13, name);

mui_rect_t clip_win_prev;
mui_rect_t clip_win_cur;
mui_canvas_get_clip_window(p_canvas, &clip_win_prev);
clip_win_cur.x = 0;
clip_win_cur.y = y;
clip_win_cur.w = mui_canvas_get_width(p_canvas);
clip_win_cur.h = mui_canvas_get_height(p_canvas) - y;
mui_canvas_set_clip_window(p_canvas, &clip_win_cur);

// text+qrcode
uint8_t square_r = 0;
if (settings_get_data()->qrcode_enabled) {
square_r = 37;
sprintf(buff, "https://pixl.amiibo.xyz/a/%08X-%08X", head, tail);
if (p_amiibo_view->desc_offset <= 33) {
draw_qrcode(p_canvas, 91, y + 2 - p_amiibo_view->desc_offset, 33, buff);
}
}
p_amiibo_view->desc_step = 8;
p_amiibo_view->desc_page_size = clip_win_cur.h;
const db_link_t *link = get_link_by_id(p_amiibo_view->game_id, head, tail);
if (strlen(ntag->notes) > 0) {
mui_element_autowrap_text(p_canvas, 0, y += 13, mui_canvas_get_width(p_canvas), 24, ntag->notes);
p_amiibo_view->desc_total = mui_element_autowrap_text_box(p_canvas, clip_win_cur.x, clip_win_cur.y, clip_win_cur.w, clip_win_cur.h, p_amiibo_view->desc_offset, square_r, ntag->notes);
} else if (link != NULL) {
const char *notes = getLanguage() == LANGUAGE_ZH_HANS ? link->note_cn : link->note_en;
mui_element_autowrap_text(p_canvas, 0, y += 13, mui_canvas_get_width(p_canvas), 24, notes);
p_amiibo_view->desc_total = mui_element_autowrap_text_box(p_canvas, clip_win_cur.x, clip_win_cur.y, clip_win_cur.w, clip_win_cur.h, p_amiibo_view->desc_offset, square_r, notes);
}
mui_canvas_set_clip_window(p_canvas, &clip_win_prev);
} else if (head > 0 && tail > 0) {
mui_canvas_draw_utf8(p_canvas, 0, y += 15, "Amiibo");
sprintf(buff, "[%08x:%08x]", head, tail);
mui_canvas_draw_utf8(p_canvas, 0, y += 15, buff);
if (settings_get_data()->qrcode_enabled) {
sprintf(buff, "https://pixl.amiibo.xyz/a/%08X-%08X", head, tail);
draw_qrcode(p_canvas, 91, 26, 33, buff);
}
} else {
mui_canvas_draw_utf8(p_canvas, 0, y += 13, getLangString(_L_BLANK_TAG));
}
}

static void amiibo_view_on_input(mui_view_t *p_view, mui_input_event_t *event) {
amiibo_view_t *p_amiibo_view = p_view->user_data;
switch (event->key) {
case INPUT_KEY_LEFT:
if (p_amiibo_view->max_ntags > 1) {
if (p_amiibo_view->focus > 0) {
p_amiibo_view->focus--;
} else {
p_amiibo_view->focus = p_amiibo_view->max_ntags - 1;
if (event->type == INPUT_TYPE_REPEAT || event->type == INPUT_TYPE_LONG) {
switch (event->key) {
case INPUT_KEY_LEFT:
if (p_amiibo_view->desc_offset >= p_amiibo_view->desc_step) {
p_amiibo_view->desc_offset -= p_amiibo_view->desc_step;
}

if (p_amiibo_view->event_cb) {
p_amiibo_view->event_cb(AMIIBO_VIEW_EVENT_UPDATE, p_amiibo_view);
p_amiibo_view->event_cb(AMIIBO_VIEW_EVENT_DESC_UPDATE, p_amiibo_view);
}
}
break;
case INPUT_KEY_RIGHT:
if (p_amiibo_view->max_ntags > 1) {
if (p_amiibo_view->focus < p_amiibo_view->max_ntags - 1) {
p_amiibo_view->focus++;
} else {
p_amiibo_view->focus = 0;
break;
case INPUT_KEY_RIGHT:
if (p_amiibo_view->desc_total > 0 && p_amiibo_view->desc_offset < p_amiibo_view->desc_page_size * ((p_amiibo_view->desc_total + p_amiibo_view->desc_page_size - 1) / p_amiibo_view->desc_page_size - 1)) {
p_amiibo_view->desc_offset += p_amiibo_view->desc_step;
}

if (p_amiibo_view->event_cb) {
p_amiibo_view->event_cb(AMIIBO_VIEW_EVENT_UPDATE, p_amiibo_view);
p_amiibo_view->event_cb(AMIIBO_VIEW_EVENT_DESC_UPDATE, p_amiibo_view);
}
break;
}
break;
case INPUT_KEY_CENTER:
} else if (event->type == INPUT_TYPE_SHORT) {
switch (event->key) {
case INPUT_KEY_LEFT:
p_amiibo_view->desc_offset = 0;
if (p_amiibo_view->max_ntags > 1) {
if (p_amiibo_view->focus > 0) {
p_amiibo_view->focus--;
} else {
p_amiibo_view->focus = p_amiibo_view->max_ntags - 1;
}

if (p_amiibo_view->event_cb) {
p_amiibo_view->event_cb(AMIIBO_VIEW_EVENT_UPDATE, p_amiibo_view);
}
}
break;
case INPUT_KEY_RIGHT:
p_amiibo_view->desc_offset = 0;
if (p_amiibo_view->max_ntags > 1) {
if (p_amiibo_view->focus < p_amiibo_view->max_ntags - 1) {
p_amiibo_view->focus++;
} else {
p_amiibo_view->focus = 0;
}

if (p_amiibo_view->event_cb) {
p_amiibo_view->event_cb(AMIIBO_VIEW_EVENT_UPDATE, p_amiibo_view);
}
}
break;
case INPUT_KEY_CENTER:

if (p_amiibo_view->event_cb) {
p_amiibo_view->event_cb(AMIIBO_VIEW_EVENT_MENU, p_amiibo_view);
if (p_amiibo_view->event_cb) {
p_amiibo_view->event_cb(AMIIBO_VIEW_EVENT_MENU, p_amiibo_view);
}
break;
}
break;
}
}

Expand Down
5 changes: 5 additions & 0 deletions fw/application/src/app/amiidb/view/amiibo_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ typedef struct amiibo_view_s amiibo_view_t;

typedef enum {
AMIIBO_VIEW_EVENT_UPDATE,
AMIIBO_VIEW_EVENT_DESC_UPDATE,
AMIIBO_VIEW_EVENT_MENU,
} amiibo_view_event_t;

Expand All @@ -26,6 +27,10 @@ struct amiibo_view_s {
uint8_t max_ntags;
uint8_t game_id;
amiibo_view_event_cb event_cb;
uint16_t desc_offset;
uint16_t desc_total;
uint16_t desc_page_size;
uint8_t desc_step;
};

amiibo_view_t *amiibo_view_create();
Expand Down
2 changes: 2 additions & 0 deletions fw/application/src/app/ble/app_ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ void app_ble_on_run(mini_app_inst_t *p_app_inst) {
p_app_handle->p_ble_view = ble_status_view_create();
p_app_handle->p_scene_dispatcher = mui_scene_dispatcher_create();

ble_status_view_set_user_data(p_app_handle->p_ble_view, p_app_handle);

mui_view_dispatcher_add_view(p_app_handle->p_view_dispatcher, BLE_VIEW_ID_MAIN,
ble_status_view_get_view(p_app_handle->p_ble_view));
mui_view_dispatcher_attach(p_app_handle->p_view_dispatcher, MUI_LAYER_WINDOW);
Expand Down
10 changes: 8 additions & 2 deletions fw/application/src/app/ble/scene/ble_scene_connect_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@


void ble_scene_connect_status_view_event_cb(ble_status_view_event_t event, ble_status_view_t *p_view){
ble_disable();
mini_app_launcher_kill(mini_app_launcher(), MINI_APP_ID_BLE);
app_ble_t *app = p_view->user_data;
if (event == BLE_STATUS_VIEW_BLE_DISABLE) {
ble_disable();
mini_app_launcher_kill(mini_app_launcher(), MINI_APP_ID_BLE);
} else if (event == BLE_STATUS_VIEW_EVENT_UPDATE) {
// NOOP
ble_status_view_set_page(app->p_ble_view, ble_status_view_get_page(app->p_ble_view));
}
}


Expand Down
27 changes: 25 additions & 2 deletions fw/application/src/app/ble/view/ble_status_view.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#include "ble_status_view.h"
#include "i18n/language.h"
#include "mui_qrcode_helper.h"

static void ble_status_view_on_draw(mui_view_t *p_view, mui_canvas_t *p_canvas) {
ble_status_view_t* p_status_view = p_view->user_data;
if (p_status_view->page == 1) {
draw_qrcode(p_canvas, 39, 0, 50, "https://pixl.amiibo.xyz");
return;
}
mui_canvas_set_font(p_canvas, u8g2_font_siji_t_6x10);
mui_canvas_draw_glyph(p_canvas, 20, 12, 0xe1b5);
mui_canvas_set_font(p_canvas, u8g2_font_wqy12_t_gb2312a);
Expand All @@ -13,8 +18,26 @@ static void ble_status_view_on_draw(mui_view_t *p_view, mui_canvas_t *p_canvas)

static void ble_status_view_on_input(mui_view_t *p_view, mui_input_event_t *event) {
ble_status_view_t *p_ble_status_view = p_view->user_data;
if (p_ble_status_view->event_cb) {
p_ble_status_view->event_cb(BLE_STATUS_VIEW_BLE_DISABLE, p_ble_status_view);
if (event->type == INPUT_TYPE_SHORT || event->type == INPUT_TYPE_REPEAT || event->type == INPUT_TYPE_LONG) {
switch (event->key) {
case INPUT_KEY_LEFT:
case INPUT_KEY_RIGHT:
if (p_ble_status_view->page == 1) {
p_ble_status_view->page = 0;
} else {
p_ble_status_view->page = 1;
}

if (p_ble_status_view->event_cb) {
p_ble_status_view->event_cb(BLE_STATUS_VIEW_EVENT_UPDATE, p_ble_status_view);
}
break;
case INPUT_KEY_CENTER:
if (p_ble_status_view->event_cb) {
p_ble_status_view->event_cb(BLE_STATUS_VIEW_BLE_DISABLE, p_ble_status_view);
}
break;
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions fw/application/src/app/ble/view/ble_status_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ typedef struct ble_status_view_s ble_status_view_t;

typedef enum {
BLE_STATUS_VIEW_BLE_DISABLE,
BLE_STATUS_VIEW_EVENT_UPDATE,
} ble_status_view_event_t;

typedef void (*ble_status_view_event_cb)(ble_status_view_event_t event, ble_status_view_t *p_view);
Expand All @@ -17,6 +18,8 @@ typedef void (*ble_status_view_event_cb)(ble_status_view_event_t event, ble_stat
mui_view_t* p_view;
ble_status_view_event_cb event_cb;
char ble_addr[20];
uint8_t page;
void* user_data;
} ;

ble_status_view_t* ble_status_view_create();
Expand All @@ -31,4 +34,12 @@ static char* ble_status_view_get_ble_addr(ble_status_view_t* p_view){
return p_view->ble_addr;
}

static inline void ble_status_view_set_user_data(ble_status_view_t* p_view, void* user_data){
p_view->user_data = user_data;
}

inline void ble_status_view_set_page(ble_status_view_t *p_view, uint8_t page) { p_view->page = page; }

inline uint8_t ble_status_view_get_page(ble_status_view_t *p_view) { return p_view->page; }

#endif
Loading

0 comments on commit f441f4f

Please sign in to comment.