@@ -27,9 +27,9 @@ LOG_MODULE_REGISTER(MODULE, CONFIG_DESKTOP_MOTION_LOG_LEVEL);
27
27
#endif
28
28
29
29
enum state {
30
+ STATE_DISCONNECTED ,
30
31
STATE_IDLE ,
31
- STATE_CONNECTED ,
32
- STATE_PENDING
32
+ STATE_FETCHING
33
33
};
34
34
35
35
enum dir {
@@ -151,6 +151,8 @@ static void clear_accumulated_motion(void)
151
151
152
152
static void send_motion (void )
153
153
{
154
+ __ASSERT_NO_MSG (state == STATE_FETCHING );
155
+
154
156
int16_t x ;
155
157
int16_t y ;
156
158
@@ -175,9 +177,9 @@ static bool handle_button_event(const struct button_event *event)
175
177
176
178
update_motion_ts (dir , get_timestamp () - ts_shift );
177
179
178
- if (state == STATE_CONNECTED ) {
180
+ if (state == STATE_IDLE ) {
181
+ state = STATE_FETCHING ;
179
182
send_motion ();
180
- state = STATE_PENDING ;
181
183
}
182
184
}
183
185
@@ -203,11 +205,10 @@ static bool handle_hid_report_sent_event(const struct hid_report_sent_event *eve
203
205
{
204
206
if ((event -> report_id == REPORT_ID_MOUSE ) ||
205
207
(event -> report_id == REPORT_ID_BOOT_MOUSE )) {
206
- if (state == STATE_PENDING ) {
207
- if (is_motion_active ()) {
208
- send_motion ();
209
- } else {
210
- state = STATE_CONNECTED ;
208
+ if (state == STATE_FETCHING ) {
209
+ send_motion ();
210
+ if (!is_motion_active ()) {
211
+ state = STATE_IDLE ;
211
212
}
212
213
}
213
214
}
@@ -231,19 +232,14 @@ static bool handle_hid_report_subscription_event(const struct hid_report_subscri
231
232
232
233
bool is_connected = (peer_count != 0 );
233
234
234
- if ((state == STATE_IDLE ) && is_connected ) {
235
- if (is_motion_active ()) {
235
+ if ((state == STATE_DISCONNECTED ) && is_connected ) {
236
+ state = is_motion_active () ? STATE_FETCHING : STATE_IDLE ;
237
+ if (state == STATE_FETCHING ) {
236
238
clear_accumulated_motion ();
237
239
send_motion ();
238
- state = STATE_PENDING ;
239
- } else {
240
- state = STATE_CONNECTED ;
241
240
}
242
- return false;
243
- }
244
- if ((state != STATE_IDLE ) && !is_connected ) {
245
- state = STATE_IDLE ;
246
- return false;
241
+ } else if ((state != STATE_DISCONNECTED ) && !is_connected ) {
242
+ state = STATE_DISCONNECTED ;
247
243
}
248
244
}
249
245
@@ -253,8 +249,7 @@ static bool handle_hid_report_subscription_event(const struct hid_report_subscri
253
249
static bool app_event_handler (const struct app_event_header * aeh )
254
250
{
255
251
if (is_hid_report_sent_event (aeh )) {
256
- return handle_hid_report_sent_event (
257
- cast_hid_report_sent_event (aeh ));
252
+ return handle_hid_report_sent_event (cast_hid_report_sent_event (aeh ));
258
253
}
259
254
260
255
if (is_button_event (aeh )) {
0 commit comments