Ver Fonte

Merge airmouse from https://github.com/ginkage/FlippAirMouse/

# Conflicts:
#	airmouse/air_mouse.c
#	airmouse/application.fam
Willy-JL há 1 ano atrás
pai
commit
95438bac96

+ 4 - 0
airmouse/CHANGELOG.md

@@ -1,5 +1,9 @@
 # Changelog
 
+## v1.3 (2024-08-15)
+
+**Fix new firmwares compatibility**
+
 ## v1.2 (2024-06-05)
 
 **Support multiple IMU models**

+ 2 - 1
airmouse/air_mouse.c

@@ -66,7 +66,6 @@ AirMouse* air_mouse_app_alloc() {
 
     // View dispatcher
     app->view_dispatcher = view_dispatcher_alloc();
-
     view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
 
     // Submenu view
@@ -132,6 +131,8 @@ AirMouse* air_mouse_app_alloc() {
     app->view_id = AirMouseViewSubmenu;
     view_dispatcher_switch_to_view(app->view_dispatcher, app->view_id);
 
+    view_dispatcher_set_tick_event_callback(app->view_dispatcher, NULL, furi_ms_to_ticks(10));
+
     return app;
 }
 

+ 1 - 1
airmouse/application.fam

@@ -6,7 +6,7 @@ App(
     stack_size=10 * 1024,
     fap_category="GPIO",
     fap_icon="mouse_10px.png",
-    fap_version="1.2",
+    fap_version="1.3",
     fap_libs=["ble_profile"],
     sources=["*.c", "*.cc"],
     fap_private_libs=[

+ 0 - 3
airmouse/build.sh

@@ -1,3 +0,0 @@
-#!/bin/bash
-
-ufbt

+ 10 - 14
airmouse/views/bt_mouse.c

@@ -150,7 +150,6 @@ void bt_mouse_connection_status_changed_callback(BtStatus status, void* context)
     if(bt_mouse->connected) {
         notification_internal_message(bt_mouse->notifications, &sequence_set_blue_255);
         tracking_begin();
-        view_dispatcher_send_custom_event(bt_mouse->view_dispatcher, 0);
     } else {
         tracking_end();
         notification_internal_message(bt_mouse->notifications, &sequence_reset_blue);
@@ -255,6 +254,11 @@ void bt_mouse_thread_stop(BtMouse* bt_mouse) {
     bt_mouse->thread = NULL;
 }
 
+void bt_mouse_tick_event_callback(void* context) {
+    furi_assert(context);
+    tracking_step(bt_mouse_move, context);
+}
+
 void bt_mouse_enter_callback(void* context) {
     furi_assert(context);
     BtMouse* bt_mouse = context;
@@ -272,6 +276,9 @@ void bt_mouse_enter_callback(void* context) {
     furi_assert(bt_mouse->hid);
     furi_hal_bt_start_advertising();
     bt_mouse_thread_start(bt_mouse);
+
+    view_dispatcher_set_event_callback_context(bt_mouse->view_dispatcher, bt_mouse);
+    view_dispatcher_set_tick_event_callback(bt_mouse->view_dispatcher, bt_mouse_tick_event_callback, furi_ms_to_ticks(10));
 }
 
 void bt_mouse_remove_pairing(void) {
@@ -291,22 +298,12 @@ void bt_mouse_remove_pairing(void) {
     furi_record_close(RECORD_BT);
 }
 
-bool bt_mouse_custom_callback(uint32_t event, void* context) {
-    UNUSED(event);
-    furi_assert(context);
-    BtMouse* bt_mouse = context;
-
-    tracking_step(bt_mouse_move, context);
-    furi_delay_ms(3); // Magic! Removing this will break the buttons
-
-    view_dispatcher_send_custom_event(bt_mouse->view_dispatcher, 0);
-    return true;
-}
-
 void bt_mouse_exit_callback(void* context) {
     furi_assert(context);
     BtMouse* bt_mouse = context;
 
+    view_dispatcher_set_tick_event_callback(bt_mouse->view_dispatcher, NULL, FuriWaitForever);
+
     bt_mouse_thread_stop(bt_mouse);
     tracking_end();
     notification_internal_message(bt_mouse->notifications, &sequence_reset_blue);
@@ -336,7 +333,6 @@ BtMouse* bt_mouse_alloc(ViewDispatcher* view_dispatcher) {
     view_set_draw_callback(bt_mouse->view, bt_mouse_draw_callback);
     view_set_input_callback(bt_mouse->view, bt_mouse_input_callback);
     view_set_enter_callback(bt_mouse->view, bt_mouse_enter_callback);
-    view_set_custom_callback(bt_mouse->view, bt_mouse_custom_callback);
     view_set_exit_callback(bt_mouse->view, bt_mouse_exit_callback);
     return bt_mouse;
 }

+ 14 - 19
airmouse/views/usb_mouse.c

@@ -75,6 +75,16 @@ static bool usb_mouse_input_callback(InputEvent* event, void* context) {
     return consumed;
 }
 
+bool usb_mouse_move(int8_t dx, int8_t dy, void* context) {
+    UNUSED(context);
+    return furi_hal_hid_mouse_move(dx, dy);
+}
+
+void usb_mouse_tick_event_callback(void* context) {
+    furi_assert(context);
+    tracking_step(usb_mouse_move, context);
+}
+
 void usb_mouse_enter_callback(void* context) {
     furi_assert(context);
     UsbMouse* usb_mouse = context;
@@ -85,30 +95,16 @@ void usb_mouse_enter_callback(void* context) {
 
     tracking_begin();
 
-    view_dispatcher_send_custom_event(usb_mouse->view_dispatcher, 0);
-}
-
-bool usb_mouse_move(int8_t dx, int8_t dy, void* context) {
-    UNUSED(context);
-    return furi_hal_hid_mouse_move(dx, dy);
-}
-
-bool usb_mouse_custom_callback(uint32_t event, void* context) {
-    UNUSED(event);
-    furi_assert(context);
-    UsbMouse* usb_mouse = context;
-
-    tracking_step(usb_mouse_move, context);
-    furi_delay_ms(3); // Magic! Removing this will break the buttons
-
-    view_dispatcher_send_custom_event(usb_mouse->view_dispatcher, 0);
-    return true;
+    view_dispatcher_set_event_callback_context(usb_mouse->view_dispatcher, usb_mouse);
+    view_dispatcher_set_tick_event_callback(usb_mouse->view_dispatcher, usb_mouse_tick_event_callback, furi_ms_to_ticks(10));
 }
 
 void usb_mouse_exit_callback(void* context) {
     furi_assert(context);
     UsbMouse* usb_mouse = context;
 
+    view_dispatcher_set_tick_event_callback(usb_mouse->view_dispatcher, NULL, FuriWaitForever);
+
     tracking_end();
 
     furi_hal_usb_set_config(usb_mouse->usb_mode_prev, NULL);
@@ -122,7 +118,6 @@ UsbMouse* usb_mouse_alloc(ViewDispatcher* view_dispatcher) {
     view_set_draw_callback(usb_mouse->view, usb_mouse_draw_callback);
     view_set_input_callback(usb_mouse->view, usb_mouse_input_callback);
     view_set_enter_callback(usb_mouse->view, usb_mouse_enter_callback);
-    view_set_custom_callback(usb_mouse->view, usb_mouse_custom_callback);
     view_set_exit_callback(usb_mouse->view, usb_mouse_exit_callback);
     return usb_mouse;
 }