From a6b84847acc450b368131e1a2a64dcf8e4c5a01e Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 28 Mar 2024 17:33:57 -0400 Subject: [PATCH 1/3] Add Ability to Display MAC --- applications/system/findmy/findmy.c | 9 +++ applications/system/findmy/findmy_i.h | 1 + applications/system/findmy/findmy_state.c | 7 +- applications/system/findmy/findmy_state.h | 2 +- .../findmy/scenes/findmy_scene_config.c | 22 ++++++ .../findmy/scenes/findmy_scene_config_mac.c | 1 + .../system/findmy/views/findmy_main.c | 77 +++++++++++++++---- .../system/findmy/views/findmy_main.h | 2 + 8 files changed, 103 insertions(+), 18 deletions(-) diff --git a/applications/system/findmy/findmy.c b/applications/system/findmy/findmy.c index 7bb10f6b73..1cafcf8cbd 100644 --- a/applications/system/findmy/findmy.c +++ b/applications/system/findmy/findmy.c @@ -53,6 +53,8 @@ static FindMy* findmy_app_alloc() { findmy_main_update_active(app->findmy_main, furi_hal_bt_extra_beacon_is_active()); findmy_main_update_interval(app->findmy_main, app->state.broadcast_interval); + findmy_main_toggle_mac(app->findmy_main, app->state.show_mac); + findmy_main_update_mac(app->findmy_main, app->state.mac); findmy_main_update_type(app->findmy_main, app->state.tag_type); return app; @@ -129,6 +131,13 @@ void findmy_change_transmit_power(FindMy* app, uint8_t value) { } } +void findmy_toggle_show_mac(FindMy* app, bool show_mac) { + app->state.show_mac = show_mac; + findmy_state_sync_config(&app->state); + findmy_state_save(&app->state); + findmy_main_toggle_mac(app->findmy_main, app->state.show_mac); +} + void findmy_toggle_beacon(FindMy* app) { app->state.beacon_active = !app->state.beacon_active; findmy_state_save(&app->state); diff --git a/applications/system/findmy/findmy_i.h b/applications/system/findmy/findmy_i.h index 8f0920157f..af7458f8c8 100644 --- a/applications/system/findmy/findmy_i.h +++ b/applications/system/findmy/findmy_i.h @@ -51,5 +51,6 @@ typedef enum { void findmy_change_broadcast_interval(FindMy* app, uint8_t value); void findmy_change_transmit_power(FindMy* app, uint8_t value); +void findmy_toggle_show_mac(FindMy* app, bool show_mac); void findmy_set_tag_type(FindMy* app, FindMyType type); void findmy_toggle_beacon(FindMy* app); diff --git a/applications/system/findmy/findmy_state.c b/applications/system/findmy/findmy_state.c index 5528080b00..0d242373a6 100644 --- a/applications/system/findmy/findmy_state.c +++ b/applications/system/findmy/findmy_state.c @@ -29,6 +29,8 @@ bool findmy_state_load(FindMyState* out_state) { if(!flipper_format_read_uint32(file, "transmit_power", &tmp, 1)) break; state.transmit_power = tmp; + if(!flipper_format_read_bool(file, "show_mac", &state.show_mac, 1)) break; + if(!flipper_format_read_uint32(file, "tag_type", &tmp, 1)) { // Support migrating from old config tmp = FindMyTypeApple; @@ -53,7 +55,7 @@ bool findmy_state_load(FindMyState* out_state) { state.beacon_active = false; state.broadcast_interval = 5; state.transmit_power = 6; - + state.show_mac = false; state.tag_type = FindMyTypeApple; // Set default mac @@ -102,6 +104,7 @@ void findmy_state_apply(FindMyState* state) { furi_check( furi_hal_bt_extra_beacon_set_data(state->data, findmy_state_data_size(state->tag_type))); + if(state->beacon_active) { furi_check(furi_hal_bt_extra_beacon_start()); } @@ -135,6 +138,8 @@ void findmy_state_save(FindMyState* state) { tmp = state->tag_type; if(!flipper_format_write_uint32(file, "tag_type", &tmp, 1)) break; + if(!flipper_format_write_bool(file, "show_mac", &state->show_mac, 1)) break; + if(!flipper_format_write_hex(file, "mac", state->mac, sizeof(state->mac))) break; if(!flipper_format_write_hex( diff --git a/applications/system/findmy/findmy_state.h b/applications/system/findmy/findmy_state.h index 4b25ffabb8..813dfee414 100644 --- a/applications/system/findmy/findmy_state.h +++ b/applications/system/findmy/findmy_state.h @@ -17,7 +17,7 @@ typedef struct { bool beacon_active; uint8_t broadcast_interval; uint8_t transmit_power; - + bool show_mac; uint8_t mac[EXTRA_BEACON_MAC_ADDR_SIZE]; uint8_t data[EXTRA_BEACON_MAX_DATA_SIZE]; FindMyType tag_type; diff --git a/applications/system/findmy/scenes/findmy_scene_config.c b/applications/system/findmy/scenes/findmy_scene_config.c index 13c671c8da..4e9babea09 100644 --- a/applications/system/findmy/scenes/findmy_scene_config.c +++ b/applications/system/findmy/scenes/findmy_scene_config.c @@ -4,9 +4,11 @@ enum VarItemListIndex { VarItemListIndexBroadcastInterval, VarItemListIndexTransmitPower, VarItemListIndexRegisterTag, + VarItemListIndexShowMac, VarItemListIndexAbout, }; + void findmy_scene_config_broadcast_interval_changed(VariableItem* item) { FindMy* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); @@ -27,6 +29,18 @@ void findmy_scene_config_transmit_power_changed(VariableItem* item) { variable_item_set_current_value_index(item, app->state.transmit_power); } +void findmy_scene_config_show_mac(VariableItem* item) { + FindMy* app = variable_item_get_context(item); + uint8_t index = variable_item_get_current_value_index(item); + findmy_toggle_show_mac(app, index); + if (app->state.show_mac == true) { + variable_item_set_current_value_text(item, "Yes"); + } else { + variable_item_set_current_value_text(item, "No"); + } + variable_item_set_current_value_index(item, app->state.show_mac); +} + void findmy_scene_config_callback(void* context, uint32_t index) { furi_assert(context); FindMy* app = context; @@ -59,6 +73,14 @@ void findmy_scene_config_on_enter(void* context) { item = variable_item_list_add(var_item_list, "Register Tag", 0, NULL, NULL); + item = variable_item_list_add(var_item_list, "Show MAC", 2, findmy_scene_config_show_mac, app); + variable_item_set_current_value_index(item, app->state.show_mac); + if(app->state.show_mac == true) + variable_item_set_current_value_text(item, "Yes"); + else + variable_item_set_current_value_text(item, "No"); + + item = variable_item_list_add( var_item_list, "Matthew KuKanich, Thanks to Chapoly1305, WillyJL, OpenHaystack, Testers", diff --git a/applications/system/findmy/scenes/findmy_scene_config_mac.c b/applications/system/findmy/scenes/findmy_scene_config_mac.c index 1b72d19278..741c8e4639 100644 --- a/applications/system/findmy/scenes/findmy_scene_config_mac.c +++ b/applications/system/findmy/scenes/findmy_scene_config_mac.c @@ -49,6 +49,7 @@ bool findmy_scene_config_mac_on_event(void* context, SceneManagerEvent event) { if(app->state.beacon_active) { furi_check(furi_hal_bt_extra_beacon_start()); } + findmy_main_update_mac(app->findmy_main, app->state.mac); scene_manager_next_scene(app->scene_manager, FindMySceneConfigPacket); break; default: diff --git a/applications/system/findmy/views/findmy_main.c b/applications/system/findmy/views/findmy_main.c index 829088be76..b98e2ca263 100644 --- a/applications/system/findmy/views/findmy_main.c +++ b/applications/system/findmy/views/findmy_main.c @@ -9,7 +9,9 @@ struct FindMyMain { typedef struct { bool active; + bool show_mac; uint8_t interval; + uint8_t mac[6]; FindMyType type; } FindMyMainModel; @@ -20,20 +22,7 @@ static void findmy_main_draw_callback(Canvas* canvas, void* _model) { canvas_set_font(canvas, FontPrimary); canvas_draw_str(canvas, 4, 11, "FindMy Flipper"); - canvas_set_font(canvas, FontSecondary); - if(model->active) { - canvas_draw_str(canvas, 4, 49, "Broadcast Active"); - canvas_draw_icon(canvas, 78, 42, &I_Ok_btn_9x9); - } else { - canvas_draw_str(canvas, 4, 49, "Broadcast Inactive"); - } - canvas_set_font(canvas, FontSecondary); - canvas_draw_str(canvas, 4, 21, "Press <- to run in background"); - canvas_set_font(canvas, FontSecondary); - char interval_str[20]; - snprintf(interval_str, sizeof(interval_str), "Ping Interval: %ds", model->interval); - canvas_draw_str(canvas, 4, 62, interval_str); - canvas_set_font(canvas, FontPrimary); + const char* network_text = ""; switch(model->type) { case FindMyTypeApple: @@ -48,8 +37,43 @@ static void findmy_main_draw_callback(Canvas* canvas, void* _model) { default: break; } - canvas_draw_str(canvas, 4, 32, network_text); - canvas_draw_icon(canvas, 6 + canvas_string_width(canvas, network_text), 24, &I_Lock_7x8); + + + if(model->show_mac == false) { + canvas_set_font(canvas, FontPrimary); + canvas_draw_str(canvas, 4, 31, network_text); + canvas_draw_icon(canvas, 6 + canvas_string_width(canvas, network_text), 24, &I_Lock_7x8); + } else if(model->show_mac == true) { + canvas_set_font(canvas, FontSecondary); + char mac_str[23]; + snprintf( + mac_str, + sizeof(mac_str), + "MAC: %02X:%02X:%02X:%02X:%02X:%02X", + model->mac[0], + model->mac[1], + model->mac[2], + model->mac[3], + model->mac[4], + model->mac[5]); + canvas_draw_str(canvas, 4, 40, mac_str); + canvas_draw_str(canvas, 4, 30, network_text); + canvas_draw_icon(canvas, 6 + canvas_string_width(canvas, network_text), 23, &I_Lock_7x8); + } + canvas_set_font(canvas, FontSecondary); + if(model->active) { + canvas_draw_str(canvas, 4, 49, "Broadcast Active"); + canvas_draw_icon(canvas, 78, 41, &I_Ok_btn_9x9); + } else { + canvas_draw_str(canvas, 4, 49, "Broadcast Inactive"); + } + canvas_set_font(canvas, FontSecondary); + canvas_draw_str(canvas, 4, 21, "Press <- to run in background"); + canvas_set_font(canvas, FontSecondary); + char interval_str[20]; + snprintf(interval_str, sizeof(interval_str), "Ping Interval: %ds", model->interval); + canvas_draw_str(canvas, 4, 62, interval_str); + canvas_set_font(canvas, FontSecondary); canvas_draw_str(canvas, 100, 61, "Config"); canvas_draw_line(canvas, 100, 51, 127, 51); @@ -107,6 +131,11 @@ FindMyMain* findmy_main_alloc(FindMy* app) { { model->active = app->state.beacon_active; model->interval = app->state.broadcast_interval; + model->show_mac = app->state.show_mac; + memcpy( + model->mac, + app->state.mac, + sizeof(model->mac)); model->type = app->state.tag_type; }, false); @@ -141,6 +170,22 @@ void findmy_main_update_active(FindMyMain* findmy_main, bool active) { findmy_main->view, FindMyMainModel * model, { model->active = active; }, true); } +void findmy_main_toggle_mac(FindMyMain* findmy_main, bool show_mac) { + furi_assert(findmy_main); + with_view_model( + findmy_main->view, FindMyMainModel * model, { model->show_mac = show_mac; }, true); +} + +void findmy_main_update_mac(FindMyMain* findmy_main, uint8_t* mac) { + with_view_model( + findmy_main->view, + FindMyMainModel * model, + { + memcpy(model->mac, mac, sizeof(model->mac)); + furi_hal_bt_reverse_mac_addr(model->mac); + }, + false); +} void findmy_main_update_interval(FindMyMain* findmy_main, uint8_t interval) { furi_assert(findmy_main); with_view_model( diff --git a/applications/system/findmy/views/findmy_main.h b/applications/system/findmy/views/findmy_main.h index d73040ee24..a8d575cd49 100644 --- a/applications/system/findmy/views/findmy_main.h +++ b/applications/system/findmy/views/findmy_main.h @@ -27,4 +27,6 @@ void findmy_main_set_callback(FindMyMain* findmy_main, FindMyMainCallback callba // To redraw when info changes void findmy_main_update_active(FindMyMain* findmy_main, bool active); void findmy_main_update_interval(FindMyMain* findmy_main, uint8_t interval); +void findmy_main_toggle_mac(FindMyMain* findmy_main, bool show_mac); +void findmy_main_update_mac(FindMyMain* findmy_main, uint8_t* mac); void findmy_main_update_type(FindMyMain* findmy_main, FindMyType type); \ No newline at end of file From 9f20389fc6b2914551a484a2d5ef16dada098757 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 28 Mar 2024 17:45:14 -0400 Subject: [PATCH 2/3] Fix FileCompat, Small fixes --- applications/system/findmy/findmy_state.c | 7 +++++-- applications/system/findmy/scenes/findmy_scene_config.c | 9 ++------- applications/system/findmy/views/findmy_main.c | 8 ++------ 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/applications/system/findmy/findmy_state.c b/applications/system/findmy/findmy_state.c index 0d242373a6..ae81eab839 100644 --- a/applications/system/findmy/findmy_state.c +++ b/applications/system/findmy/findmy_state.c @@ -29,7 +29,11 @@ bool findmy_state_load(FindMyState* out_state) { if(!flipper_format_read_uint32(file, "transmit_power", &tmp, 1)) break; state.transmit_power = tmp; - if(!flipper_format_read_bool(file, "show_mac", &state.show_mac, 1)) break; + if(!flipper_format_read_bool(file, "show_mac", &state.show_mac, 1)) { + // Support migrating from old config + state.show_mac = false; + flipper_format_rewind(file); + } if(!flipper_format_read_uint32(file, "tag_type", &tmp, 1)) { // Support migrating from old config @@ -104,7 +108,6 @@ void findmy_state_apply(FindMyState* state) { furi_check( furi_hal_bt_extra_beacon_set_data(state->data, findmy_state_data_size(state->tag_type))); - if(state->beacon_active) { furi_check(furi_hal_bt_extra_beacon_start()); } diff --git a/applications/system/findmy/scenes/findmy_scene_config.c b/applications/system/findmy/scenes/findmy_scene_config.c index 4e9babea09..3a79e3e104 100644 --- a/applications/system/findmy/scenes/findmy_scene_config.c +++ b/applications/system/findmy/scenes/findmy_scene_config.c @@ -8,7 +8,6 @@ enum VarItemListIndex { VarItemListIndexAbout, }; - void findmy_scene_config_broadcast_interval_changed(VariableItem* item) { FindMy* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); @@ -33,7 +32,7 @@ void findmy_scene_config_show_mac(VariableItem* item) { FindMy* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); findmy_toggle_show_mac(app, index); - if (app->state.show_mac == true) { + if(app->state.show_mac == true) { variable_item_set_current_value_text(item, "Yes"); } else { variable_item_set_current_value_text(item, "No"); @@ -75,11 +74,7 @@ void findmy_scene_config_on_enter(void* context) { item = variable_item_list_add(var_item_list, "Show MAC", 2, findmy_scene_config_show_mac, app); variable_item_set_current_value_index(item, app->state.show_mac); - if(app->state.show_mac == true) - variable_item_set_current_value_text(item, "Yes"); - else - variable_item_set_current_value_text(item, "No"); - + variable_item_set_current_value_text(item, app->state.show_mac ? "Yes" : "No"); item = variable_item_list_add( var_item_list, diff --git a/applications/system/findmy/views/findmy_main.c b/applications/system/findmy/views/findmy_main.c index b98e2ca263..a18bb7c775 100644 --- a/applications/system/findmy/views/findmy_main.c +++ b/applications/system/findmy/views/findmy_main.c @@ -38,7 +38,6 @@ static void findmy_main_draw_callback(Canvas* canvas, void* _model) { break; } - if(model->show_mac == false) { canvas_set_font(canvas, FontPrimary); canvas_draw_str(canvas, 4, 31, network_text); @@ -132,10 +131,7 @@ FindMyMain* findmy_main_alloc(FindMy* app) { model->active = app->state.beacon_active; model->interval = app->state.broadcast_interval; model->show_mac = app->state.show_mac; - memcpy( - model->mac, - app->state.mac, - sizeof(model->mac)); + memcpy(model->mac, app->state.mac, sizeof(model->mac)); model->type = app->state.tag_type; }, false); @@ -184,7 +180,7 @@ void findmy_main_update_mac(FindMyMain* findmy_main, uint8_t* mac) { memcpy(model->mac, mac, sizeof(model->mac)); furi_hal_bt_reverse_mac_addr(model->mac); }, - false); + true); } void findmy_main_update_interval(FindMyMain* findmy_main, uint8_t interval) { furi_assert(findmy_main); From 0c3c6271cfcc2d62b78e15754cb4e8f316e4a1e5 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Thu, 28 Mar 2024 21:54:34 +0000 Subject: [PATCH 3/3] This one too :) --- applications/system/findmy/scenes/findmy_scene_config.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/applications/system/findmy/scenes/findmy_scene_config.c b/applications/system/findmy/scenes/findmy_scene_config.c index 3a79e3e104..0ab63be428 100644 --- a/applications/system/findmy/scenes/findmy_scene_config.c +++ b/applications/system/findmy/scenes/findmy_scene_config.c @@ -32,11 +32,7 @@ void findmy_scene_config_show_mac(VariableItem* item) { FindMy* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); findmy_toggle_show_mac(app, index); - if(app->state.show_mac == true) { - variable_item_set_current_value_text(item, "Yes"); - } else { - variable_item_set_current_value_text(item, "No"); - } + variable_item_set_current_value_text(item, app->state.show_mac ? "Yes" : "No"); variable_item_set_current_value_index(item, app->state.show_mac); }