Skip to content

Commit

Permalink
fix(ble): Properly send mouse HoG using worker.
Browse files Browse the repository at this point in the history
* Properly send mouse HoG reports using our worker to avoid thread issues.
  • Loading branch information
petejohanson committed Jan 5, 2024
1 parent 7487531 commit 395ffaa
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions app/src/hog.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,26 +373,25 @@ void send_mouse_report_callback(struct k_work *work) {
}
};

int zmk_hog_send_mouse_report(struct zmk_hid_mouse_report_body *report) {
struct bt_conn *conn = destination_connection();
if (conn == NULL) {
return 1;
}
K_WORK_DEFINE(hog_mouse_work, send_mouse_report_callback);

struct bt_gatt_notify_params notify_params = {
.attr = &hog_svc.attrs[13],
.data = report,
.len = sizeof(*report),
};

int err = bt_gatt_notify_cb(conn, &notify_params);
if (err == -EPERM) {
bt_conn_set_security(conn, BT_SECURITY_L2);
} else if (err) {
LOG_DBG("Error notifying %d", err);
int zmk_hog_send_mouse_report(struct zmk_hid_mouse_report_body *report) {
int err = k_msgq_put(&zmk_hog_mouse_msgq, report, K_MSEC(100));
if (err) {
switch (err) {
case -EAGAIN: {
LOG_WRN("Consumer message queue full, popping first message and queueing again");
struct zmk_hid_mouse_report_body discarded_report;
k_msgq_get(&zmk_hog_mouse_msgq, &discarded_report, K_NO_WAIT);
return zmk_hog_send_mouse_report(report);
}
default:
LOG_WRN("Failed to queue mouse report to send (%d)", err);
return err;
}
}

bt_conn_unref(conn);
k_work_submit_to_queue(&hog_work_q, &hog_mouse_work);

return 0;
};
Expand Down

0 comments on commit 395ffaa

Please sign in to comment.