Add Touchpad to Feedback Sender

This commit is contained in:
Florian Märkl 2020-07-02 19:40:34 +02:00
commit cd3d700df8
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
3 changed files with 37 additions and 4 deletions

View file

@ -63,7 +63,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_feedback_history_event_set_button(ChiakiFee
* @param x from 0 to 1920
* @param y from 0 to 942
*/
CHIAKI_EXPORT ChiakiErrorCode chiaki_feedback_history_event_set_touchpad(ChiakiFeedbackHistoryEvent *event,
CHIAKI_EXPORT void chiaki_feedback_history_event_set_touchpad(ChiakiFeedbackHistoryEvent *event,
bool down, uint8_t pointer_id, uint16_t x, uint16_t y);
/**

View file

@ -119,7 +119,7 @@ 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,
CHIAKI_EXPORT void chiaki_feedback_history_event_set_touchpad(ChiakiFeedbackHistoryEvent *event,
bool down, uint8_t pointer_id, uint16_t x, uint16_t y)
{
event->len = 5;

View file

@ -118,9 +118,19 @@ static void feedback_sender_send_state(ChiakiFeedbackSender *feedback_sender)
static bool controller_state_equals_for_feedback_history(ChiakiControllerState *a, ChiakiControllerState *b)
{
return a->buttons == b->buttons
if(!(a->buttons == b->buttons
&& a->l2_state == b->l2_state
&& a->r2_state == b->r2_state;
&& a->r2_state == b->r2_state))
return false;
for(size_t i=0; i<CHIAKI_CONTROLLER_TOUCHES_MAX; i++)
{
if(a->touches[i].id != b->touches[i].id)
return false;
if(a->touches[i].id >= 0 && (a->touches[i].x != b->touches[i].x || a->touches[i].y != b->touches[i].y))
return false;
}
return true;
}
static void feedback_sender_send_history_packet(ChiakiFeedbackSender *feedback_sender)
@ -189,6 +199,29 @@ static void feedback_sender_send_history(ChiakiFeedbackSender *feedback_sender)
else
CHIAKI_LOGE(feedback_sender->log, "Feedback Sender failed to format button history event for R2");
}
for(size_t i=0; i<CHIAKI_CONTROLLER_TOUCHES_MAX; i++)
{
if(state_prev->touches[i].id != state_now->touches[i].id && state_prev->touches[i].id >= 0)
{
ChiakiFeedbackHistoryEvent event;
chiaki_feedback_history_event_set_touchpad(&event, false, (uint8_t)state_prev->touches[i].id,
state_prev->touches[i].x, state_prev->touches[i].y);
chiaki_feedback_history_buffer_push(&feedback_sender->history_buf, &event);
feedback_sender_send_history_packet(feedback_sender);
}
else if(state_now->touches[i].id >= 0
&& (state_prev->touches[i].id != state_now->touches[i].id
|| state_prev->touches[i].x != state_now->touches[i].x
|| state_prev->touches[i].y != state_now->touches[i].y))
{
ChiakiFeedbackHistoryEvent event;
chiaki_feedback_history_event_set_touchpad(&event, true, (uint8_t)state_now->touches[i].id,
state_now->touches[i].x, state_now->touches[i].y);
chiaki_feedback_history_buffer_push(&feedback_sender->history_buf, &event);
feedback_sender_send_history_packet(feedback_sender);
}
}
}
static bool state_cond_check(void *user)