diff --git a/lib/include/chiaki/feedback.h b/lib/include/chiaki/feedback.h index 19e9d7f..83cb08a 100644 --- a/lib/include/chiaki/feedback.h +++ b/lib/include/chiaki/feedback.h @@ -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); /** diff --git a/lib/src/feedback.c b/lib/src/feedback.c index b852f7d..d7a8b49 100644 --- a/lib/src/feedback.c +++ b/lib/src/feedback.c @@ -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; diff --git a/lib/src/feedbacksender.c b/lib/src/feedbacksender.c index b812d39..2fee4b6 100644 --- a/lib/src/feedbacksender.c +++ b/lib/src/feedbacksender.c @@ -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; itouches[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; itouches[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)