|
|
@@ -1,80 +1,12 @@
|
|
|
#include "key_copier.h"
|
|
|
-#include "key_copier_icons.h"
|
|
|
-#include "key_formats.h"
|
|
|
-#include <applications/services/dialogs/dialogs.h>
|
|
|
-#include <applications/services/storage/storage.h>
|
|
|
-#include <flipper_format.h>
|
|
|
-#include <furi.h>
|
|
|
-#include <furi_hal.h>
|
|
|
-#include <gui/gui.h>
|
|
|
-#include <gui/modules/submenu.h>
|
|
|
-#include <gui/modules/text_input.h>
|
|
|
-#include <gui/modules/variable_item_list.h>
|
|
|
-#include <gui/modules/widget.h>
|
|
|
-#include <gui/view.h>
|
|
|
-#include <gui/view_dispatcher.h>
|
|
|
-#include <math.h>
|
|
|
-#include <notification/notification.h>
|
|
|
-#include <notification/notification_messages.h>
|
|
|
-#include <stdbool.h>
|
|
|
-
|
|
|
-#define TAG "KeyCopier"
|
|
|
-
|
|
|
-#define BACKLIGHT_ON 1
|
|
|
-
|
|
|
-typedef enum {
|
|
|
- KeyCopierSubmenuIndexMeasure,
|
|
|
- KeyCopierSubmenuIndexConfigure,
|
|
|
- KeyCopierSubmenuIndexSave,
|
|
|
- KeyCopierSubmenuIndexLoad,
|
|
|
- KeyCopierSubmenuIndexAbout,
|
|
|
-} KeyCopierSubmenuIndex;
|
|
|
-
|
|
|
-typedef enum {
|
|
|
- KeyCopierViewSubmenu,
|
|
|
- KeyCopierViewTextInput,
|
|
|
- KeyCopierViewConfigure_i,
|
|
|
- KeyCopierViewConfigure_e,
|
|
|
- KeyCopierViewSave,
|
|
|
- KeyCopierViewLoad,
|
|
|
- KeyCopierViewMeasure,
|
|
|
- KeyCopierViewAbout,
|
|
|
- KeyCopierViewManufacturerList,
|
|
|
- KeyCopierViewFormatList,
|
|
|
-} KeyCopierView;
|
|
|
-
|
|
|
-typedef struct {
|
|
|
- ViewDispatcher* view_dispatcher;
|
|
|
- NotificationApp* notifications;
|
|
|
- Submenu* submenu;
|
|
|
- TextInput* text_input;
|
|
|
- VariableItemList* variable_item_list_config;
|
|
|
- View* view_measure;
|
|
|
- View* view_config_e;
|
|
|
- View* view_save;
|
|
|
- View* view_load;
|
|
|
- Widget* widget_about;
|
|
|
- VariableItem* key_name_item;
|
|
|
- VariableItem* format_item;
|
|
|
- VariableItem* format_name_item;
|
|
|
- char* temp_buffer;
|
|
|
- uint32_t temp_buffer_size;
|
|
|
-
|
|
|
- DialogsApp* dialogs;
|
|
|
- FuriString* file_path;
|
|
|
- Submenu* manufacturer_list;
|
|
|
- Submenu* format_list;
|
|
|
- char* selected_manufacturer;
|
|
|
-} KeyCopierApp;
|
|
|
-
|
|
|
-typedef struct {
|
|
|
- uint32_t format_index;
|
|
|
- FuriString* key_name_str;
|
|
|
- uint8_t pin_slc; // The pin that is being adjusted
|
|
|
- uint8_t* depth; // The cutting depth
|
|
|
- bool data_loaded;
|
|
|
- KeyFormat format;
|
|
|
-} KeyCopierModel;
|
|
|
+
|
|
|
+void exit_widget_callback(GuiButtonType result, InputType type, void* context) {
|
|
|
+ KeyCopierApp* app = context;
|
|
|
+ UNUSED(result);
|
|
|
+ if(type == InputTypeShort) {
|
|
|
+ view_dispatcher_switch_to_view(app->view_dispatcher, KeyCopierViewSubmenu);
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
void initialize_model(KeyCopierModel* model) {
|
|
|
if(model->depth != NULL) {
|
|
|
@@ -119,6 +51,9 @@ static void key_copier_submenu_callback(void* context, uint32_t index) {
|
|
|
case KeyCopierSubmenuIndexAbout:
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, KeyCopierViewAbout);
|
|
|
break;
|
|
|
+ case KeyCopierSubmenuIndexQRCode:
|
|
|
+ view_dispatcher_switch_to_view(app->view_dispatcher, KeyCopierViewQRCode);
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
@@ -135,17 +70,16 @@ void initialize_manufacturers(char** manufacturers) {
|
|
|
static void manufacturer_selected_callback(void* context, uint32_t index);
|
|
|
static void format_selected_callback(void* context, uint32_t index);
|
|
|
|
|
|
-
|
|
|
static void key_copier_config_enter_callback(void* context) {
|
|
|
KeyCopierApp* app = (KeyCopierApp*)context;
|
|
|
-
|
|
|
+
|
|
|
// Clear manufacturer list
|
|
|
submenu_reset(app->manufacturer_list);
|
|
|
-
|
|
|
+
|
|
|
// Track added manufacturers to avoid duplicates
|
|
|
char* added_manufacturers[COUNT_OF(all_formats)];
|
|
|
size_t added_count = 0;
|
|
|
-
|
|
|
+
|
|
|
// Add unique manufacturers
|
|
|
for(size_t i = 0; i < COUNT_OF(all_formats); i++) {
|
|
|
bool already_added = false;
|
|
|
@@ -155,7 +89,7 @@ static void key_copier_config_enter_callback(void* context) {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if(!already_added) {
|
|
|
submenu_add_item(
|
|
|
app->manufacturer_list,
|
|
|
@@ -326,7 +260,7 @@ static void key_copier_view_measure_draw_callback(Canvas* canvas, void* model) {
|
|
|
int bottom_post_extra_x_px = 0; // new
|
|
|
int bottom_pre_extra_x_px = 0; // new
|
|
|
int level_contour_px =
|
|
|
- (int)round((my_format.last_pin_inch + my_format.elbow_inch) / inches_per_px);
|
|
|
+ (int)round((my_format.last_pin_inch + my_format.elbow_inch) / inches_per_px);
|
|
|
for(int current_pin = 1; current_pin <= my_model->format.pin_num; current_pin += 1) {
|
|
|
double current_center_px =
|
|
|
my_format.first_pin_inch + (current_pin - 1) * my_format.pin_increment_inch;
|
|
|
@@ -658,29 +592,25 @@ static bool key_copier_view_measure_input_callback(InputEvent* event, void* cont
|
|
|
static void manufacturer_selected_callback(void* context, uint32_t index) {
|
|
|
KeyCopierApp* app = context;
|
|
|
app->selected_manufacturer = all_formats[index].manufacturer;
|
|
|
-
|
|
|
+
|
|
|
// Clear and populate format list for selected manufacturer
|
|
|
submenu_reset(app->format_list);
|
|
|
-
|
|
|
+
|
|
|
// Add all formats for this manufacturer
|
|
|
for(size_t i = 0; i < COUNT_OF(all_formats); i++) {
|
|
|
if(strcmp(all_formats[i].manufacturer, app->selected_manufacturer) == 0) {
|
|
|
submenu_add_item(
|
|
|
- app->format_list,
|
|
|
- all_formats[i].format_name,
|
|
|
- i,
|
|
|
- format_selected_callback,
|
|
|
- app);
|
|
|
+ app->format_list, all_formats[i].format_name, i, format_selected_callback, app);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, KeyCopierViewFormatList);
|
|
|
}
|
|
|
|
|
|
static void format_selected_callback(void* context, uint32_t index) {
|
|
|
KeyCopierApp* app = context;
|
|
|
KeyCopierModel* model = view_get_model(app->view_measure);
|
|
|
-
|
|
|
+
|
|
|
model->format_index = index;
|
|
|
model->format = all_formats[index];
|
|
|
if(model->depth != NULL) {
|
|
|
@@ -722,6 +652,13 @@ static KeyCopierApp* key_copier_app_alloc() {
|
|
|
app->submenu, "Load", KeyCopierSubmenuIndexLoad, key_copier_submenu_callback, app);
|
|
|
submenu_add_item(
|
|
|
app->submenu, "Help", KeyCopierSubmenuIndexAbout, key_copier_submenu_callback, app);
|
|
|
+ submenu_add_item(
|
|
|
+ app->submenu,
|
|
|
+ "Video Instruction",
|
|
|
+ KeyCopierSubmenuIndexQRCode,
|
|
|
+ key_copier_submenu_callback,
|
|
|
+ app);
|
|
|
+
|
|
|
view_set_previous_callback(
|
|
|
submenu_get_view(app->submenu), key_copier_navigation_exit_callback);
|
|
|
view_dispatcher_add_view(
|
|
|
@@ -784,10 +721,28 @@ static KeyCopierApp* key_copier_app_alloc() {
|
|
|
view_dispatcher_add_view(
|
|
|
app->view_dispatcher, KeyCopierViewAbout, widget_get_view(app->widget_about));
|
|
|
|
|
|
+ app->widget_qr_code = widget_alloc();
|
|
|
+ widget_add_icon_element(app->widget_qr_code, 92, 7, &I_QR_Code);
|
|
|
+ widget_add_string_element(
|
|
|
+ app->widget_qr_code, 0, 10, AlignLeft, AlignBottom, FontSecondary, "Check out");
|
|
|
+ widget_add_string_element(
|
|
|
+ app->widget_qr_code, 0, 23, AlignLeft, AlignBottom, FontSecondary, "@TalkingSasquach's");
|
|
|
+ widget_add_string_element(
|
|
|
+ app->widget_qr_code, 0, 36, AlignLeft, AlignBottom, FontSecondary, "video from decoding");
|
|
|
+ widget_add_string_element(
|
|
|
+ app->widget_qr_code, 0, 49, AlignLeft, AlignBottom, FontSecondary, "a key to eventually");
|
|
|
+ widget_add_string_element(
|
|
|
+ app->widget_qr_code, 0, 62, AlignLeft, AlignBottom, FontSecondary, "3D-printing a copy!");
|
|
|
+ widget_add_button_element(
|
|
|
+ app->widget_qr_code, GuiButtonTypeRight, "Back", exit_widget_callback, app);
|
|
|
+ view_set_previous_callback(
|
|
|
+ widget_get_view(app->widget_qr_code), key_copier_navigation_submenu_callback);
|
|
|
+ view_dispatcher_add_view(
|
|
|
+ app->view_dispatcher, KeyCopierViewQRCode, widget_get_view(app->widget_qr_code));
|
|
|
+
|
|
|
app->manufacturer_list = submenu_alloc();
|
|
|
view_set_previous_callback(
|
|
|
- submenu_get_view(app->manufacturer_list),
|
|
|
- key_copier_navigation_submenu_callback);
|
|
|
+ submenu_get_view(app->manufacturer_list), key_copier_navigation_submenu_callback);
|
|
|
view_dispatcher_add_view(
|
|
|
app->view_dispatcher,
|
|
|
KeyCopierViewManufacturerList,
|
|
|
@@ -795,17 +750,14 @@ static KeyCopierApp* key_copier_app_alloc() {
|
|
|
|
|
|
app->format_list = submenu_alloc();
|
|
|
view_set_previous_callback(
|
|
|
- submenu_get_view(app->format_list),
|
|
|
- key_copier_navigation_submenu_callback);
|
|
|
+ submenu_get_view(app->format_list), key_copier_navigation_submenu_callback);
|
|
|
view_dispatcher_add_view(
|
|
|
- app->view_dispatcher,
|
|
|
- KeyCopierViewFormatList,
|
|
|
- submenu_get_view(app->format_list));
|
|
|
+ app->view_dispatcher, KeyCopierViewFormatList, submenu_get_view(app->format_list));
|
|
|
|
|
|
app->notifications = furi_record_open(RECORD_NOTIFICATION);
|
|
|
|
|
|
#ifdef BACKLIGHT_ON
|
|
|
- notification_message(app->notifications, &sequence_display_backlight_enforce_on);
|
|
|
+ notification_message(app->notifications, &sequence_display_backlight_on);
|
|
|
#endif
|
|
|
|
|
|
return app;
|
|
|
@@ -822,6 +774,8 @@ static void key_copier_app_free(KeyCopierApp* app) {
|
|
|
free(app->temp_buffer);
|
|
|
view_dispatcher_remove_view(app->view_dispatcher, KeyCopierViewAbout);
|
|
|
widget_free(app->widget_about);
|
|
|
+ view_dispatcher_remove_view(app->view_dispatcher, KeyCopierViewQRCode);
|
|
|
+ widget_free(app->widget_qr_code);
|
|
|
view_dispatcher_remove_view(app->view_dispatcher, KeyCopierViewMeasure);
|
|
|
with_view_model(
|
|
|
app->view_measure,
|