Skip to content

Commit af9ec17

Browse files
MarekPietakapi-no
authored andcommitted
applications: nrf_desktop: Update motion buttons HW interface
Change aligns state names with the motion sensor HW interface and sends an additional motion event when leaving the fetching state. Jira: NCSDK-35474 Signed-off-by: Marek Pieta <[email protected]>
1 parent 9232b7f commit af9ec17

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

applications/nrf_desktop/src/hw_interface/motion_buttons.c

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ LOG_MODULE_REGISTER(MODULE, CONFIG_DESKTOP_MOTION_LOG_LEVEL);
2727
#endif
2828

2929
enum state {
30+
STATE_DISCONNECTED,
3031
STATE_IDLE,
31-
STATE_CONNECTED,
32-
STATE_PENDING
32+
STATE_FETCHING
3333
};
3434

3535
enum dir {
@@ -151,6 +151,8 @@ static void clear_accumulated_motion(void)
151151

152152
static void send_motion(void)
153153
{
154+
__ASSERT_NO_MSG(state == STATE_FETCHING);
155+
154156
int16_t x;
155157
int16_t y;
156158

@@ -175,9 +177,9 @@ static bool handle_button_event(const struct button_event *event)
175177

176178
update_motion_ts(dir, get_timestamp() - ts_shift);
177179

178-
if (state == STATE_CONNECTED) {
180+
if (state == STATE_IDLE) {
181+
state = STATE_FETCHING;
179182
send_motion();
180-
state = STATE_PENDING;
181183
}
182184
}
183185

@@ -203,11 +205,10 @@ static bool handle_hid_report_sent_event(const struct hid_report_sent_event *eve
203205
{
204206
if ((event->report_id == REPORT_ID_MOUSE) ||
205207
(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;
211212
}
212213
}
213214
}
@@ -231,19 +232,14 @@ static bool handle_hid_report_subscription_event(const struct hid_report_subscri
231232

232233
bool is_connected = (peer_count != 0);
233234

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) {
236238
clear_accumulated_motion();
237239
send_motion();
238-
state = STATE_PENDING;
239-
} else {
240-
state = STATE_CONNECTED;
241240
}
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;
247243
}
248244
}
249245

@@ -253,8 +249,7 @@ static bool handle_hid_report_subscription_event(const struct hid_report_subscri
253249
static bool app_event_handler(const struct app_event_header *aeh)
254250
{
255251
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));
258253
}
259254

260255
if (is_button_event(aeh)) {

0 commit comments

Comments
 (0)