Skip to content

Commit 05c5f45

Browse files
committed
Format and make scrolling more intuitive
1 parent 6f45b0e commit 05c5f45

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

tracking/main_loop.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
extern "C" {
77
#endif
88

9-
typedef bool (*MouseMoveCallback)(int8_t x, int8_t y, void *context);
9+
typedef bool (*MouseMoveCallback)(int8_t x, int8_t y, void* context);
1010

1111
void calibration_begin();
1212
bool calibration_step();
1313
void calibration_end();
1414

1515
void tracking_begin();
16-
void tracking_step(MouseMoveCallback mouse_move, void *context);
16+
void tracking_step(MouseMoveCallback mouse_move, void* context);
1717
void tracking_end();
1818

1919
#ifdef __cplusplus

views/bt_mouse.c

+15-17
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ struct BtMouse {
4444
#define BT_MOUSE_FLAG_KILL_THREAD (1UL << 1)
4545
#define BT_MOUSE_FLAG_ALL (BT_MOUSE_FLAG_INPUT_EVENT | BT_MOUSE_FLAG_KILL_THREAD)
4646

47-
#define MOUSE_MOVE_SHORT 5
48-
#define MOUSE_MOVE_LONG 20
49-
#define MOUSE_SCROLL 20
47+
#define MOUSE_SCROLL 2
5048

5149
static void bt_mouse_notify_event(BtMouse* bt_mouse) {
5250
FuriThreadId thread_id = furi_thread_get_id(bt_mouse->thread);
@@ -68,7 +66,7 @@ static void bt_mouse_button_state(BtMouse* bt_mouse, int8_t button, bool state)
6866
event.button = button;
6967
event.state = state;
7068

71-
if (bt_mouse->connected) {
69+
if(bt_mouse->connected) {
7270
furi_mutex_acquire(bt_mouse->mutex, FuriWaitForever);
7371
bt_mouse->queue[bt_mouse->qtail++] = event;
7472
bt_mouse->qtail %= BTN_EVT_QUEUE_SIZE;
@@ -102,11 +100,11 @@ static void bt_mouse_process(BtMouse* bt_mouse, InputEvent* event) {
102100
bt_mouse_button_state(bt_mouse, HID_MOUSE_BTN_WHEEL, false);
103101
}
104102
} else if(event->key == InputKeyRight) {
105-
if(event->type == InputTypePress) {
103+
if(event->type == InputTypePress || event->type == InputTypeRepeat) {
106104
bt_mouse->wheel = MOUSE_SCROLL;
107105
}
108106
} else if(event->key == InputKeyLeft) {
109-
if(event->type == InputTypePress) {
107+
if(event->type == InputTypePress || event->type == InputTypeRepeat) {
110108
bt_mouse->wheel = -MOUSE_SCROLL;
111109
}
112110
}
@@ -147,11 +145,11 @@ void bt_mouse_connection_status_changed_callback(BtStatus status, void* context)
147145
// bt_mouse->view, void * model, { model->connected = connected; }, true);
148146
}
149147

150-
bool bt_mouse_move(int8_t dx, int8_t dy, void *context) {
148+
bool bt_mouse_move(int8_t dx, int8_t dy, void* context) {
151149
furi_assert(context);
152150
BtMouse* bt_mouse = context;
153151

154-
if (bt_mouse->connected) {
152+
if(bt_mouse->connected) {
155153
furi_mutex_acquire(bt_mouse->mutex, FuriWaitForever);
156154
bt_mouse->dx += dx;
157155
bt_mouse->dy += dy;
@@ -203,10 +201,9 @@ void bt_mouse_exit_callback(void* context) {
203201
}
204202

205203
static int8_t clamp(int t) {
206-
if (t < -128) {
204+
if(t < -128) {
207205
return -128;
208-
}
209-
else if (t > 127) {
206+
} else if(t > 127) {
210207
return 127;
211208
}
212209
return t;
@@ -217,7 +214,8 @@ static int32_t bt_mouse_thread_callback(void* context) {
217214
BtMouse* bt_mouse = (BtMouse*)context;
218215

219216
while(1) {
220-
uint32_t flags = furi_thread_flags_wait(BT_MOUSE_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever);
217+
uint32_t flags =
218+
furi_thread_flags_wait(BT_MOUSE_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever);
221219
if(flags & BT_MOUSE_FLAG_KILL_THREAD) {
222220
break;
223221
}
@@ -226,7 +224,7 @@ static int32_t bt_mouse_thread_callback(void* context) {
226224

227225
ButtonEvent event;
228226
bool send_buttons = false;
229-
if (bt_mouse->qhead != bt_mouse->qtail) {
227+
if(bt_mouse->qhead != bt_mouse->qtail) {
230228
event = bt_mouse->queue[bt_mouse->qhead++];
231229
bt_mouse->qhead %= BTN_EVT_QUEUE_SIZE;
232230
send_buttons = true;
@@ -241,19 +239,19 @@ static int32_t bt_mouse_thread_callback(void* context) {
241239

242240
furi_mutex_release(bt_mouse->mutex);
243241

244-
if (bt_mouse->connected && send_buttons) {
245-
if (event.state) {
242+
if(bt_mouse->connected && send_buttons) {
243+
if(event.state) {
246244
furi_hal_bt_hid_mouse_press(event.button);
247245
} else {
248246
furi_hal_bt_hid_mouse_release(event.button);
249247
}
250248
}
251249

252-
if (bt_mouse->connected && (dx != 0 || dy != 0)) {
250+
if(bt_mouse->connected && (dx != 0 || dy != 0)) {
253251
furi_hal_bt_hid_mouse_move(dx, dy);
254252
}
255253

256-
if (bt_mouse->connected && wheel != 0) {
254+
if(bt_mouse->connected && wheel != 0) {
257255
furi_hal_bt_hid_mouse_scroll(wheel);
258256
}
259257
}

views/usb_mouse.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static void usb_mouse_draw_callback(Canvas* canvas, void* context) {
2121
canvas_draw_str(canvas, 0, 63, "Hold [back] to exit");
2222
}
2323

24-
#define MOUSE_SCROLL 20
24+
#define MOUSE_SCROLL 2
2525

2626
static void usb_mouse_process(UsbMouse* usb_mouse, InputEvent* event) {
2727
with_view_model(
@@ -48,11 +48,11 @@ static void usb_mouse_process(UsbMouse* usb_mouse, InputEvent* event) {
4848
furi_hal_hid_mouse_release(HID_MOUSE_BTN_WHEEL);
4949
}
5050
} else if(event->key == InputKeyRight) {
51-
if(event->type == InputTypePress) {
51+
if(event->type == InputTypePress || event->type == InputTypeRepeat) {
5252
furi_hal_hid_mouse_scroll(MOUSE_SCROLL);
5353
}
5454
} else if(event->key == InputKeyLeft) {
55-
if(event->type == InputTypePress) {
55+
if(event->type == InputTypePress || event->type == InputTypeRepeat) {
5656
furi_hal_hid_mouse_scroll(-MOUSE_SCROLL);
5757
}
5858
}
@@ -88,7 +88,7 @@ void usb_mouse_enter_callback(void* context) {
8888
view_dispatcher_send_custom_event(usb_mouse->view_dispatcher, 0);
8989
}
9090

91-
bool usb_mouse_move(int8_t dx, int8_t dy, void *context) {
91+
bool usb_mouse_move(int8_t dx, int8_t dy, void* context) {
9292
UNUSED(context);
9393
return furi_hal_hid_mouse_move(dx, dy);
9494
}

0 commit comments

Comments
 (0)