74 lines
1.8 KiB
C
74 lines
1.8 KiB
C
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "../../../headers/input/touch/touch_data.h"
|
|
|
|
touch_event* touch_event_new(){
|
|
touch_event* te = malloc( sizeof( touch_event));
|
|
te->slot_number = 0;
|
|
te->tracking_id = 0;
|
|
te->position.x = 0;
|
|
te->position.y = 0;
|
|
return te;
|
|
}
|
|
|
|
/* could use memcpy...*/
|
|
void touch_event_copy( touch_event *dst, touch_event *src){
|
|
dst->slot_number = src->slot_number;
|
|
dst->tracking_id = src->tracking_id;
|
|
dst->position.x = src->position.x;
|
|
dst->position.y = src->position.y;
|
|
}
|
|
|
|
touch_coordinates* new_touch_coordinates_buffer( uint8_t count){
|
|
if( ! count){
|
|
return NULL;
|
|
}
|
|
touch_coordinates* buffer = malloc( count * sizeof( touch_coordinates));
|
|
return buffer;
|
|
}
|
|
|
|
void free_touch_coordinates_buffer( touch_coordinates* buffer){
|
|
if( buffer){
|
|
free( buffer);
|
|
}
|
|
}
|
|
|
|
void print_touch_event( touch_event *event){
|
|
printf("touch_event info : %p\n", (void*) event);
|
|
printf("slot_number : %ld\n", event->slot_number);
|
|
printf("tracking_id : %ld\n", event->tracking_id);
|
|
printf("position_x : %ld\n", event->position.x);
|
|
printf("position_y : %ld\n", event->position.y);
|
|
printf("touch_event info end\n");
|
|
}
|
|
|
|
void touch_events_array_copy( touch_event ***dst, touch_event **src, uint8_t count){
|
|
//printf("begin copy\n");
|
|
if( ! count){
|
|
//printf("nothing to copy\n");
|
|
*dst = NULL;
|
|
return;
|
|
}
|
|
*dst = malloc( count * sizeof( touch_event*));
|
|
//printf("will copy %d items, into %p, taken from %p\n", count, ( void*) (*dst), ( void*) src);
|
|
for( uint8_t i ; i < count; i++){
|
|
//print_touch_event( src[i]);
|
|
( *dst)[i] = touch_event_new();
|
|
|
|
//print_touch_event( ( *dst)[i]);
|
|
|
|
touch_event_copy( ( *dst)[i], src[i]);
|
|
//print_touch_event( ( *dst)[i]);
|
|
}
|
|
//printf("end copy\n");
|
|
}
|
|
|
|
void free_touch_events_array( touch_event **buffer, uint8_t count){
|
|
for( uint8_t i; i < count; i++){
|
|
free( buffer[i]);
|
|
}
|
|
free( buffer);
|
|
}
|