fix(ble): Properly send mouse HoG using worker.
* Properly send mouse HoG reports using our worker to avoid thread issues.
This commit is contained in:
parent
74875314f8
commit
395ffaa790
1 changed files with 16 additions and 17 deletions
|
@ -373,26 +373,25 @@ void send_mouse_report_callback(struct k_work *work) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
K_WORK_DEFINE(hog_mouse_work, send_mouse_report_callback);
|
||||||
|
|
||||||
int zmk_hog_send_mouse_report(struct zmk_hid_mouse_report_body *report) {
|
int zmk_hog_send_mouse_report(struct zmk_hid_mouse_report_body *report) {
|
||||||
struct bt_conn *conn = destination_connection();
|
int err = k_msgq_put(&zmk_hog_mouse_msgq, report, K_MSEC(100));
|
||||||
if (conn == NULL) {
|
if (err) {
|
||||||
return 1;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bt_gatt_notify_params notify_params = {
|
k_work_submit_to_queue(&hog_work_q, &hog_mouse_work);
|
||||||
.attr = &hog_svc.attrs[13],
|
|
||||||
.data = report,
|
|
||||||
.len = sizeof(*report),
|
|
||||||
};
|
|
||||||
|
|
||||||
int err = bt_gatt_notify_cb(conn, ¬ify_params);
|
|
||||||
if (err == -EPERM) {
|
|
||||||
bt_conn_set_security(conn, BT_SECURITY_L2);
|
|
||||||
} else if (err) {
|
|
||||||
LOG_DBG("Error notifying %d", err);
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_conn_unref(conn);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue