mirror of
https://github.com/UberGuidoZ/Flipper.git
synced 2026-09-18 17:31:30 +00:00
Removing FAP files (use FlipC or Official store!)
This commit is contained in:
+48
@@ -0,0 +1,48 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// VB Lab Migration Assistant for Flipper Zero
|
||||
// Copyright (C) 2022 cyanic
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "vb_migrate_scene.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const vb_migrate_on_enter_handlers[])(void*) = {
|
||||
#include "vb_migrate_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||
bool (*const vb_migrate_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "vb_migrate_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||
void (*const vb_migrate_on_exit_handlers[])(void* context) = {
|
||||
#include "vb_migrate_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers vb_migrate_scene_handlers = {
|
||||
.on_enter_handlers = vb_migrate_on_enter_handlers,
|
||||
.on_event_handlers = vb_migrate_on_event_handlers,
|
||||
.on_exit_handlers = vb_migrate_on_exit_handlers,
|
||||
.scene_num = VbMigrateSceneNum,
|
||||
};
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// VB Lab Migration Assistant for Flipper Zero
|
||||
// Copyright (C) 2022 cyanic
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) VbMigrateScene##id,
|
||||
typedef enum {
|
||||
#include "vb_migrate_scene_config.h"
|
||||
VbMigrateSceneNum,
|
||||
} VbMigrateScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers vb_migrate_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "vb_migrate_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) \
|
||||
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
|
||||
#include "vb_migrate_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
|
||||
#include "vb_migrate_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// VB Lab Migration Assistant for Flipper Zero
|
||||
// Copyright (C) 2022 cyanic
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "../vb_migrate_i.h"
|
||||
|
||||
void vb_migrate_scene_about_on_enter(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Perform your setup here
|
||||
FuriString* temp_str = furi_string_alloc_printf(
|
||||
"\e#Information\n"
|
||||
"Version: %s\n"
|
||||
"Developed by: cyanic\n"
|
||||
"Graphics by: Aderek\n"
|
||||
"GitHub: https://github.com/GMMan/flipperzero-vb-migrate\n"
|
||||
"\n"
|
||||
"\e#Description\n"
|
||||
"Makes transferring\n"
|
||||
"characters with VB Lab/\n"
|
||||
"Arena less cumbersome",
|
||||
VB_MIGRATE_VERSION);
|
||||
|
||||
Widget* widget = inst->widget;
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeNone);
|
||||
widget_add_text_scroll_element(widget, 8, 16, 113, 33, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
}
|
||||
|
||||
bool vb_migrate_scene_about_on_event(void* context, SceneManagerEvent event) {
|
||||
UNUSED(context);
|
||||
UNUSED(event);
|
||||
return false;
|
||||
}
|
||||
|
||||
void vb_migrate_scene_about_on_exit(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Perform your cleanup here
|
||||
widget_reset(inst->widget);
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// VB Lab Migration Assistant for Flipper Zero
|
||||
// Copyright (C) 2022 cyanic
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
ADD_SCENE(vb_migrate, main_menu, MainMenu)
|
||||
ADD_SCENE(vb_migrate, register, Register)
|
||||
ADD_SCENE(vb_migrate, register_save, RegisterSave)
|
||||
ADD_SCENE(vb_migrate, save_success, SaveSuccess)
|
||||
ADD_SCENE(vb_migrate, select, Select)
|
||||
ADD_SCENE(vb_migrate, load, Load)
|
||||
ADD_SCENE(vb_migrate, info, Info)
|
||||
ADD_SCENE(vb_migrate, dev_menu, DevMenu)
|
||||
ADD_SCENE(vb_migrate, delete, Delete)
|
||||
ADD_SCENE(vb_migrate, delete_success, DeleteSuccess)
|
||||
ADD_SCENE(vb_migrate, from_app, FromApp)
|
||||
ADD_SCENE(vb_migrate, to_app, ToApp)
|
||||
ADD_SCENE(vb_migrate, delete_captures, DeleteCaptures)
|
||||
ADD_SCENE(vb_migrate, delete_captures_success, DeleteCapturesSuccess)
|
||||
ADD_SCENE(vb_migrate, about, About)
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// VB Lab Migration Assistant for Flipper Zero
|
||||
// Copyright (C) 2022 cyanic
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "../vb_migrate_i.h"
|
||||
#include "../vb_tag.h"
|
||||
|
||||
static void
|
||||
vb_migrate_scene_delete_widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
if(type == InputTypeShort) {
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, result);
|
||||
}
|
||||
}
|
||||
|
||||
void vb_migrate_scene_delete_on_enter(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Perform your setup here
|
||||
Widget* widget = inst->widget;
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton | VbMigrateBgTypeRightButton);
|
||||
widget_add_icon_element(widget, 11, 18, &I_Delete_32x20);
|
||||
widget_add_icon_element(widget, 48, 18, &I_TextDeleteVb_49x13);
|
||||
|
||||
FuriString* temp_str = furi_string_alloc_printf("%d", inst->num_captured);
|
||||
widget_add_string_element(
|
||||
widget, 99, 24, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
widget_add_button_element(
|
||||
inst->widget, GuiButtonTypeLeft, "Cancel", vb_migrate_scene_delete_widget_callback, inst);
|
||||
widget_add_button_element(
|
||||
inst->widget, GuiButtonTypeRight, "Delete", vb_migrate_scene_delete_widget_callback, inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
}
|
||||
|
||||
bool vb_migrate_scene_delete_on_event(void* context, SceneManagerEvent event) {
|
||||
VbMigrate* inst = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == GuiButtonTypeLeft) {
|
||||
consumed = scene_manager_previous_scene(inst->scene_manager);
|
||||
} else if(event.event == GuiButtonTypeRight) {
|
||||
if(vb_migrate_delete(inst, inst->text_store, true)) {
|
||||
scene_manager_next_scene(inst->scene_manager, VbMigrateSceneDeleteSuccess);
|
||||
consumed = true;
|
||||
} else {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
inst->scene_manager, VbMigrateSceneSelect);
|
||||
}
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void vb_migrate_scene_delete_on_exit(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Perform your cleanup here
|
||||
widget_reset(inst->widget);
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// VB Lab Migration Assistant for Flipper Zero
|
||||
// Copyright (C) 2022 cyanic
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "../vb_migrate_i.h"
|
||||
|
||||
static void vb_migrate_scene_delete_captures_widget_callback(
|
||||
GuiButtonType result,
|
||||
InputType type,
|
||||
void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
if(type == InputTypeShort) {
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, result);
|
||||
}
|
||||
}
|
||||
|
||||
void vb_migrate_scene_delete_captures_on_enter(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Perform your setup here
|
||||
Widget* widget = inst->widget;
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton | VbMigrateBgTypeRightButton);
|
||||
widget_add_icon_element(widget, 11, 18, &I_Delete_32x20);
|
||||
widget_add_icon_element(widget, 48, 18, &I_TextClearCaptures_49x13);
|
||||
|
||||
FuriString* temp_str = furi_string_alloc_printf("%d", inst->num_captured);
|
||||
widget_add_string_element(
|
||||
widget, 99, 24, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
widget_add_button_element(
|
||||
inst->widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Cancel",
|
||||
vb_migrate_scene_delete_captures_widget_callback,
|
||||
inst);
|
||||
widget_add_button_element(
|
||||
inst->widget,
|
||||
GuiButtonTypeRight,
|
||||
"Delete",
|
||||
vb_migrate_scene_delete_captures_widget_callback,
|
||||
inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
}
|
||||
|
||||
bool vb_migrate_scene_delete_captures_on_event(void* context, SceneManagerEvent event) {
|
||||
VbMigrate* inst = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == GuiButtonTypeLeft) {
|
||||
consumed = scene_manager_previous_scene(inst->scene_manager);
|
||||
} else if(event.event == GuiButtonTypeRight) {
|
||||
if(vb_migrate_delete(inst, inst->text_store, false)) {
|
||||
scene_manager_next_scene(inst->scene_manager, VbMigrateSceneDeleteCapturesSuccess);
|
||||
consumed = true;
|
||||
} else {
|
||||
consumed = scene_manager_previous_scene(inst->scene_manager);
|
||||
}
|
||||
inst->num_captured = vb_migrate_count_captured_mons(inst, inst->text_store);
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void vb_migrate_scene_delete_captures_on_exit(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Perform your cleanup here
|
||||
widget_reset(inst->widget);
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// VB Lab Migration Assistant for Flipper Zero
|
||||
// Copyright (C) 2022 cyanic
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "../vb_migrate_i.h"
|
||||
|
||||
static void vb_migrate_scene_delete_captures_success_widget_callback(
|
||||
GuiButtonType result,
|
||||
InputType type,
|
||||
void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
if(type == InputTypeShort) {
|
||||
if(result == GuiButtonTypeRight)
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void vb_migrate_scene_delete_captures_success_on_enter(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Perform your setup here
|
||||
Widget* widget = inst->widget;
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeRightButton);
|
||||
widget_add_icon_element(widget, 11, 18, &I_Delete_32x20);
|
||||
widget_add_icon_element(widget, 48, 18, &I_TextCleared_47x6);
|
||||
widget_add_icon_element(widget, 9, 41, &I_PulsemonRightSad_15x15);
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeRight,
|
||||
"OK",
|
||||
vb_migrate_scene_delete_captures_success_widget_callback,
|
||||
inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
}
|
||||
|
||||
bool vb_migrate_scene_delete_captures_success_on_event(void* context, SceneManagerEvent event) {
|
||||
VbMigrate* inst = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom || event.type == SceneManagerEventTypeBack) {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
inst->scene_manager, VbMigrateSceneDevMenu);
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void vb_migrate_scene_delete_captures_success_on_exit(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Perform your cleanup here
|
||||
widget_reset(inst->widget);
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// VB Lab Migration Assistant for Flipper Zero
|
||||
// Copyright (C) 2022 cyanic
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "../vb_migrate_i.h"
|
||||
|
||||
static void vb_migrate_scene_delete_success_widget_callback(
|
||||
GuiButtonType result,
|
||||
InputType type,
|
||||
void* context) {
|
||||
VbMigrate* inst = context;
|
||||
if(type == InputTypeShort) {
|
||||
if(result == GuiButtonTypeRight)
|
||||
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void vb_migrate_scene_delete_success_on_enter(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Perform your setup here
|
||||
Widget* widget = inst->widget;
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeRightButton);
|
||||
widget_add_icon_element(widget, 11, 18, &I_Delete_32x20);
|
||||
widget_add_icon_element(widget, 48, 18, &I_TextDeleted_46x6);
|
||||
widget_add_icon_element(widget, 9, 41, &I_PulsemonRightSad_15x15);
|
||||
widget_add_button_element(
|
||||
widget, GuiButtonTypeRight, "OK", vb_migrate_scene_delete_success_widget_callback, inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
}
|
||||
|
||||
bool vb_migrate_scene_delete_success_on_event(void* context, SceneManagerEvent event) {
|
||||
VbMigrate* inst = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom || event.type == SceneManagerEventTypeBack) {
|
||||
uint32_t back_scenes[] = {VbMigrateSceneSelect, VbMigrateSceneMainMenu};
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene_one_of(
|
||||
inst->scene_manager, back_scenes, COUNT_OF(back_scenes));
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void vb_migrate_scene_delete_success_on_exit(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Perform your cleanup here
|
||||
widget_reset(inst->widget);
|
||||
}
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// VB Lab Migration Assistant for Flipper Zero
|
||||
// Copyright (C) 2022 cyanic
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "../vb_migrate_i.h"
|
||||
|
||||
typedef enum {
|
||||
SubmenuDevMenuIndexTransferFromApp,
|
||||
SubmenuDevMenuIndexTransferToApp,
|
||||
SubmenuDevMenuClearAccountId,
|
||||
SubmenuDevMenuIndexSpoof,
|
||||
SubmenuDevMenuIndexClearCaptures,
|
||||
SubmenuDevMenuIndexDeleteVb,
|
||||
// -----
|
||||
SubmenuDevMenuClearAccountIdOff,
|
||||
SubmenuDevMenuClearAccountIdOn,
|
||||
// -----
|
||||
SubmenuDevMenuIndexSpoofSelection, // Always keep this last because we add tag type to it
|
||||
} SubmenuDevMenuIndex;
|
||||
|
||||
static void vb_migrate_scene_dev_menu_var_list_enter_callback(void* context, uint32_t index) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, index);
|
||||
}
|
||||
|
||||
static VbTagType
|
||||
vb_migrate_scene_dev_menu_spoof_set_item_by_index(VariableItemEx* item, uint8_t index) {
|
||||
VbTagType type;
|
||||
if(index >= 2) { // VBC
|
||||
type = (VbTagType)(index + 2);
|
||||
} else {
|
||||
type = (VbTagType)(index + 1);
|
||||
}
|
||||
|
||||
variable_item_ex_set_current_value_index(item, index);
|
||||
variable_item_ex_set_current_value_text(item, vb_tag_get_tag_type_name(type));
|
||||
return type;
|
||||
}
|
||||
|
||||
static uint8_t
|
||||
vb_migrate_scene_dev_menu_spoof_set_item_by_type(VariableItemEx* item, VbTagType type) {
|
||||
uint8_t index;
|
||||
if(type >= VbTagTypeVH) {
|
||||
index = (uint8_t)type - 2;
|
||||
} else {
|
||||
index = (uint8_t)type - 1;
|
||||
}
|
||||
|
||||
variable_item_ex_set_current_value_index(item, index);
|
||||
variable_item_ex_set_current_value_text(item, vb_tag_get_tag_type_name(type));
|
||||
return index;
|
||||
}
|
||||
|
||||
static void vb_migrate_scene_dev_menu_spoof_change_callback(VariableItemEx* item) {
|
||||
VbMigrate* inst = variable_item_ex_get_context(item);
|
||||
uint8_t index = variable_item_ex_get_current_value_index(item);
|
||||
|
||||
VbTagType tag_type = vb_migrate_scene_dev_menu_spoof_set_item_by_index(item, index);
|
||||
view_dispatcher_send_custom_event(
|
||||
inst->view_dispatcher, SubmenuDevMenuIndexSpoofSelection + tag_type);
|
||||
}
|
||||
|
||||
static void vb_migrate_scene_dev_menu_clear_account_id_change_callback(VariableItemEx* item) {
|
||||
VbMigrate* inst = variable_item_ex_get_context(item);
|
||||
uint8_t index = variable_item_ex_get_current_value_index(item);
|
||||
|
||||
variable_item_ex_set_current_value_text(item, index ? "On" : "Off");
|
||||
view_dispatcher_send_custom_event(
|
||||
inst->view_dispatcher,
|
||||
index ? SubmenuDevMenuClearAccountIdOn : SubmenuDevMenuClearAccountIdOff);
|
||||
}
|
||||
|
||||
void vb_migrate_scene_dev_menu_on_enter(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
VariableItemListEx* variable_list = inst->variable_list;
|
||||
VariableItemEx* item;
|
||||
|
||||
variable_item_list_ex_set_enter_callback(
|
||||
variable_list, vb_migrate_scene_dev_menu_var_list_enter_callback, inst);
|
||||
variable_item_list_ex_add(
|
||||
variable_list, "Transfer App > Flipper", 0, NULL, NULL, SubmenuDevMenuIndexTransferFromApp);
|
||||
|
||||
if(inst->num_captured != 0) {
|
||||
variable_item_list_ex_add(
|
||||
variable_list,
|
||||
"Transfer Flipper > App",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
SubmenuDevMenuIndexTransferToApp);
|
||||
}
|
||||
|
||||
item = variable_item_list_ex_add(
|
||||
variable_list,
|
||||
"Unlink Account",
|
||||
2,
|
||||
vb_migrate_scene_dev_menu_clear_account_id_change_callback,
|
||||
inst,
|
||||
SubmenuDevMenuClearAccountId);
|
||||
variable_item_ex_set_current_value_index(item, inst->clear_account_id ? 1 : 0);
|
||||
variable_item_ex_set_current_value_text(item, inst->clear_account_id ? "On" : "Off");
|
||||
|
||||
if(inst->orig_type == VbTagTypeVBDM || inst->orig_type == VbTagTypeVBV ||
|
||||
inst->orig_type == VbTagTypeVH) {
|
||||
item = variable_item_list_ex_add(
|
||||
variable_list,
|
||||
"Spoof Version",
|
||||
VbTagTypeMax - 1 - 2, // Removing VBC from list, skip VBBE
|
||||
vb_migrate_scene_dev_menu_spoof_change_callback,
|
||||
inst,
|
||||
SubmenuDevMenuIndexSpoof);
|
||||
vb_migrate_scene_dev_menu_spoof_set_item_by_type(item, inst->override_type);
|
||||
}
|
||||
|
||||
if(inst->num_captured != 0) {
|
||||
variable_item_list_ex_add(
|
||||
variable_list, "Clear Captures", 0, NULL, NULL, SubmenuDevMenuIndexClearCaptures);
|
||||
}
|
||||
|
||||
variable_item_list_ex_add(
|
||||
variable_list, "Delete Vital Bracelet", 0, NULL, NULL, SubmenuDevMenuIndexDeleteVb);
|
||||
|
||||
// variable_item_list_ex_set_selected_item(
|
||||
// variable_list, scene_manager_get_scene_state(inst->scene_manager, VbMigrateSceneDevMenu));
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewVariableItemList);
|
||||
}
|
||||
|
||||
bool vb_migrate_scene_dev_menu_on_event(void* context, SceneManagerEvent event) {
|
||||
VbMigrate* inst = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
// if(event.event < SubmenuDevMenuIndexSpoofSelection) {
|
||||
// scene_manager_set_scene_state(inst->scene_manager, VbMigrateSceneDevMenu, event.event);
|
||||
// }
|
||||
|
||||
if(event.event == SubmenuDevMenuIndexTransferFromApp) {
|
||||
scene_manager_next_scene(inst->scene_manager, VbMigrateSceneFromApp);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuDevMenuIndexTransferToApp) {
|
||||
scene_manager_next_scene(inst->scene_manager, VbMigrateSceneToApp);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuDevMenuIndexClearCaptures) {
|
||||
scene_manager_next_scene(inst->scene_manager, VbMigrateSceneDeleteCaptures);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuDevMenuIndexDeleteVb) {
|
||||
scene_manager_next_scene(inst->scene_manager, VbMigrateSceneDelete);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuDevMenuClearAccountIdOff) {
|
||||
inst->clear_account_id = false;
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuDevMenuClearAccountIdOn) {
|
||||
inst->clear_account_id = true;
|
||||
consumed = true;
|
||||
} else if(event.event >= SubmenuDevMenuIndexSpoofSelection) {
|
||||
// Note: skipping SubmenuDevMenuIndexSpoof because there's nothing to do on enter
|
||||
inst->override_type = event.event - SubmenuDevMenuIndexSpoofSelection;
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void vb_migrate_scene_dev_menu_on_exit(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
variable_item_list_ex_reset(inst->variable_list);
|
||||
}
|
||||
+370
@@ -0,0 +1,370 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// VB Lab Migration Assistant for Flipper Zero
|
||||
// Copyright (C) 2022 cyanic
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <notification/notification_messages.h>
|
||||
|
||||
#include "../vb_migrate_i.h"
|
||||
#include "../vb_tag.h"
|
||||
|
||||
#define TAG "vb_migrate_scene_from_app"
|
||||
|
||||
typedef enum {
|
||||
FromAppStateInitial,
|
||||
FromAppStateInstructions,
|
||||
FromAppStateEmulateReady,
|
||||
FromAppStateEmulateCheckDim,
|
||||
FromAppStateEmulateTransferFromApp,
|
||||
FromAppStateTemplateError,
|
||||
FromAppStateSaveError,
|
||||
} FromAppState;
|
||||
|
||||
typedef enum {
|
||||
FromAppEventTypeWidgetLeft,
|
||||
FromAppEventTypeWidgetRight,
|
||||
FromAppEventTypeTemplateLoadError,
|
||||
FromAppEventTypeTagWrite,
|
||||
FromAppEventTypeCaptureSaveError,
|
||||
FromAppEventTypeCaptureSaveSuccess,
|
||||
} FromAppEventType;
|
||||
|
||||
static void
|
||||
vb_migrate_scene_from_app_widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
if(type == InputTypeShort) {
|
||||
if(result == GuiButtonTypeLeft)
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, FromAppEventTypeWidgetLeft);
|
||||
else if(result == GuiButtonTypeRight)
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, FromAppEventTypeWidgetRight);
|
||||
}
|
||||
}
|
||||
|
||||
static bool vb_migrate_scene_from_app_worker_callback(NfcWorkerEvent event, void* context) {
|
||||
VbMigrate* inst = context;
|
||||
bool result = false;
|
||||
|
||||
if(event == NfcWorkerEventSuccess) {
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, FromAppEventTypeTagWrite);
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void vb_migrate_scene_from_app_set_nfc_state(VbMigrate* inst, FromAppState state) {
|
||||
BantBlock* bant = vb_tag_get_bant_block(&inst->nfc_dev->dev_data);
|
||||
if(state == FromAppStateEmulateReady) {
|
||||
vb_tag_set_random_nonce(bant);
|
||||
vb_tag_set_status(bant, VbTagStatusReady);
|
||||
vb_tag_set_operation(bant, VbTagOperationReady);
|
||||
} else if(state == FromAppStateEmulateCheckDim) {
|
||||
vb_tag_set_status(bant, VbTagStatusReady | VbTagStatusDimReady);
|
||||
vb_tag_set_operation(bant, VbTagOperationReady);
|
||||
} else if(state == FromAppStateEmulateTransferFromApp) {
|
||||
vb_tag_set_status(bant, 0);
|
||||
vb_tag_set_operation(bant, VbTagOperationIdle);
|
||||
}
|
||||
|
||||
// Override tag type
|
||||
if(inst->override_type != inst->orig_type && inst->override_type != VbTagTypeUnknown) {
|
||||
vb_tag_set_item_id_no(bant, vb_tag_get_default_product(inst->override_type));
|
||||
}
|
||||
|
||||
if(inst->clear_account_id) {
|
||||
vb_tag_set_app_flag(bant, false);
|
||||
}
|
||||
}
|
||||
|
||||
static bool vb_migrate_scene_from_app_is_state_changed(VbMigrate* inst, FromAppState state) {
|
||||
BantBlock* bant = vb_tag_get_bant_block(&inst->nfc_dev->dev_data);
|
||||
VbTagOperation operation = vb_tag_get_operation(bant);
|
||||
|
||||
if(state == FromAppStateEmulateReady) {
|
||||
return operation == VbTagOperationCheckDim;
|
||||
} else if(state == FromAppStateEmulateCheckDim) {
|
||||
return operation == VbTagOperationCheckDim || operation == VbTagOperationReturnFromApp;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void vb_migrate_scene_from_app_set_state(VbMigrate* inst, FromAppState state) {
|
||||
uint32_t curr_state =
|
||||
scene_manager_get_scene_state(inst->scene_manager, VbMigrateSceneFromApp);
|
||||
if(state != curr_state) {
|
||||
Widget* widget = inst->widget;
|
||||
|
||||
if(state == FromAppStateInstructions) {
|
||||
widget_reset(widget);
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton | VbMigrateBgTypeRightButton);
|
||||
widget_add_text_scroll_element(
|
||||
widget,
|
||||
8,
|
||||
16,
|
||||
113,
|
||||
33,
|
||||
"\e#To transfer\n"
|
||||
"\e#characters to Flipper:\n"
|
||||
"0. If on VB Arena, select\n"
|
||||
"the device type that\n"
|
||||
"matches your current\n"
|
||||
"settings\n"
|
||||
"1. If on VB Lab, wake up\n"
|
||||
"character from storage\n"
|
||||
"2. Sync character to\n"
|
||||
"Flipper as if it was a\n"
|
||||
"Vital Bracelet. Flipper\n"
|
||||
"will beep when it is\n"
|
||||
"ready for the next step\n"
|
||||
"3. The character is\n"
|
||||
"automatically saved when\n"
|
||||
"the transfer is complete,\n"
|
||||
"and will be ready for\n"
|
||||
"another transfer\n"
|
||||
"4. Repeat the above until\n"
|
||||
"you have transferred all\n"
|
||||
"the characters you want\n"
|
||||
"\n"
|
||||
"You can cancel at any\n"
|
||||
"time to finish transferring.");
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Cancel",
|
||||
vb_migrate_scene_from_app_widget_callback,
|
||||
inst);
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeRight,
|
||||
"Next",
|
||||
vb_migrate_scene_from_app_widget_callback,
|
||||
inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
} else if(state == FromAppStateEmulateReady) {
|
||||
vb_migrate_show_loading_popup(inst, true);
|
||||
if(vb_migrate_load_nfc(inst, inst->text_store, VB_MIGRATE_TEMPLATE_NAME)) {
|
||||
widget_reset(widget);
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton);
|
||||
widget_add_icon_element(widget, 11, 18, &I_CommReady_32x27);
|
||||
widget_add_icon_element(widget, 48, 18, &I_TextTransferDimCheck_70x20);
|
||||
FuriString* temp_str = furi_string_alloc_printf("%d", inst->num_captured);
|
||||
widget_add_string_element(
|
||||
widget,
|
||||
100,
|
||||
31,
|
||||
AlignLeft,
|
||||
AlignTop,
|
||||
FontSecondary,
|
||||
furi_string_get_cstr(temp_str));
|
||||
widget_add_icon_element(widget, 106, 40, &I_PulsemonRightWaiting_15x16);
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Cancel",
|
||||
vb_migrate_scene_from_app_widget_callback,
|
||||
inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
furi_string_free(temp_str);
|
||||
|
||||
vb_migrate_scene_from_app_set_nfc_state(inst, state);
|
||||
nfc_worker_start(
|
||||
inst->worker,
|
||||
NfcWorkerStateMfUltralightEmulate,
|
||||
&inst->nfc_dev->dev_data,
|
||||
vb_migrate_scene_from_app_worker_callback,
|
||||
inst);
|
||||
vb_migrate_blink_emulate(inst);
|
||||
} else {
|
||||
view_dispatcher_send_custom_event(
|
||||
inst->view_dispatcher, FromAppEventTypeTemplateLoadError);
|
||||
}
|
||||
vb_migrate_show_loading_popup(inst, false);
|
||||
} else if(state == FromAppStateEmulateCheckDim) {
|
||||
widget_reset(widget);
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton);
|
||||
widget_add_icon_element(widget, 11, 18, &I_CommReady_32x27);
|
||||
widget_add_icon_element(widget, 48, 18, &I_TextTransferSecondDimCheck_71x20);
|
||||
widget_add_icon_element(widget, 106, 40, &I_PulsemonRightWaiting_15x16);
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Cancel",
|
||||
vb_migrate_scene_from_app_widget_callback,
|
||||
inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
notification_message(inst->notifications, &sequence_success);
|
||||
vb_migrate_scene_from_app_set_nfc_state(inst, state);
|
||||
nfc_worker_start(
|
||||
inst->worker,
|
||||
NfcWorkerStateMfUltralightEmulate,
|
||||
&inst->nfc_dev->dev_data,
|
||||
vb_migrate_scene_from_app_worker_callback,
|
||||
inst);
|
||||
vb_migrate_blink_emulate(inst);
|
||||
} else if(state == FromAppStateEmulateTransferFromApp) {
|
||||
widget_reset(widget);
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton);
|
||||
widget_add_icon_element(widget, 15, 18, &I_TextTransferCaptured_97x13);
|
||||
widget_add_icon_element(widget, 106, 40, &I_PulsemonRightWaiting_15x16);
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Cancel",
|
||||
vb_migrate_scene_from_app_widget_callback,
|
||||
inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
nfc_worker_stop(inst->worker);
|
||||
vb_migrate_blink_stop(inst);
|
||||
vb_migrate_scene_from_app_set_nfc_state(inst, state);
|
||||
notification_message(inst->notifications, &sequence_success);
|
||||
|
||||
// Restore original tag type if necessary
|
||||
if(inst->override_type != inst->orig_type && inst->override_type != VbTagTypeUnknown) {
|
||||
BantBlock* bant = vb_tag_get_bant_block(&inst->nfc_dev->dev_data);
|
||||
vb_tag_set_item_id_no(bant, inst->orig_product);
|
||||
}
|
||||
|
||||
// Save the tag
|
||||
inst->next_id = vb_migrate_get_next_id(inst, inst->text_store, inst->next_id, false);
|
||||
FuriString* save_path = furi_string_alloc_printf(
|
||||
VB_MIGRATE_CAPTURE_FORMAT, inst->next_id, NFC_APP_EXTENSION);
|
||||
if(vb_migrate_save_nfc(inst, inst->text_store, furi_string_get_cstr(save_path))) {
|
||||
view_dispatcher_send_custom_event(
|
||||
inst->view_dispatcher, FromAppEventTypeCaptureSaveSuccess);
|
||||
} else {
|
||||
view_dispatcher_send_custom_event(
|
||||
inst->view_dispatcher, FromAppEventTypeCaptureSaveError);
|
||||
}
|
||||
furi_string_free(save_path);
|
||||
} else if(state == FromAppStateTemplateError) {
|
||||
widget_reset(widget);
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton);
|
||||
widget_add_icon_element(widget, 11, 18, &I_WrongDevice_32x27);
|
||||
widget_add_icon_element(widget, 48, 18, &I_TextErrLoadTemplate_69x13);
|
||||
widget_add_icon_element(widget, 104, 41, &I_PulsemonLeftWait_15x15);
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Cancel",
|
||||
vb_migrate_scene_from_app_widget_callback,
|
||||
inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
notification_message(inst->notifications, &sequence_error);
|
||||
notification_message(inst->notifications, &sequence_set_red_255);
|
||||
} else if(state == FromAppStateSaveError) {
|
||||
widget_reset(widget);
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton);
|
||||
widget_add_icon_element(widget, 11, 18, &I_WrongDevice_32x27);
|
||||
widget_add_icon_element(widget, 48, 18, &I_TextErrSaveCapture_65x13);
|
||||
widget_add_icon_element(widget, 104, 41, &I_PulsemonLeftWait_15x15);
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Cancel",
|
||||
vb_migrate_scene_from_app_widget_callback,
|
||||
inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
notification_message(inst->notifications, &sequence_error);
|
||||
notification_message(inst->notifications, &sequence_set_red_255);
|
||||
} else {
|
||||
furi_crash("Unknown new state in vb_migrate_scene_from_app_set_state");
|
||||
}
|
||||
|
||||
scene_manager_set_scene_state(inst->scene_manager, VbMigrateSceneFromApp, state);
|
||||
}
|
||||
}
|
||||
|
||||
void vb_migrate_scene_from_app_on_enter(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Perform your setup here
|
||||
inst->next_id = 0;
|
||||
scene_manager_set_scene_state(inst->scene_manager, VbMigrateSceneFromApp, FromAppStateInitial);
|
||||
vb_migrate_scene_from_app_set_state(inst, FromAppStateInstructions);
|
||||
}
|
||||
|
||||
bool vb_migrate_scene_from_app_on_event(void* context, SceneManagerEvent event) {
|
||||
VbMigrate* inst = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == FromAppEventTypeWidgetLeft) {
|
||||
consumed = scene_manager_previous_scene(inst->scene_manager);
|
||||
} else if(event.event == FromAppEventTypeWidgetRight) {
|
||||
vb_migrate_scene_from_app_set_state(inst, FromAppStateEmulateReady);
|
||||
consumed = true;
|
||||
} else if(event.event == FromAppEventTypeTagWrite) {
|
||||
uint32_t state =
|
||||
scene_manager_get_scene_state(inst->scene_manager, VbMigrateSceneFromApp);
|
||||
if(vb_migrate_scene_from_app_is_state_changed(inst, state)) {
|
||||
if(state == FromAppStateEmulateReady) {
|
||||
nfc_worker_stop(inst->worker);
|
||||
vb_migrate_blink_stop(inst);
|
||||
vb_migrate_scene_from_app_set_state(inst, FromAppStateEmulateCheckDim);
|
||||
consumed = true;
|
||||
} else if(state == FromAppStateEmulateCheckDim) {
|
||||
BantBlock* bant = vb_tag_get_bant_block(&inst->nfc_dev->dev_data);
|
||||
VbTagOperation operation = vb_tag_get_operation(bant);
|
||||
|
||||
if(operation == VbTagOperationReturnFromApp) {
|
||||
nfc_worker_stop(inst->worker);
|
||||
vb_migrate_blink_stop(inst);
|
||||
vb_migrate_scene_from_app_set_state(
|
||||
inst, FromAppStateEmulateTransferFromApp);
|
||||
consumed = true;
|
||||
} else if(operation == VbTagOperationCheckDim) {
|
||||
// Don't need to reset tag, but should make a beep
|
||||
vb_migrate_blink_stop(inst);
|
||||
notification_message_block(inst->notifications, &sequence_success);
|
||||
vb_migrate_blink_emulate(inst);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(event.event == FromAppEventTypeTemplateLoadError) {
|
||||
vb_migrate_scene_from_app_set_state(inst, FromAppStateTemplateError);
|
||||
consumed = true;
|
||||
} else if(event.event == FromAppEventTypeCaptureSaveError) {
|
||||
vb_migrate_scene_from_app_set_state(inst, FromAppStateSaveError);
|
||||
consumed = true;
|
||||
} else if(event.event == FromAppEventTypeCaptureSaveSuccess) {
|
||||
++inst->num_captured;
|
||||
++inst->next_id;
|
||||
vb_migrate_scene_from_app_set_state(inst, FromAppStateEmulateReady);
|
||||
consumed = true;
|
||||
} else {
|
||||
furi_crash("Unknown event in vb_migrate_scene_from_app_on_event");
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void vb_migrate_scene_from_app_on_exit(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Perform your cleanup here
|
||||
widget_reset(inst->widget);
|
||||
nfc_worker_stop(inst->worker);
|
||||
vb_migrate_blink_stop(inst);
|
||||
notification_message_block(inst->notifications, &sequence_reset_red);
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// VB Lab Migration Assistant for Flipper Zero
|
||||
// Copyright (C) 2022 cyanic
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "../vb_migrate_i.h"
|
||||
#include "../vb_tag.h"
|
||||
|
||||
static void
|
||||
vb_migrate_scene_info_button_callback(GuiButtonType result, InputType type, void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
if(type == InputTypeShort) {
|
||||
if(result == GuiButtonTypeRight) {
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vb_migrate_scene_info_on_enter(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
FuriString* temp_str = furi_string_alloc();
|
||||
|
||||
// Build info scroll
|
||||
// Name
|
||||
furi_string_cat_printf(temp_str, "\ec%s\n", inst->text_store);
|
||||
|
||||
// Type
|
||||
if(inst->orig_product == NULL)
|
||||
furi_string_cat(temp_str, "Unknown product\n");
|
||||
else
|
||||
furi_string_cat_printf(temp_str, "\e#%s\n", inst->orig_product->name);
|
||||
|
||||
// Number of mons loaded
|
||||
furi_string_cat_printf(temp_str, "Charas. captured: %d", inst->num_captured);
|
||||
|
||||
vb_migrate_add_bg(inst->widget, VbMigrateBgTypeRightButton);
|
||||
|
||||
widget_add_text_scroll_element(inst->widget, 8, 16, 113, 33, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
widget_add_button_element(
|
||||
inst->widget, GuiButtonTypeRight, "More", vb_migrate_scene_info_button_callback, inst);
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
}
|
||||
|
||||
bool vb_migrate_scene_info_on_event(void* context, SceneManagerEvent event) {
|
||||
VbMigrate* inst = context;
|
||||
bool consumed = false;
|
||||
UNUSED(inst);
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == GuiButtonTypeRight) {
|
||||
// Reset menu selection index
|
||||
scene_manager_set_scene_state(inst->scene_manager, VbMigrateSceneDevMenu, 0);
|
||||
scene_manager_next_scene(inst->scene_manager, VbMigrateSceneDevMenu);
|
||||
consumed = true;
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeBack) {
|
||||
uint32_t back_scenes[] = {VbMigrateSceneSelect, VbMigrateSceneMainMenu};
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene_one_of(
|
||||
inst->scene_manager, back_scenes, COUNT_OF(back_scenes));
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void vb_migrate_scene_info_on_exit(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Perform your cleanup here
|
||||
widget_reset(inst->widget);
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// VB Lab Migration Assistant for Flipper Zero
|
||||
// Copyright (C) 2022 cyanic
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "../vb_migrate_i.h"
|
||||
|
||||
#define TAG "vb_migrate_scene_load"
|
||||
|
||||
void vb_migrate_scene_load_on_enter(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Perform your setup here
|
||||
vb_migrate_show_loading_popup(inst, true);
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, 0);
|
||||
}
|
||||
|
||||
bool vb_migrate_scene_load_on_event(void* context, SceneManagerEvent event) {
|
||||
VbMigrate* inst = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(vb_migrate_load_nfc(inst, inst->text_store, VB_MIGRATE_TEMPLATE_NAME)) {
|
||||
inst->num_captured = vb_migrate_count_captured_mons(inst, inst->text_store);
|
||||
|
||||
BantBlock* bant = vb_tag_get_bant_block(&inst->nfc_dev->dev_data);
|
||||
const VbTagProduct* product = vb_tag_find_product(bant);
|
||||
inst->orig_product = product;
|
||||
if(product) {
|
||||
inst->orig_type = product->type;
|
||||
} else {
|
||||
inst->orig_type = VbTagTypeUnknown;
|
||||
}
|
||||
inst->override_type = inst->orig_type;
|
||||
|
||||
scene_manager_next_scene(inst->scene_manager, VbMigrateSceneInfo);
|
||||
consumed = true;
|
||||
} else {
|
||||
consumed = scene_manager_previous_scene(inst->scene_manager);
|
||||
}
|
||||
vb_migrate_show_loading_popup(inst, false);
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void vb_migrate_scene_load_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// VB Lab Migration Assistant for Flipper Zero
|
||||
// Copyright (C) 2022 cyanic
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "../vb_migrate_i.h"
|
||||
|
||||
typedef enum {
|
||||
SubmenuMainIndexRegister,
|
||||
SubmenuMainIndexSelect,
|
||||
SubmenuMainIndexAbout,
|
||||
} SubmenuMainIndex;
|
||||
|
||||
static void vb_migrate_scene_main_menu_submenu_callback(void* context, uint32_t index) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void vb_migrate_scene_main_menu_on_enter(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
Submenu* submenu = inst->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Register Vital Bracelet",
|
||||
SubmenuMainIndexRegister,
|
||||
vb_migrate_scene_main_menu_submenu_callback,
|
||||
inst);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Select Vital Bracelet",
|
||||
SubmenuMainIndexSelect,
|
||||
vb_migrate_scene_main_menu_submenu_callback,
|
||||
inst);
|
||||
submenu_add_item(
|
||||
submenu, "About", SubmenuMainIndexAbout, vb_migrate_scene_main_menu_submenu_callback, inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewMenu);
|
||||
}
|
||||
|
||||
bool vb_migrate_scene_main_menu_on_event(void* context, SceneManagerEvent event) {
|
||||
VbMigrate* inst = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubmenuMainIndexRegister) {
|
||||
scene_manager_next_scene(inst->scene_manager, VbMigrateSceneRegister);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuMainIndexSelect) {
|
||||
scene_manager_next_scene(inst->scene_manager, VbMigrateSceneSelect);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuMainIndexAbout) {
|
||||
scene_manager_next_scene(inst->scene_manager, VbMigrateSceneAbout);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void vb_migrate_scene_main_menu_on_exit(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
submenu_reset(inst->submenu);
|
||||
}
|
||||
+420
@@ -0,0 +1,420 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// VB Lab Migration Assistant for Flipper Zero
|
||||
// Copyright (C) 2022 cyanic
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <notification/notification_messages.h>
|
||||
|
||||
#include "../vb_tag.h"
|
||||
#include "../vb_migrate_i.h"
|
||||
|
||||
typedef enum {
|
||||
RegisterStateInitial,
|
||||
RegisterStateInstructionInitial,
|
||||
RegisterStateInstructionConnect,
|
||||
RegisterStateCaptureInitial,
|
||||
RegisterStateCaptureInvalidTag,
|
||||
RegisterStateCapturePwd,
|
||||
RegisterStateCaptureFull,
|
||||
RegisterStateCaptureFailed,
|
||||
RegisterStateCaptureIncorrectTag,
|
||||
} RegisterState;
|
||||
|
||||
typedef enum {
|
||||
RegisterEventTypeNextButton,
|
||||
RegisterEventTypePrevButton,
|
||||
RegisterEventTypeVbReadInitial,
|
||||
RegisterEventTypeVbPwdAuth,
|
||||
RegisterEventTypeVbReadFullSuccess,
|
||||
RegisterEventTypeVbReadFullFail,
|
||||
} RegisterEventType;
|
||||
|
||||
static void
|
||||
vb_migrate_scene_register_widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
if(type == InputTypeShort) {
|
||||
if(result == GuiButtonTypeRight)
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, RegisterEventTypeNextButton);
|
||||
else if(result == GuiButtonTypeLeft)
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, RegisterEventTypePrevButton);
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
vb_migrate_scene_register_worker_read_initial_callback(NfcWorkerEvent event, void* context) {
|
||||
VbMigrate* inst = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event == NfcWorkerEventReadMfUltralight) {
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, RegisterEventTypeVbReadInitial);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
static bool vb_migrate_scene_register_worker_auth_callback(NfcWorkerEvent event, void* context) {
|
||||
VbMigrate* inst = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event == NfcWorkerEventMfUltralightPwdAuth) {
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, RegisterEventTypeVbPwdAuth);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
static bool
|
||||
vb_migrate_scene_register_worker_full_capture_callback(NfcWorkerEvent event, void* context) {
|
||||
VbMigrate* inst = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event == NfcWorkerEventMfUltralightPassKey) {
|
||||
memcpy(
|
||||
inst->nfc_dev->dev_data.mf_ul_data.auth_key,
|
||||
inst->captured_pwd,
|
||||
sizeof(inst->captured_pwd));
|
||||
consumed = true;
|
||||
} else if(event == NfcWorkerEventSuccess) {
|
||||
view_dispatcher_send_custom_event(
|
||||
inst->view_dispatcher, RegisterEventTypeVbReadFullSuccess);
|
||||
consumed = true;
|
||||
} else if(event == NfcWorkerEventFail) {
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, RegisterEventTypeVbReadFullFail);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
static void vb_migrate_scene_register_cleanup_state(VbMigrate* inst, RegisterState state) {
|
||||
if(state == RegisterStateCaptureInvalidTag || state == RegisterStateCaptureFailed ||
|
||||
state == RegisterStateCaptureIncorrectTag) {
|
||||
notification_message(inst->notifications, &sequence_reset_red);
|
||||
} else if(
|
||||
state == RegisterStateCaptureInitial || state == RegisterStateCapturePwd ||
|
||||
state == RegisterStateCaptureFull) {
|
||||
vb_migrate_blink_stop(inst);
|
||||
nfc_worker_stop(inst->worker);
|
||||
}
|
||||
}
|
||||
|
||||
static void vb_migrate_scene_register_set_state(VbMigrate* inst, RegisterState state) {
|
||||
uint32_t curr_state =
|
||||
scene_manager_get_scene_state(inst->scene_manager, VbMigrateSceneRegister);
|
||||
if(state != curr_state) {
|
||||
vb_migrate_scene_register_cleanup_state(inst, curr_state);
|
||||
Widget* widget = inst->widget;
|
||||
|
||||
if(state == RegisterStateInstructionInitial) {
|
||||
widget_reset(widget);
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton | VbMigrateBgTypeRightButton);
|
||||
widget_add_text_scroll_element(
|
||||
widget,
|
||||
8,
|
||||
16,
|
||||
113,
|
||||
33,
|
||||
"Please make sure your\n"
|
||||
"current character has\n"
|
||||
"been sent to VB Lab/\n"
|
||||
"Arena before\n"
|
||||
"continuing.");
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Cancel",
|
||||
vb_migrate_scene_register_widget_callback,
|
||||
inst);
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeRight,
|
||||
"Next",
|
||||
vb_migrate_scene_register_widget_callback,
|
||||
inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
} else if(state == RegisterStateInstructionConnect) {
|
||||
widget_reset(widget);
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton | VbMigrateBgTypeRightButton);
|
||||
widget_add_text_scroll_element(
|
||||
widget,
|
||||
8,
|
||||
16,
|
||||
113,
|
||||
33,
|
||||
"Prepare VB Lab:\n"
|
||||
"1. Ensure current\n"
|
||||
"character in VB Lab has\n"
|
||||
"been put in storage\n"
|
||||
"2. Open the \"Scan\" screen\n"
|
||||
"3. Tap \"Vital Bracelet ->\n"
|
||||
"App\"\n"
|
||||
"\n"
|
||||
"Prepare VB Arena:\n"
|
||||
"1. Select the device type\n"
|
||||
"that matches your VB\n"
|
||||
"2. Tap the \"Send\" button");
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Cancel",
|
||||
vb_migrate_scene_register_widget_callback,
|
||||
inst);
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeRight,
|
||||
"Next",
|
||||
vb_migrate_scene_register_widget_callback,
|
||||
inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
} else if(state == RegisterStateCaptureInitial) {
|
||||
widget_reset(widget);
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton);
|
||||
widget_add_icon_element(widget, 11, 25, &I_CommVB_32x20);
|
||||
widget_add_icon_element(widget, 21, 17, &I_CommWave_12x8);
|
||||
widget_add_icon_element(widget, 48, 18, &I_TextRegister1_71x20);
|
||||
widget_add_icon_element(widget, 105, 40, &I_PulsemonLeftStand_14x16);
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Previous",
|
||||
vb_migrate_scene_register_widget_callback,
|
||||
inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
nfc_device_clear(inst->nfc_dev);
|
||||
inst->nfc_dev->dev_data.read_mode = NfcReadModeMfUltralight;
|
||||
nfc_worker_start(
|
||||
inst->worker,
|
||||
NfcWorkerStateRead,
|
||||
&inst->nfc_dev->dev_data,
|
||||
vb_migrate_scene_register_worker_read_initial_callback,
|
||||
inst);
|
||||
vb_migrate_blink_read(inst);
|
||||
} else if(state == RegisterStateCaptureInvalidTag) {
|
||||
widget_reset(widget);
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton);
|
||||
widget_add_icon_element(widget, 11, 18, &I_WrongDevice_32x27);
|
||||
widget_add_icon_element(widget, 48, 18, &I_TextRegisterErrNotVb_71x20);
|
||||
widget_add_icon_element(widget, 104, 41, &I_PulsemonLeftWait_15x15);
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Retry",
|
||||
vb_migrate_scene_register_widget_callback,
|
||||
inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
notification_message(inst->notifications, &sequence_set_red_255);
|
||||
} else if(state == RegisterStateCapturePwd) {
|
||||
widget_reset(widget);
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton);
|
||||
widget_add_icon_element(widget, 11, 18, &I_AppInteract_32x27);
|
||||
widget_add_icon_element(widget, 48, 18, &I_TextTapApp_56x27);
|
||||
widget_add_icon_element(widget, 105, 40, &I_PulsemonLeftStand_14x16);
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Previous",
|
||||
vb_migrate_scene_register_widget_callback,
|
||||
inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
|
||||
BantBlock* bant = vb_tag_get_bant_block(&inst->nfc_dev->dev_data);
|
||||
vb_tag_set_operation(bant, VbTagOperationReady);
|
||||
vb_tag_set_status(bant, VbTagStatusReady);
|
||||
nfc_worker_start(
|
||||
inst->worker,
|
||||
NfcWorkerStateMfUltralightEmulate,
|
||||
&inst->nfc_dev->dev_data,
|
||||
vb_migrate_scene_register_worker_auth_callback,
|
||||
inst);
|
||||
vb_migrate_blink_emulate(inst);
|
||||
} else if(state == RegisterStateCaptureFull) {
|
||||
widget_reset(widget);
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton);
|
||||
widget_add_icon_element(widget, 11, 25, &I_CommVB_32x20);
|
||||
widget_add_icon_element(widget, 23, 18, &I_CommReturn_10x8);
|
||||
widget_add_icon_element(widget, 48, 18, &I_TextRegisterTapAgain_67x20);
|
||||
widget_add_icon_element(widget, 104, 41, &I_PulsemonLeftWait_15x15);
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Previous",
|
||||
vb_migrate_scene_register_widget_callback,
|
||||
inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
|
||||
inst->nfc_dev->dev_data.mf_ul_data.auth_method = MfUltralightAuthMethodAuto;
|
||||
nfc_worker_start(
|
||||
inst->worker,
|
||||
NfcWorkerStateReadMfUltralightReadAuth,
|
||||
&inst->nfc_dev->dev_data,
|
||||
vb_migrate_scene_register_worker_full_capture_callback,
|
||||
inst);
|
||||
vb_migrate_blink_read(inst);
|
||||
} else if(state == RegisterStateCaptureFailed) {
|
||||
widget_reset(widget);
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton);
|
||||
widget_add_icon_element(widget, 11, 18, &I_WrongDevice_32x27);
|
||||
widget_add_icon_element(widget, 48, 18, &I_TextErrReadFailed_71x20);
|
||||
widget_add_icon_element(widget, 104, 41, &I_PulsemonLeftWait_15x15);
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Retry",
|
||||
vb_migrate_scene_register_widget_callback,
|
||||
inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
notification_message(inst->notifications, &sequence_set_red_255);
|
||||
} else if(state == RegisterStateCaptureIncorrectTag) {
|
||||
widget_reset(widget);
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton);
|
||||
widget_add_icon_element(widget, 11, 18, &I_WrongDevice_32x27);
|
||||
widget_add_icon_element(widget, 48, 18, &I_TextErrRegisterDifferentTag_47x20);
|
||||
widget_add_icon_element(widget, 104, 41, &I_PulsemonLeftWait_15x15);
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Retry",
|
||||
vb_migrate_scene_register_widget_callback,
|
||||
inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
notification_message(inst->notifications, &sequence_set_red_255);
|
||||
} else {
|
||||
furi_crash("Unknown new state in vb_migrate_scene_register_set_state");
|
||||
}
|
||||
|
||||
scene_manager_set_scene_state(inst->scene_manager, VbMigrateSceneRegister, state);
|
||||
}
|
||||
}
|
||||
|
||||
static bool vb_migrate_scene_register_next_state(VbMigrate* inst, RegisterState state) {
|
||||
if(state == RegisterStateInstructionInitial) {
|
||||
vb_migrate_scene_register_set_state(inst, RegisterStateInstructionConnect);
|
||||
return true;
|
||||
} else if(state == RegisterStateInstructionConnect) {
|
||||
vb_migrate_scene_register_set_state(inst, RegisterStateCaptureInitial);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
vb_migrate_scene_register_prev_state(VbMigrate* inst, RegisterState state, bool is_back) {
|
||||
UNUSED(is_back);
|
||||
|
||||
if(state == RegisterStateInstructionInitial || state == RegisterStateInstructionConnect) {
|
||||
return scene_manager_previous_scene(inst->scene_manager);
|
||||
} else if(state == RegisterStateCaptureInitial) {
|
||||
vb_migrate_scene_register_set_state(inst, RegisterStateInstructionConnect);
|
||||
return true;
|
||||
} else if(
|
||||
state == RegisterStateCaptureInvalidTag || state == RegisterStateCapturePwd ||
|
||||
state == RegisterStateCaptureFull) {
|
||||
vb_migrate_scene_register_set_state(inst, RegisterStateCaptureInitial);
|
||||
return true;
|
||||
} else if(state == RegisterStateCaptureFailed || state == RegisterStateCaptureIncorrectTag) {
|
||||
vb_migrate_scene_register_set_state(inst, RegisterStateCaptureFull);
|
||||
return true;
|
||||
}
|
||||
|
||||
return is_back;
|
||||
}
|
||||
|
||||
void vb_migrate_scene_register_on_enter(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
scene_manager_set_scene_state(
|
||||
inst->scene_manager, VbMigrateSceneRegister, RegisterStateInitial);
|
||||
vb_migrate_scene_register_set_state(inst, RegisterStateInstructionInitial);
|
||||
}
|
||||
|
||||
bool vb_migrate_scene_register_on_event(void* context, SceneManagerEvent event) {
|
||||
VbMigrate* inst = context;
|
||||
bool consumed = false;
|
||||
RegisterState state =
|
||||
scene_manager_get_scene_state(inst->scene_manager, VbMigrateSceneRegister);
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == RegisterEventTypeNextButton) {
|
||||
consumed = vb_migrate_scene_register_next_state(inst, state);
|
||||
} else if(event.event == RegisterEventTypePrevButton) {
|
||||
consumed = vb_migrate_scene_register_prev_state(inst, state, false);
|
||||
} else if(event.event == RegisterEventTypeVbReadInitial) {
|
||||
if(vb_tag_validate_product(&inst->nfc_dev->dev_data)) {
|
||||
memcpy(
|
||||
inst->captured_uid,
|
||||
inst->nfc_dev->dev_data.nfc_data.uid,
|
||||
sizeof(inst->captured_uid));
|
||||
notification_message(inst->notifications, &sequence_success);
|
||||
vb_migrate_scene_register_set_state(inst, RegisterStateCapturePwd);
|
||||
} else {
|
||||
notification_message(inst->notifications, &sequence_error);
|
||||
vb_migrate_scene_register_set_state(inst, RegisterStateCaptureInvalidTag);
|
||||
}
|
||||
consumed = true;
|
||||
} else if(event.event == RegisterEventTypeVbPwdAuth) {
|
||||
// Set up for auth
|
||||
memcpy(
|
||||
inst->captured_pwd,
|
||||
inst->nfc_dev->dev_data.mf_ul_auth.pwd.raw,
|
||||
sizeof(inst->captured_pwd));
|
||||
|
||||
notification_message(inst->notifications, &sequence_success);
|
||||
vb_migrate_scene_register_set_state(inst, RegisterStateCaptureFull);
|
||||
consumed = true;
|
||||
} else if(event.event == RegisterEventTypeVbReadFullSuccess) {
|
||||
NfcDeviceData* dev_data = &inst->nfc_dev->dev_data;
|
||||
if(memcmp(dev_data->nfc_data.uid, inst->captured_uid, sizeof(inst->captured_uid)) ||
|
||||
dev_data->mf_ul_data.data_read != dev_data->mf_ul_data.data_size) {
|
||||
notification_message(inst->notifications, &sequence_error);
|
||||
vb_migrate_scene_register_set_state(inst, RegisterStateCaptureIncorrectTag);
|
||||
} else {
|
||||
notification_message(inst->notifications, &sequence_success);
|
||||
scene_manager_next_scene(inst->scene_manager, VbMigrateSceneRegisterSave);
|
||||
}
|
||||
consumed = true;
|
||||
} else if(event.event == RegisterEventTypeVbReadFullFail) {
|
||||
notification_message(inst->notifications, &sequence_error);
|
||||
vb_migrate_scene_register_set_state(inst, RegisterStateCaptureFailed);
|
||||
consumed = true;
|
||||
} else {
|
||||
furi_crash("Unknown event in vb_migrate_scene_register_on_event");
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeBack) {
|
||||
consumed = vb_migrate_scene_register_prev_state(inst, state, true);
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void vb_migrate_scene_register_on_exit(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
RegisterState state =
|
||||
scene_manager_get_scene_state(inst->scene_manager, VbMigrateSceneRegister);
|
||||
|
||||
vb_migrate_scene_register_cleanup_state(inst, state);
|
||||
widget_reset(inst->widget);
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// VB Lab Migration Assistant for Flipper Zero
|
||||
// Copyright (C) 2022 cyanic
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <notification/notification_messages.h>
|
||||
|
||||
#include "../vb_migrate_i.h"
|
||||
#include "../vb_tag.h"
|
||||
|
||||
// This thing doesn't know what a FuriString is
|
||||
#include <gui/modules/validators.h>
|
||||
|
||||
typedef enum {
|
||||
RegisterSaveEventTextInput,
|
||||
} RegisterSaveEvent;
|
||||
|
||||
static void vb_migrate_scene_register_save_text_input_callback(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, RegisterSaveEventTextInput);
|
||||
}
|
||||
|
||||
void vb_migrate_scene_register_save_on_enter(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Setup view
|
||||
TextInput* text_input = inst->text_input;
|
||||
text_input_set_header_text(text_input, "Name this Vital Bracelet");
|
||||
text_input_set_result_callback(
|
||||
text_input,
|
||||
vb_migrate_scene_register_save_text_input_callback,
|
||||
inst,
|
||||
inst->text_store,
|
||||
VB_MIGRATE_MAX_DEV_NAME_LENGTH,
|
||||
true);
|
||||
|
||||
// Set default name
|
||||
FuriString* temp_str;
|
||||
NfcDeviceData* dev_data = &inst->nfc_dev->dev_data;
|
||||
BantBlock* bant = vb_tag_get_bant_block(dev_data);
|
||||
const VbTagProduct* prod = vb_tag_find_product(bant);
|
||||
temp_str = furi_string_alloc_printf("%s_", prod->short_name);
|
||||
for(size_t i = 0; i < dev_data->nfc_data.uid_len; ++i) {
|
||||
furi_string_cat_printf(temp_str, "%02x", dev_data->nfc_data.uid[i]);
|
||||
}
|
||||
vb_migrate_text_store_set(inst, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
// We're validating whether folder exists
|
||||
ValidatorIsFile* validator_is_file =
|
||||
validator_is_file_alloc_init(VB_MIGRATE_FOLDER, "/" VB_MIGRATE_TEMPLATE_NAME, NULL);
|
||||
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewTextInput);
|
||||
notification_message(inst->notifications, &sequence_set_green_255);
|
||||
}
|
||||
|
||||
bool vb_migrate_scene_register_save_on_event(void* context, SceneManagerEvent event) {
|
||||
VbMigrate* inst = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == RegisterSaveEventTextInput) {
|
||||
if(strlen(inst->text_store) != 0) {
|
||||
vb_migrate_show_loading_popup(inst, true);
|
||||
if(vb_migrate_save_nfc(inst, inst->text_store, VB_MIGRATE_TEMPLATE_NAME)) {
|
||||
inst->num_captured = 0;
|
||||
|
||||
BantBlock* bant = vb_tag_get_bant_block(&inst->nfc_dev->dev_data);
|
||||
const VbTagProduct* product = vb_tag_find_product(bant);
|
||||
inst->orig_product = product;
|
||||
if(product) {
|
||||
inst->orig_type = product->type;
|
||||
} else {
|
||||
inst->orig_type = VbTagTypeUnknown;
|
||||
}
|
||||
inst->override_type = inst->orig_type;
|
||||
|
||||
// Go to success
|
||||
scene_manager_next_scene(inst->scene_manager, VbMigrateSceneSaveSuccess);
|
||||
} else {
|
||||
// Otherwise just stay here
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewTextInput);
|
||||
}
|
||||
vb_migrate_show_loading_popup(inst, false);
|
||||
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void vb_migrate_scene_register_save_on_exit(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Clear view
|
||||
TextInput* text_input = inst->text_input;
|
||||
ValidatorIsFile* validator = text_input_get_validator_callback_context(text_input);
|
||||
text_input_set_validator(text_input, NULL, NULL);
|
||||
validator_is_file_free(validator);
|
||||
|
||||
text_input_reset(text_input);
|
||||
notification_message_block(inst->notifications, &sequence_reset_green);
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// VB Lab Migration Assistant for Flipper Zero
|
||||
// Copyright (C) 2022 cyanic
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "../vb_migrate_i.h"
|
||||
|
||||
static void vb_migrate_scene_save_success_widget_callback(
|
||||
GuiButtonType result,
|
||||
InputType type,
|
||||
void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
if(type == InputTypeShort) {
|
||||
if(result == GuiButtonTypeRight)
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void vb_migrate_scene_save_success_on_enter(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Setup view
|
||||
Widget* widget = inst->widget;
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeRightButton);
|
||||
widget_add_icon_element(widget, 11, 18, &I_CommComplete_32x20);
|
||||
widget_add_icon_element(widget, 48, 18, &I_TextSaved_30x6);
|
||||
widget_add_icon_element(widget, 9, 40, &I_PulsemonRightHappy_14x16);
|
||||
widget_add_button_element(
|
||||
widget, GuiButtonTypeRight, "OK", vb_migrate_scene_save_success_widget_callback, inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
}
|
||||
|
||||
bool vb_migrate_scene_save_success_on_event(void* context, SceneManagerEvent event) {
|
||||
VbMigrate* inst = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom || event.type == SceneManagerEventTypeBack) {
|
||||
scene_manager_next_scene(inst->scene_manager, VbMigrateSceneInfo);
|
||||
consumed = true;
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void vb_migrate_scene_save_success_on_exit(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Clear view
|
||||
widget_reset(inst->widget);
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// VB Lab Migration Assistant for Flipper Zero
|
||||
// Copyright (C) 2022 cyanic
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "../vb_migrate_i.h"
|
||||
|
||||
static void vb_migrate_scene_select_file_select_callback(bool result, void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, result);
|
||||
}
|
||||
|
||||
void vb_migrate_scene_select_on_enter(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Perform your setup here
|
||||
file_select_set_callback(
|
||||
inst->file_select, vb_migrate_scene_select_file_select_callback, inst);
|
||||
file_select_set_filter(inst->file_select, VB_MIGRATE_FOLDER, "*");
|
||||
file_select_set_result_buffer(inst->file_select, inst->text_store, sizeof(inst->text_store));
|
||||
file_select_init(inst->file_select);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewFileSelect);
|
||||
}
|
||||
|
||||
bool vb_migrate_scene_select_on_event(void* context, SceneManagerEvent event) {
|
||||
VbMigrate* inst = context;
|
||||
bool consumed = false;
|
||||
UNUSED(inst);
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event) {
|
||||
// File selected
|
||||
scene_manager_next_scene(inst->scene_manager, VbMigrateSceneLoad);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void vb_migrate_scene_select_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
}
|
||||
+297
@@ -0,0 +1,297 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// VB Lab Migration Assistant for Flipper Zero
|
||||
// Copyright (C) 2022 cyanic
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <notification/notification_messages.h>
|
||||
|
||||
#include "../vb_migrate_i.h"
|
||||
#include "../vb_tag.h"
|
||||
|
||||
#define TAG "vb_migrate_scene_to_app"
|
||||
|
||||
typedef enum {
|
||||
ToAppStateInitial,
|
||||
ToAppStateInstructions,
|
||||
ToAppStateEmulateReady,
|
||||
ToAppStateEmulateTransferToApp,
|
||||
ToAppStateLoadError,
|
||||
ToAppStateComplete,
|
||||
} ToAppState;
|
||||
|
||||
typedef enum {
|
||||
ToAppEventTypeWidgetLeft,
|
||||
ToAppEventTypeWidgetRight,
|
||||
ToAppEventTypeEmulateStart,
|
||||
ToAppEventTypeCaptureLoadError,
|
||||
ToAppEventTypeTagWrite,
|
||||
} ToAppEventType;
|
||||
|
||||
static void
|
||||
vb_migrate_scene_to_app_widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
if(type == InputTypeShort) {
|
||||
if(result == GuiButtonTypeLeft)
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, ToAppEventTypeWidgetLeft);
|
||||
else if(result == GuiButtonTypeRight)
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, ToAppEventTypeWidgetRight);
|
||||
}
|
||||
}
|
||||
|
||||
static bool vb_migrate_scene_to_app_worker_callback(NfcWorkerEvent event, void* context) {
|
||||
VbMigrate* inst = context;
|
||||
bool result = false;
|
||||
|
||||
if(event == NfcWorkerEventSuccess) {
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, ToAppEventTypeTagWrite);
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void vb_migrate_scene_to_app_set_nfc_state(VbMigrate* inst, ToAppState state) {
|
||||
BantBlock* bant = vb_tag_get_bant_block(&inst->nfc_dev->dev_data);
|
||||
if(state == ToAppStateEmulateReady) {
|
||||
vb_tag_set_random_nonce(bant);
|
||||
vb_tag_set_status(bant, VbTagStatusReady);
|
||||
vb_tag_set_operation(bant, VbTagOperationReady);
|
||||
}
|
||||
|
||||
// Override tag type
|
||||
if(inst->override_type != inst->orig_type && inst->override_type != VbTagTypeUnknown) {
|
||||
vb_tag_set_item_id_no(bant, vb_tag_get_default_product(inst->override_type));
|
||||
}
|
||||
|
||||
if(inst->clear_account_id) {
|
||||
vb_tag_set_app_flag(bant, false);
|
||||
}
|
||||
}
|
||||
|
||||
static bool vb_migrate_scene_to_app_is_state_changed(VbMigrate* inst, ToAppState state) {
|
||||
BantBlock* bant = vb_tag_get_bant_block(&inst->nfc_dev->dev_data);
|
||||
VbTagOperation operation = vb_tag_get_operation(bant);
|
||||
|
||||
if(state == ToAppStateEmulateReady) {
|
||||
return operation == VbTagOperationTransferToApp;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void vb_migrate_scene_to_app_set_state(VbMigrate* inst, ToAppState state) {
|
||||
uint32_t curr_state = scene_manager_get_scene_state(inst->scene_manager, VbMigrateSceneToApp);
|
||||
if(state != curr_state) {
|
||||
Widget* widget = inst->widget;
|
||||
|
||||
if(state == ToAppStateInstructions) {
|
||||
widget_reset(widget);
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton | VbMigrateBgTypeRightButton);
|
||||
widget_add_text_scroll_element(
|
||||
widget,
|
||||
8,
|
||||
16,
|
||||
113,
|
||||
33,
|
||||
"\e#To transfer\n"
|
||||
"\e#characters from\n"
|
||||
"\e#Flipper:\n"
|
||||
"0. If on VB Arena, select\n"
|
||||
"the device type that\n"
|
||||
"matches your current\n"
|
||||
"settings and the correct\n"
|
||||
"franchise for the\n"
|
||||
"characters you're\n"
|
||||
"transferring\n"
|
||||
"1. If on VB Lab, put the\n"
|
||||
"current character into\n"
|
||||
"storage\n"
|
||||
"2. Sync character from\n"
|
||||
"Flipper as if it was a Vital\n"
|
||||
"Bracelet. Flipper will beep\n"
|
||||
"and automatically\n"
|
||||
"advance to the next\n"
|
||||
"captured character when\n"
|
||||
"VB Lab/Arena has\n"
|
||||
"transferred the current\n"
|
||||
"character\n"
|
||||
"\n"
|
||||
"-> You can press the right\n"
|
||||
"key to skip sending the\n"
|
||||
"current character\n"
|
||||
"3. Repeat the above until\n"
|
||||
"you have transferred all\n"
|
||||
"the characters you want\n"
|
||||
"\n"
|
||||
"You can cancel at any\n"
|
||||
"time to finish transferring.");
|
||||
widget_add_button_element(
|
||||
widget, GuiButtonTypeLeft, "Cancel", vb_migrate_scene_to_app_widget_callback, inst);
|
||||
widget_add_button_element(
|
||||
widget, GuiButtonTypeRight, "Next", vb_migrate_scene_to_app_widget_callback, inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
} else if(state == ToAppStateEmulateReady) {
|
||||
view_dispatcher_send_custom_event(inst->view_dispatcher, ToAppEventTypeEmulateStart);
|
||||
} else if(state == ToAppStateLoadError) {
|
||||
widget_reset(widget);
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton);
|
||||
widget_add_icon_element(widget, 11, 18, &I_WrongDevice_32x27);
|
||||
widget_add_icon_element(widget, 48, 18, &I_TextErrLoadCapture_65x13);
|
||||
widget_add_icon_element(widget, 104, 41, &I_PulsemonLeftWait_15x15);
|
||||
FuriString* temp_str = furi_string_alloc_printf("%03d", inst->next_id);
|
||||
widget_add_string_multiline_element(
|
||||
widget, 48, 32, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(temp_str));
|
||||
widget_add_button_element(
|
||||
widget, GuiButtonTypeLeft, "Cancel", vb_migrate_scene_to_app_widget_callback, inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
furi_string_free(temp_str);
|
||||
notification_message(inst->notifications, &sequence_error);
|
||||
notification_message(inst->notifications, &sequence_set_red_255);
|
||||
} else if(state == ToAppStateComplete) {
|
||||
widget_reset(widget);
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeRightButton);
|
||||
widget_add_icon_element(widget, 11, 18, &I_CommComplete_32x20);
|
||||
widget_add_icon_element(widget, 48, 18, &I_TextTransfersDone_51x13);
|
||||
widget_add_icon_element(widget, 9, 40, &I_PulsemonRightHappy_14x16);
|
||||
widget_add_button_element(
|
||||
widget, GuiButtonTypeRight, "OK", vb_migrate_scene_to_app_widget_callback, inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
} else {
|
||||
furi_crash("Unknown new state in vb_migrate_scene_to_app_set_state");
|
||||
}
|
||||
|
||||
scene_manager_set_scene_state(inst->scene_manager, VbMigrateSceneToApp, state);
|
||||
}
|
||||
}
|
||||
|
||||
static void vb_migrate_scene_to_app_load_capture(VbMigrate* inst, bool go_next) {
|
||||
if(go_next) {
|
||||
nfc_worker_stop(inst->worker);
|
||||
vb_migrate_blink_stop(inst);
|
||||
++inst->next_id;
|
||||
++inst->num_sent;
|
||||
}
|
||||
|
||||
if(inst->num_sent == inst->num_captured) {
|
||||
vb_migrate_scene_to_app_set_state(inst, ToAppStateComplete);
|
||||
} else {
|
||||
uint32_t state = scene_manager_get_scene_state(inst->scene_manager, VbMigrateSceneToApp);
|
||||
inst->next_id = vb_migrate_get_next_id(inst, inst->text_store, inst->next_id, true);
|
||||
FuriString* temp_str =
|
||||
furi_string_alloc_printf(VB_MIGRATE_CAPTURE_FORMAT, inst->next_id, NFC_APP_EXTENSION);
|
||||
|
||||
vb_migrate_show_loading_popup(inst, true);
|
||||
if(vb_migrate_load_nfc(inst, inst->text_store, furi_string_get_cstr(temp_str))) {
|
||||
Widget* widget = inst->widget;
|
||||
|
||||
widget_reset(widget);
|
||||
vb_migrate_add_bg(widget, VbMigrateBgTypeLeftButton | VbMigrateBgTypeRightButton);
|
||||
widget_add_icon_element(widget, 11, 18, &I_AppInteract_32x27);
|
||||
widget_add_icon_element(widget, 48, 18, &I_TextTapApp_56x27);
|
||||
furi_string_printf(temp_str, "%d/%d", inst->num_sent + 1, inst->num_captured);
|
||||
widget_add_string_element(
|
||||
widget,
|
||||
120,
|
||||
48,
|
||||
AlignRight,
|
||||
AlignBottom,
|
||||
FontSecondary,
|
||||
furi_string_get_cstr(temp_str));
|
||||
widget_add_button_element(
|
||||
widget, GuiButtonTypeLeft, "Cancel", vb_migrate_scene_to_app_widget_callback, inst);
|
||||
widget_add_button_element(
|
||||
widget, GuiButtonTypeRight, "Skip", vb_migrate_scene_to_app_widget_callback, inst);
|
||||
|
||||
view_dispatcher_switch_to_view(inst->view_dispatcher, VbMigrateViewWidget);
|
||||
|
||||
vb_migrate_scene_to_app_set_nfc_state(inst, state);
|
||||
nfc_worker_start(
|
||||
inst->worker,
|
||||
NfcWorkerStateMfUltralightEmulate,
|
||||
&inst->nfc_dev->dev_data,
|
||||
vb_migrate_scene_to_app_worker_callback,
|
||||
inst);
|
||||
vb_migrate_blink_emulate(inst);
|
||||
} else {
|
||||
view_dispatcher_send_custom_event(
|
||||
inst->view_dispatcher, ToAppEventTypeCaptureLoadError);
|
||||
}
|
||||
vb_migrate_show_loading_popup(inst, false);
|
||||
furi_string_free(temp_str);
|
||||
}
|
||||
}
|
||||
|
||||
void vb_migrate_scene_to_app_on_enter(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Perform your setup here
|
||||
inst->next_id = 0;
|
||||
inst->num_sent = 0;
|
||||
scene_manager_set_scene_state(inst->scene_manager, VbMigrateSceneToApp, ToAppStateInitial);
|
||||
vb_migrate_scene_to_app_set_state(inst, ToAppStateInstructions);
|
||||
}
|
||||
|
||||
bool vb_migrate_scene_to_app_on_event(void* context, SceneManagerEvent event) {
|
||||
VbMigrate* inst = context;
|
||||
uint32_t state = scene_manager_get_scene_state(inst->scene_manager, VbMigrateSceneToApp);
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == ToAppEventTypeWidgetLeft) {
|
||||
consumed = scene_manager_previous_scene(inst->scene_manager);
|
||||
} else if(event.event == ToAppEventTypeWidgetRight) {
|
||||
if(state == ToAppStateInstructions) {
|
||||
vb_migrate_scene_to_app_set_state(inst, ToAppStateEmulateReady);
|
||||
consumed = true;
|
||||
} else if(state == ToAppStateEmulateReady) {
|
||||
vb_migrate_scene_to_app_load_capture(inst, true);
|
||||
consumed = true;
|
||||
} else if(state == ToAppStateComplete) {
|
||||
consumed = scene_manager_previous_scene(inst->scene_manager);
|
||||
}
|
||||
} else if(event.event == ToAppEventTypeEmulateStart) {
|
||||
vb_migrate_scene_to_app_load_capture(inst, false);
|
||||
} else if(event.event == ToAppEventTypeTagWrite) {
|
||||
if(vb_migrate_scene_to_app_is_state_changed(inst, state)) {
|
||||
if(state == ToAppStateEmulateReady) {
|
||||
notification_message(inst->notifications, &sequence_success);
|
||||
vb_migrate_scene_to_app_load_capture(inst, true);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
} else if(event.event == ToAppEventTypeCaptureLoadError) {
|
||||
vb_migrate_scene_to_app_set_state(inst, ToAppStateLoadError);
|
||||
consumed = true;
|
||||
} else {
|
||||
furi_crash("Unknown event in vb_migrate_scene_to_app_on_event");
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void vb_migrate_scene_to_app_on_exit(void* context) {
|
||||
VbMigrate* inst = context;
|
||||
|
||||
// Perform your cleanup here
|
||||
widget_reset(inst->widget);
|
||||
nfc_worker_stop(inst->worker);
|
||||
vb_migrate_blink_stop(inst);
|
||||
notification_message_block(inst->notifications, &sequence_reset_red);
|
||||
}
|
||||
Reference in New Issue
Block a user