Skip to content

Commit

Permalink
Fixed multitouch scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
devos50 committed Oct 2, 2022
1 parent beaf938 commit a5ac611
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
6 changes: 4 additions & 2 deletions hw/arm/ipod_touch_lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,16 @@ static void ipod_touch_lcd_mouse_event(void *opaque, int x, int y, int z, int bu
float fy = 1 - y / pow(2, 15);

IPodTouchLCDState *lcd = (IPodTouchLCDState *) opaque;
lcd->mt->prev_touch_x = lcd->mt->touch_x;
lcd->mt->prev_touch_y = lcd->mt->touch_y;
lcd->mt->touch_x = fx;
lcd->mt->touch_y = fy;

if(buttons_state && !lcd->mt->touch_down) {
ipod_touch_multitouch_on_touch(lcd->mt, fx, fy);
ipod_touch_multitouch_on_touch(lcd->mt);
}
else if(!buttons_state && lcd->mt->touch_down) {
ipod_touch_multitouch_on_release(lcd->mt, fx, fy);
ipod_touch_multitouch_on_release(lcd->mt);
}
}

Expand Down
18 changes: 15 additions & 3 deletions hw/arm/ipod_touch_multitouch.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@ static MTFrame *get_frame(IPodTouchMultitouchState *s, uint8_t event, float x, f
frame->finger_data.event = event;
frame->finger_data.unk_2 = 2;
frame->finger_data.unk_3 = 1;

// compute the velocity
int diff_x = (int)((x - s->prev_touch_x) * MT_INTERNAL_SENSOR_SURFACE_WIDTH);
int diff_y = (int)((x - s->prev_touch_y) * MT_INTERNAL_SENSOR_SURFACE_HEIGHT);
frame->finger_data.velX = diff_x / (elapsed_ns - s->last_frame_timestamp) * 1000;
frame->finger_data.velY = diff_y / (elapsed_ns - s->last_frame_timestamp) * 1000;

frame->finger_data.x = (int)(x * MT_INTERNAL_SENSOR_SURFACE_WIDTH);
frame->finger_data.y = (int)(y * MT_INTERNAL_SENSOR_SURFACE_HEIGHT);
frame->finger_data.radius1 = radius1;
Expand All @@ -324,6 +331,7 @@ static MTFrame *get_frame(IPodTouchMultitouchState *s, uint8_t event, float x, f
frame->checksum1 = (checksum & 0xFF);
frame->checksum2 = (checksum >> 8) & 0xFF;

s->last_frame_timestamp = elapsed_ns;
s->frame_counter += 1;

return frame;
Expand All @@ -334,16 +342,16 @@ static void ipod_touch_multitouch_inform_frame_ready(IPodTouchMultitouchState *s
qemu_irq_raise(s->sysic->gpio_irqs[4]);
}

void ipod_touch_multitouch_on_touch(IPodTouchMultitouchState *s, float x, float y) {
void ipod_touch_multitouch_on_touch(IPodTouchMultitouchState *s) {
s->touch_down = true;

s->next_frame = get_frame(s, MT_EVENT_TOUCH_START, x, y, 100, 660, 580, 150);
s->next_frame = get_frame(s, MT_EVENT_TOUCH_START, s->touch_x, s->touch_y, 100, 660, 580, 150);
ipod_touch_multitouch_inform_frame_ready(s);

timer_mod(s->touch_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + NANOSECONDS_PER_SECOND / 10);
}

void ipod_touch_multitouch_on_release(IPodTouchMultitouchState *s, float x, float y) {
void ipod_touch_multitouch_on_release(IPodTouchMultitouchState *s) {
s->next_frame = get_frame(s, MT_EVENT_TOUCH_ENDED, s->touch_x, s->touch_y, 0, 0, 0, 0);
s->touch_down = false;
ipod_touch_multitouch_inform_frame_ready(s);
Expand Down Expand Up @@ -379,6 +387,10 @@ static void ipod_touch_multitouch_realize(SSIPeripheral *d, Error **errp)
memset(s->hbpp_atn_ack_response, 0, 2);
s->touch_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, touch_timer_tick, s);
s->touch_end_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, touch_end_timer_tick, s);

s->prev_touch_x = 0;
s->prev_touch_y = 0;
s->last_frame_timestamp = 0;
}

static void ipod_touch_multitouch_class_init(ObjectClass *klass, void *data)
Expand Down
7 changes: 5 additions & 2 deletions include/hw/arm/ipod_touch_multitouch.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,12 @@ typedef struct IPodTouchMultitouchState {
IPodTouchGPIOState *gpio_state;
float touch_x;
float touch_y;
float prev_touch_x;
float prev_touch_y;
uint64_t last_frame_timestamp;
} IPodTouchMultitouchState;

void ipod_touch_multitouch_on_touch(IPodTouchMultitouchState *s, float x, float y);
void ipod_touch_multitouch_on_release(IPodTouchMultitouchState *s, float x, float y);
void ipod_touch_multitouch_on_touch(IPodTouchMultitouchState *s);
void ipod_touch_multitouch_on_release(IPodTouchMultitouchState *s);

#endif

0 comments on commit a5ac611

Please sign in to comment.