project for a (works on my devices) demo
This commit is contained in:
110
sources/input/touch/touch_controller_L3_deltas_compute.c
Normal file
110
sources/input/touch/touch_controller_L3_deltas_compute.c
Normal file
@@ -0,0 +1,110 @@
|
||||
#include "../../../headers/input/touch/touch_controller_L3_deltas_compute.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void delta_store(
|
||||
tracked_delta *delta, uint8_t state_flag, uint8_t cursor, uint64_t *ids_buffer
|
||||
){
|
||||
(*delta).state = state_flag;
|
||||
(*delta).tracking_id = ids_buffer[cursor];
|
||||
}
|
||||
|
||||
void increase_and_flag(
|
||||
uint8_t *cursor, uint8_t buffer_length, uint8_t *buffer_completed
|
||||
){
|
||||
(*cursor)++;
|
||||
|
||||
if( (*cursor) >= buffer_length){
|
||||
*buffer_completed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* a lot of params since sizeof(arr) does not work with heap arrays */
|
||||
/* takes two sorted arrays of ids : previous and current
|
||||
returns an array of tracked_delta(s)
|
||||
*/
|
||||
void touch_events_sorted_ids_deltas(
|
||||
tracked_delta **endbuffer, uint16_t *endcount,
|
||||
uint64_t *previous_ids, uint8_t previous_count,
|
||||
uint64_t *current_ids, uint8_t current_count
|
||||
){
|
||||
uint16_t accumulatedCounter = 0;
|
||||
|
||||
uint8_t previous_completed = 0;
|
||||
uint8_t current_completed = 0;
|
||||
|
||||
uint8_t previous_cursor = 0;
|
||||
uint8_t current_cursor = 0;
|
||||
|
||||
//until at least one of the lists has not been fully traversed, checks must be done to avoid collisions
|
||||
while( ! previous_completed && ! current_completed){
|
||||
|
||||
accumulatedCounter++;
|
||||
|
||||
if( previous_ids[previous_cursor] < current_ids[current_cursor]){
|
||||
increase_and_flag( &previous_cursor, previous_count, &previous_completed);
|
||||
}
|
||||
else if( previous_ids[previous_cursor] == current_ids[current_cursor]){
|
||||
increase_and_flag( &previous_cursor, previous_count, &previous_completed);
|
||||
increase_and_flag( ¤t_cursor, current_count, ¤t_completed);
|
||||
}
|
||||
else{
|
||||
increase_and_flag( ¤t_cursor, current_count, ¤t_completed);
|
||||
}
|
||||
}
|
||||
|
||||
accumulatedCounter += ( previous_count - previous_cursor);
|
||||
accumulatedCounter += ( current_count - current_cursor);
|
||||
|
||||
*endcount = accumulatedCounter;
|
||||
|
||||
*endbuffer = malloc( *endcount * sizeof( tracked_delta));
|
||||
|
||||
/* since the scan has already been done once, previous_completed and current_completed could be substituted by a counter_threshold variable... */
|
||||
accumulatedCounter = (uint16_t) -1u;
|
||||
|
||||
previous_completed = 0;
|
||||
current_completed = 0;
|
||||
|
||||
previous_cursor = 0;
|
||||
current_cursor = 0;
|
||||
|
||||
while( ! previous_completed && ! current_completed){
|
||||
|
||||
accumulatedCounter++;
|
||||
|
||||
if( previous_ids[previous_cursor] < current_ids[current_cursor]){
|
||||
endbuffer[accumulatedCounter]->old_index = previous_cursor;
|
||||
delta_store( endbuffer[accumulatedCounter], TRACKED_DELTA_EXITED, previous_cursor, previous_ids);
|
||||
increase_and_flag( &previous_cursor, previous_count, &previous_completed);
|
||||
}
|
||||
else if( previous_ids[previous_cursor] == current_ids[current_cursor]){
|
||||
endbuffer[accumulatedCounter]->old_index = previous_cursor;
|
||||
endbuffer[accumulatedCounter]->new_index = current_cursor;
|
||||
// both the combinations of cursor and ids_buffer will work
|
||||
delta_store( endbuffer[accumulatedCounter], TRACKED_DELTA_UNCHANGED, previous_cursor, previous_ids);
|
||||
increase_and_flag( &previous_cursor, previous_count, &previous_completed);
|
||||
increase_and_flag( ¤t_cursor, current_count, ¤t_completed);
|
||||
}
|
||||
else{
|
||||
endbuffer[accumulatedCounter]->new_index = current_cursor;
|
||||
delta_store( endbuffer[accumulatedCounter], TRACKED_DELTA_ENTERED, current_cursor, current_ids );
|
||||
increase_and_flag( ¤t_cursor, current_count, ¤t_completed);
|
||||
}
|
||||
}
|
||||
|
||||
while( ! previous_completed){
|
||||
accumulatedCounter++;
|
||||
endbuffer[accumulatedCounter]->old_index = previous_cursor;
|
||||
delta_store( endbuffer[accumulatedCounter], TRACKED_DELTA_EXITED, previous_cursor, previous_ids);
|
||||
increase_and_flag( &previous_cursor, previous_count, &previous_completed);
|
||||
}
|
||||
|
||||
while( ! current_completed){
|
||||
accumulatedCounter++;
|
||||
endbuffer[accumulatedCounter]->new_index = current_cursor;
|
||||
delta_store( endbuffer[accumulatedCounter], TRACKED_DELTA_ENTERED, current_cursor, current_ids );
|
||||
increase_and_flag( ¤t_cursor, current_count, ¤t_completed);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user