mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-26 05:54:46 -07:00
Add FindMy Flipper to system apps
This commit is contained in:
31
applications/system/findmy/scenes/findmy_scene.c
Normal file
31
applications/system/findmy/scenes/findmy_scene.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "findmy_scene.h"
|
||||
#include "findmy.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const findmy_on_enter_handlers[])(void*) = {
|
||||
#include "findmy_scenes.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||
bool (*const findmy_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "findmy_scenes.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||
void (*const findmy_on_exit_handlers[])(void* context) = {
|
||||
#include "findmy_scenes.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers findmy_scene_handlers = {
|
||||
.on_enter_handlers = findmy_on_enter_handlers,
|
||||
.on_event_handlers = findmy_on_event_handlers,
|
||||
.on_exit_handlers = findmy_on_exit_handlers,
|
||||
.scene_num = FindMySceneNum,
|
||||
};
|
||||
30
applications/system/findmy/scenes/findmy_scene.h
Normal file
30
applications/system/findmy/scenes/findmy_scene.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
#include "findmy.h"
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) FindMyScene##id,
|
||||
typedef enum {
|
||||
#include "findmy_scenes.h"
|
||||
FindMySceneNum,
|
||||
} FindMyScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers findmy_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "findmy_scenes.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 "findmy_scenes.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 "findmy_scenes.h"
|
||||
#undef ADD_SCENE
|
||||
98
applications/system/findmy/scenes/findmy_scene_config.c
Normal file
98
applications/system/findmy/scenes/findmy_scene_config.c
Normal file
@@ -0,0 +1,98 @@
|
||||
#include "../findmy_i.h"
|
||||
|
||||
enum VarItemListIndex {
|
||||
VarItemListIndexBroadcastInterval,
|
||||
VarItemListIndexTransmitPower,
|
||||
VarItemListIndexRegisterTag,
|
||||
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);
|
||||
findmy_change_broadcast_interval(app, index + 1);
|
||||
char str[5];
|
||||
snprintf(str, sizeof(str), "%ds", app->broadcast_interval);
|
||||
variable_item_set_current_value_text(item, str);
|
||||
variable_item_set_current_value_index(item, app->broadcast_interval - 1);
|
||||
}
|
||||
|
||||
void findmy_scene_config_transmit_power_changed(VariableItem* item) {
|
||||
FindMy* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
findmy_change_transmit_power(app, index);
|
||||
char str[7];
|
||||
snprintf(str, sizeof(str), "%ddBm", app->transmit_power);
|
||||
variable_item_set_current_value_text(item, str);
|
||||
variable_item_set_current_value_index(item, app->transmit_power);
|
||||
}
|
||||
|
||||
void findmy_scene_config_callback(void* context, uint32_t index) {
|
||||
furi_assert(context);
|
||||
FindMy* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void findmy_scene_config_on_enter(void* context) {
|
||||
FindMy* app = context;
|
||||
VariableItemList* var_item_list = app->var_item_list;
|
||||
VariableItem* item;
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list,
|
||||
"Broadcast Interval",
|
||||
10,
|
||||
findmy_scene_config_broadcast_interval_changed,
|
||||
app);
|
||||
// Broadcast Interval is 1-10, so use 0-9 and offset indexes by 1
|
||||
variable_item_set_current_value_index(item, app->broadcast_interval - 1);
|
||||
char broadcast_interval_s[5];
|
||||
snprintf(broadcast_interval_s, sizeof(broadcast_interval_s), "%ds", app->broadcast_interval);
|
||||
variable_item_set_current_value_text(item, broadcast_interval_s);
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list, "Transmit Power", 7, findmy_scene_config_transmit_power_changed, app);
|
||||
variable_item_set_current_value_index(item, app->transmit_power);
|
||||
char transmit_power_s[7];
|
||||
snprintf(transmit_power_s, sizeof(transmit_power_s), "%ddBm", app->transmit_power);
|
||||
variable_item_set_current_value_text(item, transmit_power_s);
|
||||
|
||||
item = variable_item_list_add(var_item_list, "Register Tag", 0, NULL, NULL);
|
||||
item = variable_item_list_add(var_item_list, "Matthew KuKanich, Thanks to Chapoly1305, WillyJL, OpenHaystack, Testers", 1, NULL, NULL);
|
||||
variable_item_set_current_value_text(item, "Credits");
|
||||
|
||||
variable_item_list_set_enter_callback(var_item_list, findmy_scene_config_callback, app);
|
||||
|
||||
variable_item_list_set_selected_item(
|
||||
var_item_list, scene_manager_get_scene_state(app->scene_manager, FindMySceneConfig));
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, FindMyViewVarItemList);
|
||||
}
|
||||
|
||||
bool findmy_scene_config_on_event(void* context, SceneManagerEvent event) {
|
||||
FindMy* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
scene_manager_set_scene_state(app->scene_manager, FindMySceneConfig, event.event);
|
||||
consumed = true;
|
||||
switch(event.event) {
|
||||
case VarItemListIndexRegisterTag:
|
||||
scene_manager_next_scene(app->scene_manager, FindMySceneConfigMac);
|
||||
break;
|
||||
case VarItemListIndexAbout:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void findmy_scene_config_on_exit(void* context) {
|
||||
FindMy* app = context;
|
||||
VariableItemList* var_item_list = app->var_item_list;
|
||||
|
||||
variable_item_list_reset(var_item_list);
|
||||
}
|
||||
60
applications/system/findmy/scenes/findmy_scene_config_mac.c
Normal file
60
applications/system/findmy/scenes/findmy_scene_config_mac.c
Normal file
@@ -0,0 +1,60 @@
|
||||
#include "../findmy_i.h"
|
||||
|
||||
enum ByteInputResult {
|
||||
ByteInputResultOk,
|
||||
};
|
||||
|
||||
static void findmy_scene_config_mac_callback(void* context) {
|
||||
FindMy* app = context;
|
||||
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, ByteInputResultOk);
|
||||
}
|
||||
|
||||
void findmy_scene_config_mac_on_enter(void* context) {
|
||||
FindMy* app = context;
|
||||
ByteInput* byte_input = app->byte_input;
|
||||
|
||||
byte_input_set_header_text(byte_input, "Enter Bluetooth MAC:");
|
||||
|
||||
memcpy(app->mac_buf, &app->config.address, sizeof(app->mac_buf));
|
||||
furi_hal_bt_reverse_mac_addr(app->mac_buf);
|
||||
|
||||
byte_input_set_result_callback(
|
||||
byte_input,
|
||||
findmy_scene_config_mac_callback,
|
||||
NULL,
|
||||
app,
|
||||
app->mac_buf,
|
||||
sizeof(app->mac_buf));
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, FindMyViewByteInput);
|
||||
}
|
||||
|
||||
bool findmy_scene_config_mac_on_event(void* context, SceneManagerEvent event) {
|
||||
FindMy* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
switch(event.event) {
|
||||
case ByteInputResultOk:
|
||||
furi_hal_bt_reverse_mac_addr(app->mac_buf);
|
||||
memcpy(&app->config.address, app->mac_buf, sizeof(app->config.address));
|
||||
furi_hal_bt_extra_beacon_set_config(&app->config);
|
||||
scene_manager_next_scene(app->scene_manager, FindMySceneConfigPacket);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void findmy_scene_config_mac_on_exit(void* context) {
|
||||
FindMy* app = context;
|
||||
|
||||
byte_input_set_result_callback(app->byte_input, NULL, NULL, NULL, NULL, 0);
|
||||
byte_input_set_header_text(app->byte_input, "");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#include "../findmy_i.h"
|
||||
|
||||
enum ByteInputResult {
|
||||
ByteInputResultOk,
|
||||
};
|
||||
|
||||
static void findmy_scene_config_packet_callback(void* context) {
|
||||
FindMy* app = context;
|
||||
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, ByteInputResultOk);
|
||||
}
|
||||
|
||||
void findmy_scene_config_packet_on_enter(void* context) {
|
||||
FindMy* app = context;
|
||||
ByteInput* byte_input = app->byte_input;
|
||||
|
||||
byte_input_set_header_text(byte_input, "Enter Bluetooth Payload:");
|
||||
|
||||
memset(app->packet_buf, 0, sizeof(app->packet_buf));
|
||||
furi_hal_bt_extra_beacon_get_data(app->packet_buf);
|
||||
|
||||
byte_input_set_result_callback(
|
||||
byte_input,
|
||||
findmy_scene_config_packet_callback,
|
||||
NULL,
|
||||
app,
|
||||
app->packet_buf,
|
||||
sizeof(app->packet_buf));
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, FindMyViewByteInput);
|
||||
}
|
||||
|
||||
bool findmy_scene_config_packet_on_event(void* context, SceneManagerEvent event) {
|
||||
FindMy* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
switch(event.event) {
|
||||
case ByteInputResultOk:
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
app->scene_manager, FindMySceneConfig);
|
||||
furi_check(furi_hal_bt_extra_beacon_set_data(app->packet_buf, sizeof(app->packet_buf)));
|
||||
if (app->packet_buf[0] == 0x1E && app->packet_buf[3] == 0x00) {
|
||||
app->apple = true; // Checks payload data for Apple identifier
|
||||
} else {
|
||||
app->apple = false;
|
||||
}
|
||||
findmy_main_update_apple(app->findmy_main, app->apple);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void findmy_scene_config_packet_on_exit(void* context) {
|
||||
FindMy* app = context;
|
||||
|
||||
byte_input_set_result_callback(app->byte_input, NULL, NULL, NULL, NULL, 0);
|
||||
byte_input_set_header_text(app->byte_input, "");
|
||||
}
|
||||
54
applications/system/findmy/scenes/findmy_scene_main.c
Normal file
54
applications/system/findmy/scenes/findmy_scene_main.c
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "../findmy_i.h"
|
||||
|
||||
void findmy_scene_main_callback(FindMyMainEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
FindMy* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, event);
|
||||
}
|
||||
|
||||
void findmy_scene_main_on_enter(void* context) {
|
||||
FindMy* app = context;
|
||||
|
||||
findmy_main_set_callback(app->findmy_main, findmy_scene_main_callback, app);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, FindMyViewMain);
|
||||
}
|
||||
|
||||
bool findmy_scene_main_on_event(void* context, SceneManagerEvent event) {
|
||||
FindMy* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
switch(event.event) {
|
||||
case FindMyMainEventToggle:
|
||||
findmy_toggle_beacon(app);
|
||||
break;
|
||||
case FindMyMainEventBackground:
|
||||
furi_hal_bt_extra_beacon_start();
|
||||
view_dispatcher_stop(app->view_dispatcher);
|
||||
break;
|
||||
case FindMyMainEventConfig:
|
||||
scene_manager_next_scene(app->scene_manager, FindMySceneConfig);
|
||||
break;
|
||||
case FindMyMainEventIntervalUp:
|
||||
findmy_change_broadcast_interval(app, app->broadcast_interval + 1);
|
||||
break;
|
||||
case FindMyMainEventIntervalDown:
|
||||
findmy_change_broadcast_interval(app, app->broadcast_interval - 1);
|
||||
break;
|
||||
case FindMyMainEventQuit:
|
||||
break;
|
||||
default:
|
||||
consumed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void findmy_scene_main_on_exit(void* context) {
|
||||
FindMy* app = context;
|
||||
UNUSED(app);
|
||||
}
|
||||
4
applications/system/findmy/scenes/findmy_scenes.h
Normal file
4
applications/system/findmy/scenes/findmy_scenes.h
Normal file
@@ -0,0 +1,4 @@
|
||||
ADD_SCENE(findmy, main, Main)
|
||||
ADD_SCENE(findmy, config, Config)
|
||||
ADD_SCENE(findmy, config_mac, ConfigMac)
|
||||
ADD_SCENE(findmy, config_packet, ConfigPacket)
|
||||
Reference in New Issue
Block a user