From 02d026f20528a30da53ef61fbbb94d0802a0c9a7 Mon Sep 17 00:00:00 2001 From: Florian Maerkl Date: Thu, 2 Jul 2020 13:04:02 +0200 Subject: [PATCH] Add Touchpad Feedback History Formatting --- lib/include/chiaki/feedback.h | 10 +++++++++- lib/src/feedback.c | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/include/chiaki/feedback.h b/lib/include/chiaki/feedback.h index 6a74ae1..19e9d7f 100644 --- a/lib/include/chiaki/feedback.h +++ b/lib/include/chiaki/feedback.h @@ -44,7 +44,7 @@ typedef struct chiaki_feedback_state_t CHIAKI_EXPORT void chiaki_feedback_state_format(uint8_t *buf, ChiakiFeedbackState *state); -#define CHIAKI_HISTORY_EVENT_SIZE_MAX 0x3 // TODO: will be bigger later for touchpad at least +#define CHIAKI_HISTORY_EVENT_SIZE_MAX 0x5 typedef struct chiaki_feedback_history_event_t { @@ -58,6 +58,14 @@ typedef struct chiaki_feedback_history_event_t */ CHIAKI_EXPORT ChiakiErrorCode chiaki_feedback_history_event_set_button(ChiakiFeedbackHistoryEvent *event, uint64_t button, uint8_t state); +/** + * @param pointer_id identifier for the touch from 0 to 127 + * @param x from 0 to 1920 + * @param y from 0 to 942 + */ +CHIAKI_EXPORT ChiakiErrorCode chiaki_feedback_history_event_set_touchpad(ChiakiFeedbackHistoryEvent *event, + bool down, uint8_t pointer_id, uint16_t x, uint16_t y); + /** * Ring buffer of ChiakiFeedbackHistoryEvent */ diff --git a/lib/src/feedback.c b/lib/src/feedback.c index c294264..b852f7d 100644 --- a/lib/src/feedback.c +++ b/lib/src/feedback.c @@ -119,6 +119,17 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_feedback_history_event_set_button(ChiakiFee return CHIAKI_ERR_SUCCESS; } +CHIAKI_EXPORT ChiakiErrorCode chiaki_feedback_history_event_set_touchpad(ChiakiFeedbackHistoryEvent *event, + bool down, uint8_t pointer_id, uint16_t x, uint16_t y) +{ + event->len = 5; + event->buf[0] = down ? 0xd0 : 0xc0; + event->buf[1] = pointer_id / 0x7f; + event->buf[2] = (uint8_t)(x >> 4); + event->buf[3] = (uint8_t)((x & 0xf) << 4) | (uint8_t)(y >> 8); + event->buf[4] = (uint8_t)y; +} + CHIAKI_EXPORT ChiakiErrorCode chiaki_feedback_history_buffer_init(ChiakiFeedbackHistoryBuffer *feedback_history_buffer, size_t size) { feedback_history_buffer->events = calloc(size, sizeof(ChiakiFeedbackHistoryEvent));