mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-10 05:59:08 -07:00
Merge branch 'ble-refactor' into xfw-dev
This commit is contained in:
11
applications/examples/example_ble_beacon/application.fam
Normal file
11
applications/examples/example_ble_beacon/application.fam
Normal file
@@ -0,0 +1,11 @@
|
||||
App(
|
||||
appid="example_ble_beacon",
|
||||
name="Example: BLE Beacon",
|
||||
apptype=FlipperAppType.EXTERNAL,
|
||||
entry_point="ble_beacon_app",
|
||||
requires=["gui"],
|
||||
stack_size=1 * 1024,
|
||||
fap_icon="example_ble_beacon_10px.png",
|
||||
fap_category="Examples",
|
||||
fap_icon_assets="images",
|
||||
)
|
||||
149
applications/examples/example_ble_beacon/ble_beacon_app.c
Normal file
149
applications/examples/example_ble_beacon/ble_beacon_app.c
Normal file
@@ -0,0 +1,149 @@
|
||||
#include "ble_beacon_app.h"
|
||||
|
||||
#include <extra_beacon.h>
|
||||
#include <furi_hal_version.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define TAG "ble_beacon_app"
|
||||
|
||||
static bool ble_beacon_app_custom_event_callback(void* context, uint32_t event) {
|
||||
furi_assert(context);
|
||||
BleBeaconApp* app = context;
|
||||
return scene_manager_handle_custom_event(app->scene_manager, event);
|
||||
}
|
||||
|
||||
static bool ble_beacon_app_back_event_callback(void* context) {
|
||||
furi_assert(context);
|
||||
BleBeaconApp* app = context;
|
||||
return scene_manager_handle_back_event(app->scene_manager);
|
||||
}
|
||||
|
||||
static void ble_beacon_app_tick_event_callback(void* context) {
|
||||
furi_assert(context);
|
||||
BleBeaconApp* app = context;
|
||||
scene_manager_handle_tick_event(app->scene_manager);
|
||||
}
|
||||
|
||||
static void ble_beacon_app_restore_beacon_state(BleBeaconApp* app) {
|
||||
// Restore beacon data from service
|
||||
GapExtraBeaconConfig* local_config = &app->beacon_config;
|
||||
const GapExtraBeaconConfig* config = furi_hal_bt_extra_beacon_get_config();
|
||||
if(config) {
|
||||
// We have a config, copy it
|
||||
memcpy(local_config, config, sizeof(app->beacon_config));
|
||||
} else {
|
||||
// No config, set up default values - they will stay until overriden or device is reset
|
||||
local_config->min_adv_interval_ms = 50;
|
||||
local_config->max_adv_interval_ms = 150;
|
||||
|
||||
local_config->adv_channel_map = GapAdvChannelMapAll;
|
||||
local_config->adv_power_level = GapAdvPowerLevel_0dBm;
|
||||
|
||||
local_config->address_type = GapAddressTypePublic;
|
||||
memcpy(
|
||||
local_config->address, furi_hal_version_get_ble_mac(), sizeof(local_config->address));
|
||||
// Modify MAC address to make it different from the one used by the main app
|
||||
local_config->address[0] ^= 0xFF;
|
||||
local_config->address[3] ^= 0xFF;
|
||||
|
||||
furi_check(furi_hal_bt_extra_beacon_set_config(local_config));
|
||||
}
|
||||
|
||||
// Get beacon state
|
||||
app->is_beacon_active = furi_hal_bt_extra_beacon_is_active();
|
||||
|
||||
// Restore last beacon data
|
||||
app->beacon_data_len = furi_hal_bt_extra_beacon_get_data(app->beacon_data);
|
||||
}
|
||||
|
||||
static BleBeaconApp* ble_beacon_app_alloc() {
|
||||
BleBeaconApp* app = malloc(sizeof(BleBeaconApp));
|
||||
|
||||
app->gui = furi_record_open(RECORD_GUI);
|
||||
|
||||
app->scene_manager = scene_manager_alloc(&ble_beacon_app_scene_handlers, app);
|
||||
app->view_dispatcher = view_dispatcher_alloc();
|
||||
|
||||
app->status_string = furi_string_alloc();
|
||||
|
||||
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
|
||||
view_dispatcher_set_custom_event_callback(
|
||||
app->view_dispatcher, ble_beacon_app_custom_event_callback);
|
||||
view_dispatcher_set_navigation_event_callback(
|
||||
app->view_dispatcher, ble_beacon_app_back_event_callback);
|
||||
view_dispatcher_set_tick_event_callback(
|
||||
app->view_dispatcher, ble_beacon_app_tick_event_callback, 100);
|
||||
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
||||
view_dispatcher_enable_queue(app->view_dispatcher);
|
||||
|
||||
app->submenu = submenu_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, BleBeaconAppViewSubmenu, submenu_get_view(app->submenu));
|
||||
|
||||
app->dialog_ex = dialog_ex_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, BleBeaconAppViewDialog, dialog_ex_get_view(app->dialog_ex));
|
||||
|
||||
app->byte_input = byte_input_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, BleBeaconAppViewByteInput, byte_input_get_view(app->byte_input));
|
||||
|
||||
ble_beacon_app_restore_beacon_state(app);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
static void ble_beacon_app_free(BleBeaconApp* app) {
|
||||
view_dispatcher_remove_view(app->view_dispatcher, BleBeaconAppViewByteInput);
|
||||
view_dispatcher_remove_view(app->view_dispatcher, BleBeaconAppViewSubmenu);
|
||||
view_dispatcher_remove_view(app->view_dispatcher, BleBeaconAppViewDialog);
|
||||
|
||||
free(app->byte_input);
|
||||
free(app->submenu);
|
||||
free(app->dialog_ex);
|
||||
|
||||
free(app->scene_manager);
|
||||
free(app->view_dispatcher);
|
||||
|
||||
free(app->status_string);
|
||||
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
furi_record_close(RECORD_GUI);
|
||||
app->gui = NULL;
|
||||
|
||||
free(app);
|
||||
}
|
||||
|
||||
int32_t ble_beacon_app(void* args) {
|
||||
UNUSED(args);
|
||||
|
||||
BleBeaconApp* app = ble_beacon_app_alloc();
|
||||
|
||||
scene_manager_next_scene(app->scene_manager, BleBeaconAppSceneRunBeacon);
|
||||
|
||||
view_dispatcher_run(app->view_dispatcher);
|
||||
|
||||
ble_beacon_app_free(app);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ble_beacon_app_update_state(BleBeaconApp* app) {
|
||||
furi_hal_bt_extra_beacon_stop();
|
||||
|
||||
furi_check(furi_hal_bt_extra_beacon_set_config(&app->beacon_config));
|
||||
|
||||
app->beacon_data_len = 0;
|
||||
while((app->beacon_data[app->beacon_data_len] != 0) &&
|
||||
(app->beacon_data_len < sizeof(app->beacon_data))) {
|
||||
app->beacon_data_len++;
|
||||
}
|
||||
|
||||
FURI_LOG_I(TAG, "beacon_data_len: %d", app->beacon_data_len);
|
||||
|
||||
furi_check(furi_hal_bt_extra_beacon_set_data(app->beacon_data, app->beacon_data_len));
|
||||
|
||||
if(app->is_beacon_active) {
|
||||
furi_check(furi_hal_bt_extra_beacon_start());
|
||||
}
|
||||
}
|
||||
50
applications/examples/example_ble_beacon/ble_beacon_app.h
Normal file
50
applications/examples/example_ble_beacon/ble_beacon_app.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include "extra_beacon.h"
|
||||
#include <furi.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/scene_manager.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
#include <gui/modules/widget.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/modules/byte_input.h>
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
|
||||
#include <rpc/rpc_app.h>
|
||||
#include <notification/notification_messages.h>
|
||||
|
||||
#include <furi_hal_bt.h>
|
||||
|
||||
#include "scenes/scenes.h"
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
Gui* gui;
|
||||
SceneManager* scene_manager;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
|
||||
Submenu* submenu;
|
||||
ByteInput* byte_input;
|
||||
DialogEx* dialog_ex;
|
||||
|
||||
FuriString* status_string;
|
||||
|
||||
GapExtraBeaconConfig beacon_config;
|
||||
uint8_t beacon_data[EXTRA_BEACON_MAX_DATA_SIZE];
|
||||
uint8_t beacon_data_len;
|
||||
bool is_beacon_active;
|
||||
} BleBeaconApp;
|
||||
|
||||
typedef enum {
|
||||
BleBeaconAppViewSubmenu,
|
||||
BleBeaconAppViewByteInput,
|
||||
BleBeaconAppViewDialog,
|
||||
} BleBeaconAppView;
|
||||
|
||||
typedef enum {
|
||||
BleBeaconAppCustomEventDataEditResult = 100,
|
||||
} BleBeaconAppCustomEvent;
|
||||
|
||||
void ble_beacon_app_update_state(BleBeaconApp* app);
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 8.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 8.7 KiB |
@@ -0,0 +1,4 @@
|
||||
ADD_SCENE(ble_beacon_app, menu, Menu)
|
||||
ADD_SCENE(ble_beacon_app, input_mac_addr, InputMacAddress)
|
||||
ADD_SCENE(ble_beacon_app, input_beacon_data, InputBeaconData)
|
||||
ADD_SCENE(ble_beacon_app, run_beacon, RunBeacon)
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "../ble_beacon_app.h"
|
||||
|
||||
static void ble_beacon_app_scene_add_type_byte_input_callback(void* context) {
|
||||
BleBeaconApp* ble_beacon = context;
|
||||
view_dispatcher_send_custom_event(
|
||||
ble_beacon->view_dispatcher, BleBeaconAppCustomEventDataEditResult);
|
||||
}
|
||||
|
||||
void ble_beacon_app_scene_input_beacon_data_on_enter(void* context) {
|
||||
BleBeaconApp* ble_beacon = context;
|
||||
byte_input_set_header_text(ble_beacon->byte_input, "Enter beacon data");
|
||||
|
||||
byte_input_set_result_callback(
|
||||
ble_beacon->byte_input,
|
||||
ble_beacon_app_scene_add_type_byte_input_callback,
|
||||
NULL,
|
||||
context,
|
||||
ble_beacon->beacon_data,
|
||||
sizeof(ble_beacon->beacon_data));
|
||||
|
||||
view_dispatcher_switch_to_view(ble_beacon->view_dispatcher, BleBeaconAppViewByteInput);
|
||||
}
|
||||
|
||||
bool ble_beacon_app_scene_input_beacon_data_on_event(void* context, SceneManagerEvent event) {
|
||||
BleBeaconApp* ble_beacon = context;
|
||||
SceneManager* scene_manager = ble_beacon->scene_manager;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == BleBeaconAppCustomEventDataEditResult) {
|
||||
ble_beacon_app_update_state(ble_beacon);
|
||||
scene_manager_previous_scene(scene_manager);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ble_beacon_app_scene_input_beacon_data_on_exit(void* context) {
|
||||
BleBeaconApp* ble_beacon = context;
|
||||
|
||||
byte_input_set_result_callback(ble_beacon->byte_input, NULL, NULL, NULL, NULL, 0);
|
||||
byte_input_set_header_text(ble_beacon->byte_input, NULL);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "../ble_beacon_app.h"
|
||||
|
||||
static void ble_beacon_app_scene_add_type_byte_input_callback(void* context) {
|
||||
BleBeaconApp* ble_beacon = context;
|
||||
view_dispatcher_send_custom_event(
|
||||
ble_beacon->view_dispatcher, BleBeaconAppCustomEventDataEditResult);
|
||||
}
|
||||
|
||||
void ble_beacon_app_scene_input_mac_addr_on_enter(void* context) {
|
||||
BleBeaconApp* ble_beacon = context;
|
||||
byte_input_set_header_text(ble_beacon->byte_input, "Enter MAC (reversed)");
|
||||
|
||||
byte_input_set_result_callback(
|
||||
ble_beacon->byte_input,
|
||||
ble_beacon_app_scene_add_type_byte_input_callback,
|
||||
NULL,
|
||||
context,
|
||||
ble_beacon->beacon_config.address,
|
||||
sizeof(ble_beacon->beacon_config.address));
|
||||
|
||||
view_dispatcher_switch_to_view(ble_beacon->view_dispatcher, BleBeaconAppViewByteInput);
|
||||
}
|
||||
|
||||
bool ble_beacon_app_scene_input_mac_addr_on_event(void* context, SceneManagerEvent event) {
|
||||
BleBeaconApp* ble_beacon = context;
|
||||
SceneManager* scene_manager = ble_beacon->scene_manager;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == BleBeaconAppCustomEventDataEditResult) {
|
||||
ble_beacon_app_update_state(ble_beacon);
|
||||
scene_manager_previous_scene(scene_manager);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ble_beacon_app_scene_input_mac_addr_on_exit(void* context) {
|
||||
BleBeaconApp* ble_beacon = context;
|
||||
|
||||
byte_input_set_result_callback(ble_beacon->byte_input, NULL, NULL, NULL, NULL, 0);
|
||||
byte_input_set_header_text(ble_beacon->byte_input, NULL);
|
||||
}
|
||||
56
applications/examples/example_ble_beacon/scenes/scene_menu.c
Normal file
56
applications/examples/example_ble_beacon/scenes/scene_menu.c
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "../ble_beacon_app.h"
|
||||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexSetMac,
|
||||
SubmenuIndexSetData,
|
||||
};
|
||||
|
||||
static void ble_beacon_app_scene_menu_submenu_callback(void* context, uint32_t index) {
|
||||
BleBeaconApp* ble_beacon = context;
|
||||
view_dispatcher_send_custom_event(ble_beacon->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void ble_beacon_app_scene_menu_on_enter(void* context) {
|
||||
BleBeaconApp* ble_beacon = context;
|
||||
Submenu* submenu = ble_beacon->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Set MAC",
|
||||
SubmenuIndexSetMac,
|
||||
ble_beacon_app_scene_menu_submenu_callback,
|
||||
ble_beacon);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Set Data",
|
||||
SubmenuIndexSetData,
|
||||
ble_beacon_app_scene_menu_submenu_callback,
|
||||
ble_beacon);
|
||||
|
||||
view_dispatcher_switch_to_view(ble_beacon->view_dispatcher, BleBeaconAppViewSubmenu);
|
||||
}
|
||||
|
||||
bool ble_beacon_app_scene_menu_on_event(void* context, SceneManagerEvent event) {
|
||||
BleBeaconApp* ble_beacon = context;
|
||||
SceneManager* scene_manager = ble_beacon->scene_manager;
|
||||
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
const uint32_t submenu_index = event.event;
|
||||
if(submenu_index == SubmenuIndexSetMac) {
|
||||
scene_manager_next_scene(scene_manager, BleBeaconAppSceneInputMacAddress);
|
||||
consumed = true;
|
||||
} else if(submenu_index == SubmenuIndexSetData) {
|
||||
scene_manager_next_scene(scene_manager, BleBeaconAppSceneInputBeaconData);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void ble_beacon_app_scene_menu_on_exit(void* context) {
|
||||
BleBeaconApp* ble_beacon = context;
|
||||
submenu_reset(ble_beacon->submenu);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
#include "../ble_beacon_app.h"
|
||||
#include <example_ble_beacon_icons.h>
|
||||
|
||||
static void
|
||||
ble_beacon_app_scene_run_beacon_confirm_dialog_callback(DialogExResult result, void* context) {
|
||||
BleBeaconApp* ble_beacon = context;
|
||||
|
||||
view_dispatcher_send_custom_event(ble_beacon->view_dispatcher, result);
|
||||
}
|
||||
|
||||
static void update_status_text(BleBeaconApp* ble_beacon) {
|
||||
DialogEx* dialog_ex = ble_beacon->dialog_ex;
|
||||
|
||||
dialog_ex_set_header(dialog_ex, "BLE Beacon Demo", 64, 0, AlignCenter, AlignTop);
|
||||
|
||||
FuriString* status = ble_beacon->status_string;
|
||||
|
||||
furi_string_reset(status);
|
||||
|
||||
furi_string_cat_str(status, "Status: ");
|
||||
if(ble_beacon->is_beacon_active) {
|
||||
furi_string_cat_str(status, "Running\n");
|
||||
} else {
|
||||
furi_string_cat_str(status, "Stopped\n");
|
||||
}
|
||||
|
||||
// Output MAC in reverse order
|
||||
for(int i = sizeof(ble_beacon->beacon_config.address) - 1; i >= 0; i--) {
|
||||
furi_string_cat_printf(status, "%02X", ble_beacon->beacon_config.address[i]);
|
||||
if(i > 0) {
|
||||
furi_string_cat_str(status, ":");
|
||||
}
|
||||
}
|
||||
|
||||
furi_string_cat_printf(status, "\nData length: %d", ble_beacon->beacon_data_len);
|
||||
|
||||
dialog_ex_set_text(dialog_ex, furi_string_get_cstr(status), 0, 29, AlignLeft, AlignCenter);
|
||||
|
||||
dialog_ex_set_icon(dialog_ex, 93, 20, &I_lighthouse_35x44);
|
||||
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Config");
|
||||
|
||||
dialog_ex_set_center_button_text(dialog_ex, ble_beacon->is_beacon_active ? "Stop" : "Start");
|
||||
|
||||
dialog_ex_set_result_callback(
|
||||
dialog_ex, ble_beacon_app_scene_run_beacon_confirm_dialog_callback);
|
||||
dialog_ex_set_context(dialog_ex, ble_beacon);
|
||||
}
|
||||
|
||||
void ble_beacon_app_scene_run_beacon_on_enter(void* context) {
|
||||
BleBeaconApp* ble_beacon = context;
|
||||
|
||||
update_status_text(ble_beacon);
|
||||
|
||||
view_dispatcher_switch_to_view(ble_beacon->view_dispatcher, BleBeaconAppViewDialog);
|
||||
}
|
||||
|
||||
bool ble_beacon_app_scene_run_beacon_on_event(void* context, SceneManagerEvent event) {
|
||||
BleBeaconApp* ble_beacon = context;
|
||||
SceneManager* scene_manager = ble_beacon->scene_manager;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == DialogExResultLeft) {
|
||||
scene_manager_next_scene(scene_manager, BleBeaconAppSceneMenu);
|
||||
return true;
|
||||
} else if(event.event == DialogExResultCenter) {
|
||||
ble_beacon->is_beacon_active = !ble_beacon->is_beacon_active;
|
||||
ble_beacon_app_update_state(ble_beacon);
|
||||
update_status_text(ble_beacon);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ble_beacon_app_scene_run_beacon_on_exit(void* context) {
|
||||
BleBeaconApp* ble_beacon = context;
|
||||
UNUSED(ble_beacon);
|
||||
}
|
||||
30
applications/examples/example_ble_beacon/scenes/scenes.c
Normal file
30
applications/examples/example_ble_beacon/scenes/scenes.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "scenes.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const ble_beacon_app_on_enter_handlers[])(void*) = {
|
||||
#include "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 ble_beacon_app_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "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 ble_beacon_app_on_exit_handlers[])(void* context) = {
|
||||
#include "scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers ble_beacon_app_scene_handlers = {
|
||||
.on_enter_handlers = ble_beacon_app_on_enter_handlers,
|
||||
.on_event_handlers = ble_beacon_app_on_event_handlers,
|
||||
.on_exit_handlers = ble_beacon_app_on_exit_handlers,
|
||||
.scene_num = BleBeaconAppSceneNum,
|
||||
};
|
||||
29
applications/examples/example_ble_beacon/scenes/scenes.h
Normal file
29
applications/examples/example_ble_beacon/scenes/scenes.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) BleBeaconAppScene##id,
|
||||
typedef enum {
|
||||
#include "scene_config.h"
|
||||
BleBeaconAppSceneNum,
|
||||
} BleBeaconAppScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers ble_beacon_app_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "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 "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 "scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
@@ -1,9 +1,9 @@
|
||||
App(
|
||||
appid="example_custom_font",
|
||||
name="Example: custom font",
|
||||
apptype=FlipperAppType.DEBUG,
|
||||
apptype=FlipperAppType.EXTERNAL,
|
||||
entry_point="example_custom_font_main",
|
||||
requires=["gui"],
|
||||
stack_size=1 * 1024,
|
||||
fap_category="Debug",
|
||||
fap_category="Examples",
|
||||
)
|
||||
Submodule applications/external updated: c389bb7442...6798ec01a7
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "archive_files.h"
|
||||
|
||||
typedef enum {
|
||||
ArchiveAppTypeU2f,
|
||||
ArchiveAppTypeSearch,
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
#include "bad_kb_app.h"
|
||||
#include "bad_kb_app_i.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <storage/storage.h>
|
||||
#include <lib/toolbox/path.h>
|
||||
#include <xtreme/xtreme.h>
|
||||
#include <lib/flipper_format/flipper_format.h>
|
||||
|
||||
#include <bt/bt_service/bt_i.h>
|
||||
#include <bt/bt_service/bt.h>
|
||||
#include "helpers/ducky_script_i.h"
|
||||
|
||||
// Adjusts to serial MAC +2 in app init
|
||||
uint8_t BAD_KB_BOUND_MAC[GAP_MAC_ADDR_SIZE] = {0};
|
||||
|
||||
static bool bad_kb_app_custom_event_callback(void* context, uint32_t event) {
|
||||
furi_assert(context);
|
||||
@@ -30,12 +32,6 @@ static void bad_kb_app_tick_event_callback(void* context) {
|
||||
static void bad_kb_load_settings(BadKbApp* app) {
|
||||
furi_string_reset(app->keyboard_layout);
|
||||
BadKbConfig* cfg = &app->config;
|
||||
strcpy(cfg->bt_name, "");
|
||||
memcpy(cfg->bt_mac, BAD_KB_EMPTY_MAC, BAD_KB_MAC_LEN);
|
||||
strcpy(cfg->usb_cfg.manuf, "");
|
||||
strcpy(cfg->usb_cfg.product, "");
|
||||
cfg->usb_cfg.vid = 0;
|
||||
cfg->usb_cfg.pid = 0;
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
@@ -45,29 +41,30 @@ static void bad_kb_load_settings(BadKbApp* app) {
|
||||
furi_string_reset(app->keyboard_layout);
|
||||
}
|
||||
if(flipper_format_read_string(file, "Bt_Name", tmp_str) && !furi_string_empty(tmp_str)) {
|
||||
strlcpy(cfg->bt_name, furi_string_get_cstr(tmp_str), BAD_KB_NAME_LEN);
|
||||
strlcpy(cfg->ble.name, furi_string_get_cstr(tmp_str), sizeof(cfg->ble.name));
|
||||
} else {
|
||||
strcpy(cfg->bt_name, "");
|
||||
strcpy(cfg->ble.name, "");
|
||||
}
|
||||
if(!flipper_format_read_hex(file, "Bt_Mac", (uint8_t*)&cfg->bt_mac, BAD_KB_MAC_LEN)) {
|
||||
memcpy(cfg->bt_mac, BAD_KB_EMPTY_MAC, BAD_KB_MAC_LEN);
|
||||
if(!flipper_format_read_hex(
|
||||
file, "Bt_Mac", (uint8_t*)&cfg->ble.mac, sizeof(cfg->ble.mac))) {
|
||||
memset(cfg->ble.mac, 0, sizeof(cfg->ble.mac));
|
||||
}
|
||||
if(flipper_format_read_string(file, "Usb_Manuf", tmp_str) && !furi_string_empty(tmp_str)) {
|
||||
strlcpy(cfg->usb_cfg.manuf, furi_string_get_cstr(tmp_str), BAD_KB_USB_LEN);
|
||||
strlcpy(cfg->usb.manuf, furi_string_get_cstr(tmp_str), sizeof(cfg->usb.manuf));
|
||||
} else {
|
||||
strcpy(cfg->usb_cfg.manuf, "");
|
||||
strcpy(cfg->usb.manuf, "");
|
||||
}
|
||||
if(flipper_format_read_string(file, "Usb_Product", tmp_str) &&
|
||||
!furi_string_empty(tmp_str)) {
|
||||
strlcpy(cfg->usb_cfg.product, furi_string_get_cstr(tmp_str), BAD_KB_USB_LEN);
|
||||
strlcpy(cfg->usb.product, furi_string_get_cstr(tmp_str), sizeof(cfg->usb.product));
|
||||
} else {
|
||||
strcpy(cfg->usb_cfg.product, "");
|
||||
strcpy(cfg->usb.product, "");
|
||||
}
|
||||
if(!flipper_format_read_uint32(file, "Usb_Vid", &cfg->usb_cfg.vid, 1)) {
|
||||
cfg->usb_cfg.vid = 0;
|
||||
if(!flipper_format_read_uint32(file, "Usb_Vid", &cfg->usb.vid, 1)) {
|
||||
cfg->usb.vid = 0;
|
||||
}
|
||||
if(!flipper_format_read_uint32(file, "Usb_Pid", &cfg->usb_cfg.pid, 1)) {
|
||||
cfg->usb_cfg.pid = 0;
|
||||
if(!flipper_format_read_uint32(file, "Usb_Pid", &cfg->usb.pid, 1)) {
|
||||
cfg->usb.pid = 0;
|
||||
}
|
||||
furi_string_free(tmp_str);
|
||||
flipper_format_file_close(file);
|
||||
@@ -96,12 +93,12 @@ static void bad_kb_save_settings(BadKbApp* app) {
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
if(flipper_format_file_open_always(file, BAD_KB_SETTINGS_PATH)) {
|
||||
flipper_format_write_string(file, "Keyboard_Layout", app->keyboard_layout);
|
||||
flipper_format_write_string_cstr(file, "Bt_Name", cfg->bt_name);
|
||||
flipper_format_write_hex(file, "Bt_Mac", (uint8_t*)&cfg->bt_mac, BAD_KB_MAC_LEN);
|
||||
flipper_format_write_string_cstr(file, "Usb_Manuf", cfg->usb_cfg.manuf);
|
||||
flipper_format_write_string_cstr(file, "Usb_Product", cfg->usb_cfg.product);
|
||||
flipper_format_write_uint32(file, "Usb_Vid", &cfg->usb_cfg.vid, 1);
|
||||
flipper_format_write_uint32(file, "Usb_Pid", &cfg->usb_cfg.pid, 1);
|
||||
flipper_format_write_string_cstr(file, "Bt_Name", cfg->ble.name);
|
||||
flipper_format_write_hex(file, "Bt_Mac", (uint8_t*)&cfg->ble.mac, sizeof(cfg->ble.mac));
|
||||
flipper_format_write_string_cstr(file, "Usb_Manuf", cfg->usb.manuf);
|
||||
flipper_format_write_string_cstr(file, "Usb_Product", cfg->usb.product);
|
||||
flipper_format_write_uint32(file, "Usb_Vid", &cfg->usb.vid, 1);
|
||||
flipper_format_write_uint32(file, "Usb_Pid", &cfg->usb.pid, 1);
|
||||
flipper_format_file_close(file);
|
||||
}
|
||||
flipper_format_free(file);
|
||||
@@ -119,6 +116,165 @@ void bad_kb_app_show_loading_popup(BadKbApp* app, bool show) {
|
||||
}
|
||||
}
|
||||
|
||||
int32_t bad_kb_conn_apply(BadKbApp* app) {
|
||||
if(app->is_bt) {
|
||||
bt_timeout = bt_hid_delays[LevelRssi39_0];
|
||||
bt_disconnect(app->bt);
|
||||
furi_delay_ms(200);
|
||||
bt_keys_storage_set_storage_path(app->bt, BAD_KB_KEYS_PATH);
|
||||
|
||||
// Setup new config
|
||||
BadKbConfig* cfg = app->set_bt_id ? &app->id_config : &app->config;
|
||||
memcpy(&app->cur_ble_cfg, &cfg->ble, sizeof(cfg->ble));
|
||||
app->cur_ble_cfg.bonding = app->bt_remember;
|
||||
if(app->bt_remember) {
|
||||
app->cur_ble_cfg.pairing = GapPairingPinCodeVerifyYesNo;
|
||||
} else {
|
||||
app->cur_ble_cfg.pairing = GapPairingNone;
|
||||
memcpy(app->cur_ble_cfg.mac, BAD_KB_BOUND_MAC, sizeof(BAD_KB_BOUND_MAC));
|
||||
}
|
||||
|
||||
// Set profile
|
||||
app->ble_hid = bt_profile_start(app->bt, ble_profile_hid, &app->cur_ble_cfg);
|
||||
furi_check(app->ble_hid);
|
||||
|
||||
// Advertise even if BT is off in settings
|
||||
furi_hal_bt_start_advertising();
|
||||
|
||||
app->conn_mode = BadKbConnModeBt;
|
||||
|
||||
} else {
|
||||
// Unlock RPC connections
|
||||
furi_hal_usb_unlock();
|
||||
|
||||
// Context will apply with set_config only if pointer address is different, so we use a copy
|
||||
FuriHalUsbHidConfig* cur_usb_cfg = malloc(sizeof(FuriHalUsbHidConfig));
|
||||
|
||||
// Setup new config
|
||||
BadKbConfig* cfg = app->set_usb_id ? &app->id_config : &app->config;
|
||||
memcpy(cur_usb_cfg, &cfg->usb, sizeof(cfg->usb));
|
||||
|
||||
// Set profile
|
||||
furi_check(furi_hal_usb_set_config(&usb_hid, cur_usb_cfg));
|
||||
if(app->cur_usb_cfg) free(app->cur_usb_cfg);
|
||||
app->cur_usb_cfg = cur_usb_cfg;
|
||||
|
||||
app->conn_mode = BadKbConnModeUsb;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bad_kb_conn_reset(BadKbApp* app) {
|
||||
if(app->conn_mode == BadKbConnModeBt) {
|
||||
bt_disconnect(app->bt);
|
||||
furi_delay_ms(200);
|
||||
bt_keys_storage_set_default_path(app->bt);
|
||||
furi_check(bt_profile_restore_default(app->bt));
|
||||
} else if(app->conn_mode == BadKbConnModeUsb) {
|
||||
// TODO: maybe also restore USB context?
|
||||
furi_check(furi_hal_usb_set_config(app->prev_usb_mode, NULL));
|
||||
}
|
||||
|
||||
app->conn_mode = BadKbConnModeNone;
|
||||
}
|
||||
|
||||
void bad_kb_config_adjust(BadKbConfig* cfg) {
|
||||
// Avoid empty name
|
||||
if(cfg->ble.name[0] == '\0') {
|
||||
snprintf(
|
||||
cfg->ble.name, sizeof(cfg->ble.name), "Control %s", furi_hal_version_get_name_ptr());
|
||||
}
|
||||
|
||||
const uint8_t* normal_mac = furi_hal_version_get_ble_mac();
|
||||
uint8_t empty_mac[sizeof(cfg->ble.mac)] = {0};
|
||||
uint8_t default_mac[sizeof(cfg->ble.mac)] = {0x6c, 0x7a, 0xd8, 0xac, 0x57, 0x72}; //furi_hal_bt
|
||||
if(memcmp(cfg->ble.mac, empty_mac, sizeof(cfg->ble.mac)) == 0 ||
|
||||
memcmp(cfg->ble.mac, normal_mac, sizeof(cfg->ble.mac)) == 0 ||
|
||||
memcmp(cfg->ble.mac, default_mac, sizeof(cfg->ble.mac)) == 0) {
|
||||
memcpy(cfg->ble.mac, normal_mac, sizeof(cfg->ble.mac));
|
||||
cfg->ble.mac[2]++;
|
||||
}
|
||||
|
||||
// Use defaults if vid or pid are unset
|
||||
if(cfg->usb.vid == 0) cfg->usb.vid = HID_VID_DEFAULT;
|
||||
if(cfg->usb.pid == 0) cfg->usb.pid = HID_PID_DEFAULT;
|
||||
}
|
||||
|
||||
void bad_kb_config_refresh(BadKbApp* app) {
|
||||
bt_set_status_changed_callback(app->bt, NULL, NULL);
|
||||
furi_hal_hid_set_state_callback(NULL, NULL);
|
||||
if(app->bad_kb_script) {
|
||||
furi_thread_flags_set(furi_thread_get_id(app->bad_kb_script->thread), WorkerEvtDisconnect);
|
||||
}
|
||||
if(app->conn_init_thread) {
|
||||
furi_thread_join(app->conn_init_thread);
|
||||
}
|
||||
|
||||
bool apply = false;
|
||||
if(app->is_bt) {
|
||||
BadKbConfig* cfg = app->set_bt_id ? &app->id_config : &app->config;
|
||||
bad_kb_config_adjust(cfg);
|
||||
|
||||
if(app->conn_mode != BadKbConnModeBt) {
|
||||
apply = true;
|
||||
bad_kb_conn_reset(app);
|
||||
} else {
|
||||
BleProfileHidParams* cur = &app->cur_ble_cfg;
|
||||
apply = apply || cfg->ble.bonding != app->bt_remember;
|
||||
apply = apply || strncmp(cfg->ble.name, cur->name, sizeof(cfg->ble.name));
|
||||
apply = apply || memcmp(cfg->ble.mac, cur->mac, sizeof(cfg->ble.mac));
|
||||
}
|
||||
} else {
|
||||
BadKbConfig* cfg = app->set_usb_id ? &app->id_config : &app->config;
|
||||
bad_kb_config_adjust(cfg);
|
||||
|
||||
if(app->conn_mode != BadKbConnModeUsb) {
|
||||
apply = true;
|
||||
bad_kb_conn_reset(app);
|
||||
} else {
|
||||
FuriHalUsbHidConfig* cur = app->cur_usb_cfg;
|
||||
apply = apply || cfg->usb.vid != cur->vid;
|
||||
apply = apply || cfg->usb.pid != cur->pid;
|
||||
apply = apply || strncmp(cfg->usb.manuf, cur->manuf, sizeof(cur->manuf));
|
||||
apply = apply || strncmp(cfg->usb.product, cur->product, sizeof(cur->product));
|
||||
}
|
||||
}
|
||||
|
||||
if(apply) {
|
||||
bad_kb_conn_apply(app);
|
||||
}
|
||||
|
||||
if(app->bad_kb_script) {
|
||||
BadKbScript* script = app->bad_kb_script;
|
||||
script->st.is_bt = app->is_bt;
|
||||
script->bt = app->is_bt ? app->bt : NULL;
|
||||
bool connected;
|
||||
if(app->is_bt) {
|
||||
bt_set_status_changed_callback(app->bt, bad_kb_bt_hid_state_callback, script);
|
||||
connected = furi_hal_bt_is_connected();
|
||||
} else {
|
||||
furi_hal_hid_set_state_callback(bad_kb_usb_hid_state_callback, script);
|
||||
connected = furi_hal_hid_is_connected();
|
||||
}
|
||||
if(connected) {
|
||||
furi_thread_flags_set(furi_thread_get_id(script->thread), WorkerEvtConnect);
|
||||
}
|
||||
}
|
||||
|
||||
// Reload config page
|
||||
scene_manager_next_scene(app->scene_manager, BadKbSceneConfig);
|
||||
scene_manager_previous_scene(app->scene_manager);
|
||||
|
||||
// Update settings
|
||||
if(xtreme_settings.bad_bt != app->is_bt ||
|
||||
xtreme_settings.bad_bt_remember != app->bt_remember) {
|
||||
xtreme_settings.bad_bt = app->is_bt;
|
||||
xtreme_settings.bad_bt_remember = app->bt_remember;
|
||||
xtreme_settings_save();
|
||||
}
|
||||
}
|
||||
|
||||
BadKbApp* bad_kb_app_alloc(char* arg) {
|
||||
BadKbApp* app = malloc(sizeof(BadKbApp));
|
||||
|
||||
@@ -158,13 +314,9 @@ BadKbApp* bad_kb_app_alloc(char* arg) {
|
||||
|
||||
// Save prev config
|
||||
app->prev_usb_mode = furi_hal_usb_get_config();
|
||||
FuriHalBtProfile kbd = FuriHalBtProfileHidKeyboard;
|
||||
app->prev_bt_mode = furi_hal_bt_get_profile_pairing_method(kbd);
|
||||
memcpy(app->prev_bt_mac, furi_hal_bt_get_profile_mac_addr(kbd), BAD_KB_MAC_LEN);
|
||||
strlcpy(app->prev_bt_name, furi_hal_bt_get_profile_adv_name(kbd), BAD_KB_NAME_LEN);
|
||||
|
||||
// Adjust BT remember MAC to be serial MAC +2
|
||||
memcpy(BAD_KB_BOUND_MAC, furi_hal_version_get_ble_mac(), BAD_KB_MAC_LEN);
|
||||
memcpy(BAD_KB_BOUND_MAC, furi_hal_version_get_ble_mac(), sizeof(BAD_KB_BOUND_MAC));
|
||||
BAD_KB_BOUND_MAC[2] += 2;
|
||||
|
||||
// Custom Widget
|
||||
@@ -256,7 +408,7 @@ void bad_kb_app_free(BadKbApp* app) {
|
||||
app->conn_init_thread = NULL;
|
||||
}
|
||||
bad_kb_conn_reset(app);
|
||||
if(app->hid_cfg) free(app->hid_cfg);
|
||||
if(app->cur_usb_cfg) free(app->cur_usb_cfg);
|
||||
|
||||
// Close records
|
||||
furi_record_close(RECORD_GUI);
|
||||
@@ -272,8 +424,8 @@ void bad_kb_app_free(BadKbApp* app) {
|
||||
free(app);
|
||||
}
|
||||
|
||||
int32_t bad_kb_app(char* p) {
|
||||
BadKbApp* bad_kb_app = bad_kb_app_alloc(p);
|
||||
int32_t bad_kb_app(void* p) {
|
||||
BadKbApp* bad_kb_app = bad_kb_app_alloc((char*)p);
|
||||
|
||||
view_dispatcher_run(bad_kb_app->view_dispatcher);
|
||||
|
||||
|
||||
@@ -1,30 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "scenes/bad_kb_scene.h"
|
||||
#include "helpers/ducky_script.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <gui/gui.h>
|
||||
#include <assets_icons.h>
|
||||
#include <gui/scene_manager.h>
|
||||
#include <dialogs/dialogs.h>
|
||||
#include <notification/notification_messages.h>
|
||||
typedef struct BadKbApp BadKbApp;
|
||||
|
||||
#define BAD_KB_APP_SCRIPT_EXTENSION ".txt"
|
||||
#define BAD_KB_APP_LAYOUT_EXTENSION ".kl"
|
||||
|
||||
typedef enum BadKbCustomEvent {
|
||||
BadKbAppCustomEventTextInputDone,
|
||||
BadKbAppCustomEventByteInputDone,
|
||||
BadKbCustomEventErrorBack
|
||||
} BadKbCustomEvent;
|
||||
|
||||
typedef enum {
|
||||
BadKbAppViewWidget,
|
||||
BadKbAppViewWork,
|
||||
BadKbAppViewVarItemList,
|
||||
BadKbAppViewByteInput,
|
||||
BadKbAppViewTextInput,
|
||||
BadKbAppViewLoading,
|
||||
} BadKbAppView;
|
||||
|
||||
void bad_kb_app_show_loading_popup(BadKbApp* app, bool show);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
111
applications/main/bad_kb/bad_kb_app_i.h
Normal file
111
applications/main/bad_kb/bad_kb_app_i.h
Normal file
@@ -0,0 +1,111 @@
|
||||
#pragma once
|
||||
|
||||
#include "bad_kb_app.h"
|
||||
#include "scenes/bad_kb_scene.h"
|
||||
#include "helpers/ducky_script.h"
|
||||
#include "helpers/ble_hid.h"
|
||||
#include "bad_kb_paths.h"
|
||||
|
||||
#include <gui/gui.h>
|
||||
#include <assets_icons.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/scene_manager.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <dialogs/dialogs.h>
|
||||
#include <notification/notification_messages.h>
|
||||
#include <gui/modules/variable_item_list.h>
|
||||
#include <gui/modules/text_input.h>
|
||||
#include <gui/modules/byte_input.h>
|
||||
#include <gui/modules/loading.h>
|
||||
#include <gui/modules/widget.h>
|
||||
#include "views/bad_kb_view.h"
|
||||
#include <furi_hal_usb.h>
|
||||
|
||||
#define BAD_KB_APP_SCRIPT_EXTENSION ".txt"
|
||||
#define BAD_KB_APP_LAYOUT_EXTENSION ".kl"
|
||||
|
||||
extern uint8_t BAD_KB_BOUND_MAC[GAP_MAC_ADDR_SIZE]; // For remember mode
|
||||
|
||||
typedef enum BadKbCustomEvent {
|
||||
BadKbAppCustomEventTextInputDone,
|
||||
BadKbAppCustomEventByteInputDone,
|
||||
BadKbCustomEventErrorBack
|
||||
} BadKbCustomEvent;
|
||||
|
||||
typedef enum {
|
||||
BadKbAppErrorNoFiles,
|
||||
} BadKbAppError;
|
||||
|
||||
typedef struct {
|
||||
BleProfileHidParams ble;
|
||||
FuriHalUsbHidConfig usb;
|
||||
} BadKbConfig;
|
||||
|
||||
typedef enum {
|
||||
BadKbConnModeNone,
|
||||
BadKbConnModeUsb,
|
||||
BadKbConnModeBt,
|
||||
} BadKbConnMode;
|
||||
|
||||
struct BadKbApp {
|
||||
Gui* gui;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
SceneManager* scene_manager;
|
||||
NotificationApp* notifications;
|
||||
DialogsApp* dialogs;
|
||||
Widget* widget;
|
||||
VariableItemList* var_item_list;
|
||||
TextInput* text_input;
|
||||
ByteInput* byte_input;
|
||||
Loading* loading;
|
||||
|
||||
char bt_name_buf[FURI_HAL_BT_ADV_NAME_LENGTH];
|
||||
uint8_t bt_mac_buf[GAP_MAC_ADDR_SIZE];
|
||||
char usb_name_buf[HID_MANUF_PRODUCT_NAME_LEN];
|
||||
uint16_t usb_vidpid_buf[2];
|
||||
|
||||
BadKbAppError error;
|
||||
FuriString* file_path;
|
||||
FuriString* keyboard_layout;
|
||||
BadKb* bad_kb_view;
|
||||
BadKbScript* bad_kb_script;
|
||||
|
||||
Bt* bt;
|
||||
bool is_bt;
|
||||
bool bt_remember;
|
||||
BadKbConfig config; // User options
|
||||
BadKbConfig id_config; // ID and BT_ID values
|
||||
|
||||
bool set_bt_id;
|
||||
bool set_usb_id;
|
||||
bool has_bt_id;
|
||||
bool has_usb_id;
|
||||
|
||||
FuriHalBleProfileBase* ble_hid;
|
||||
FuriHalUsbInterface* prev_usb_mode;
|
||||
|
||||
BleProfileHidParams cur_ble_cfg;
|
||||
FuriHalUsbHidConfig* cur_usb_cfg;
|
||||
|
||||
BadKbConnMode conn_mode;
|
||||
FuriThread* conn_init_thread;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
BadKbAppViewWidget,
|
||||
BadKbAppViewWork,
|
||||
BadKbAppViewVarItemList,
|
||||
BadKbAppViewByteInput,
|
||||
BadKbAppViewTextInput,
|
||||
BadKbAppViewLoading,
|
||||
} BadKbAppView;
|
||||
|
||||
void bad_kb_app_show_loading_popup(BadKbApp* app, bool show);
|
||||
|
||||
int32_t bad_kb_conn_apply(BadKbApp* app);
|
||||
|
||||
void bad_kb_conn_reset(BadKbApp* app);
|
||||
|
||||
void bad_kb_config_refresh(BadKbApp* app);
|
||||
|
||||
void bad_kb_config_adjust(BadKbConfig* cfg);
|
||||
416
applications/main/bad_kb/helpers/ble_hid.c
Normal file
416
applications/main/bad_kb/helpers/ble_hid.c
Normal file
@@ -0,0 +1,416 @@
|
||||
#include "ble_hid.h"
|
||||
|
||||
#include <furi_hal_usb_hid.h>
|
||||
#include <services/dev_info_service.h>
|
||||
#include <services/battery_service.h>
|
||||
#include "ble_hid_svc.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <usb_hid.h>
|
||||
#include <ble/ble.h>
|
||||
|
||||
#define HID_INFO_BASE_USB_SPECIFICATION (0x0101)
|
||||
#define HID_INFO_COUNTRY_CODE (0x00)
|
||||
#define BLE_PROFILE_HID_INFO_FLAG_REMOTE_WAKE_MSK (0x01)
|
||||
#define BLE_PROFILE_HID_INFO_FLAG_NORMALLY_CONNECTABLE_MSK (0x02)
|
||||
|
||||
#define BLE_PROFILE_HID_KB_MAX_KEYS (6)
|
||||
#define BLE_PROFILE_CONSUMER_MAX_KEYS (1)
|
||||
|
||||
// Report ids cant be 0
|
||||
enum HidReportId {
|
||||
ReportIdKeyboard = 1,
|
||||
ReportIdMouse = 2,
|
||||
ReportIdConsumer = 3,
|
||||
};
|
||||
// Report numbers corresponded to the report id with an offset of 1
|
||||
enum HidInputNumber {
|
||||
ReportNumberKeyboard = 0,
|
||||
ReportNumberMouse = 1,
|
||||
ReportNumberConsumer = 2,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t mods;
|
||||
uint8_t reserved;
|
||||
uint8_t key[BLE_PROFILE_HID_KB_MAX_KEYS];
|
||||
} FURI_PACKED FuriHalBtHidKbReport;
|
||||
|
||||
typedef struct {
|
||||
uint8_t btn;
|
||||
int8_t x;
|
||||
int8_t y;
|
||||
int8_t wheel;
|
||||
} FURI_PACKED FuriHalBtHidMouseReport;
|
||||
|
||||
typedef struct {
|
||||
uint16_t key[BLE_PROFILE_CONSUMER_MAX_KEYS];
|
||||
} FURI_PACKED FuriHalBtHidConsumerReport;
|
||||
|
||||
// keyboard+mouse+consumer hid report
|
||||
static const uint8_t ble_profile_hid_report_map_data[] = {
|
||||
// Keyboard Report
|
||||
HID_USAGE_PAGE(HID_PAGE_DESKTOP),
|
||||
HID_USAGE(HID_DESKTOP_KEYBOARD),
|
||||
HID_COLLECTION(HID_APPLICATION_COLLECTION),
|
||||
HID_REPORT_ID(ReportIdKeyboard),
|
||||
HID_USAGE_PAGE(HID_DESKTOP_KEYPAD),
|
||||
HID_USAGE_MINIMUM(HID_KEYBOARD_L_CTRL),
|
||||
HID_USAGE_MAXIMUM(HID_KEYBOARD_R_GUI),
|
||||
HID_LOGICAL_MINIMUM(0),
|
||||
HID_LOGICAL_MAXIMUM(1),
|
||||
HID_REPORT_SIZE(1),
|
||||
HID_REPORT_COUNT(8),
|
||||
HID_INPUT(HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
HID_REPORT_COUNT(1),
|
||||
HID_REPORT_SIZE(8),
|
||||
HID_INPUT(HID_IOF_CONSTANT | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
HID_USAGE_PAGE(HID_PAGE_LED),
|
||||
HID_REPORT_COUNT(8),
|
||||
HID_REPORT_SIZE(1),
|
||||
HID_USAGE_MINIMUM(1),
|
||||
HID_USAGE_MAXIMUM(8),
|
||||
HID_OUTPUT(HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
HID_REPORT_COUNT(BLE_PROFILE_HID_KB_MAX_KEYS),
|
||||
HID_REPORT_SIZE(8),
|
||||
HID_LOGICAL_MINIMUM(0),
|
||||
HID_LOGICAL_MAXIMUM(101),
|
||||
HID_USAGE_PAGE(HID_DESKTOP_KEYPAD),
|
||||
HID_USAGE_MINIMUM(0),
|
||||
HID_USAGE_MAXIMUM(101),
|
||||
HID_INPUT(HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
|
||||
HID_END_COLLECTION,
|
||||
// Mouse Report
|
||||
HID_USAGE_PAGE(HID_PAGE_DESKTOP),
|
||||
HID_USAGE(HID_DESKTOP_MOUSE),
|
||||
HID_COLLECTION(HID_APPLICATION_COLLECTION),
|
||||
HID_USAGE(HID_DESKTOP_POINTER),
|
||||
HID_COLLECTION(HID_PHYSICAL_COLLECTION),
|
||||
HID_REPORT_ID(ReportIdMouse),
|
||||
HID_USAGE_PAGE(HID_PAGE_BUTTON),
|
||||
HID_USAGE_MINIMUM(1),
|
||||
HID_USAGE_MAXIMUM(3),
|
||||
HID_LOGICAL_MINIMUM(0),
|
||||
HID_LOGICAL_MAXIMUM(1),
|
||||
HID_REPORT_COUNT(3),
|
||||
HID_REPORT_SIZE(1),
|
||||
HID_INPUT(HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
HID_REPORT_SIZE(1),
|
||||
HID_REPORT_COUNT(5),
|
||||
HID_INPUT(HID_IOF_CONSTANT | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
HID_USAGE_PAGE(HID_PAGE_DESKTOP),
|
||||
HID_USAGE(HID_DESKTOP_X),
|
||||
HID_USAGE(HID_DESKTOP_Y),
|
||||
HID_USAGE(HID_DESKTOP_WHEEL),
|
||||
HID_LOGICAL_MINIMUM(-127),
|
||||
HID_LOGICAL_MAXIMUM(127),
|
||||
HID_REPORT_SIZE(8),
|
||||
HID_REPORT_COUNT(3),
|
||||
HID_INPUT(HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
|
||||
HID_END_COLLECTION,
|
||||
HID_END_COLLECTION,
|
||||
// Consumer Report
|
||||
HID_USAGE_PAGE(HID_PAGE_CONSUMER),
|
||||
HID_USAGE(HID_CONSUMER_CONTROL),
|
||||
HID_COLLECTION(HID_APPLICATION_COLLECTION),
|
||||
HID_REPORT_ID(ReportIdConsumer),
|
||||
HID_LOGICAL_MINIMUM(0),
|
||||
HID_RI_LOGICAL_MAXIMUM(16, 0x3FF),
|
||||
HID_USAGE_MINIMUM(0),
|
||||
HID_RI_USAGE_MAXIMUM(16, 0x3FF),
|
||||
HID_REPORT_COUNT(BLE_PROFILE_CONSUMER_MAX_KEYS),
|
||||
HID_REPORT_SIZE(16),
|
||||
HID_INPUT(HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
|
||||
HID_END_COLLECTION,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
FuriHalBleProfileBase base;
|
||||
|
||||
FuriHalBtHidKbReport* kb_report;
|
||||
FuriHalBtHidMouseReport* mouse_report;
|
||||
FuriHalBtHidConsumerReport* consumer_report;
|
||||
|
||||
BleServiceBattery* battery_svc;
|
||||
BleServiceDevInfo* dev_info_svc;
|
||||
BleServiceHid* hid_svc;
|
||||
} BleProfileHid;
|
||||
_Static_assert(offsetof(BleProfileHid, base) == 0, "Wrong layout");
|
||||
|
||||
static FuriHalBleProfileBase* ble_profile_hid_start(FuriHalBleProfileParams profile_params) {
|
||||
UNUSED(profile_params);
|
||||
|
||||
BleProfileHid* profile = malloc(sizeof(BleProfileHid));
|
||||
|
||||
profile->base.config = ble_profile_hid;
|
||||
|
||||
profile->battery_svc = ble_svc_battery_start(true);
|
||||
profile->dev_info_svc = ble_svc_dev_info_start();
|
||||
profile->hid_svc = ble_svc_hid_start();
|
||||
|
||||
// Configure HID Keyboard
|
||||
profile->kb_report = malloc(sizeof(FuriHalBtHidKbReport));
|
||||
profile->mouse_report = malloc(sizeof(FuriHalBtHidMouseReport));
|
||||
profile->consumer_report = malloc(sizeof(FuriHalBtHidConsumerReport));
|
||||
|
||||
// Configure Report Map characteristic
|
||||
ble_svc_hid_update_report_map(
|
||||
profile->hid_svc,
|
||||
ble_profile_hid_report_map_data,
|
||||
sizeof(ble_profile_hid_report_map_data));
|
||||
// Configure HID Information characteristic
|
||||
uint8_t hid_info_val[4] = {
|
||||
HID_INFO_BASE_USB_SPECIFICATION & 0x00ff,
|
||||
(HID_INFO_BASE_USB_SPECIFICATION & 0xff00) >> 8,
|
||||
HID_INFO_COUNTRY_CODE,
|
||||
BLE_PROFILE_HID_INFO_FLAG_REMOTE_WAKE_MSK |
|
||||
BLE_PROFILE_HID_INFO_FLAG_NORMALLY_CONNECTABLE_MSK,
|
||||
};
|
||||
ble_svc_hid_update_info(profile->hid_svc, hid_info_val);
|
||||
|
||||
return &profile->base;
|
||||
}
|
||||
|
||||
static void ble_profile_hid_stop(FuriHalBleProfileBase* profile) {
|
||||
furi_check(profile);
|
||||
furi_check(profile->config == ble_profile_hid);
|
||||
|
||||
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||
ble_svc_battery_stop(hid_profile->battery_svc);
|
||||
ble_svc_dev_info_stop(hid_profile->dev_info_svc);
|
||||
ble_svc_hid_stop(hid_profile->hid_svc);
|
||||
|
||||
free(hid_profile->kb_report);
|
||||
free(hid_profile->mouse_report);
|
||||
free(hid_profile->consumer_report);
|
||||
}
|
||||
|
||||
bool ble_profile_hid_kb_press(FuriHalBleProfileBase* profile, uint16_t button) {
|
||||
furi_check(profile);
|
||||
furi_check(profile->config == ble_profile_hid);
|
||||
|
||||
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||
FuriHalBtHidKbReport* kb_report = hid_profile->kb_report;
|
||||
for(uint8_t i = 0; i < BLE_PROFILE_HID_KB_MAX_KEYS; i++) {
|
||||
if(kb_report->key[i] == 0) {
|
||||
kb_report->key[i] = button & 0xFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
kb_report->mods |= (button >> 8);
|
||||
return ble_svc_hid_update_input_report(
|
||||
hid_profile->hid_svc,
|
||||
ReportNumberKeyboard,
|
||||
(uint8_t*)kb_report,
|
||||
sizeof(FuriHalBtHidKbReport));
|
||||
}
|
||||
|
||||
bool ble_profile_hid_kb_release(FuriHalBleProfileBase* profile, uint16_t button) {
|
||||
furi_check(profile);
|
||||
furi_check(profile->config == ble_profile_hid);
|
||||
|
||||
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||
|
||||
FuriHalBtHidKbReport* kb_report = hid_profile->kb_report;
|
||||
for(uint8_t i = 0; i < BLE_PROFILE_HID_KB_MAX_KEYS; i++) {
|
||||
if(kb_report->key[i] == (button & 0xFF)) {
|
||||
kb_report->key[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
kb_report->mods &= ~(button >> 8);
|
||||
return ble_svc_hid_update_input_report(
|
||||
hid_profile->hid_svc,
|
||||
ReportNumberKeyboard,
|
||||
(uint8_t*)kb_report,
|
||||
sizeof(FuriHalBtHidKbReport));
|
||||
}
|
||||
|
||||
bool ble_profile_hid_kb_release_all(FuriHalBleProfileBase* profile) {
|
||||
furi_check(profile);
|
||||
furi_check(profile->config == ble_profile_hid);
|
||||
|
||||
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||
FuriHalBtHidKbReport* kb_report = hid_profile->kb_report;
|
||||
for(uint8_t i = 0; i < BLE_PROFILE_HID_KB_MAX_KEYS; i++) {
|
||||
kb_report->key[i] = 0;
|
||||
}
|
||||
kb_report->mods = 0;
|
||||
return ble_svc_hid_update_input_report(
|
||||
hid_profile->hid_svc,
|
||||
ReportNumberKeyboard,
|
||||
(uint8_t*)kb_report,
|
||||
sizeof(FuriHalBtHidKbReport));
|
||||
}
|
||||
|
||||
bool ble_profile_hid_consumer_key_press(FuriHalBleProfileBase* profile, uint16_t button) {
|
||||
furi_check(profile);
|
||||
furi_check(profile->config == ble_profile_hid);
|
||||
|
||||
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||
FuriHalBtHidConsumerReport* consumer_report = hid_profile->consumer_report;
|
||||
for(uint8_t i = 0; i < BLE_PROFILE_CONSUMER_MAX_KEYS; i++) { //-V1008
|
||||
if(consumer_report->key[i] == 0) {
|
||||
consumer_report->key[i] = button;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ble_svc_hid_update_input_report(
|
||||
hid_profile->hid_svc,
|
||||
ReportNumberConsumer,
|
||||
(uint8_t*)consumer_report,
|
||||
sizeof(FuriHalBtHidConsumerReport));
|
||||
}
|
||||
|
||||
bool ble_profile_hid_consumer_key_release(FuriHalBleProfileBase* profile, uint16_t button) {
|
||||
furi_check(profile);
|
||||
furi_check(profile->config == ble_profile_hid);
|
||||
|
||||
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||
FuriHalBtHidConsumerReport* consumer_report = hid_profile->consumer_report;
|
||||
for(uint8_t i = 0; i < BLE_PROFILE_CONSUMER_MAX_KEYS; i++) { //-V1008
|
||||
if(consumer_report->key[i] == button) {
|
||||
consumer_report->key[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ble_svc_hid_update_input_report(
|
||||
hid_profile->hid_svc,
|
||||
ReportNumberConsumer,
|
||||
(uint8_t*)consumer_report,
|
||||
sizeof(FuriHalBtHidConsumerReport));
|
||||
}
|
||||
|
||||
bool ble_profile_hid_consumer_key_release_all(FuriHalBleProfileBase* profile) {
|
||||
furi_check(profile);
|
||||
furi_check(profile->config == ble_profile_hid);
|
||||
|
||||
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||
FuriHalBtHidConsumerReport* consumer_report = hid_profile->consumer_report;
|
||||
for(uint8_t i = 0; i < BLE_PROFILE_CONSUMER_MAX_KEYS; i++) { //-V1008
|
||||
consumer_report->key[i] = 0;
|
||||
}
|
||||
return ble_svc_hid_update_input_report(
|
||||
hid_profile->hid_svc,
|
||||
ReportNumberConsumer,
|
||||
(uint8_t*)consumer_report,
|
||||
sizeof(FuriHalBtHidConsumerReport));
|
||||
}
|
||||
|
||||
bool ble_profile_hid_mouse_move(FuriHalBleProfileBase* profile, int8_t dx, int8_t dy) {
|
||||
furi_check(profile);
|
||||
furi_check(profile->config == ble_profile_hid);
|
||||
|
||||
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||
FuriHalBtHidMouseReport* mouse_report = hid_profile->mouse_report;
|
||||
mouse_report->x = dx;
|
||||
mouse_report->y = dy;
|
||||
bool state = ble_svc_hid_update_input_report(
|
||||
hid_profile->hid_svc,
|
||||
ReportNumberMouse,
|
||||
(uint8_t*)mouse_report,
|
||||
sizeof(FuriHalBtHidMouseReport));
|
||||
mouse_report->x = 0;
|
||||
mouse_report->y = 0;
|
||||
return state;
|
||||
}
|
||||
|
||||
bool ble_profile_hid_mouse_press(FuriHalBleProfileBase* profile, uint8_t button) {
|
||||
furi_check(profile);
|
||||
furi_check(profile->config == ble_profile_hid);
|
||||
|
||||
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||
FuriHalBtHidMouseReport* mouse_report = hid_profile->mouse_report;
|
||||
mouse_report->btn |= button;
|
||||
return ble_svc_hid_update_input_report(
|
||||
hid_profile->hid_svc,
|
||||
ReportNumberMouse,
|
||||
(uint8_t*)mouse_report,
|
||||
sizeof(FuriHalBtHidMouseReport));
|
||||
}
|
||||
|
||||
bool ble_profile_hid_mouse_release(FuriHalBleProfileBase* profile, uint8_t button) {
|
||||
furi_check(profile);
|
||||
furi_check(profile->config == ble_profile_hid);
|
||||
|
||||
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||
FuriHalBtHidMouseReport* mouse_report = hid_profile->mouse_report;
|
||||
mouse_report->btn &= ~button;
|
||||
return ble_svc_hid_update_input_report(
|
||||
hid_profile->hid_svc,
|
||||
ReportNumberMouse,
|
||||
(uint8_t*)mouse_report,
|
||||
sizeof(FuriHalBtHidMouseReport));
|
||||
}
|
||||
|
||||
bool ble_profile_hid_mouse_release_all(FuriHalBleProfileBase* profile) {
|
||||
furi_check(profile);
|
||||
furi_check(profile->config == ble_profile_hid);
|
||||
|
||||
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||
FuriHalBtHidMouseReport* mouse_report = hid_profile->mouse_report;
|
||||
mouse_report->btn = 0;
|
||||
return ble_svc_hid_update_input_report(
|
||||
hid_profile->hid_svc,
|
||||
ReportNumberMouse,
|
||||
(uint8_t*)mouse_report,
|
||||
sizeof(FuriHalBtHidMouseReport));
|
||||
}
|
||||
|
||||
bool ble_profile_hid_mouse_scroll(FuriHalBleProfileBase* profile, int8_t delta) {
|
||||
furi_check(profile);
|
||||
furi_check(profile->config == ble_profile_hid);
|
||||
|
||||
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||
FuriHalBtHidMouseReport* mouse_report = hid_profile->mouse_report;
|
||||
mouse_report->wheel = delta;
|
||||
bool state = ble_svc_hid_update_input_report(
|
||||
hid_profile->hid_svc,
|
||||
ReportNumberMouse,
|
||||
(uint8_t*)mouse_report,
|
||||
sizeof(FuriHalBtHidMouseReport));
|
||||
mouse_report->wheel = 0;
|
||||
return state;
|
||||
}
|
||||
|
||||
static GapConfig template_config = {
|
||||
.adv_service_uuid = HUMAN_INTERFACE_DEVICE_SERVICE_UUID,
|
||||
.appearance_char = GAP_APPEARANCE_KEYBOARD,
|
||||
.bonding_mode = true,
|
||||
.pairing_method = GapPairingPinCodeVerifyYesNo,
|
||||
.conn_param =
|
||||
{
|
||||
.conn_int_min = 0x18, // 30 ms
|
||||
.conn_int_max = 0x24, // 45 ms
|
||||
.slave_latency = 0,
|
||||
.supervisor_timeout = 0,
|
||||
},
|
||||
};
|
||||
|
||||
static void ble_profile_hid_get_config(GapConfig* config, FuriHalBleProfileParams profile_params) {
|
||||
BleProfileHidParams* hid_profile_params = profile_params;
|
||||
|
||||
furi_check(config);
|
||||
memcpy(config, &template_config, sizeof(GapConfig));
|
||||
|
||||
// Set mac address
|
||||
memcpy(config->mac_address, hid_profile_params->mac, sizeof(config->mac_address));
|
||||
|
||||
// Set advertise name
|
||||
config->adv_name[0] = furi_hal_version_get_ble_local_device_name_ptr()[0];
|
||||
strlcpy(config->adv_name + 1, hid_profile_params->name, sizeof(config->adv_name) - 1);
|
||||
|
||||
// Set bonding mode
|
||||
config->bonding_mode = hid_profile_params->bonding;
|
||||
|
||||
// Set pairing method
|
||||
config->pairing_method = hid_profile_params->pairing;
|
||||
}
|
||||
|
||||
static const FuriHalBleProfileTemplate profile_callbacks = {
|
||||
.start = ble_profile_hid_start,
|
||||
.stop = ble_profile_hid_stop,
|
||||
.get_gap_config = ble_profile_hid_get_config,
|
||||
};
|
||||
|
||||
const FuriHalBleProfileTemplate* ble_profile_hid = &profile_callbacks;
|
||||
107
applications/main/bad_kb/helpers/ble_hid.h
Normal file
107
applications/main/bad_kb/helpers/ble_hid.h
Normal file
@@ -0,0 +1,107 @@
|
||||
#pragma once
|
||||
|
||||
#include <furi_ble/profile_interface.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Optional arguments to pass along with profile template as
|
||||
* FuriHalBleProfileParams for tuning profile behavior
|
||||
**/
|
||||
typedef struct {
|
||||
char name[FURI_HAL_BT_ADV_NAME_LENGTH]; /**< Full device name */
|
||||
uint8_t mac[GAP_MAC_ADDR_SIZE]; /**< Full device address */
|
||||
bool bonding; /**< Save paired devices */
|
||||
GapPairing pairing; /**< Pairing security method */
|
||||
} BleProfileHidParams;
|
||||
|
||||
/** Hid Keyboard Profile descriptor */
|
||||
extern const FuriHalBleProfileTemplate* ble_profile_hid;
|
||||
|
||||
/** Press keyboard button
|
||||
*
|
||||
* @param profile profile instance
|
||||
* @param button button code from HID specification
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
bool ble_profile_hid_kb_press(FuriHalBleProfileBase* profile, uint16_t button);
|
||||
|
||||
/** Release keyboard button
|
||||
*
|
||||
* @param profile profile instance
|
||||
* @param button button code from HID specification
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
bool ble_profile_hid_kb_release(FuriHalBleProfileBase* profile, uint16_t button);
|
||||
|
||||
/** Release all keyboard buttons
|
||||
*
|
||||
* @param profile profile instance
|
||||
* @return true on success
|
||||
*/
|
||||
bool ble_profile_hid_kb_release_all(FuriHalBleProfileBase* profile);
|
||||
|
||||
/** Set the following consumer key to pressed state and send HID report
|
||||
*
|
||||
* @param profile profile instance
|
||||
* @param button key code
|
||||
*/
|
||||
bool ble_profile_hid_consumer_key_press(FuriHalBleProfileBase* profile, uint16_t button);
|
||||
|
||||
/** Set the following consumer key to released state and send HID report
|
||||
*
|
||||
* @param profile profile instance
|
||||
* @param button key code
|
||||
*/
|
||||
bool ble_profile_hid_consumer_key_release(FuriHalBleProfileBase* profile, uint16_t button);
|
||||
|
||||
/** Set consumer key to released state and send HID report
|
||||
*
|
||||
* @param profile profile instance
|
||||
* @param button key code
|
||||
*/
|
||||
bool ble_profile_hid_consumer_key_release_all(FuriHalBleProfileBase* profile);
|
||||
|
||||
/** Set mouse movement and send HID report
|
||||
*
|
||||
* @param profile profile instance
|
||||
* @param dx x coordinate delta
|
||||
* @param dy y coordinate delta
|
||||
*/
|
||||
bool ble_profile_hid_mouse_move(FuriHalBleProfileBase* profile, int8_t dx, int8_t dy);
|
||||
|
||||
/** Set mouse button to pressed state and send HID report
|
||||
*
|
||||
* @param profile profile instance
|
||||
* @param button key code
|
||||
*/
|
||||
bool ble_profile_hid_mouse_press(FuriHalBleProfileBase* profile, uint8_t button);
|
||||
|
||||
/** Set mouse button to released state and send HID report
|
||||
*
|
||||
* @param profile profile instance
|
||||
* @param button key code
|
||||
*/
|
||||
bool ble_profile_hid_mouse_release(FuriHalBleProfileBase* profile, uint8_t button);
|
||||
|
||||
/** Set mouse button to released state and send HID report
|
||||
*
|
||||
* @param profile profile instance
|
||||
* @param button key code
|
||||
*/
|
||||
bool ble_profile_hid_mouse_release_all(FuriHalBleProfileBase* profile);
|
||||
|
||||
/** Set mouse wheel position and send HID report
|
||||
*
|
||||
* @param profile profile instance
|
||||
* @param delta number of scroll steps
|
||||
*/
|
||||
bool ble_profile_hid_mouse_scroll(FuriHalBleProfileBase* profile, int8_t delta);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
320
applications/main/bad_kb/helpers/ble_hid_svc.c
Normal file
320
applications/main/bad_kb/helpers/ble_hid_svc.c
Normal file
@@ -0,0 +1,320 @@
|
||||
#include "ble_hid_svc.h"
|
||||
#include "app_common.h"
|
||||
#include <ble/ble.h>
|
||||
#include <furi_ble/event_dispatcher.h>
|
||||
#include <furi_ble/gatt.h>
|
||||
|
||||
#include <furi.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define TAG "BleHid"
|
||||
|
||||
#define BLE_SVC_HID_REPORT_MAP_MAX_LEN (255)
|
||||
#define BLE_SVC_HID_REPORT_MAX_LEN (255)
|
||||
#define BLE_SVC_HID_REPORT_REF_LEN (2)
|
||||
#define BLE_SVC_HID_INFO_LEN (4)
|
||||
#define BLE_SVC_HID_CONTROL_POINT_LEN (1)
|
||||
|
||||
#define BLE_SVC_HID_INPUT_REPORT_COUNT (3)
|
||||
#define BLE_SVC_HID_OUTPUT_REPORT_COUNT (0)
|
||||
#define BLE_SVC_HID_FEATURE_REPORT_COUNT (0)
|
||||
#define BLE_SVC_HID_REPORT_COUNT \
|
||||
(BLE_SVC_HID_INPUT_REPORT_COUNT + BLE_SVC_HID_OUTPUT_REPORT_COUNT + \
|
||||
BLE_SVC_HID_FEATURE_REPORT_COUNT)
|
||||
|
||||
typedef enum {
|
||||
HidSvcGattCharacteristicProtocolMode = 0,
|
||||
HidSvcGattCharacteristicReportMap,
|
||||
HidSvcGattCharacteristicInfo,
|
||||
HidSvcGattCharacteristicCtrlPoint,
|
||||
HidSvcGattCharacteristicCount,
|
||||
} HidSvcGattCharacteristicId;
|
||||
|
||||
typedef struct {
|
||||
uint8_t report_idx;
|
||||
uint8_t report_type;
|
||||
} HidSvcReportId;
|
||||
|
||||
static_assert(sizeof(HidSvcReportId) == sizeof(uint16_t), "HidSvcReportId must be 2 bytes");
|
||||
|
||||
static const Service_UUID_t ble_svc_hid_uuid = {
|
||||
.Service_UUID_16 = HUMAN_INTERFACE_DEVICE_SERVICE_UUID,
|
||||
};
|
||||
|
||||
static bool ble_svc_hid_char_desc_data_callback(
|
||||
const void* context,
|
||||
const uint8_t** data,
|
||||
uint16_t* data_len) {
|
||||
const HidSvcReportId* report_id = context;
|
||||
*data_len = sizeof(HidSvcReportId);
|
||||
if(data) {
|
||||
*data = (const uint8_t*)report_id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
const void* data_ptr;
|
||||
uint16_t data_len;
|
||||
} HidSvcDataWrapper;
|
||||
|
||||
static bool ble_svc_hid_report_data_callback(
|
||||
const void* context,
|
||||
const uint8_t** data,
|
||||
uint16_t* data_len) {
|
||||
const HidSvcDataWrapper* report_data = context;
|
||||
if(data) {
|
||||
*data = report_data->data_ptr;
|
||||
*data_len = report_data->data_len;
|
||||
} else {
|
||||
*data_len = BLE_SVC_HID_REPORT_MAP_MAX_LEN;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static const BleGattCharacteristicParams ble_svc_hid_chars[HidSvcGattCharacteristicCount] = {
|
||||
[HidSvcGattCharacteristicProtocolMode] =
|
||||
{.name = "Protocol Mode",
|
||||
.data_prop_type = FlipperGattCharacteristicDataFixed,
|
||||
.data.fixed.length = 1,
|
||||
.uuid.Char_UUID_16 = PROTOCOL_MODE_CHAR_UUID,
|
||||
.uuid_type = UUID_TYPE_16,
|
||||
.char_properties = CHAR_PROP_READ | CHAR_PROP_WRITE_WITHOUT_RESP,
|
||||
.security_permissions = ATTR_PERMISSION_NONE,
|
||||
.gatt_evt_mask = GATT_NOTIFY_ATTRIBUTE_WRITE,
|
||||
.is_variable = CHAR_VALUE_LEN_CONSTANT},
|
||||
[HidSvcGattCharacteristicReportMap] =
|
||||
{.name = "Report Map",
|
||||
.data_prop_type = FlipperGattCharacteristicDataCallback,
|
||||
.data.callback.fn = ble_svc_hid_report_data_callback,
|
||||
.data.callback.context = NULL,
|
||||
.uuid.Char_UUID_16 = REPORT_MAP_CHAR_UUID,
|
||||
.uuid_type = UUID_TYPE_16,
|
||||
.char_properties = CHAR_PROP_READ,
|
||||
.security_permissions = ATTR_PERMISSION_NONE,
|
||||
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
||||
.is_variable = CHAR_VALUE_LEN_VARIABLE},
|
||||
[HidSvcGattCharacteristicInfo] =
|
||||
{.name = "HID Information",
|
||||
.data_prop_type = FlipperGattCharacteristicDataFixed,
|
||||
.data.fixed.length = BLE_SVC_HID_INFO_LEN,
|
||||
.data.fixed.ptr = NULL,
|
||||
.uuid.Char_UUID_16 = HID_INFORMATION_CHAR_UUID,
|
||||
.uuid_type = UUID_TYPE_16,
|
||||
.char_properties = CHAR_PROP_READ,
|
||||
.security_permissions = ATTR_PERMISSION_NONE,
|
||||
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
||||
.is_variable = CHAR_VALUE_LEN_CONSTANT},
|
||||
[HidSvcGattCharacteristicCtrlPoint] =
|
||||
{.name = "HID Control Point",
|
||||
.data_prop_type = FlipperGattCharacteristicDataFixed,
|
||||
.data.fixed.length = BLE_SVC_HID_CONTROL_POINT_LEN,
|
||||
.uuid.Char_UUID_16 = HID_CONTROL_POINT_CHAR_UUID,
|
||||
.uuid_type = UUID_TYPE_16,
|
||||
.char_properties = CHAR_PROP_WRITE_WITHOUT_RESP,
|
||||
.security_permissions = ATTR_PERMISSION_NONE,
|
||||
.gatt_evt_mask = GATT_NOTIFY_ATTRIBUTE_WRITE,
|
||||
.is_variable = CHAR_VALUE_LEN_CONSTANT},
|
||||
};
|
||||
|
||||
static const BleGattCharacteristicDescriptorParams ble_svc_hid_char_descr_template = {
|
||||
.uuid_type = UUID_TYPE_16,
|
||||
.uuid.Char_UUID_16 = REPORT_REFERENCE_DESCRIPTOR_UUID,
|
||||
.max_length = BLE_SVC_HID_REPORT_REF_LEN,
|
||||
.data_callback.fn = ble_svc_hid_char_desc_data_callback,
|
||||
.security_permissions = ATTR_PERMISSION_NONE,
|
||||
.access_permissions = ATTR_ACCESS_READ_WRITE,
|
||||
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
||||
.is_variable = CHAR_VALUE_LEN_CONSTANT,
|
||||
};
|
||||
|
||||
static const BleGattCharacteristicParams ble_svc_hid_report_template = {
|
||||
.name = "Report",
|
||||
.data_prop_type = FlipperGattCharacteristicDataCallback,
|
||||
.data.callback.fn = ble_svc_hid_report_data_callback,
|
||||
.data.callback.context = NULL,
|
||||
.uuid.Char_UUID_16 = REPORT_CHAR_UUID,
|
||||
.uuid_type = UUID_TYPE_16,
|
||||
.char_properties = CHAR_PROP_READ | CHAR_PROP_NOTIFY,
|
||||
.security_permissions = ATTR_PERMISSION_NONE,
|
||||
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
||||
.is_variable = CHAR_VALUE_LEN_VARIABLE,
|
||||
};
|
||||
|
||||
struct BleServiceHid {
|
||||
uint16_t svc_handle;
|
||||
BleGattCharacteristicInstance chars[HidSvcGattCharacteristicCount];
|
||||
BleGattCharacteristicInstance input_report_chars[BLE_SVC_HID_INPUT_REPORT_COUNT];
|
||||
BleGattCharacteristicInstance output_report_chars[BLE_SVC_HID_OUTPUT_REPORT_COUNT];
|
||||
BleGattCharacteristicInstance feature_report_chars[BLE_SVC_HID_FEATURE_REPORT_COUNT];
|
||||
GapSvcEventHandler* event_handler;
|
||||
};
|
||||
|
||||
static BleEventAckStatus ble_svc_hid_event_handler(void* event, void* context) {
|
||||
UNUSED(context);
|
||||
|
||||
BleEventAckStatus ret = BleEventNotAck;
|
||||
hci_event_pckt* event_pckt = (hci_event_pckt*)(((hci_uart_pckt*)event)->data);
|
||||
evt_blecore_aci* blecore_evt = (evt_blecore_aci*)event_pckt->data;
|
||||
// aci_gatt_attribute_modified_event_rp0* attribute_modified;
|
||||
if(event_pckt->evt == HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE) {
|
||||
if(blecore_evt->ecode == ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE) {
|
||||
// Process modification events
|
||||
ret = BleEventAckFlowEnable;
|
||||
} else if(blecore_evt->ecode == ACI_GATT_SERVER_CONFIRMATION_VSEVT_CODE) {
|
||||
// Process notification confirmation
|
||||
ret = BleEventAckFlowEnable;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
BleServiceHid* ble_svc_hid_start() {
|
||||
BleServiceHid* hid_svc = malloc(sizeof(BleServiceHid));
|
||||
|
||||
// Register event handler
|
||||
hid_svc->event_handler =
|
||||
ble_event_dispatcher_register_svc_handler(ble_svc_hid_event_handler, hid_svc);
|
||||
/**
|
||||
* Add Human Interface Device Service
|
||||
*/
|
||||
if(!ble_gatt_service_add(
|
||||
UUID_TYPE_16,
|
||||
&ble_svc_hid_uuid,
|
||||
PRIMARY_SERVICE,
|
||||
2 + /* protocol mode */
|
||||
(4 * BLE_SVC_HID_INPUT_REPORT_COUNT) + (3 * BLE_SVC_HID_OUTPUT_REPORT_COUNT) +
|
||||
(3 * BLE_SVC_HID_FEATURE_REPORT_COUNT) + 1 + 2 + 2 +
|
||||
2, /* Service + Report Map + HID Information + HID Control Point */
|
||||
&hid_svc->svc_handle)) {
|
||||
free(hid_svc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Maintain previously defined characteristic order
|
||||
ble_gatt_characteristic_init(
|
||||
hid_svc->svc_handle,
|
||||
&ble_svc_hid_chars[HidSvcGattCharacteristicProtocolMode],
|
||||
&hid_svc->chars[HidSvcGattCharacteristicProtocolMode]);
|
||||
|
||||
uint8_t protocol_mode = 1;
|
||||
ble_gatt_characteristic_update(
|
||||
hid_svc->svc_handle,
|
||||
&hid_svc->chars[HidSvcGattCharacteristicProtocolMode],
|
||||
&protocol_mode);
|
||||
|
||||
// reports
|
||||
BleGattCharacteristicDescriptorParams ble_svc_hid_char_descr;
|
||||
BleGattCharacteristicParams report_char;
|
||||
HidSvcReportId report_id;
|
||||
|
||||
memcpy(
|
||||
&ble_svc_hid_char_descr, &ble_svc_hid_char_descr_template, sizeof(ble_svc_hid_char_descr));
|
||||
memcpy(&report_char, &ble_svc_hid_report_template, sizeof(report_char));
|
||||
|
||||
ble_svc_hid_char_descr.data_callback.context = &report_id;
|
||||
report_char.descriptor_params = &ble_svc_hid_char_descr;
|
||||
|
||||
typedef struct {
|
||||
uint8_t report_type;
|
||||
uint8_t report_count;
|
||||
BleGattCharacteristicInstance* chars;
|
||||
} HidSvcReportCharProps;
|
||||
|
||||
HidSvcReportCharProps hid_report_chars[] = {
|
||||
{0x01, BLE_SVC_HID_INPUT_REPORT_COUNT, hid_svc->input_report_chars},
|
||||
{0x02, BLE_SVC_HID_OUTPUT_REPORT_COUNT, hid_svc->output_report_chars},
|
||||
{0x03, BLE_SVC_HID_FEATURE_REPORT_COUNT, hid_svc->feature_report_chars},
|
||||
};
|
||||
|
||||
for(size_t report_type_idx = 0; report_type_idx < COUNT_OF(hid_report_chars);
|
||||
report_type_idx++) {
|
||||
report_id.report_type = hid_report_chars[report_type_idx].report_type;
|
||||
for(size_t report_idx = 0; report_idx < hid_report_chars[report_type_idx].report_count;
|
||||
report_idx++) {
|
||||
report_id.report_idx = report_idx + 1;
|
||||
ble_gatt_characteristic_init(
|
||||
hid_svc->svc_handle,
|
||||
&report_char,
|
||||
&hid_report_chars[report_type_idx].chars[report_idx]);
|
||||
}
|
||||
}
|
||||
|
||||
// Setup remaining characteristics
|
||||
for(size_t i = HidSvcGattCharacteristicReportMap; i < HidSvcGattCharacteristicCount; i++) {
|
||||
ble_gatt_characteristic_init(
|
||||
hid_svc->svc_handle, &ble_svc_hid_chars[i], &hid_svc->chars[i]);
|
||||
}
|
||||
|
||||
return hid_svc;
|
||||
}
|
||||
|
||||
bool ble_svc_hid_update_report_map(BleServiceHid* hid_svc, const uint8_t* data, uint16_t len) {
|
||||
furi_assert(data);
|
||||
furi_assert(hid_svc);
|
||||
|
||||
HidSvcDataWrapper report_data = {
|
||||
.data_ptr = data,
|
||||
.data_len = len,
|
||||
};
|
||||
return ble_gatt_characteristic_update(
|
||||
hid_svc->svc_handle, &hid_svc->chars[HidSvcGattCharacteristicReportMap], &report_data);
|
||||
}
|
||||
|
||||
bool ble_svc_hid_update_input_report(
|
||||
BleServiceHid* hid_svc,
|
||||
uint8_t input_report_num,
|
||||
uint8_t* data,
|
||||
uint16_t len) {
|
||||
furi_assert(data);
|
||||
furi_assert(hid_svc);
|
||||
furi_assert(input_report_num < BLE_SVC_HID_INPUT_REPORT_COUNT);
|
||||
|
||||
HidSvcDataWrapper report_data = {
|
||||
.data_ptr = data,
|
||||
.data_len = len,
|
||||
};
|
||||
return ble_gatt_characteristic_update(
|
||||
hid_svc->svc_handle, &hid_svc->input_report_chars[input_report_num], &report_data);
|
||||
}
|
||||
|
||||
bool ble_svc_hid_update_info(BleServiceHid* hid_svc, uint8_t* data) {
|
||||
furi_assert(data);
|
||||
furi_assert(hid_svc);
|
||||
|
||||
return ble_gatt_characteristic_update(
|
||||
hid_svc->svc_handle, &hid_svc->chars[HidSvcGattCharacteristicInfo], &data);
|
||||
}
|
||||
|
||||
void ble_svc_hid_stop(BleServiceHid* hid_svc) {
|
||||
furi_assert(hid_svc);
|
||||
ble_event_dispatcher_unregister_svc_handler(hid_svc->event_handler);
|
||||
// Delete characteristics
|
||||
for(size_t i = 0; i < HidSvcGattCharacteristicCount; i++) {
|
||||
ble_gatt_characteristic_delete(hid_svc->svc_handle, &hid_svc->chars[i]);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
uint8_t report_count;
|
||||
BleGattCharacteristicInstance* chars;
|
||||
} HidSvcReportCharProps;
|
||||
|
||||
HidSvcReportCharProps hid_report_chars[] = {
|
||||
{BLE_SVC_HID_INPUT_REPORT_COUNT, hid_svc->input_report_chars},
|
||||
{BLE_SVC_HID_OUTPUT_REPORT_COUNT, hid_svc->output_report_chars},
|
||||
{BLE_SVC_HID_FEATURE_REPORT_COUNT, hid_svc->feature_report_chars},
|
||||
};
|
||||
|
||||
for(size_t report_type_idx = 0; report_type_idx < COUNT_OF(hid_report_chars);
|
||||
report_type_idx++) {
|
||||
for(size_t report_idx = 0; report_idx < hid_report_chars[report_type_idx].report_count;
|
||||
report_idx++) {
|
||||
ble_gatt_characteristic_delete(
|
||||
hid_svc->svc_handle, &hid_report_chars[report_type_idx].chars[report_idx]);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete service
|
||||
ble_gatt_service_delete(hid_svc->svc_handle);
|
||||
free(hid_svc);
|
||||
}
|
||||
29
applications/main/bad_kb/helpers/ble_hid_svc.h
Normal file
29
applications/main/bad_kb/helpers/ble_hid_svc.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct BleServiceHid BleServiceHid;
|
||||
|
||||
BleServiceHid* ble_svc_hid_start();
|
||||
|
||||
void ble_svc_hid_stop(BleServiceHid* service);
|
||||
|
||||
bool ble_svc_hid_update_report_map(BleServiceHid* service, const uint8_t* data, uint16_t len);
|
||||
|
||||
bool ble_svc_hid_update_input_report(
|
||||
BleServiceHid* service,
|
||||
uint8_t input_report_num,
|
||||
uint8_t* data,
|
||||
uint16_t len);
|
||||
|
||||
// Expects data to be of length BLE_SVC_HID_INFO_LEN (4 bytes)
|
||||
bool ble_svc_hid_update_info(BleServiceHid* service, uint8_t* data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,23 +1,16 @@
|
||||
#include "../bad_kb_app_i.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <gui/gui.h>
|
||||
#include <input/input.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
#include <furi_hal_bt_hid.h>
|
||||
#include <furi_hal_usb_hid.h>
|
||||
#include <bt/bt_service/bt.h>
|
||||
#include "ble_hid.h"
|
||||
#include <storage/storage.h>
|
||||
#include "ducky_script.h"
|
||||
#include "ducky_script_i.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
#include <toolbox/hex.h>
|
||||
#include <xtreme/xtreme.h>
|
||||
#include "../scenes/bad_kb_scene.h"
|
||||
|
||||
const uint8_t BAD_KB_EMPTY_MAC[BAD_KB_MAC_LEN] = FURI_HAL_BT_EMPTY_MAC_ADDR;
|
||||
|
||||
// Adjusts to serial MAC +2 in app init
|
||||
uint8_t BAD_KB_BOUND_MAC[BAD_KB_MAC_LEN] = FURI_HAL_BT_EMPTY_MAC_ADDR;
|
||||
|
||||
#define TAG "BadKb"
|
||||
#define WORKER_TAG TAG "Worker"
|
||||
@@ -27,11 +20,11 @@ uint8_t BAD_KB_BOUND_MAC[BAD_KB_MAC_LEN] = FURI_HAL_BT_EMPTY_MAC_ADDR;
|
||||
|
||||
// Delays for waiting between HID key press and key release
|
||||
const uint8_t bt_hid_delays[LevelRssiNum] = {
|
||||
45, // LevelRssi122_100
|
||||
38, // LevelRssi99_80
|
||||
30, // LevelRssi79_60
|
||||
26, // LevelRssi59_40
|
||||
21, // LevelRssi39_0
|
||||
60, // LevelRssi122_100
|
||||
55, // LevelRssi99_80
|
||||
50, // LevelRssi79_60
|
||||
47, // LevelRssi59_40
|
||||
34, // LevelRssi39_0
|
||||
};
|
||||
|
||||
uint8_t bt_timeout = 0;
|
||||
@@ -63,14 +56,6 @@ static inline void update_bt_timeout(Bt* bt) {
|
||||
}
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
WorkerEvtStartStop = (1 << 0),
|
||||
WorkerEvtPauseResume = (1 << 1),
|
||||
WorkerEvtEnd = (1 << 2),
|
||||
WorkerEvtConnect = (1 << 3),
|
||||
WorkerEvtDisconnect = (1 << 4),
|
||||
} WorkerEvtFlags;
|
||||
|
||||
static const char ducky_cmd_id[] = {"ID"};
|
||||
static const char ducky_cmd_bt_id[] = {"BT_ID"};
|
||||
|
||||
@@ -120,12 +105,17 @@ bool ducky_get_number(const char* param, uint32_t* val) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t furi_hal_bt_hid_get_led_state() {
|
||||
// FIXME
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ducky_numlock_on(BadKbScript* bad_kb) {
|
||||
if(bad_kb->bt) {
|
||||
if((furi_hal_bt_hid_get_led_state() & HID_KB_LED_NUM) == 0) {
|
||||
furi_hal_bt_hid_kb_press(HID_KEYBOARD_LOCK_NUM_LOCK);
|
||||
ble_profile_hid_kb_press(bad_kb->app->ble_hid, HID_KEYBOARD_LOCK_NUM_LOCK);
|
||||
furi_delay_ms(bt_timeout);
|
||||
furi_hal_bt_hid_kb_release(HID_KEYBOARD_LOCK_NUM_LOCK);
|
||||
ble_profile_hid_kb_release(bad_kb->app->ble_hid, HID_KEYBOARD_LOCK_NUM_LOCK);
|
||||
}
|
||||
} else {
|
||||
if((furi_hal_hid_get_led_state() & HID_KB_LED_NUM) == 0) {
|
||||
@@ -140,9 +130,9 @@ bool ducky_numpad_press(BadKbScript* bad_kb, const char num) {
|
||||
|
||||
uint16_t key = numpad_keys[num - '0'];
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_press(key);
|
||||
ble_profile_hid_kb_press(bad_kb->app->ble_hid, key);
|
||||
furi_delay_ms(bt_timeout);
|
||||
furi_hal_bt_hid_kb_release(key);
|
||||
ble_profile_hid_kb_release(bad_kb->app->ble_hid, key);
|
||||
} else {
|
||||
furi_hal_hid_kb_press(key);
|
||||
furi_hal_hid_kb_release(key);
|
||||
@@ -156,7 +146,7 @@ bool ducky_altchar(BadKbScript* bad_kb, const char* charcode) {
|
||||
bool state = false;
|
||||
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_press(KEY_MOD_LEFT_ALT);
|
||||
ble_profile_hid_kb_press(bad_kb->app->ble_hid, KEY_MOD_LEFT_ALT);
|
||||
} else {
|
||||
furi_hal_hid_kb_press(KEY_MOD_LEFT_ALT);
|
||||
}
|
||||
@@ -168,7 +158,7 @@ bool ducky_altchar(BadKbScript* bad_kb, const char* charcode) {
|
||||
}
|
||||
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_release(KEY_MOD_LEFT_ALT);
|
||||
ble_profile_hid_kb_release(bad_kb->app->ble_hid, KEY_MOD_LEFT_ALT);
|
||||
} else {
|
||||
furi_hal_hid_kb_release(KEY_MOD_LEFT_ALT);
|
||||
}
|
||||
@@ -213,9 +203,9 @@ bool ducky_string(BadKbScript* bad_kb, const char* param) {
|
||||
uint16_t keycode = BADKB_ASCII_TO_KEY(bad_kb, param[i]);
|
||||
if(keycode != HID_KEYBOARD_NONE) {
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_press(keycode);
|
||||
ble_profile_hid_kb_press(bad_kb->app->ble_hid, keycode);
|
||||
furi_delay_ms(bt_timeout);
|
||||
furi_hal_bt_hid_kb_release(keycode);
|
||||
ble_profile_hid_kb_release(bad_kb->app->ble_hid, keycode);
|
||||
} else {
|
||||
furi_hal_hid_kb_press(keycode);
|
||||
furi_hal_hid_kb_release(keycode);
|
||||
@@ -223,9 +213,9 @@ bool ducky_string(BadKbScript* bad_kb, const char* param) {
|
||||
}
|
||||
} else {
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_press(HID_KEYBOARD_RETURN);
|
||||
ble_profile_hid_kb_press(bad_kb->app->ble_hid, HID_KEYBOARD_RETURN);
|
||||
furi_delay_ms(bt_timeout);
|
||||
furi_hal_bt_hid_kb_release(HID_KEYBOARD_RETURN);
|
||||
ble_profile_hid_kb_release(bad_kb->app->ble_hid, HID_KEYBOARD_RETURN);
|
||||
} else {
|
||||
furi_hal_hid_kb_press(HID_KEYBOARD_RETURN);
|
||||
furi_hal_hid_kb_release(HID_KEYBOARD_RETURN);
|
||||
@@ -248,9 +238,9 @@ static bool ducky_string_next(BadKbScript* bad_kb) {
|
||||
uint16_t keycode = BADKB_ASCII_TO_KEY(bad_kb, print_char);
|
||||
if(keycode != HID_KEYBOARD_NONE) {
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_press(keycode);
|
||||
ble_profile_hid_kb_press(bad_kb->app->ble_hid, keycode);
|
||||
furi_delay_ms(bt_timeout);
|
||||
furi_hal_bt_hid_kb_release(keycode);
|
||||
ble_profile_hid_kb_release(bad_kb->app->ble_hid, keycode);
|
||||
} else {
|
||||
furi_hal_hid_kb_press(keycode);
|
||||
furi_hal_hid_kb_release(keycode);
|
||||
@@ -258,9 +248,9 @@ static bool ducky_string_next(BadKbScript* bad_kb) {
|
||||
}
|
||||
} else {
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_press(HID_KEYBOARD_RETURN);
|
||||
ble_profile_hid_kb_press(bad_kb->app->ble_hid, HID_KEYBOARD_RETURN);
|
||||
furi_delay_ms(bt_timeout);
|
||||
furi_hal_bt_hid_kb_release(HID_KEYBOARD_RETURN);
|
||||
ble_profile_hid_kb_release(bad_kb->app->ble_hid, HID_KEYBOARD_RETURN);
|
||||
} else {
|
||||
furi_hal_hid_kb_press(HID_KEYBOARD_RETURN);
|
||||
furi_hal_hid_kb_release(HID_KEYBOARD_RETURN);
|
||||
@@ -302,9 +292,9 @@ static int32_t ducky_parse_line(BadKbScript* bad_kb, FuriString* line) {
|
||||
}
|
||||
}
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_press(key);
|
||||
ble_profile_hid_kb_press(bad_kb->app->ble_hid, key);
|
||||
furi_delay_ms(bt_timeout);
|
||||
furi_hal_bt_hid_kb_release(key);
|
||||
ble_profile_hid_kb_release(bad_kb->app->ble_hid, key);
|
||||
} else {
|
||||
furi_hal_hid_kb_press(key);
|
||||
furi_hal_hid_kb_release(key);
|
||||
@@ -313,7 +303,7 @@ static int32_t ducky_parse_line(BadKbScript* bad_kb, FuriString* line) {
|
||||
}
|
||||
|
||||
static bool ducky_set_usb_id(BadKbScript* bad_kb, const char* line) {
|
||||
FuriHalUsbHidConfig* cfg = &bad_kb->app->id_config.usb_cfg;
|
||||
FuriHalUsbHidConfig* cfg = &bad_kb->app->id_config.usb;
|
||||
|
||||
if(sscanf(line, "%lX:%lX", &cfg->vid, &cfg->pid) == 2) {
|
||||
cfg->manuf[0] = '\0';
|
||||
@@ -339,20 +329,20 @@ static bool ducky_set_bt_id(BadKbScript* bad_kb, const char* line) {
|
||||
BadKbConfig* cfg = &bad_kb->app->id_config;
|
||||
|
||||
size_t line_len = strlen(line);
|
||||
size_t mac_len = BAD_KB_MAC_LEN * 3; // 2 text chars + separator per byte
|
||||
size_t mac_len = sizeof(cfg->ble.mac) * 3; // 2 text chars + separator per byte
|
||||
if(line_len < mac_len + 1) return false; // MAC + at least 1 char for name
|
||||
|
||||
for(size_t i = 0; i < BAD_KB_MAC_LEN; i++) {
|
||||
for(size_t i = 0; i < sizeof(cfg->ble.mac); i++) {
|
||||
char a = line[i * 3];
|
||||
char b = line[i * 3 + 1];
|
||||
if((a < 'A' && a > 'F') || (a < '0' && a > '9') || (b < 'A' && b > 'F') ||
|
||||
(b < '0' && b > '9') || !hex_char_to_uint8(a, b, &cfg->bt_mac[i])) {
|
||||
(b < '0' && b > '9') || !hex_char_to_uint8(a, b, &cfg->ble.mac[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
furi_hal_bt_reverse_mac_addr(cfg->bt_mac);
|
||||
furi_hal_bt_reverse_mac_addr(cfg->ble.mac);
|
||||
|
||||
strlcpy(cfg->bt_name, line + mac_len, BAD_KB_NAME_LEN);
|
||||
strlcpy(cfg->ble.name, line + mac_len, sizeof(cfg->ble.name));
|
||||
FURI_LOG_D(WORKER_TAG, "set bt id: %s", line);
|
||||
return true;
|
||||
}
|
||||
@@ -473,7 +463,7 @@ static int32_t ducky_script_execute_next(BadKbScript* bad_kb, File* script_file)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void bad_kb_bt_hid_state_callback(BtStatus status, void* context) {
|
||||
void bad_kb_bt_hid_state_callback(BtStatus status, void* context) {
|
||||
furi_assert(context);
|
||||
BadKbScript* bad_kb = context;
|
||||
bool state = (status == BtStatusConnected);
|
||||
@@ -489,7 +479,7 @@ static void bad_kb_bt_hid_state_callback(BtStatus status, void* context) {
|
||||
}
|
||||
}
|
||||
|
||||
static void bad_kb_usb_hid_state_callback(bool state, void* context) {
|
||||
void bad_kb_usb_hid_state_callback(bool state, void* context) {
|
||||
furi_assert(context);
|
||||
BadKbScript* bad_kb = context;
|
||||
|
||||
@@ -513,188 +503,6 @@ static uint32_t bad_kb_flags_get(uint32_t flags_mask, uint32_t timeout) {
|
||||
return flags;
|
||||
}
|
||||
|
||||
int32_t bad_kb_conn_apply(BadKbApp* app) {
|
||||
if(app->is_bt) {
|
||||
// Shorthands so this bs is readable
|
||||
BadKbConfig* cfg = app->set_bt_id ? &app->id_config : &app->config;
|
||||
FuriHalBtProfile kbd = FuriHalBtProfileHidKeyboard;
|
||||
|
||||
// Setup new config
|
||||
bt_timeout = bt_hid_delays[LevelRssi39_0];
|
||||
bt_disconnect(app->bt);
|
||||
furi_delay_ms(200);
|
||||
bt_keys_storage_set_storage_path(app->bt, BAD_KB_KEYS_PATH);
|
||||
furi_hal_bt_set_profile_adv_name(kbd, cfg->bt_name);
|
||||
if(app->bt_remember) {
|
||||
furi_hal_bt_set_profile_mac_addr(kbd, BAD_KB_BOUND_MAC);
|
||||
furi_hal_bt_set_profile_pairing_method(kbd, GapPairingPinCodeVerifyYesNo);
|
||||
} else {
|
||||
furi_hal_bt_set_profile_mac_addr(kbd, cfg->bt_mac);
|
||||
furi_hal_bt_set_profile_pairing_method(kbd, GapPairingNone);
|
||||
}
|
||||
|
||||
// Set profile, restart BT, adjust defaults
|
||||
furi_check(bt_set_profile(app->bt, BtProfileHidKeyboard));
|
||||
|
||||
// Advertise even if BT is off in settings
|
||||
furi_hal_bt_start_advertising();
|
||||
|
||||
// Toggle key callback after since BT restart resets it
|
||||
if(app->bt_remember) {
|
||||
bt_enable_peer_key_update(app->bt);
|
||||
} else {
|
||||
bt_disable_peer_key_update(app->bt);
|
||||
}
|
||||
|
||||
app->conn_mode = BadKbConnModeBt;
|
||||
|
||||
} else {
|
||||
// Unlock RPC connections
|
||||
furi_hal_usb_unlock();
|
||||
|
||||
// Context will apply with set_config only if pointer address is different, so we use a copy
|
||||
FuriHalUsbHidConfig* hid_cfg = malloc(sizeof(FuriHalUsbHidConfig));
|
||||
memcpy(
|
||||
hid_cfg,
|
||||
app->set_usb_id ? &app->id_config.usb_cfg : &app->config.usb_cfg,
|
||||
sizeof(FuriHalUsbHidConfig));
|
||||
furi_check(furi_hal_usb_set_config(&usb_hid, hid_cfg));
|
||||
if(app->hid_cfg) free(app->hid_cfg);
|
||||
app->hid_cfg = hid_cfg;
|
||||
|
||||
app->conn_mode = BadKbConnModeUsb;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bad_kb_conn_reset(BadKbApp* app) {
|
||||
if(app->conn_mode == BadKbConnModeBt) {
|
||||
// TODO: maybe also restore BT profile?
|
||||
bt_disconnect(app->bt);
|
||||
furi_delay_ms(200);
|
||||
bt_keys_storage_set_default_path(app->bt);
|
||||
FuriHalBtProfile kbd = FuriHalBtProfileHidKeyboard;
|
||||
furi_hal_bt_set_profile_mac_addr(kbd, app->prev_bt_mac);
|
||||
furi_hal_bt_set_profile_adv_name(kbd, app->prev_bt_name);
|
||||
furi_hal_bt_set_profile_pairing_method(kbd, app->prev_bt_mode);
|
||||
furi_check(bt_set_profile(app->bt, BtProfileSerial));
|
||||
bt_enable_peer_key_update(app->bt);
|
||||
|
||||
} else if(app->conn_mode == BadKbConnModeUsb) {
|
||||
// TODO: maybe also restore USB context?
|
||||
furi_check(furi_hal_usb_set_config(app->prev_usb_mode, NULL));
|
||||
}
|
||||
|
||||
app->conn_mode = BadKbConnModeNone;
|
||||
}
|
||||
|
||||
void bad_kb_config_adjust(BadKbConfig* cfg) {
|
||||
// Avoid empty name
|
||||
if(strcmp(cfg->bt_name, "") == 0) {
|
||||
snprintf(cfg->bt_name, BAD_KB_NAME_LEN, "Control %s", furi_hal_version_get_name_ptr());
|
||||
}
|
||||
|
||||
// MAC is adjusted by furi_hal_bt, adjust here too so it matches after applying
|
||||
const uint8_t* normal_mac = furi_hal_version_get_ble_mac();
|
||||
uint8_t empty_mac[BAD_KB_MAC_LEN] = FURI_HAL_BT_EMPTY_MAC_ADDR;
|
||||
uint8_t default_mac[BAD_KB_MAC_LEN] = FURI_HAL_BT_DEFAULT_MAC_ADDR;
|
||||
if(memcmp(cfg->bt_mac, empty_mac, BAD_KB_MAC_LEN) == 0 ||
|
||||
memcmp(cfg->bt_mac, normal_mac, BAD_KB_MAC_LEN) == 0 ||
|
||||
memcmp(cfg->bt_mac, default_mac, BAD_KB_MAC_LEN) == 0) {
|
||||
memcpy(cfg->bt_mac, normal_mac, BAD_KB_MAC_LEN);
|
||||
cfg->bt_mac[2]++;
|
||||
}
|
||||
|
||||
// Use defaults if vid or pid are unset
|
||||
if(cfg->usb_cfg.vid == 0) cfg->usb_cfg.vid = HID_VID_DEFAULT;
|
||||
if(cfg->usb_cfg.pid == 0) cfg->usb_cfg.pid = HID_PID_DEFAULT;
|
||||
}
|
||||
|
||||
void bad_kb_config_refresh(BadKbApp* app) {
|
||||
bt_set_status_changed_callback(app->bt, NULL, NULL);
|
||||
furi_hal_hid_set_state_callback(NULL, NULL);
|
||||
if(app->bad_kb_script) {
|
||||
furi_thread_flags_set(furi_thread_get_id(app->bad_kb_script->thread), WorkerEvtDisconnect);
|
||||
}
|
||||
if(app->conn_init_thread) {
|
||||
furi_thread_join(app->conn_init_thread);
|
||||
}
|
||||
|
||||
bool apply = false;
|
||||
if(app->is_bt) {
|
||||
BadKbConfig* cfg = app->set_bt_id ? &app->id_config : &app->config;
|
||||
bad_kb_config_adjust(cfg);
|
||||
|
||||
if(app->conn_mode != BadKbConnModeBt) {
|
||||
apply = true;
|
||||
bad_kb_conn_reset(app);
|
||||
} else {
|
||||
apply = apply || strncmp(
|
||||
cfg->bt_name,
|
||||
furi_hal_bt_get_profile_adv_name(FuriHalBtProfileHidKeyboard),
|
||||
BAD_KB_NAME_LEN);
|
||||
apply = apply || memcmp(
|
||||
app->bt_remember ? BAD_KB_BOUND_MAC : cfg->bt_mac,
|
||||
furi_hal_bt_get_profile_mac_addr(FuriHalBtProfileHidKeyboard),
|
||||
BAD_KB_MAC_LEN);
|
||||
}
|
||||
} else {
|
||||
BadKbConfig* cfg = app->set_usb_id ? &app->id_config : &app->config;
|
||||
bad_kb_config_adjust(cfg);
|
||||
|
||||
if(app->conn_mode != BadKbConnModeUsb) {
|
||||
apply = true;
|
||||
bad_kb_conn_reset(app);
|
||||
} else {
|
||||
void* ctx;
|
||||
if(furi_hal_usb_get_config() == &usb_hid &&
|
||||
(ctx = furi_hal_usb_get_config_context()) != NULL) {
|
||||
FuriHalUsbHidConfig* cur = ctx;
|
||||
apply = apply || cfg->usb_cfg.vid != cur->vid;
|
||||
apply = apply || cfg->usb_cfg.pid != cur->pid;
|
||||
apply = apply || strncmp(cfg->usb_cfg.manuf, cur->manuf, sizeof(cur->manuf));
|
||||
apply = apply || strncmp(cfg->usb_cfg.product, cur->product, sizeof(cur->product));
|
||||
} else {
|
||||
apply = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(apply) {
|
||||
bad_kb_conn_apply(app);
|
||||
}
|
||||
|
||||
if(app->bad_kb_script) {
|
||||
BadKbScript* script = app->bad_kb_script;
|
||||
script->st.is_bt = app->is_bt;
|
||||
script->bt = app->is_bt ? app->bt : NULL;
|
||||
bool connected;
|
||||
if(app->is_bt) {
|
||||
bt_set_status_changed_callback(app->bt, bad_kb_bt_hid_state_callback, script);
|
||||
connected = furi_hal_bt_is_connected();
|
||||
} else {
|
||||
furi_hal_hid_set_state_callback(bad_kb_usb_hid_state_callback, script);
|
||||
connected = furi_hal_hid_is_connected();
|
||||
}
|
||||
if(connected) {
|
||||
furi_thread_flags_set(furi_thread_get_id(script->thread), WorkerEvtConnect);
|
||||
}
|
||||
}
|
||||
|
||||
// Reload config page
|
||||
scene_manager_next_scene(app->scene_manager, BadKbSceneConfig);
|
||||
scene_manager_previous_scene(app->scene_manager);
|
||||
|
||||
// Update settings
|
||||
if(xtreme_settings.bad_bt != app->is_bt ||
|
||||
xtreme_settings.bad_bt_remember != app->bt_remember) {
|
||||
xtreme_settings.bad_bt = app->is_bt;
|
||||
xtreme_settings.bad_bt_remember = app->bt_remember;
|
||||
xtreme_settings_save();
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t bad_kb_worker(void* context) {
|
||||
BadKbScript* bad_kb = context;
|
||||
|
||||
@@ -838,14 +646,14 @@ static int32_t bad_kb_worker(void* context) {
|
||||
} else if(flags & WorkerEvtStartStop) {
|
||||
worker_state = BadKbStateIdle; // Stop executing script
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_release_all();
|
||||
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||
} else {
|
||||
furi_hal_hid_kb_release_all();
|
||||
}
|
||||
} else if(flags & WorkerEvtDisconnect) {
|
||||
worker_state = BadKbStateNotConnected; // Disconnected
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_release_all();
|
||||
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||
} else {
|
||||
furi_hal_hid_kb_release_all();
|
||||
}
|
||||
@@ -871,7 +679,7 @@ static int32_t bad_kb_worker(void* context) {
|
||||
worker_state = BadKbStateScriptError;
|
||||
bad_kb->st.state = worker_state;
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_release_all();
|
||||
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||
} else {
|
||||
furi_hal_hid_kb_release_all();
|
||||
}
|
||||
@@ -880,7 +688,7 @@ static int32_t bad_kb_worker(void* context) {
|
||||
worker_state = BadKbStateIdle;
|
||||
bad_kb->st.state = BadKbStateDone;
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_release_all();
|
||||
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||
} else {
|
||||
furi_hal_hid_kb_release_all();
|
||||
}
|
||||
@@ -917,7 +725,7 @@ static int32_t bad_kb_worker(void* context) {
|
||||
} else if(flags & WorkerEvtDisconnect) {
|
||||
worker_state = BadKbStateNotConnected; // Disconnected
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_release_all();
|
||||
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||
} else {
|
||||
furi_hal_hid_kb_release_all();
|
||||
}
|
||||
@@ -940,7 +748,7 @@ static int32_t bad_kb_worker(void* context) {
|
||||
worker_state = BadKbStateIdle; // Stop executing script
|
||||
bad_kb->st.state = worker_state;
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_release_all();
|
||||
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||
} else {
|
||||
furi_hal_hid_kb_release_all();
|
||||
}
|
||||
@@ -948,7 +756,7 @@ static int32_t bad_kb_worker(void* context) {
|
||||
worker_state = BadKbStateNotConnected; // Disconnected
|
||||
bad_kb->st.state = worker_state;
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_release_all();
|
||||
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||
} else {
|
||||
furi_hal_hid_kb_release_all();
|
||||
}
|
||||
@@ -983,14 +791,14 @@ static int32_t bad_kb_worker(void* context) {
|
||||
} else if(flags & WorkerEvtStartStop) {
|
||||
worker_state = BadKbStateIdle; // Stop executing script
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_release_all();
|
||||
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||
} else {
|
||||
furi_hal_hid_kb_release_all();
|
||||
}
|
||||
} else if(flags & WorkerEvtDisconnect) {
|
||||
worker_state = BadKbStateNotConnected; // Disconnected
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_release_all();
|
||||
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||
} else {
|
||||
furi_hal_hid_kb_release_all();
|
||||
}
|
||||
|
||||
@@ -6,18 +6,9 @@ extern "C" {
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <bt/bt_service/bt_i.h>
|
||||
#include <bt/bt_service/bt.h>
|
||||
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/modules/widget.h>
|
||||
#include <gui/modules/variable_item_list.h>
|
||||
#include <gui/modules/text_input.h>
|
||||
#include <gui/modules/byte_input.h>
|
||||
#include <gui/modules/loading.h>
|
||||
#include "../views/bad_kb_view.h"
|
||||
#include "../bad_kb_paths.h"
|
||||
|
||||
#define FILE_BUFFER_LEN 16
|
||||
#include "../bad_kb_app.h"
|
||||
|
||||
typedef enum {
|
||||
LevelRssi122_100,
|
||||
@@ -33,6 +24,14 @@ extern const uint8_t bt_hid_delays[LevelRssiNum];
|
||||
|
||||
extern uint8_t bt_timeout;
|
||||
|
||||
typedef enum {
|
||||
WorkerEvtStartStop = (1 << 0),
|
||||
WorkerEvtPauseResume = (1 << 1),
|
||||
WorkerEvtEnd = (1 << 2),
|
||||
WorkerEvtConnect = (1 << 3),
|
||||
WorkerEvtDisconnect = (1 << 4),
|
||||
} WorkerEvtFlags;
|
||||
|
||||
typedef enum {
|
||||
BadKbStateInit,
|
||||
BadKbStateNotConnected,
|
||||
@@ -48,7 +47,7 @@ typedef enum {
|
||||
BadKbStateFileError,
|
||||
} BadKbWorkerState;
|
||||
|
||||
struct BadKbState {
|
||||
typedef struct {
|
||||
BadKbWorkerState state;
|
||||
bool is_bt;
|
||||
uint32_t pin;
|
||||
@@ -58,36 +57,9 @@ struct BadKbState {
|
||||
size_t error_line;
|
||||
char error[64];
|
||||
uint32_t elapsed;
|
||||
};
|
||||
} BadKbState;
|
||||
|
||||
typedef struct BadKbApp BadKbApp;
|
||||
|
||||
typedef struct {
|
||||
FuriThread* thread;
|
||||
BadKbState st;
|
||||
|
||||
FuriString* file_path;
|
||||
FuriString* keyboard_layout;
|
||||
uint8_t file_buf[FILE_BUFFER_LEN + 1];
|
||||
uint8_t buf_start;
|
||||
uint8_t buf_len;
|
||||
bool file_end;
|
||||
|
||||
uint32_t defdelay;
|
||||
uint32_t stringdelay;
|
||||
uint16_t layout[128];
|
||||
|
||||
FuriString* line;
|
||||
FuriString* line_prev;
|
||||
uint32_t repeat_cnt;
|
||||
uint8_t key_hold_nb;
|
||||
|
||||
FuriString* string_print;
|
||||
size_t string_print_pos;
|
||||
|
||||
Bt* bt;
|
||||
BadKbApp* app;
|
||||
} BadKbScript;
|
||||
typedef struct BadKbScript BadKbScript;
|
||||
|
||||
BadKbScript* bad_kb_script_open(FuriString* file_path, Bt* bt, BadKbApp* app);
|
||||
|
||||
@@ -105,79 +77,9 @@ void bad_kb_script_pause_resume(BadKbScript* bad_kb);
|
||||
|
||||
BadKbState* bad_kb_script_get_state(BadKbScript* bad_kb);
|
||||
|
||||
#define BAD_KB_NAME_LEN FURI_HAL_BT_ADV_NAME_LENGTH
|
||||
#define BAD_KB_MAC_LEN GAP_MAC_ADDR_SIZE
|
||||
#define BAD_KB_USB_LEN HID_MANUF_PRODUCT_NAME_LEN
|
||||
void bad_kb_bt_hid_state_callback(BtStatus status, void* context);
|
||||
|
||||
extern const uint8_t BAD_KB_EMPTY_MAC[BAD_KB_MAC_LEN];
|
||||
extern uint8_t BAD_KB_BOUND_MAC[BAD_KB_MAC_LEN]; // For remember mode
|
||||
|
||||
typedef enum {
|
||||
BadKbAppErrorNoFiles,
|
||||
} BadKbAppError;
|
||||
|
||||
typedef struct {
|
||||
char bt_name[BAD_KB_NAME_LEN];
|
||||
uint8_t bt_mac[BAD_KB_MAC_LEN];
|
||||
FuriHalUsbHidConfig usb_cfg;
|
||||
} BadKbConfig;
|
||||
|
||||
typedef enum {
|
||||
BadKbConnModeNone,
|
||||
BadKbConnModeUsb,
|
||||
BadKbConnModeBt,
|
||||
} BadKbConnMode;
|
||||
|
||||
struct BadKbApp {
|
||||
Gui* gui;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
SceneManager* scene_manager;
|
||||
NotificationApp* notifications;
|
||||
DialogsApp* dialogs;
|
||||
Widget* widget;
|
||||
VariableItemList* var_item_list;
|
||||
TextInput* text_input;
|
||||
ByteInput* byte_input;
|
||||
Loading* loading;
|
||||
char usb_name_buf[BAD_KB_USB_LEN];
|
||||
uint16_t usb_vidpid_buf[2];
|
||||
char bt_name_buf[BAD_KB_NAME_LEN];
|
||||
uint8_t bt_mac_buf[BAD_KB_MAC_LEN];
|
||||
|
||||
BadKbAppError error;
|
||||
FuriString* file_path;
|
||||
FuriString* keyboard_layout;
|
||||
BadKb* bad_kb_view;
|
||||
BadKbScript* bad_kb_script;
|
||||
|
||||
Bt* bt;
|
||||
bool is_bt;
|
||||
bool bt_remember;
|
||||
BadKbConfig config; // User options
|
||||
BadKbConfig id_config; // ID and BT_ID values
|
||||
|
||||
bool set_usb_id;
|
||||
bool set_bt_id;
|
||||
bool has_usb_id;
|
||||
bool has_bt_id;
|
||||
|
||||
GapPairing prev_bt_mode;
|
||||
char prev_bt_name[BAD_KB_NAME_LEN];
|
||||
uint8_t prev_bt_mac[BAD_KB_MAC_LEN];
|
||||
FuriHalUsbInterface* prev_usb_mode;
|
||||
|
||||
FuriHalUsbHidConfig* hid_cfg;
|
||||
BadKbConnMode conn_mode;
|
||||
FuriThread* conn_init_thread;
|
||||
};
|
||||
|
||||
int32_t bad_kb_conn_apply(BadKbApp* app);
|
||||
|
||||
void bad_kb_conn_reset(BadKbApp* app);
|
||||
|
||||
void bad_kb_config_refresh(BadKbApp* app);
|
||||
|
||||
void bad_kb_config_adjust(BadKbConfig* cfg);
|
||||
void bad_kb_usb_hid_state_callback(bool state, void* context);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "../bad_kb_app_i.h"
|
||||
#include <furi_hal.h>
|
||||
#include <furi_hal_bt_hid.h>
|
||||
#include <furi_hal_usb_hid.h>
|
||||
#include "ble_hid.h"
|
||||
#include "ducky_script.h"
|
||||
#include "ducky_script_i.h"
|
||||
|
||||
@@ -83,10 +84,11 @@ static int32_t ducky_fnc_sysrq(BadKbScript* bad_kb, const char* line, int32_t pa
|
||||
line = &line[ducky_get_command_len(line) + 1];
|
||||
uint16_t key = ducky_get_keycode(bad_kb, line, true);
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_press(KEY_MOD_LEFT_ALT | HID_KEYBOARD_PRINT_SCREEN);
|
||||
furi_hal_bt_hid_kb_press(key);
|
||||
ble_profile_hid_kb_press(
|
||||
bad_kb->app->ble_hid, KEY_MOD_LEFT_ALT | HID_KEYBOARD_PRINT_SCREEN);
|
||||
ble_profile_hid_kb_press(bad_kb->app->ble_hid, key);
|
||||
furi_delay_ms(bt_timeout);
|
||||
furi_hal_bt_hid_kb_release_all();
|
||||
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||
} else {
|
||||
furi_hal_hid_kb_press(KEY_MOD_LEFT_ALT | HID_KEYBOARD_PRINT_SCREEN);
|
||||
furi_hal_hid_kb_press(key);
|
||||
@@ -132,7 +134,7 @@ static int32_t ducky_fnc_hold(BadKbScript* bad_kb, const char* line, int32_t par
|
||||
return ducky_error(bad_kb, "Too many keys are hold");
|
||||
}
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_press(key);
|
||||
ble_profile_hid_kb_press(bad_kb->app->ble_hid, key);
|
||||
} else {
|
||||
furi_hal_hid_kb_press(key);
|
||||
}
|
||||
@@ -152,7 +154,7 @@ static int32_t ducky_fnc_release(BadKbScript* bad_kb, const char* line, int32_t
|
||||
}
|
||||
bad_kb->key_hold_nb--;
|
||||
if(bad_kb->bt) {
|
||||
furi_hal_bt_hid_kb_release(key);
|
||||
ble_profile_hid_kb_release(bad_kb->app->ble_hid, key);
|
||||
} else {
|
||||
furi_hal_hid_kb_release(key);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,35 @@ extern "C" {
|
||||
#define SCRIPT_STATE_STRING_START (-5)
|
||||
#define SCRIPT_STATE_WAIT_FOR_BTN (-6)
|
||||
|
||||
#define FILE_BUFFER_LEN 16
|
||||
|
||||
struct BadKbScript {
|
||||
FuriThread* thread;
|
||||
BadKbState st;
|
||||
|
||||
FuriString* file_path;
|
||||
FuriString* keyboard_layout;
|
||||
uint8_t file_buf[FILE_BUFFER_LEN + 1];
|
||||
uint8_t buf_start;
|
||||
uint8_t buf_len;
|
||||
bool file_end;
|
||||
|
||||
uint32_t defdelay;
|
||||
uint32_t stringdelay;
|
||||
uint16_t layout[128];
|
||||
|
||||
FuriString* line;
|
||||
FuriString* line_prev;
|
||||
uint32_t repeat_cnt;
|
||||
uint8_t key_hold_nb;
|
||||
|
||||
FuriString* string_print;
|
||||
size_t string_print_pos;
|
||||
|
||||
Bt* bt;
|
||||
BadKbApp* app;
|
||||
};
|
||||
|
||||
uint16_t ducky_get_keycode(BadKbScript* bad_kb, const char* param, bool accept_chars);
|
||||
|
||||
uint32_t ducky_get_command_len(const char* line);
|
||||
|
||||
0
applications/main/bad_kb/resources/badkb/assets/layouts/sk-SK.kl
Normal file → Executable file
0
applications/main/bad_kb/resources/badkb/assets/layouts/sk-SK.kl
Normal file → Executable file
@@ -1,5 +1,4 @@
|
||||
#include "../bad_kb_app.h"
|
||||
#include "../helpers/ducky_script.h"
|
||||
#include "../bad_kb_app_i.h"
|
||||
#include "furi_hal_power.h"
|
||||
#include "furi_hal_usb.h"
|
||||
#include <xtreme/xtreme.h>
|
||||
@@ -143,7 +142,7 @@ bool bad_kb_scene_config_on_event(void* context, SceneManagerEvent event) {
|
||||
scene_manager_next_scene(bad_kb->scene_manager, BadKbSceneConfigBtMac);
|
||||
break;
|
||||
case VarItemListIndexBtRandomizeMac:
|
||||
furi_hal_random_fill_buf(bad_kb->config.bt_mac, BAD_KB_MAC_LEN);
|
||||
furi_hal_random_fill_buf(bad_kb->config.ble.mac, sizeof(bad_kb->config.ble.mac));
|
||||
bad_kb_config_refresh(bad_kb);
|
||||
break;
|
||||
default:
|
||||
@@ -167,8 +166,8 @@ bool bad_kb_scene_config_on_event(void* context, SceneManagerEvent event) {
|
||||
case VarItemListIndexUsbRandomizeVidPid:
|
||||
furi_hal_random_fill_buf(
|
||||
(void*)bad_kb->usb_vidpid_buf, sizeof(bad_kb->usb_vidpid_buf));
|
||||
bad_kb->config.usb_cfg.vid = bad_kb->usb_vidpid_buf[0];
|
||||
bad_kb->config.usb_cfg.pid = bad_kb->usb_vidpid_buf[1];
|
||||
bad_kb->config.usb.vid = bad_kb->usb_vidpid_buf[0];
|
||||
bad_kb->config.usb.pid = bad_kb->usb_vidpid_buf[1];
|
||||
bad_kb_config_refresh(bad_kb);
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../bad_kb_app.h"
|
||||
#include "../bad_kb_app_i.h"
|
||||
|
||||
void bad_kb_scene_config_bt_mac_byte_input_callback(void* context) {
|
||||
BadKbApp* bad_kb = context;
|
||||
@@ -10,7 +10,7 @@ void bad_kb_scene_config_bt_mac_on_enter(void* context) {
|
||||
BadKbApp* bad_kb = context;
|
||||
ByteInput* byte_input = bad_kb->byte_input;
|
||||
|
||||
memmove(bad_kb->bt_mac_buf, bad_kb->config.bt_mac, BAD_KB_MAC_LEN);
|
||||
memcpy(bad_kb->bt_mac_buf, bad_kb->config.ble.mac, sizeof(bad_kb->bt_mac_buf));
|
||||
furi_hal_bt_reverse_mac_addr(bad_kb->bt_mac_buf);
|
||||
byte_input_set_header_text(byte_input, "Set BT MAC address");
|
||||
|
||||
@@ -20,7 +20,7 @@ void bad_kb_scene_config_bt_mac_on_enter(void* context) {
|
||||
NULL,
|
||||
bad_kb,
|
||||
bad_kb->bt_mac_buf,
|
||||
BAD_KB_MAC_LEN);
|
||||
sizeof(bad_kb->bt_mac_buf));
|
||||
|
||||
view_dispatcher_switch_to_view(bad_kb->view_dispatcher, BadKbAppViewByteInput);
|
||||
}
|
||||
@@ -33,7 +33,7 @@ bool bad_kb_scene_config_bt_mac_on_event(void* context, SceneManagerEvent event)
|
||||
consumed = true;
|
||||
if(event.event == BadKbAppCustomEventByteInputDone) {
|
||||
furi_hal_bt_reverse_mac_addr(bad_kb->bt_mac_buf);
|
||||
memmove(bad_kb->config.bt_mac, bad_kb->bt_mac_buf, BAD_KB_MAC_LEN);
|
||||
memcpy(bad_kb->config.ble.mac, bad_kb->bt_mac_buf, sizeof(bad_kb->config.ble.mac));
|
||||
bad_kb_config_refresh(bad_kb);
|
||||
}
|
||||
scene_manager_previous_scene(bad_kb->scene_manager);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../bad_kb_app.h"
|
||||
#include "../bad_kb_app_i.h"
|
||||
|
||||
static void bad_kb_scene_config_bt_name_text_input_callback(void* context) {
|
||||
BadKbApp* bad_kb = context;
|
||||
@@ -10,7 +10,7 @@ void bad_kb_scene_config_bt_name_on_enter(void* context) {
|
||||
BadKbApp* bad_kb = context;
|
||||
TextInput* text_input = bad_kb->text_input;
|
||||
|
||||
strlcpy(bad_kb->bt_name_buf, bad_kb->config.bt_name, BAD_KB_NAME_LEN);
|
||||
strlcpy(bad_kb->bt_name_buf, bad_kb->config.ble.name, sizeof(bad_kb->bt_name_buf));
|
||||
text_input_set_header_text(text_input, "Set BT device name");
|
||||
|
||||
text_input_set_result_callback(
|
||||
@@ -18,7 +18,7 @@ void bad_kb_scene_config_bt_name_on_enter(void* context) {
|
||||
bad_kb_scene_config_bt_name_text_input_callback,
|
||||
bad_kb,
|
||||
bad_kb->bt_name_buf,
|
||||
BAD_KB_NAME_LEN,
|
||||
sizeof(bad_kb->bt_name_buf),
|
||||
true);
|
||||
|
||||
view_dispatcher_switch_to_view(bad_kb->view_dispatcher, BadKbAppViewTextInput);
|
||||
@@ -31,7 +31,7 @@ bool bad_kb_scene_config_bt_name_on_event(void* context, SceneManagerEvent event
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
if(event.event == BadKbAppCustomEventTextInputDone) {
|
||||
strlcpy(bad_kb->config.bt_name, bad_kb->bt_name_buf, BAD_KB_NAME_LEN);
|
||||
strlcpy(bad_kb->config.ble.name, bad_kb->bt_name_buf, sizeof(bad_kb->config.ble.name));
|
||||
bad_kb_config_refresh(bad_kb);
|
||||
}
|
||||
scene_manager_previous_scene(bad_kb->scene_manager);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../bad_kb_app.h"
|
||||
#include "../bad_kb_app_i.h"
|
||||
#include "furi_hal_power.h"
|
||||
#include "furi_hal_usb.h"
|
||||
#include <storage/storage.h>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../bad_kb_app.h"
|
||||
#include "../bad_kb_app_i.h"
|
||||
|
||||
static void bad_kb_scene_config_usb_name_text_input_callback(void* context) {
|
||||
BadKbApp* bad_kb = context;
|
||||
@@ -11,10 +11,10 @@ void bad_kb_scene_config_usb_name_on_enter(void* context) {
|
||||
TextInput* text_input = bad_kb->text_input;
|
||||
|
||||
if(scene_manager_get_scene_state(bad_kb->scene_manager, BadKbSceneConfigUsbName)) {
|
||||
strlcpy(bad_kb->usb_name_buf, bad_kb->config.usb_cfg.manuf, BAD_KB_USB_LEN);
|
||||
strlcpy(bad_kb->usb_name_buf, bad_kb->config.usb.manuf, sizeof(bad_kb->usb_name_buf));
|
||||
text_input_set_header_text(text_input, "Set USB manufacturer name");
|
||||
} else {
|
||||
strlcpy(bad_kb->usb_name_buf, bad_kb->config.usb_cfg.product, BAD_KB_USB_LEN);
|
||||
strlcpy(bad_kb->usb_name_buf, bad_kb->config.usb.product, sizeof(bad_kb->usb_name_buf));
|
||||
text_input_set_header_text(text_input, "Set USB product name");
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ void bad_kb_scene_config_usb_name_on_enter(void* context) {
|
||||
bad_kb_scene_config_usb_name_text_input_callback,
|
||||
bad_kb,
|
||||
bad_kb->usb_name_buf,
|
||||
BAD_KB_USB_LEN,
|
||||
sizeof(bad_kb->usb_name_buf),
|
||||
true);
|
||||
|
||||
view_dispatcher_switch_to_view(bad_kb->view_dispatcher, BadKbAppViewTextInput);
|
||||
@@ -37,9 +37,15 @@ bool bad_kb_scene_config_usb_name_on_event(void* context, SceneManagerEvent even
|
||||
consumed = true;
|
||||
if(event.event == BadKbAppCustomEventTextInputDone) {
|
||||
if(scene_manager_get_scene_state(bad_kb->scene_manager, BadKbSceneConfigUsbName)) {
|
||||
strlcpy(bad_kb->config.usb_cfg.manuf, bad_kb->usb_name_buf, BAD_KB_USB_LEN);
|
||||
strlcpy(
|
||||
bad_kb->config.usb.manuf,
|
||||
bad_kb->usb_name_buf,
|
||||
sizeof(bad_kb->config.usb.product));
|
||||
} else {
|
||||
strlcpy(bad_kb->config.usb_cfg.product, bad_kb->usb_name_buf, BAD_KB_USB_LEN);
|
||||
strlcpy(
|
||||
bad_kb->config.usb.product,
|
||||
bad_kb->usb_name_buf,
|
||||
sizeof(bad_kb->config.usb.product));
|
||||
}
|
||||
bad_kb_config_refresh(bad_kb);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../bad_kb_app.h"
|
||||
#include "../bad_kb_app_i.h"
|
||||
|
||||
void bad_kb_scene_config_usb_vidpid_byte_input_callback(void* context) {
|
||||
BadKbApp* bad_kb = context;
|
||||
@@ -10,8 +10,8 @@ void bad_kb_scene_config_usb_vidpid_on_enter(void* context) {
|
||||
BadKbApp* bad_kb = context;
|
||||
ByteInput* byte_input = bad_kb->byte_input;
|
||||
|
||||
bad_kb->usb_vidpid_buf[0] = __REVSH(bad_kb->config.usb_cfg.vid);
|
||||
bad_kb->usb_vidpid_buf[1] = __REVSH(bad_kb->config.usb_cfg.pid);
|
||||
bad_kb->usb_vidpid_buf[0] = __REVSH(bad_kb->config.usb.vid);
|
||||
bad_kb->usb_vidpid_buf[1] = __REVSH(bad_kb->config.usb.pid);
|
||||
byte_input_set_header_text(byte_input, "Set USB VID:PID");
|
||||
|
||||
byte_input_set_result_callback(
|
||||
@@ -32,8 +32,8 @@ bool bad_kb_scene_config_usb_vidpid_on_event(void* context, SceneManagerEvent ev
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
if(event.event == BadKbAppCustomEventByteInputDone) {
|
||||
bad_kb->config.usb_cfg.vid = __REVSH(bad_kb->usb_vidpid_buf[0]);
|
||||
bad_kb->config.usb_cfg.pid = __REVSH(bad_kb->usb_vidpid_buf[1]);
|
||||
bad_kb->config.usb.vid = __REVSH(bad_kb->usb_vidpid_buf[0]);
|
||||
bad_kb->config.usb.pid = __REVSH(bad_kb->usb_vidpid_buf[1]);
|
||||
bad_kb_config_refresh(bad_kb);
|
||||
}
|
||||
scene_manager_previous_scene(bad_kb->scene_manager);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../bad_kb_app.h"
|
||||
#include "../bad_kb_app_i.h"
|
||||
|
||||
static void
|
||||
bad_kb_scene_error_event_callback(GuiButtonType result, InputType type, void* context) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../bad_kb_app.h"
|
||||
#include "../bad_kb_app_i.h"
|
||||
#include <furi_hal_power.h>
|
||||
#include <furi_hal_usb.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "../helpers/ducky_script.h"
|
||||
#include "../bad_kb_app.h"
|
||||
#include "../bad_kb_app_i.h"
|
||||
#include "../views/bad_kb_view.h"
|
||||
#include <furi_hal.h>
|
||||
#include "toolbox/path.h"
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
#include "../bad_kb_app_i.h"
|
||||
#include "bad_kb_view.h"
|
||||
#include "../helpers/ducky_script.h"
|
||||
#include "../bad_kb_app.h"
|
||||
#include <toolbox/path.h>
|
||||
#include <gui/elements.h>
|
||||
#include <assets_icons.h>
|
||||
#include <xtreme/xtreme.h>
|
||||
#include <bt/bt_service/bt_i.h>
|
||||
|
||||
#define MAX_NAME_LEN 64
|
||||
|
||||
struct BadKb {
|
||||
View* view;
|
||||
BadKbButtonCallback callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char file_name[MAX_NAME_LEN];
|
||||
char layout[MAX_NAME_LEN];
|
||||
@@ -44,6 +51,8 @@ static void bad_kb_draw_callback(Canvas* canvas, void* _model) {
|
||||
canvas_draw_str(
|
||||
canvas, 2, 8 + canvas_current_font_height(canvas), furi_string_get_cstr(disp_str));
|
||||
|
||||
furi_string_reset(disp_str);
|
||||
|
||||
canvas_draw_icon(canvas, 22, 24, &I_UsbTree_48x22);
|
||||
|
||||
if((state == BadKbStateIdle) || (state == BadKbStateDone) ||
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../helpers/ducky_script.h"
|
||||
|
||||
typedef struct BadKb BadKb;
|
||||
typedef void (*BadKbButtonCallback)(InputKey key, void* context);
|
||||
|
||||
typedef struct {
|
||||
View* view;
|
||||
BadKbButtonCallback callback;
|
||||
void* context;
|
||||
} BadKb;
|
||||
|
||||
typedef struct BadKbState BadKbState;
|
||||
|
||||
BadKb* bad_kb_alloc();
|
||||
|
||||
void bad_kb_free(BadKb* bad_kb);
|
||||
|
||||
@@ -61,7 +61,7 @@ static const char* opal_usages[14] = {
|
||||
};
|
||||
|
||||
// Opal file 0x7 structure. Assumes a little-endian CPU.
|
||||
typedef struct __attribute__((__packed__)) {
|
||||
typedef struct FURI_PACKED {
|
||||
uint32_t serial : 32;
|
||||
uint8_t check_digit : 4;
|
||||
bool blocked : 1;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <ble/ble.h>
|
||||
#include "bt_settings.h"
|
||||
#include "bt_service/bt.h"
|
||||
#include <profiles/serial_profile.h>
|
||||
|
||||
static void bt_cli_command_hci_info(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(cli);
|
||||
@@ -45,7 +46,7 @@ static void bt_cli_command_carrier_tx(Cli* cli, FuriString* args, void* context)
|
||||
}
|
||||
furi_hal_bt_stop_tone_tx();
|
||||
|
||||
bt_set_profile(bt, BtProfileSerial);
|
||||
bt_profile_restore_default(bt);
|
||||
furi_record_close(RECORD_BT);
|
||||
} while(false);
|
||||
}
|
||||
@@ -76,7 +77,7 @@ static void bt_cli_command_carrier_rx(Cli* cli, FuriString* args, void* context)
|
||||
|
||||
furi_hal_bt_stop_packet_test();
|
||||
|
||||
bt_set_profile(bt, BtProfileSerial);
|
||||
bt_profile_restore_default(bt);
|
||||
furi_record_close(RECORD_BT);
|
||||
} while(false);
|
||||
}
|
||||
@@ -124,7 +125,7 @@ static void bt_cli_command_packet_tx(Cli* cli, FuriString* args, void* context)
|
||||
furi_hal_bt_stop_packet_test();
|
||||
printf("Transmitted %lu packets", furi_hal_bt_get_transmitted_packets());
|
||||
|
||||
bt_set_profile(bt, BtProfileSerial);
|
||||
bt_profile_restore_default(bt);
|
||||
furi_record_close(RECORD_BT);
|
||||
} while(false);
|
||||
}
|
||||
@@ -159,7 +160,7 @@ static void bt_cli_command_packet_rx(Cli* cli, FuriString* args, void* context)
|
||||
uint16_t packets_received = furi_hal_bt_stop_packet_test();
|
||||
printf("Received %hu packets", packets_received);
|
||||
|
||||
bt_set_profile(bt, BtProfileSerial);
|
||||
bt_profile_restore_default(bt);
|
||||
furi_record_close(RECORD_BT);
|
||||
} while(false);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
#include "bt_i.h"
|
||||
#include "bt_keys_storage.h"
|
||||
|
||||
#include <core/check.h>
|
||||
#include <furi_hal_bt.h>
|
||||
#include <services/battery_service.h>
|
||||
#include <notification/notification_messages.h>
|
||||
#include <gui/elements.h>
|
||||
#include <assets_icons.h>
|
||||
#include <profiles/serial_profile.h>
|
||||
|
||||
#define TAG "BtSrv"
|
||||
|
||||
@@ -12,14 +15,21 @@
|
||||
#define BT_RPC_EVENT_DISCONNECTED (1UL << 1)
|
||||
#define BT_RPC_EVENT_ALL (BT_RPC_EVENT_BUFF_SENT | BT_RPC_EVENT_DISCONNECTED)
|
||||
|
||||
#define ICON_SPACER 2
|
||||
|
||||
static void bt_draw_statusbar_callback(Canvas* canvas, void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
Bt* bt = context;
|
||||
uint8_t draw_offset = 0;
|
||||
if(bt->beacon_active) {
|
||||
canvas_draw_icon(canvas, 0, 0, &I_BLE_beacon_7x8);
|
||||
draw_offset += icon_get_width(&I_BLE_beacon_7x8) + ICON_SPACER;
|
||||
}
|
||||
if(bt->status == BtStatusAdvertising) {
|
||||
canvas_draw_icon(canvas, 0, 0, &I_Bluetooth_Idle_5x8);
|
||||
canvas_draw_icon(canvas, draw_offset, 0, &I_Bluetooth_Idle_5x8);
|
||||
} else if(bt->status == BtStatusConnected) {
|
||||
canvas_draw_icon(canvas, 0, 0, &I_Bluetooth_Connected_16x8);
|
||||
canvas_draw_icon(canvas, draw_offset, 0, &I_Bluetooth_Connected_16x8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,8 +70,12 @@ static ViewPort* bt_pin_code_view_port_alloc(Bt* bt) {
|
||||
}
|
||||
|
||||
static void bt_pin_code_show(Bt* bt, uint32_t pin_code) {
|
||||
furi_assert(bt);
|
||||
bt->pin_code = pin_code;
|
||||
if(!bt->pin_code_view_port) {
|
||||
// Pin code view port
|
||||
bt->pin_code_view_port = bt_pin_code_view_port_alloc(bt);
|
||||
gui_add_view_port(bt->gui, bt->pin_code_view_port, GuiLayerFullscreen);
|
||||
}
|
||||
notification_message(bt->notification, &sequence_display_backlight_on);
|
||||
if(bt->suppress_pin_screen) return;
|
||||
|
||||
@@ -71,7 +85,7 @@ static void bt_pin_code_show(Bt* bt, uint32_t pin_code) {
|
||||
|
||||
static void bt_pin_code_hide(Bt* bt) {
|
||||
bt->pin_code = 0;
|
||||
if(view_port_is_enabled(bt->pin_code_view_port)) {
|
||||
if(bt->pin_code_view_port && view_port_is_enabled(bt->pin_code_view_port)) {
|
||||
view_port_enabled_set(bt->pin_code_view_port, false);
|
||||
}
|
||||
}
|
||||
@@ -83,6 +97,9 @@ static bool bt_pin_code_verify_event_handler(Bt* bt, uint32_t pin) {
|
||||
if(bt->suppress_pin_screen) return true;
|
||||
|
||||
FuriString* pin_str;
|
||||
if(!bt->dialog_message) {
|
||||
bt->dialog_message = dialog_message_alloc();
|
||||
}
|
||||
dialog_message_set_icon(bt->dialog_message, &I_BLE_Pairing_128x64, 0, 0);
|
||||
pin_str = furi_string_alloc_printf("Verify code\n%06lu", pin);
|
||||
dialog_message_set_text(
|
||||
@@ -100,25 +117,32 @@ static void bt_battery_level_changed_callback(const void* _event, void* context)
|
||||
Bt* bt = context;
|
||||
BtMessage message = {};
|
||||
const PowerEvent* event = _event;
|
||||
if(event->type == PowerEventTypeBatteryLevelChanged) {
|
||||
bool is_charging = false;
|
||||
switch(event->type) {
|
||||
case PowerEventTypeBatteryLevelChanged:
|
||||
message.type = BtMessageTypeUpdateBatteryLevel;
|
||||
message.data.battery_level = event->data.battery_level;
|
||||
furi_check(
|
||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||
} else if(
|
||||
event->type == PowerEventTypeStartCharging || event->type == PowerEventTypeFullyCharged ||
|
||||
event->type == PowerEventTypeStopCharging) {
|
||||
break;
|
||||
case PowerEventTypeStartCharging:
|
||||
is_charging = true;
|
||||
/* fallthrough */
|
||||
case PowerEventTypeFullyCharged:
|
||||
case PowerEventTypeStopCharging:
|
||||
message.type = BtMessageTypeUpdatePowerState;
|
||||
message.data.power_state_charging = is_charging;
|
||||
furi_check(
|
||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Bt* bt_alloc() {
|
||||
Bt* bt = malloc(sizeof(Bt));
|
||||
// Init default maximum packet size
|
||||
bt->max_packet_size = FURI_HAL_BT_SERIAL_PACKET_SIZE_MAX;
|
||||
bt->profile = BtProfileSerial;
|
||||
bt->max_packet_size = BLE_PROFILE_SERIAL_PACKET_SIZE_MAX;
|
||||
bt->current_profile = NULL;
|
||||
// Load settings
|
||||
bt_settings_load(&bt->bt_settings);
|
||||
// Keys storage
|
||||
@@ -128,18 +152,14 @@ Bt* bt_alloc() {
|
||||
|
||||
// Setup statusbar view port
|
||||
bt->statusbar_view_port = bt_statusbar_view_port_alloc(bt);
|
||||
// Pin code view port
|
||||
bt->pin_code_view_port = bt_pin_code_view_port_alloc(bt);
|
||||
// Notification
|
||||
bt->notification = furi_record_open(RECORD_NOTIFICATION);
|
||||
// Gui
|
||||
bt->gui = furi_record_open(RECORD_GUI);
|
||||
gui_add_view_port(bt->gui, bt->statusbar_view_port, GuiLayerStatusBarLeft);
|
||||
gui_add_view_port(bt->gui, bt->pin_code_view_port, GuiLayerFullscreen);
|
||||
|
||||
// Dialogs
|
||||
bt->dialogs = furi_record_open(RECORD_DIALOGS);
|
||||
bt->dialog_message = dialog_message_alloc();
|
||||
|
||||
// Power
|
||||
bt->power = furi_record_open(RECORD_POWER);
|
||||
@@ -176,7 +196,11 @@ static uint16_t bt_serial_event_callback(SerialServiceEvent event, void* context
|
||||
furi_event_flag_set(bt->rpc_event, BT_RPC_EVENT_BUFF_SENT);
|
||||
} else if(event.event == SerialServiceEventTypesBleResetRequest) {
|
||||
FURI_LOG_I(TAG, "BLE restart request received");
|
||||
BtMessage message = {.type = BtMessageTypeSetProfile, .data.profile = BtProfileSerial};
|
||||
BtMessage message = {
|
||||
.type = BtMessageTypeSetProfile,
|
||||
.data.profile.params = NULL,
|
||||
.data.profile.template = ble_profile_serial,
|
||||
};
|
||||
furi_check(
|
||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||
}
|
||||
@@ -197,10 +221,10 @@ static void bt_rpc_send_bytes_callback(void* context, uint8_t* bytes, size_t byt
|
||||
while(bytes_sent < bytes_len) {
|
||||
size_t bytes_remain = bytes_len - bytes_sent;
|
||||
if(bytes_remain > bt->max_packet_size) {
|
||||
furi_hal_bt_serial_tx(&bytes[bytes_sent], bt->max_packet_size);
|
||||
ble_profile_serial_tx(bt->current_profile, &bytes[bytes_sent], bt->max_packet_size);
|
||||
bytes_sent += bt->max_packet_size;
|
||||
} else {
|
||||
furi_hal_bt_serial_tx(&bytes[bytes_sent], bytes_remain);
|
||||
ble_profile_serial_tx(bt->current_profile, &bytes[bytes_sent], bytes_remain);
|
||||
bytes_sent += bytes_remain;
|
||||
}
|
||||
// We want BT_RPC_EVENT_DISCONNECTED to stick, so don't clear
|
||||
@@ -215,49 +239,55 @@ static void bt_rpc_send_bytes_callback(void* context, uint8_t* bytes, size_t byt
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_serial_buffer_is_empty_callback(void* context) {
|
||||
furi_assert(context);
|
||||
Bt* bt = context;
|
||||
furi_check(furi_hal_bt_check_profile_type(bt->current_profile, ble_profile_serial));
|
||||
ble_profile_serial_notify_buffer_is_empty(bt->current_profile);
|
||||
}
|
||||
|
||||
// Called from GAP thread
|
||||
static bool bt_on_gap_event_callback(GapEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
Bt* bt = context;
|
||||
bool ret = false;
|
||||
bt->pin = 0;
|
||||
bool do_update_status = false;
|
||||
bool current_profile_is_serial =
|
||||
furi_hal_bt_check_profile_type(bt->current_profile, ble_profile_serial);
|
||||
|
||||
if(event.type == GapEventTypeConnected) {
|
||||
// Update status bar
|
||||
bt->status = BtStatusConnected;
|
||||
BtMessage message = {.type = BtMessageTypeUpdateStatus};
|
||||
furi_check(
|
||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||
do_update_status = true;
|
||||
bt_open_rpc_connection(bt);
|
||||
// Update battery level
|
||||
PowerInfo info;
|
||||
power_get_info(bt->power, &info);
|
||||
BtMessage message = {.type = BtMessageTypeUpdateStatus};
|
||||
message.type = BtMessageTypeUpdateBatteryLevel;
|
||||
message.data.battery_level = info.charge;
|
||||
furi_check(
|
||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||
ret = true;
|
||||
} else if(event.type == GapEventTypeDisconnected) {
|
||||
if(bt->profile == BtProfileSerial && bt->rpc_session) {
|
||||
if(current_profile_is_serial && bt->rpc_session) {
|
||||
FURI_LOG_I(TAG, "Close RPC connection");
|
||||
furi_hal_bt_serial_set_rpc_status(FuriHalBtSerialRpcStatusNotActive);
|
||||
ble_profile_serial_set_rpc_active(
|
||||
bt->current_profile, FuriHalBtSerialRpcStatusNotActive);
|
||||
furi_event_flag_set(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
|
||||
rpc_session_close(bt->rpc_session);
|
||||
furi_hal_bt_serial_set_event_callback(0, NULL, NULL);
|
||||
ble_profile_serial_set_event_callback(bt->current_profile, 0, NULL, NULL);
|
||||
bt->rpc_session = NULL;
|
||||
}
|
||||
ret = true;
|
||||
} else if(event.type == GapEventTypeStartAdvertising) {
|
||||
bt->status = BtStatusAdvertising;
|
||||
BtMessage message = {.type = BtMessageTypeUpdateStatus};
|
||||
furi_check(
|
||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||
do_update_status = true;
|
||||
ret = true;
|
||||
} else if(event.type == GapEventTypeStopAdvertising) {
|
||||
bt->status = BtStatusOff;
|
||||
BtMessage message = {.type = BtMessageTypeUpdateStatus};
|
||||
furi_check(
|
||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||
do_update_status = true;
|
||||
ret = true;
|
||||
} else if(event.type == GapEventTypePinCodeShow) {
|
||||
bt->pin = event.data.pin_code;
|
||||
@@ -272,6 +302,20 @@ static bool bt_on_gap_event_callback(GapEvent event, void* context) {
|
||||
} else if(event.type == GapEventTypeUpdateMTU) {
|
||||
bt->max_packet_size = event.data.max_packet_size;
|
||||
ret = true;
|
||||
} else if(event.type == GapEventTypeBeaconStart) {
|
||||
bt->beacon_active = true;
|
||||
do_update_status = true;
|
||||
ret = true;
|
||||
} else if(event.type == GapEventTypeBeaconStop) {
|
||||
bt->beacon_active = false;
|
||||
do_update_status = true;
|
||||
ret = true;
|
||||
}
|
||||
|
||||
if(do_update_status) {
|
||||
BtMessage message = {.type = BtMessageTypeUpdateStatus};
|
||||
furi_check(
|
||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -288,11 +332,18 @@ static void bt_on_key_storage_change_callback(uint8_t* addr, uint16_t size, void
|
||||
}
|
||||
|
||||
static void bt_statusbar_update(Bt* bt) {
|
||||
uint8_t active_icon_width = 0;
|
||||
if(bt->beacon_active) {
|
||||
active_icon_width = icon_get_width(&I_BLE_beacon_7x8) + ICON_SPACER;
|
||||
}
|
||||
if(bt->status == BtStatusAdvertising) {
|
||||
view_port_set_width(bt->statusbar_view_port, icon_get_width(&I_Bluetooth_Idle_5x8));
|
||||
view_port_enabled_set(bt->statusbar_view_port, true);
|
||||
active_icon_width += icon_get_width(&I_Bluetooth_Idle_5x8);
|
||||
} else if(bt->status == BtStatusConnected) {
|
||||
view_port_set_width(bt->statusbar_view_port, icon_get_width(&I_Bluetooth_Connected_16x8));
|
||||
active_icon_width += icon_get_width(&I_Bluetooth_Connected_16x8);
|
||||
}
|
||||
|
||||
if(active_icon_width > 0) {
|
||||
view_port_set_width(bt->statusbar_view_port, active_icon_width);
|
||||
view_port_enabled_set(bt->statusbar_view_port, true);
|
||||
} else {
|
||||
view_port_enabled_set(bt->statusbar_view_port, false);
|
||||
@@ -300,6 +351,9 @@ static void bt_statusbar_update(Bt* bt) {
|
||||
}
|
||||
|
||||
static void bt_show_warning(Bt* bt, const char* text) {
|
||||
if(!bt->dialog_message) {
|
||||
bt->dialog_message = dialog_message_alloc();
|
||||
}
|
||||
dialog_message_set_text(bt->dialog_message, text, 64, 28, AlignCenter, AlignCenter);
|
||||
dialog_message_set_buttons(bt->dialog_message, "Quit", NULL, NULL);
|
||||
dialog_message_show(bt->dialogs, bt->dialog_message);
|
||||
@@ -309,18 +363,19 @@ void bt_open_rpc_connection(Bt* bt) {
|
||||
if(!bt->rpc_session && bt->status == BtStatusConnected) {
|
||||
// Clear BT_RPC_EVENT_DISCONNECTED because it might be set from previous session
|
||||
furi_event_flag_clear(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
|
||||
if(bt->profile == BtProfileSerial) {
|
||||
if(furi_hal_bt_check_profile_type(bt->current_profile, ble_profile_serial)) {
|
||||
// Open RPC session
|
||||
bt->rpc_session = rpc_session_open(bt->rpc, RpcOwnerBle);
|
||||
if(bt->rpc_session) {
|
||||
FURI_LOG_I(TAG, "Open RPC connection");
|
||||
rpc_session_set_send_bytes_callback(bt->rpc_session, bt_rpc_send_bytes_callback);
|
||||
rpc_session_set_buffer_is_empty_callback(
|
||||
bt->rpc_session, furi_hal_bt_serial_notify_buffer_is_empty);
|
||||
bt->rpc_session, bt_serial_buffer_is_empty_callback);
|
||||
rpc_session_set_context(bt->rpc_session, bt);
|
||||
furi_hal_bt_serial_set_event_callback(
|
||||
RPC_BUFFER_SIZE, bt_serial_event_callback, bt);
|
||||
furi_hal_bt_serial_set_rpc_status(FuriHalBtSerialRpcStatusActive);
|
||||
ble_profile_serial_set_event_callback(
|
||||
bt->current_profile, RPC_BUFFER_SIZE, bt_serial_event_callback, bt);
|
||||
ble_profile_serial_set_rpc_active(
|
||||
bt->current_profile, FuriHalBtSerialRpcStatusActive);
|
||||
} else {
|
||||
FURI_LOG_W(TAG, "RPC is busy, failed to open new session");
|
||||
}
|
||||
@@ -329,49 +384,51 @@ void bt_open_rpc_connection(Bt* bt) {
|
||||
}
|
||||
|
||||
void bt_close_rpc_connection(Bt* bt) {
|
||||
if(bt->profile == BtProfileSerial && bt->rpc_session) {
|
||||
if(furi_hal_bt_check_profile_type(bt->current_profile, ble_profile_serial) &&
|
||||
bt->rpc_session) {
|
||||
FURI_LOG_I(TAG, "Close RPC connection");
|
||||
furi_event_flag_set(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
|
||||
rpc_session_close(bt->rpc_session);
|
||||
furi_hal_bt_serial_set_event_callback(0, NULL, NULL);
|
||||
ble_profile_serial_set_event_callback(bt->current_profile, 0, NULL, NULL);
|
||||
bt->rpc_session = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_change_profile(Bt* bt, BtMessage* message) {
|
||||
if(furi_hal_bt_is_ble_gatt_gap_supported()) {
|
||||
if(furi_hal_bt_is_gatt_gap_supported()) {
|
||||
bt_close_rpc_connection(bt);
|
||||
|
||||
FuriHalBtProfile furi_profile;
|
||||
if(message->data.profile == BtProfileHidKeyboard) {
|
||||
furi_profile = FuriHalBtProfileHidKeyboard;
|
||||
} else {
|
||||
furi_profile = FuriHalBtProfileSerial;
|
||||
}
|
||||
|
||||
bt_keys_storage_load(bt->keys_storage);
|
||||
|
||||
if(furi_hal_bt_change_app(furi_profile, bt_on_gap_event_callback, bt)) {
|
||||
bt->current_profile = furi_hal_bt_change_app(
|
||||
message->data.profile.template,
|
||||
message->data.profile.params,
|
||||
bt_on_gap_event_callback,
|
||||
bt);
|
||||
if(bt->current_profile) {
|
||||
FURI_LOG_I(TAG, "Bt App started");
|
||||
if(bt->bt_settings.enabled) {
|
||||
furi_hal_bt_start_advertising();
|
||||
}
|
||||
furi_hal_bt_set_key_storage_change_callback(bt_on_key_storage_change_callback, bt);
|
||||
bt->profile = message->data.profile;
|
||||
if(message->result) {
|
||||
*message->result = true;
|
||||
}
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Failed to start Bt App");
|
||||
if(message->result) {
|
||||
*message->result = false;
|
||||
}
|
||||
}
|
||||
if(message->profile_instance) {
|
||||
*message->profile_instance = bt->current_profile;
|
||||
}
|
||||
if(message->result) {
|
||||
*message->result = bt->current_profile != NULL;
|
||||
}
|
||||
|
||||
} else {
|
||||
bt_show_warning(bt, "Radio stack doesn't support this app");
|
||||
if(message->result) {
|
||||
*message->result = false;
|
||||
}
|
||||
if(message->profile_instance) {
|
||||
*message->profile_instance = NULL;
|
||||
}
|
||||
}
|
||||
if(message->lock) api_lock_unlock(message->lock);
|
||||
}
|
||||
@@ -382,52 +439,6 @@ static void bt_close_connection(Bt* bt, BtMessage* message) {
|
||||
if(message->lock) api_lock_unlock(message->lock);
|
||||
}
|
||||
|
||||
static inline FuriHalBtProfile get_hal_bt_profile(BtProfile profile) {
|
||||
if(profile == BtProfileHidKeyboard) {
|
||||
return FuriHalBtProfileHidKeyboard;
|
||||
} else {
|
||||
return FuriHalBtProfileSerial;
|
||||
}
|
||||
}
|
||||
|
||||
void bt_restart(Bt* bt) {
|
||||
furi_hal_bt_change_app(get_hal_bt_profile(bt->profile), bt_on_gap_event_callback, bt);
|
||||
furi_hal_bt_start_advertising();
|
||||
}
|
||||
|
||||
void bt_set_profile_adv_name(Bt* bt, const char* fmt, ...) {
|
||||
furi_assert(bt);
|
||||
furi_assert(fmt);
|
||||
|
||||
char name[FURI_HAL_BT_ADV_NAME_LENGTH];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsnprintf(name, sizeof(name), fmt, args);
|
||||
va_end(args);
|
||||
furi_hal_bt_set_profile_adv_name(get_hal_bt_profile(bt->profile), name);
|
||||
|
||||
bt_restart(bt);
|
||||
}
|
||||
|
||||
const char* bt_get_profile_adv_name(Bt* bt) {
|
||||
furi_assert(bt);
|
||||
return furi_hal_bt_get_profile_adv_name(get_hal_bt_profile(bt->profile));
|
||||
}
|
||||
|
||||
void bt_set_profile_mac_address(Bt* bt, const uint8_t mac[6]) {
|
||||
furi_assert(bt);
|
||||
furi_assert(mac);
|
||||
|
||||
furi_hal_bt_set_profile_mac_addr(get_hal_bt_profile(bt->profile), mac);
|
||||
|
||||
bt_restart(bt);
|
||||
}
|
||||
|
||||
const uint8_t* bt_get_profile_mac_address(Bt* bt) {
|
||||
furi_assert(bt);
|
||||
return furi_hal_bt_get_profile_mac_addr(get_hal_bt_profile(bt->profile));
|
||||
}
|
||||
|
||||
bool bt_remote_rssi(Bt* bt, uint8_t* rssi) {
|
||||
furi_assert(bt);
|
||||
|
||||
@@ -441,27 +452,6 @@ bool bt_remote_rssi(Bt* bt, uint8_t* rssi) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void bt_set_profile_pairing_method(Bt* bt, GapPairing pairing_method) {
|
||||
furi_assert(bt);
|
||||
furi_hal_bt_set_profile_pairing_method(get_hal_bt_profile(bt->profile), pairing_method);
|
||||
bt_restart(bt);
|
||||
}
|
||||
|
||||
GapPairing bt_get_profile_pairing_method(Bt* bt) {
|
||||
furi_assert(bt);
|
||||
return furi_hal_bt_get_profile_pairing_method(get_hal_bt_profile(bt->profile));
|
||||
}
|
||||
|
||||
void bt_disable_peer_key_update(Bt* bt) {
|
||||
UNUSED(bt);
|
||||
furi_hal_bt_set_key_storage_change_callback(NULL, NULL);
|
||||
}
|
||||
|
||||
void bt_enable_peer_key_update(Bt* bt) {
|
||||
furi_assert(bt);
|
||||
furi_hal_bt_set_key_storage_change_callback(bt_on_key_storage_change_callback, bt);
|
||||
}
|
||||
|
||||
int32_t bt_srv(void* p) {
|
||||
UNUSED(p);
|
||||
Bt* bt = bt_alloc();
|
||||
@@ -483,8 +473,10 @@ int32_t bt_srv(void* p) {
|
||||
FURI_LOG_E(TAG, "Radio stack start failed");
|
||||
}
|
||||
|
||||
if(furi_hal_bt_is_ble_gatt_gap_supported()) {
|
||||
if(!furi_hal_bt_start_app(FuriHalBtProfileSerial, bt_on_gap_event_callback, bt)) {
|
||||
if(furi_hal_bt_is_gatt_gap_supported()) {
|
||||
bt->current_profile =
|
||||
furi_hal_bt_start_app(ble_profile_serial, NULL, bt_on_gap_event_callback, bt);
|
||||
if(!bt->current_profile) {
|
||||
FURI_LOG_E(TAG, "BLE App start failed");
|
||||
} else {
|
||||
if(bt->bt_settings.enabled) {
|
||||
@@ -514,7 +506,7 @@ int32_t bt_srv(void* p) {
|
||||
// Update battery level
|
||||
furi_hal_bt_update_battery_level(message.data.battery_level);
|
||||
} else if(message.type == BtMessageTypeUpdatePowerState) {
|
||||
furi_hal_bt_update_power_state();
|
||||
furi_hal_bt_update_power_state(message.data.power_state_charging);
|
||||
} else if(message.type == BtMessageTypePinCodeShow) {
|
||||
// Display PIN code
|
||||
bt_pin_code_show(bt, message.data.pin_code);
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <furi_hal_bt.h>
|
||||
#include <furi_ble/profile_interface.h>
|
||||
#include <core/common_defines.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -19,11 +20,6 @@ typedef enum {
|
||||
BtStatusConnected,
|
||||
} BtStatus;
|
||||
|
||||
typedef enum {
|
||||
BtProfileSerial,
|
||||
BtProfileHidKeyboard,
|
||||
} BtProfile;
|
||||
|
||||
typedef struct {
|
||||
uint8_t rssi;
|
||||
uint32_t since;
|
||||
@@ -34,12 +30,25 @@ typedef void (*BtStatusChangedCallback)(BtStatus status, void* context);
|
||||
/** Change BLE Profile
|
||||
* @note Call of this function leads to 2nd core restart
|
||||
*
|
||||
* @param bt Bt instance
|
||||
* @param profile BtProfile
|
||||
* @param bt Bt instance
|
||||
* @param profile_template Profile template to change to
|
||||
* @param params Profile parameters. Can be NULL
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
bool bt_set_profile(Bt* bt, BtProfile profile);
|
||||
FURI_WARN_UNUSED FuriHalBleProfileBase* bt_profile_start(
|
||||
Bt* bt,
|
||||
const FuriHalBleProfileTemplate* profile_template,
|
||||
FuriHalBleProfileParams params);
|
||||
|
||||
/** Stop current BLE Profile and restore default profile
|
||||
* @note Call of this function leads to 2nd core restart
|
||||
*
|
||||
* @param bt Bt instance
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
bool bt_profile_restore_default(Bt* bt);
|
||||
|
||||
/** Disconnect from Central
|
||||
*
|
||||
@@ -75,30 +84,8 @@ void bt_keys_storage_set_storage_path(Bt* bt, const char* keys_storage_path);
|
||||
*/
|
||||
void bt_keys_storage_set_default_path(Bt* bt);
|
||||
|
||||
void bt_set_profile_adv_name(Bt* bt, const char* fmt, ...);
|
||||
|
||||
const char* bt_get_profile_adv_name(Bt* bt);
|
||||
|
||||
void bt_set_profile_mac_address(Bt* bt, const uint8_t mac[6]);
|
||||
|
||||
const uint8_t* bt_get_profile_mac_address(Bt* bt);
|
||||
|
||||
bool bt_remote_rssi(Bt* bt, uint8_t* rssi);
|
||||
|
||||
void bt_set_profile_pairing_method(Bt* bt, GapPairing pairing_method);
|
||||
GapPairing bt_get_profile_pairing_method(Bt* bt);
|
||||
|
||||
/** Stop saving new peer key to flash (in .bt.keys file)
|
||||
*
|
||||
*/
|
||||
void bt_disable_peer_key_update(Bt* bt);
|
||||
|
||||
/** Enable saving peer key to internal flash (enable by default)
|
||||
*
|
||||
* @note This function should be called if bt_disable_peer_key_update was called before
|
||||
*/
|
||||
void bt_enable_peer_key_update(Bt* bt);
|
||||
|
||||
/**
|
||||
*
|
||||
* (Probably bad) way of opening the RPC connection, everywhereTM
|
||||
|
||||
@@ -1,21 +1,34 @@
|
||||
#include "bt_i.h"
|
||||
#include <profiles/serial_profile.h>
|
||||
|
||||
bool bt_set_profile(Bt* bt, BtProfile profile) {
|
||||
FuriHalBleProfileBase* bt_profile_start(
|
||||
Bt* bt,
|
||||
const FuriHalBleProfileTemplate* profile_template,
|
||||
FuriHalBleProfileParams params) {
|
||||
furi_assert(bt);
|
||||
|
||||
// Send message
|
||||
bool result = false;
|
||||
FuriHalBleProfileBase* profile_instance = NULL;
|
||||
|
||||
BtMessage message = {
|
||||
.lock = api_lock_alloc_locked(),
|
||||
.type = BtMessageTypeSetProfile,
|
||||
.data.profile = profile,
|
||||
.result = &result};
|
||||
.profile_instance = &profile_instance,
|
||||
.data.profile.params = params,
|
||||
.data.profile.template = profile_template,
|
||||
};
|
||||
furi_check(
|
||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||
// Wait for unlock
|
||||
api_lock_wait_unlock_and_free(message.lock);
|
||||
|
||||
return result;
|
||||
bt->current_profile = profile_instance;
|
||||
return profile_instance;
|
||||
}
|
||||
|
||||
bool bt_profile_restore_default(Bt* bt) {
|
||||
bt->current_profile = bt_profile_start(bt, ble_profile_serial, NULL);
|
||||
return bt->current_profile != NULL;
|
||||
}
|
||||
|
||||
void bt_disconnect(Bt* bt) {
|
||||
|
||||
@@ -41,7 +41,12 @@ typedef struct {
|
||||
typedef union {
|
||||
uint32_t pin_code;
|
||||
uint8_t battery_level;
|
||||
BtProfile profile;
|
||||
bool power_state_charging;
|
||||
struct {
|
||||
const FuriHalBleProfileTemplate* template;
|
||||
FuriHalBleProfileParams params;
|
||||
} profile;
|
||||
FuriHalBleProfileParams profile_params;
|
||||
BtKeyStorageUpdateData key_storage_data;
|
||||
} BtMessageData;
|
||||
|
||||
@@ -50,6 +55,7 @@ typedef struct {
|
||||
BtMessageType type;
|
||||
BtMessageData data;
|
||||
bool* result;
|
||||
FuriHalBleProfileBase** profile_instance;
|
||||
} BtMessage;
|
||||
|
||||
struct Bt {
|
||||
@@ -59,7 +65,8 @@ struct Bt {
|
||||
BtSettings bt_settings;
|
||||
BtKeysStorage* keys_storage;
|
||||
BtStatus status;
|
||||
BtProfile profile;
|
||||
bool beacon_active;
|
||||
FuriHalBleProfileBase* current_profile;
|
||||
FuriMessageQueue* message_queue;
|
||||
NotificationApp* notification;
|
||||
Gui* gui;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "cli_command_gpio.h"
|
||||
|
||||
#include "core/string.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "cli_commands.h"
|
||||
#include "cli_command_gpio.h"
|
||||
|
||||
#include <core/thread.h>
|
||||
#include <furi_hal.h>
|
||||
#include <furi_hal_info.h>
|
||||
#include <task_control_block.h>
|
||||
@@ -398,27 +399,30 @@ void cli_command_ps(Cli* cli, FuriString* args, void* context) {
|
||||
|
||||
const uint8_t threads_num_max = 32;
|
||||
FuriThreadId threads_ids[threads_num_max];
|
||||
uint8_t thread_num = furi_thread_enumerate(threads_ids, threads_num_max);
|
||||
uint32_t thread_num = furi_thread_enumerate(threads_ids, threads_num_max);
|
||||
printf(
|
||||
"%-20s %-20s %-14s %-8s %-8s %s\r\n",
|
||||
"%-17s %-20s %-5s %-13s %-6s %-8s %s\r\n",
|
||||
"AppID",
|
||||
"Name",
|
||||
"Prio",
|
||||
"Stack start",
|
||||
"Heap",
|
||||
"Stack",
|
||||
"Stack min free");
|
||||
for(uint8_t i = 0; i < thread_num; i++) {
|
||||
TaskControlBlock* tcb = (TaskControlBlock*)threads_ids[i];
|
||||
size_t thread_heap = memmgr_heap_get_thread_memory(threads_ids[i]);
|
||||
printf(
|
||||
"%-20s %-20s 0x%-12lx %-8zu %-8lu %-8lu\r\n",
|
||||
"%-17s %-20s %-5d 0x%-11lx %-6zu %-8lu %-8lu\r\n",
|
||||
furi_thread_get_appid(threads_ids[i]),
|
||||
furi_thread_get_name(threads_ids[i]),
|
||||
furi_thread_get_priority(threads_ids[i]),
|
||||
(uint32_t)tcb->pxStack,
|
||||
memmgr_heap_get_thread_memory(threads_ids[i]),
|
||||
thread_heap == MEMMGR_HEAP_UNKNOWN ? 0u : thread_heap,
|
||||
(uint32_t)(tcb->pxEndOfStack - tcb->pxStack + 1) * sizeof(StackType_t),
|
||||
furi_thread_get_stack_space(threads_ids[i]));
|
||||
}
|
||||
printf("\r\nTotal: %d", thread_num);
|
||||
printf("\r\nTotal: %lu", thread_num);
|
||||
}
|
||||
|
||||
void cli_command_free(Cli* cli, FuriString* args, void* context) {
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../widget.h"
|
||||
#include "widget_element.h"
|
||||
#include <furi.h>
|
||||
#include <gui/view.h>
|
||||
#include <input/input.h>
|
||||
#include "widget_element.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "loader.h"
|
||||
#include "core/core_defines.h"
|
||||
#include "loader_i.h"
|
||||
#include <applications.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "profiles/serial_profile.h"
|
||||
#include "rpc_i.h"
|
||||
|
||||
#include <pb.h>
|
||||
@@ -334,7 +335,7 @@ static int32_t rpc_session_worker(void* context) {
|
||||
// Disconnect BLE session
|
||||
FURI_LOG_E("RPC", "BLE session closed due to a decode error");
|
||||
Bt* bt = furi_record_open(RECORD_BT);
|
||||
bt_set_profile(bt, BtProfileSerial);
|
||||
bt_profile_restore_default(bt);
|
||||
furi_record_close(RECORD_BT);
|
||||
FURI_LOG_E("RPC", "Finished disconnecting the BLE session");
|
||||
}
|
||||
|
||||
@@ -94,6 +94,7 @@ void rpc_session_set_send_bytes_callback(RpcSession* session, RpcSendBytesCallba
|
||||
*
|
||||
* @param session pointer to RpcSession descriptor
|
||||
* @param callback callback to notify client that buffer is empty (can be NULL)
|
||||
* @param context context to pass to callback
|
||||
*/
|
||||
void rpc_session_set_buffer_is_empty_callback(
|
||||
RpcSession* session,
|
||||
|
||||
@@ -39,7 +39,7 @@ void bt_settings_scene_start_on_enter(void* context) {
|
||||
VariableItemList* var_item_list = app->var_item_list;
|
||||
VariableItem* item;
|
||||
|
||||
if(furi_hal_bt_is_ble_gatt_gap_supported()) {
|
||||
if(furi_hal_bt_is_gatt_gap_supported()) {
|
||||
item = variable_item_list_add(
|
||||
var_item_list,
|
||||
"Bluetooth",
|
||||
|
||||
@@ -4,6 +4,10 @@ App(
|
||||
apptype=FlipperAppType.EXTERNAL,
|
||||
entry_point="hid_usb_app",
|
||||
stack_size=1 * 1024,
|
||||
sources=["*.c", "!transport_ble.c"],
|
||||
cdefines=["HID_TRANSPORT_USB"],
|
||||
fap_description="Use Flipper as a HID remote control over USB",
|
||||
fap_version="1.0",
|
||||
fap_category="USB",
|
||||
fap_icon="hid_usb_10px.png",
|
||||
fap_icon_assets="assets",
|
||||
@@ -17,6 +21,11 @@ App(
|
||||
apptype=FlipperAppType.EXTERNAL,
|
||||
entry_point="hid_ble_app",
|
||||
stack_size=1 * 1024,
|
||||
sources=["*.c", "!transport_usb.c"],
|
||||
cdefines=["HID_TRANSPORT_BLE"],
|
||||
fap_libs=["ble_profile"],
|
||||
fap_description="Use Flipper as a HID remote control over Bluetooth",
|
||||
fap_version="1.0",
|
||||
fap_category="Bluetooth",
|
||||
fap_icon="hid_ble_10px.png",
|
||||
fap_icon_assets="assets",
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "hid.h"
|
||||
#include <extra_profiles/hid_profile.h>
|
||||
#include <profiles/serial_profile.h>
|
||||
#include "views.h"
|
||||
#include <notification/notification_messages.h>
|
||||
#include <dolphin/dolphin.h>
|
||||
@@ -18,8 +20,22 @@ enum HidDebugSubmenuIndex {
|
||||
HidSubmenuIndexMouseClicker,
|
||||
HidSubmenuIndexMouseJiggler,
|
||||
HidSubmenuIndexPushToTalk,
|
||||
HidSubmenuIndexRemovePairing,
|
||||
};
|
||||
|
||||
static void bt_hid_remove_pairing(Bt* bt) {
|
||||
bt_disconnect(bt);
|
||||
|
||||
// Wait 2nd core to update nvm storage
|
||||
furi_delay_ms(200);
|
||||
|
||||
furi_hal_bt_stop_advertising();
|
||||
|
||||
bt_forget_bonded_devices(bt);
|
||||
|
||||
furi_hal_bt_start_advertising();
|
||||
}
|
||||
|
||||
static void hid_submenu_callback(void* context, uint32_t index) {
|
||||
furi_assert(context);
|
||||
Hid* app = context;
|
||||
@@ -61,6 +77,8 @@ static void hid_submenu_callback(void* context, uint32_t index) {
|
||||
} else if(index == HidSubmenuIndexPushToTalk) {
|
||||
app->view_id = HidViewPushToTalkMenu;
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewPushToTalkMenu);
|
||||
} else if(index == HidSubmenuIndexRemovePairing) {
|
||||
bt_hid_remove_pairing(app->bt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,13 +86,13 @@ static void bt_hid_connection_status_changed_callback(BtStatus status, void* con
|
||||
furi_assert(context);
|
||||
Hid* hid = context;
|
||||
bool connected = (status == BtStatusConnected);
|
||||
if(hid->transport == HidTransportBle) {
|
||||
if(connected) {
|
||||
notification_internal_message(hid->notifications, &sequence_set_blue_255);
|
||||
} else {
|
||||
notification_internal_message(hid->notifications, &sequence_reset_blue);
|
||||
}
|
||||
#ifdef HID_TRANSPORT_BLE
|
||||
if(connected) {
|
||||
notification_internal_message(hid->notifications, &sequence_set_blue_255);
|
||||
} else {
|
||||
notification_internal_message(hid->notifications, &sequence_reset_blue);
|
||||
}
|
||||
#endif
|
||||
hid_keynote_set_connected_status(hid->hid_keynote, connected);
|
||||
hid_keyboard_set_connected_status(hid->hid_keyboard, connected);
|
||||
hid_numpad_set_connected_status(hid->hid_numpad, connected);
|
||||
@@ -103,9 +121,8 @@ static uint32_t hid_ptt_menu_view(void* context) {
|
||||
return HidViewPushToTalkMenu;
|
||||
}
|
||||
|
||||
Hid* hid_alloc(HidTransport transport) {
|
||||
Hid* hid_alloc() {
|
||||
Hid* app = malloc(sizeof(Hid));
|
||||
app->transport = transport;
|
||||
|
||||
// Gui
|
||||
app->gui = furi_record_open(RECORD_GUI);
|
||||
@@ -146,14 +163,12 @@ Hid* hid_alloc(HidTransport transport) {
|
||||
app->device_type_submenu, "Movie", HidSubmenuIndexMovie, hid_submenu_callback, app);
|
||||
submenu_add_item(
|
||||
app->device_type_submenu, "Mouse", HidSubmenuIndexMouse, hid_submenu_callback, app);
|
||||
if(app->transport == HidTransportBle) {
|
||||
submenu_add_item(
|
||||
app->device_type_submenu,
|
||||
"TikTok / YT Shorts",
|
||||
HidSubmenuIndexTikShorts,
|
||||
hid_submenu_callback,
|
||||
app);
|
||||
}
|
||||
submenu_add_item(
|
||||
app->device_type_submenu,
|
||||
"TikTok / YT Shorts",
|
||||
HidSubmenuIndexTikShorts,
|
||||
hid_submenu_callback,
|
||||
app);
|
||||
submenu_add_item(
|
||||
app->device_type_submenu,
|
||||
"Mouse Clicker",
|
||||
@@ -172,6 +187,14 @@ Hid* hid_alloc(HidTransport transport) {
|
||||
HidSubmenuIndexPushToTalk,
|
||||
hid_submenu_callback,
|
||||
app);
|
||||
#ifdef HID_TRANSPORT_BLE
|
||||
submenu_add_item(
|
||||
app->device_type_submenu,
|
||||
"Remove Pairing",
|
||||
HidSubmenuIndexRemovePairing,
|
||||
hid_submenu_callback,
|
||||
app);
|
||||
#endif
|
||||
view_set_previous_callback(submenu_get_view(app->device_type_submenu), hid_exit);
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, HidViewSubmenu, submenu_get_view(app->device_type_submenu));
|
||||
@@ -265,10 +288,9 @@ void hid_free(Hid* app) {
|
||||
furi_assert(app);
|
||||
|
||||
// Reset notification
|
||||
if(app->transport == HidTransportBle) {
|
||||
notification_internal_message(app->notifications, &sequence_reset_blue);
|
||||
}
|
||||
|
||||
#ifdef HID_TRANSPORT_BLE
|
||||
notification_internal_message(app->notifications, &sequence_reset_blue);
|
||||
#endif
|
||||
// Free views
|
||||
view_dispatcher_remove_view(app->view_dispatcher, HidViewSubmenu);
|
||||
submenu_free(app->device_type_submenu);
|
||||
@@ -310,131 +332,9 @@ void hid_free(Hid* app) {
|
||||
free(app);
|
||||
}
|
||||
|
||||
void hid_hal_keyboard_press(Hid* instance, uint16_t event) {
|
||||
furi_assert(instance);
|
||||
if(instance->transport == HidTransportBle) {
|
||||
furi_hal_bt_hid_kb_press(event);
|
||||
} else if(instance->transport == HidTransportUsb) {
|
||||
furi_hal_hid_kb_press(event);
|
||||
} else {
|
||||
furi_crash();
|
||||
}
|
||||
}
|
||||
|
||||
void hid_hal_keyboard_release(Hid* instance, uint16_t event) {
|
||||
furi_assert(instance);
|
||||
if(instance->transport == HidTransportBle) {
|
||||
furi_hal_bt_hid_kb_release(event);
|
||||
} else if(instance->transport == HidTransportUsb) {
|
||||
furi_hal_hid_kb_release(event);
|
||||
} else {
|
||||
furi_crash();
|
||||
}
|
||||
}
|
||||
|
||||
void hid_hal_keyboard_release_all(Hid* instance) {
|
||||
furi_assert(instance);
|
||||
if(instance->transport == HidTransportBle) {
|
||||
furi_hal_bt_hid_kb_release_all();
|
||||
} else if(instance->transport == HidTransportUsb) {
|
||||
furi_hal_hid_kb_release_all();
|
||||
} else {
|
||||
furi_crash();
|
||||
}
|
||||
}
|
||||
|
||||
void hid_hal_consumer_key_press(Hid* instance, uint16_t event) {
|
||||
furi_assert(instance);
|
||||
if(instance->transport == HidTransportBle) {
|
||||
furi_hal_bt_hid_consumer_key_press(event);
|
||||
} else if(instance->transport == HidTransportUsb) {
|
||||
furi_hal_hid_consumer_key_press(event);
|
||||
} else {
|
||||
furi_crash();
|
||||
}
|
||||
}
|
||||
|
||||
void hid_hal_consumer_key_release(Hid* instance, uint16_t event) {
|
||||
furi_assert(instance);
|
||||
if(instance->transport == HidTransportBle) {
|
||||
furi_hal_bt_hid_consumer_key_release(event);
|
||||
} else if(instance->transport == HidTransportUsb) {
|
||||
furi_hal_hid_consumer_key_release(event);
|
||||
} else {
|
||||
furi_crash();
|
||||
}
|
||||
}
|
||||
|
||||
void hid_hal_consumer_key_release_all(Hid* instance) {
|
||||
furi_assert(instance);
|
||||
if(instance->transport == HidTransportBle) {
|
||||
furi_hal_bt_hid_consumer_key_release_all();
|
||||
} else if(instance->transport == HidTransportUsb) {
|
||||
furi_hal_hid_kb_release_all();
|
||||
} else {
|
||||
furi_crash();
|
||||
}
|
||||
}
|
||||
|
||||
void hid_hal_mouse_move(Hid* instance, int8_t dx, int8_t dy) {
|
||||
furi_assert(instance);
|
||||
if(instance->transport == HidTransportBle) {
|
||||
furi_hal_bt_hid_mouse_move(dx, dy);
|
||||
} else if(instance->transport == HidTransportUsb) {
|
||||
furi_hal_hid_mouse_move(dx, dy);
|
||||
} else {
|
||||
furi_crash();
|
||||
}
|
||||
}
|
||||
|
||||
void hid_hal_mouse_scroll(Hid* instance, int8_t delta) {
|
||||
furi_assert(instance);
|
||||
if(instance->transport == HidTransportBle) {
|
||||
furi_hal_bt_hid_mouse_scroll(delta);
|
||||
} else if(instance->transport == HidTransportUsb) {
|
||||
furi_hal_hid_mouse_scroll(delta);
|
||||
} else {
|
||||
furi_crash();
|
||||
}
|
||||
}
|
||||
|
||||
void hid_hal_mouse_press(Hid* instance, uint16_t event) {
|
||||
furi_assert(instance);
|
||||
if(instance->transport == HidTransportBle) {
|
||||
furi_hal_bt_hid_mouse_press(event);
|
||||
} else if(instance->transport == HidTransportUsb) {
|
||||
furi_hal_hid_mouse_press(event);
|
||||
} else {
|
||||
furi_crash();
|
||||
}
|
||||
}
|
||||
|
||||
void hid_hal_mouse_release(Hid* instance, uint16_t event) {
|
||||
furi_assert(instance);
|
||||
if(instance->transport == HidTransportBle) {
|
||||
furi_hal_bt_hid_mouse_release(event);
|
||||
} else if(instance->transport == HidTransportUsb) {
|
||||
furi_hal_hid_mouse_release(event);
|
||||
} else {
|
||||
furi_crash();
|
||||
}
|
||||
}
|
||||
|
||||
void hid_hal_mouse_release_all(Hid* instance) {
|
||||
furi_assert(instance);
|
||||
if(instance->transport == HidTransportBle) {
|
||||
furi_hal_bt_hid_mouse_release_all();
|
||||
} else if(instance->transport == HidTransportUsb) {
|
||||
furi_hal_hid_mouse_release(HID_MOUSE_BTN_LEFT);
|
||||
furi_hal_hid_mouse_release(HID_MOUSE_BTN_RIGHT);
|
||||
} else {
|
||||
furi_crash();
|
||||
}
|
||||
}
|
||||
|
||||
int32_t hid_usb_app(void* p) {
|
||||
UNUSED(p);
|
||||
Hid* app = hid_alloc(HidTransportUsb);
|
||||
Hid* app = hid_alloc();
|
||||
app = hid_app_alloc_view(app);
|
||||
FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();
|
||||
furi_hal_usb_unlock();
|
||||
@@ -455,7 +355,7 @@ int32_t hid_usb_app(void* p) {
|
||||
|
||||
int32_t hid_ble_app(void* p) {
|
||||
UNUSED(p);
|
||||
Hid* app = hid_alloc(HidTransportBle);
|
||||
Hid* app = hid_alloc();
|
||||
app = hid_app_alloc_view(app);
|
||||
|
||||
bt_disconnect(app->bt);
|
||||
@@ -475,7 +375,9 @@ int32_t hid_ble_app(void* p) {
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
furi_check(bt_set_profile(app->bt, BtProfileHidKeyboard));
|
||||
app->ble_hid_profile = bt_profile_start(app->bt, ble_profile_hid, NULL);
|
||||
|
||||
furi_check(app->ble_hid_profile);
|
||||
|
||||
furi_hal_bt_start_advertising();
|
||||
bt_set_status_changed_callback(app->bt, bt_hid_connection_status_changed_callback, app);
|
||||
@@ -493,7 +395,7 @@ int32_t hid_ble_app(void* p) {
|
||||
|
||||
bt_keys_storage_set_default_path(app->bt);
|
||||
|
||||
furi_check(bt_set_profile(app->bt, BtProfileSerial));
|
||||
furi_check(bt_profile_restore_default(app->bt));
|
||||
|
||||
hid_free(app);
|
||||
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal_bt.h>
|
||||
#include <furi_hal_bt_hid.h>
|
||||
#include <furi_hal_usb.h>
|
||||
#include <furi_hal_usb_hid.h>
|
||||
|
||||
#include <extra_profiles/hid_profile.h>
|
||||
|
||||
#include <bt/bt_service/bt.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view.h>
|
||||
@@ -40,6 +41,7 @@ typedef enum {
|
||||
typedef struct Hid Hid;
|
||||
|
||||
struct Hid {
|
||||
FuriHalBleProfileBase* ble_hid_profile;
|
||||
Bt* bt;
|
||||
Gui* gui;
|
||||
NotificationApp* notifications;
|
||||
|
||||
60
applications/system/hid_app/transport_ble.c
Normal file
60
applications/system/hid_app/transport_ble.c
Normal file
@@ -0,0 +1,60 @@
|
||||
#include "hid.h"
|
||||
|
||||
#ifndef HID_TRANSPORT_BLE
|
||||
#error "HID_TRANSPORT_BLE must be defined"
|
||||
#endif
|
||||
|
||||
void hid_hal_keyboard_press(Hid* instance, uint16_t event) {
|
||||
furi_assert(instance);
|
||||
ble_profile_hid_kb_press(instance->ble_hid_profile, event);
|
||||
}
|
||||
|
||||
void hid_hal_keyboard_release(Hid* instance, uint16_t event) {
|
||||
furi_assert(instance);
|
||||
ble_profile_hid_kb_release(instance->ble_hid_profile, event);
|
||||
}
|
||||
|
||||
void hid_hal_keyboard_release_all(Hid* instance) {
|
||||
furi_assert(instance);
|
||||
ble_profile_hid_kb_release_all(instance->ble_hid_profile);
|
||||
}
|
||||
|
||||
void hid_hal_consumer_key_press(Hid* instance, uint16_t event) {
|
||||
furi_assert(instance);
|
||||
ble_profile_hid_consumer_key_press(instance->ble_hid_profile, event);
|
||||
}
|
||||
|
||||
void hid_hal_consumer_key_release(Hid* instance, uint16_t event) {
|
||||
furi_assert(instance);
|
||||
ble_profile_hid_consumer_key_release(instance->ble_hid_profile, event);
|
||||
}
|
||||
|
||||
void hid_hal_consumer_key_release_all(Hid* instance) {
|
||||
furi_assert(instance);
|
||||
ble_profile_hid_consumer_key_release_all(instance->ble_hid_profile);
|
||||
}
|
||||
|
||||
void hid_hal_mouse_move(Hid* instance, int8_t dx, int8_t dy) {
|
||||
furi_assert(instance);
|
||||
ble_profile_hid_mouse_move(instance->ble_hid_profile, dx, dy);
|
||||
}
|
||||
|
||||
void hid_hal_mouse_scroll(Hid* instance, int8_t delta) {
|
||||
furi_assert(instance);
|
||||
ble_profile_hid_mouse_scroll(instance->ble_hid_profile, delta);
|
||||
}
|
||||
|
||||
void hid_hal_mouse_press(Hid* instance, uint16_t event) {
|
||||
furi_assert(instance);
|
||||
ble_profile_hid_mouse_press(instance->ble_hid_profile, event);
|
||||
}
|
||||
|
||||
void hid_hal_mouse_release(Hid* instance, uint16_t event) {
|
||||
furi_assert(instance);
|
||||
ble_profile_hid_mouse_release(instance->ble_hid_profile, event);
|
||||
}
|
||||
|
||||
void hid_hal_mouse_release_all(Hid* instance) {
|
||||
furi_assert(instance);
|
||||
ble_profile_hid_mouse_release_all(instance->ble_hid_profile);
|
||||
}
|
||||
61
applications/system/hid_app/transport_usb.c
Normal file
61
applications/system/hid_app/transport_usb.c
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "hid.h"
|
||||
|
||||
#ifndef HID_TRANSPORT_USB
|
||||
#error "HID_TRANSPORT_USB must be defined"
|
||||
#endif
|
||||
|
||||
void hid_hal_keyboard_press(Hid* instance, uint16_t event) {
|
||||
furi_assert(instance);
|
||||
furi_hal_hid_kb_press(event);
|
||||
}
|
||||
|
||||
void hid_hal_keyboard_release(Hid* instance, uint16_t event) {
|
||||
furi_assert(instance);
|
||||
furi_hal_hid_kb_release(event);
|
||||
}
|
||||
|
||||
void hid_hal_keyboard_release_all(Hid* instance) {
|
||||
furi_assert(instance);
|
||||
furi_hal_hid_kb_release_all();
|
||||
}
|
||||
|
||||
void hid_hal_consumer_key_press(Hid* instance, uint16_t event) {
|
||||
furi_assert(instance);
|
||||
furi_hal_hid_consumer_key_press(event);
|
||||
}
|
||||
|
||||
void hid_hal_consumer_key_release(Hid* instance, uint16_t event) {
|
||||
furi_assert(instance);
|
||||
furi_hal_hid_consumer_key_release(event);
|
||||
}
|
||||
|
||||
void hid_hal_consumer_key_release_all(Hid* instance) {
|
||||
furi_assert(instance);
|
||||
furi_hal_hid_kb_release_all();
|
||||
}
|
||||
|
||||
void hid_hal_mouse_move(Hid* instance, int8_t dx, int8_t dy) {
|
||||
furi_assert(instance);
|
||||
furi_hal_hid_mouse_move(dx, dy);
|
||||
}
|
||||
|
||||
void hid_hal_mouse_scroll(Hid* instance, int8_t delta) {
|
||||
furi_assert(instance);
|
||||
furi_hal_hid_mouse_scroll(delta);
|
||||
}
|
||||
|
||||
void hid_hal_mouse_press(Hid* instance, uint16_t event) {
|
||||
furi_assert(instance);
|
||||
furi_hal_hid_mouse_press(event);
|
||||
}
|
||||
|
||||
void hid_hal_mouse_release(Hid* instance, uint16_t event) {
|
||||
furi_assert(instance);
|
||||
furi_hal_hid_mouse_release(event);
|
||||
}
|
||||
|
||||
void hid_hal_mouse_release_all(Hid* instance) {
|
||||
furi_assert(instance);
|
||||
furi_hal_hid_mouse_release(HID_MOUSE_BTN_LEFT);
|
||||
furi_hal_hid_mouse_release(HID_MOUSE_BTN_RIGHT);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "hid_media.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal_bt_hid.h>
|
||||
#include <furi_hal_usb_hid.h>
|
||||
#include <extra_profiles/hid_profile.h>
|
||||
#include <gui/elements.h>
|
||||
#include "../hid.h"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "hid_movie.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal_bt_hid.h>
|
||||
#include <furi_hal_usb_hid.h>
|
||||
#include <extra_profiles/hid_profile.h>
|
||||
#include <gui/elements.h>
|
||||
#include "../hid.h"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "hid_music_macos.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal_bt_hid.h>
|
||||
#include <furi_hal_usb_hid.h>
|
||||
#include <extra_profiles/hid_profile.h>
|
||||
#include <gui/elements.h>
|
||||
#include "../hid.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user