diff --git a/app/src/hog.c b/app/src/hog.c index b82f38f4..20460914 100644 --- a/app/src/hog.c +++ b/app/src/hog.c @@ -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) { - struct bt_conn *conn = destination_connection(); - if (conn == NULL) { - return 1; + 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; + } } - struct bt_gatt_notify_params notify_params = { - .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); + k_work_submit_to_queue(&hog_work_q, &hog_mouse_work); return 0; };