MX 1 год назад
Родитель
Сommit
997b16d71a

+ 53 - 0
CHANGELOG.md

@@ -0,0 +1,53 @@
+# Changelog
+
+## v1.3 (2024-08-15)
+
+**Fix new firmwares compatibility**
+
+## v1.2 (2024-06-05)
+
+**Support multiple IMU models**
+
+ - Apart from BMI160, you can now use LSM6DS3 or LSM6DSO
+
+## v1.1 (2024-03-14)
+
+**BLE updates/fixes**
+
+## v1.0 (2024-03-09)
+
+**Update for SDK 0.99**
+
+## v0.0.6 (2023-08-09)
+
+**Fix firmware 0.88 issues**
+
+## v0.0.5 (2023-06-18)
+
+**Closed issues:**
+
+- Error on firmware 0.77.1
+- Flipper Z with airmouse like LG pilot on Android TV
+- PINOUT
+- Noob Question
+- BMI160 alternative?
+
+## v0.0.4 (2023-01-22)
+
+**Closed issues:**
+
+- Request: change directional buttons
+
+**Merged pull requests:**
+
+- Manifest build sources
+
+## v0.0.3 (2022-12-30)
+
+**Closed issues:**
+
+- Firmware requirement?
+
+**Merged pull requests:**
+
+- adjust button function \(add scrolling\)

+ 2 - 1
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
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=[

+ 10 - 4
lib/lsm6ds3tr-api/README.md

@@ -1,3 +1,5 @@
+![latest tag](https://img.shields.io/github/v/tag/STMicroelectronics/lsm6ds3tr-c-pid.svg?color=brightgreen)
+
 # 1 - Introduction
 
 Sensor driver for LSM6DS3TR-C sensor written in C programming language. This repository contains the sensor driver files (.h and .c) to be included, or linked directly as a git submodule, in your project. The driver is MISRA compliant and the documentation can be generated using the [Doxygen](http://www.doxygen.org/) tool.
@@ -16,8 +18,7 @@ Some examples of driver usage can be found [here](https://github.com/STMicroelec
 
 # 2 - Integration details
 
-The driver is platform-independent, you only need to define two  functions for read and write transactions from the sensor hardware bus  (ie. SPI or I²C). **A few devices integrate an extra bit in the  communication protocol in order to enable multi read/write access, this  bit must be managed in the read and write functions defined by the user.** Please refer to the read and write implementation in the [reference examples](https://github.com/STMicroelectronics/STMems_Standard_C_drivers/tree/master/lsm6ds3tr-c_STdC/examples).
-
+The driver is platform-independent, you only need to define two functions for read and write transactions from the sensor hardware bus (ie. SPI or I²C) and an optional one to implement a delay of millisecond granularity. **A few devices integrate an extra bit in the communication protocol in order to enable multi read/write access, this bit must be managed in the read and write functions defined by the user.** Please refer to the read and write implementation in the [reference examples](https://github.com/STMicroelectronics/STMems_Standard_C_drivers/tree/master/lsm6ds3tr-c_STdC/examples).
 
 
 ### 2.a Source code integration
@@ -27,8 +28,11 @@ The driver is platform-independent, you only need to define two  functions for r
 
 ```
 /** Please note that is MANDATORY: return 0 -> no Error.**/
-int32_t platform_write(void *handle, uint8_t Reg, const uint8_t *Bufp, uint16_t len)
-int32_t platform_read(void *handle, uint8_t Reg, uint8_t *Bufp, uint16_t len)
+int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, uint16_t len)
+int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, uint16_t len)
+
+/** Optional (may be required by driver) **/
+void platform_delay(uint32_t millisec)
 ```
 
 - Declare and initialize the structure of the device interface:
@@ -37,6 +41,8 @@ int32_t platform_read(void *handle, uint8_t Reg, uint8_t *Bufp, uint16_t len)
 xxxxxxx_ctx_t dev_ctx; /** xxxxxxx is the used part number **/
 dev_ctx.write_reg = platform_write;
 dev_ctx.read_reg = platform_read;
+dev_ctx.mdelay = platform_delay;
+
 ```
 
 - If needed by the platform read and write functions, initialize the handle parameter:

+ 3 - 3
tracking/calibration_data.h

@@ -6,10 +6,10 @@
 
 #include "util/vector.h"
 
-#define CALIBRATION_DATA_VER (1)
+#define CALIBRATION_DATA_VER       (1)
 #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_PATH      EXT_PATH("apps_data/air_mouse/" CALIBRATION_DATA_FILE_NAME)
+#define CALIBRATION_DATA_MAGIC     (0x23)
 
 #define CALIBRATION_DATA_SAVE(x)   \
     saved_struct_save(             \

+ 1 - 1
tracking/imu/bmi160.c

@@ -1,7 +1,7 @@
 #include "imu.h"
 #include "../../lib/bmi160-api/bmi160.h"
 
-#define BMI160_TAG "BMI160"
+#define BMI160_TAG      "BMI160"
 #define BMI160_DEV_ADDR (0x69 << 1)
 
 struct bmi160_dev bmi160dev;

+ 3 - 2
tracking/imu/lsm6ds3trc.c

@@ -1,7 +1,7 @@
 #include "imu.h"
 #include "../../lib/lsm6ds3tr-api/lsm6ds3tr-c_reg.h"
 
-#define LSM6DS3_TAG "LSM6DS3"
+#define LSM6DS3_TAG         "LSM6DS3"
 #define LSM6DS3_DEV_ADDRESS (0x6A << 1)
 
 stmdev_ctx_t lsm6ds3trc_ctx;
@@ -39,7 +39,8 @@ bool lsm6ds3trc_begin() {
 
     lsm6ds3tr_c_reset_set(&lsm6ds3trc_ctx, PROPERTY_ENABLE);
     uint8_t rst = PROPERTY_ENABLE;
-    while(rst) lsm6ds3tr_c_reset_get(&lsm6ds3trc_ctx, &rst);
+    while(rst)
+        lsm6ds3tr_c_reset_get(&lsm6ds3trc_ctx, &rst);
 
     lsm6ds3tr_c_block_data_update_set(&lsm6ds3trc_ctx, PROPERTY_ENABLE);
     lsm6ds3tr_c_fifo_mode_set(&lsm6ds3trc_ctx, LSM6DS3TR_C_BYPASS_MODE);

+ 3 - 2
tracking/imu/lsm6dso.c

@@ -1,7 +1,7 @@
 #include "imu.h"
 #include "../../lib/lsm6dso-api/lsm6dso_reg.h"
 
-#define LSM6DSO_TAG "LSM6DO"
+#define LSM6DSO_TAG         "LSM6DO"
 #define LSM6DSO_DEV_ADDRESS (0x6B << 1)
 
 stmdev_ctx_t lsm6dso_ctx;
@@ -38,7 +38,8 @@ bool lsm6dso_begin() {
 
     lsm6dso_reset_set(&lsm6dso_ctx, PROPERTY_ENABLE);
     uint8_t rst = PROPERTY_ENABLE;
-    while(rst) lsm6dso_reset_get(&lsm6dso_ctx, &rst);
+    while(rst)
+        lsm6dso_reset_get(&lsm6dso_ctx, &rst);
 
     lsm6dso_block_data_update_set(&lsm6dso_ctx, PROPERTY_ENABLE);
     lsm6dso_fifo_mode_set(&lsm6dso_ctx, LSM6DSO_BYPASS_MODE);

+ 12 - 15
views/bt_mouse.c

@@ -50,7 +50,7 @@ static const BleProfileHidParams ble_hid_params = {
 
 #define BT_MOUSE_FLAG_INPUT_EVENT (1UL << 0)
 #define BT_MOUSE_FLAG_KILL_THREAD (1UL << 1)
-#define BT_MOUSE_FLAG_ALL (BT_MOUSE_FLAG_INPUT_EVENT | BT_MOUSE_FLAG_KILL_THREAD)
+#define BT_MOUSE_FLAG_ALL         (BT_MOUSE_FLAG_INPUT_EVENT | BT_MOUSE_FLAG_KILL_THREAD)
 
 #define MOUSE_SCROLL 2
 
@@ -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,10 @@ 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 +299,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 +334,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;
 }

+ 15 - 19
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,17 @@ 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 +119,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;
 }