Skip to content

Commit

Permalink
upd airmouse
Browse files Browse the repository at this point in the history
by Willy-JL
  • Loading branch information
xMasterX committed Feb 19, 2024
1 parent 0c46ae9 commit a534b79
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
7 changes: 7 additions & 0 deletions non_catalog_apps/airmouse/air_mouse.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "air_mouse.h"
#include <storage/storage.h>

#include <furi.h>
#include "tracking/imu/imu.h"
Expand Down Expand Up @@ -51,6 +52,12 @@ uint32_t air_mouse_exit(void* context) {
AirMouse* air_mouse_app_alloc() {
AirMouse* app = malloc(sizeof(AirMouse));

Storage* storage = furi_record_open(RECORD_STORAGE);
storage_simply_mkdir(storage, EXT_PATH("apps_data/air_mouse"));
storage_common_migrate(
storage, EXT_PATH(".calibration.data"), EXT_PATH("apps_data/air_mouse/calibration.data"));
furi_record_close(RECORD_STORAGE);

// Gui
app->gui = furi_record_open(RECORD_GUI);

Expand Down
3 changes: 2 additions & 1 deletion non_catalog_apps/airmouse/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ App(
stack_size=10 * 1024,
fap_category="GPIO",
fap_icon="mouse_10px.png",
fap_version="0.8",
fap_version="0.9",
sources=["*.c", "*.cc"],
fap_libs=["ble_profile"],
)
4 changes: 2 additions & 2 deletions non_catalog_apps/airmouse/tracking/calibration_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include "util/vector.h"

#define CALIBRATION_DATA_VER (1)
#define CALIBRATION_DATA_FILE_NAME ".calibration.data"
#define CALIBRATION_DATA_PATH EXT_PATH(CALIBRATION_DATA_FILE_NAME)
#define CALIBRATION_DATA_FILE_NAME "calibration.data"
#define CALIBRATION_DATA_PATH EXT_PATH("apps_data/air_mouse/" CALIBRATION_DATA_FILE_NAME)
#define CALIBRATION_DATA_MAGIC (0x23)

#define CALIBRATION_DATA_SAVE(x) \
Expand Down
20 changes: 11 additions & 9 deletions non_catalog_apps/airmouse/views/bt_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <furi.h>
#include <furi_hal_bt.h>
#include <furi_hal_bt_hid.h>
#include <extra_profiles/hid_profile.h>
#include <furi_hal_usb_hid.h>
#include <bt/bt_service/bt.h>
#include <gui/elements.h>
Expand All @@ -21,6 +21,7 @@ struct BtMouse {
View* view;
ViewDispatcher* view_dispatcher;
Bt* bt;
FuriHalBleProfileBase* ble_hid_profile;
NotificationApp* notifications;
FuriMutex* mutex;
FuriThread* thread;
Expand Down Expand Up @@ -118,7 +119,7 @@ static bool bt_mouse_input_callback(InputEvent* event, void* context) {
bool consumed = false;

if(event->type == InputTypeLong && event->key == InputKeyBack) {
furi_hal_bt_hid_mouse_release_all();
ble_profile_hid_mouse_release_all(bt_mouse->ble_hid_profile);
} else {
bt_mouse_process(bt_mouse, event);
consumed = true;
Expand Down Expand Up @@ -203,18 +204,18 @@ static int32_t bt_mouse_thread_callback(void* context) {

if(bt_mouse->connected && send_buttons) {
if(event.state) {
furi_hal_bt_hid_mouse_press(event.button);
ble_profile_hid_mouse_press(bt_mouse->ble_hid_profile, event.button);
} else {
furi_hal_bt_hid_mouse_release(event.button);
ble_profile_hid_mouse_release(bt_mouse->ble_hid_profile, event.button);
}
}

if(bt_mouse->connected && (dx != 0 || dy != 0)) {
furi_hal_bt_hid_mouse_move(dx, dy);
ble_profile_hid_mouse_move(bt_mouse->ble_hid_profile, dx, dy);
}

if(bt_mouse->connected && wheel != 0) {
furi_hal_bt_hid_mouse_scroll(wheel);
ble_profile_hid_mouse_scroll(bt_mouse->ble_hid_profile, wheel);
}
}
}
Expand Down Expand Up @@ -253,7 +254,8 @@ void bt_mouse_enter_callback(void* context) {
bt_mouse->notifications = furi_record_open(RECORD_NOTIFICATION);
bt_set_status_changed_callback(
bt_mouse->bt, bt_mouse_connection_status_changed_callback, bt_mouse);
furi_assert(bt_set_profile(bt_mouse->bt, BtProfileHidKeyboard));
bt_mouse->ble_hid_profile = bt_profile_start(bt_mouse->bt, ble_profile_hid, NULL);
furi_check(bt_mouse->ble_hid_profile);
furi_hal_bt_start_advertising();
bt_mouse_thread_start(bt_mouse);
}
Expand All @@ -278,8 +280,8 @@ void bt_mouse_exit_callback(void* context) {
tracking_end();
notification_internal_message(bt_mouse->notifications, &sequence_reset_blue);

furi_hal_bt_stop_advertising();
bt_set_profile(bt_mouse->bt, BtProfileSerial);
bt_set_status_changed_callback(bt_mouse->bt, NULL, NULL);
furi_check(bt_profile_restore_default(bt_mouse->bt));

furi_record_close(RECORD_NOTIFICATION);
bt_mouse->notifications = NULL;
Expand Down

0 comments on commit a534b79

Please sign in to comment.