Add messages to BLE queue without a waiting interval

This commit is contained in:
krikun98 2021-08-31 01:49:28 +03:00 committed by Alexander Krikun
parent c2c2961bfc
commit a6d5ed15c9
3 changed files with 5 additions and 8 deletions

View file

@ -309,14 +309,12 @@ void send_mouse_report_callback(struct k_work *work) {
K_WORK_DEFINE(hog_mouse_work, send_mouse_report_callback); 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) {
int err = k_msgq_put(&zmk_hog_mouse_msgq, report, K_MSEC(100)); int err = k_msgq_put(&zmk_hog_mouse_msgq, report, K_NO_WAIT);
if (err) { if (err) {
switch (err) { switch (err) {
case -EAGAIN: { case -EAGAIN: {
LOG_WRN("Mouse message queue full, popping first message and queueing again"); LOG_WRN("Mouse message queue full, dropping report");
struct zmk_hid_mouse_report_body discarded_report; return err;
k_msgq_get(&zmk_hog_mouse_msgq, &discarded_report, K_NO_WAIT);
return zmk_hog_send_mouse_report(report);
} }
default: default:
LOG_WRN("Failed to queue mouse report to send (%d)", err); LOG_WRN("Failed to queue mouse report to send (%d)", err);

View file

@ -41,7 +41,7 @@ void mouse_timer_cb(struct k_timer *dummy) {
k_work_submit_to_queue(zmk_mouse_work_q(), &mouse_tick); k_work_submit_to_queue(zmk_mouse_work_q(), &mouse_tick);
} }
K_TIMER_DEFINE(mouse_timer, mouse_timer_cb, mouse_timer_cb); K_TIMER_DEFINE(mouse_timer, mouse_timer_cb, NULL);
static int mouse_timer_ref_count = 0; static int mouse_timer_ref_count = 0;
@ -50,8 +50,6 @@ void mouse_timer_ref() {
k_timer_start(&mouse_timer, K_NO_WAIT, K_MSEC(CONFIG_ZMK_MOUSE_TICK_DURATION)); k_timer_start(&mouse_timer, K_NO_WAIT, K_MSEC(CONFIG_ZMK_MOUSE_TICK_DURATION));
} }
mouse_timer_ref_count += 1; mouse_timer_ref_count += 1;
// trigger the first mouse tick event immediately
mouse_tick_timer_handler(NULL);
} }
void mouse_timer_unref() { void mouse_timer_unref() {

View file

@ -5,6 +5,7 @@
*/ */
#include <kernel.h> #include <kernel.h>
#include <zmk/mouse.h>
#if IS_ENABLED(CONFIG_ZMK_MOUSE_WORK_QUEUE_DEDICATED) #if IS_ENABLED(CONFIG_ZMK_MOUSE_WORK_QUEUE_DEDICATED)