Add Touchpad Feedback History Formatting

This commit is contained in:
Florian Maerkl 2020-07-02 13:04:02 +02:00 committed by Florian Märkl
commit 02d026f205
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
2 changed files with 20 additions and 1 deletions

View file

@ -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
*/

View file

@ -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));