Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FindMy Add Ability to Show MAC #58

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions applications/system/findmy/findmy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions applications/system/findmy/findmy_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
10 changes: 9 additions & 1 deletion applications/system/findmy/findmy_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ 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)) {
// 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
tmp = FindMyTypeApple;
Expand All @@ -53,7 +59,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
Expand Down Expand Up @@ -135,6 +141,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(
Expand Down
2 changes: 1 addition & 1 deletion applications/system/findmy/findmy_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions applications/system/findmy/scenes/findmy_scene_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ enum VarItemListIndex {
VarItemListIndexBroadcastInterval,
VarItemListIndexTransmitPower,
VarItemListIndexRegisterTag,
VarItemListIndexShowMac,
VarItemListIndexAbout,
};

Expand All @@ -27,6 +28,14 @@ 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);
variable_item_set_current_value_text(item, app->state.show_mac ? "Yes" : "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;
Expand Down Expand Up @@ -59,6 +68,10 @@ 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);
variable_item_set_current_value_text(item, app->state.show_mac ? "Yes" : "No");

item = variable_item_list_add(
var_item_list,
"Matthew KuKanich, Thanks to Chapoly1305, WillyJL, OpenHaystack, Testers",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
73 changes: 57 additions & 16 deletions applications/system/findmy/views/findmy_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ struct FindMyMain {

typedef struct {
bool active;
bool show_mac;
uint8_t interval;
uint8_t mac[6];
FindMyType type;
} FindMyMainModel;

Expand All @@ -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:
Expand All @@ -48,8 +37,42 @@ 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);
Expand Down Expand Up @@ -107,6 +130,8 @@ 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);
Expand Down Expand Up @@ -141,6 +166,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);
},
true);
}
void findmy_main_update_interval(FindMyMain* findmy_main, uint8_t interval) {
furi_assert(findmy_main);
with_view_model(
Expand Down
2 changes: 2 additions & 0 deletions applications/system/findmy/views/findmy_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Loading