Skip to content

Commit

Permalink
Working touchscreen cursor tracking (clicks nonstop though)
Browse files Browse the repository at this point in the history
  • Loading branch information
lazd committed Jan 6, 2020
1 parent cb9e149 commit 94aea07
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>VoodooI2CGoodix.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>5</integer>
<integer>4</integer>
</dict>
</dict>
</dict>
Expand Down
62 changes: 40 additions & 22 deletions VoodooI2CGoodix/VoodooI2CGoodixEventDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,51 @@ void VoodooI2CGoodixEventDriver::reportTouches(struct Touch touches[], int numTo
clock_get_uptime(&timestamp);

IOLog("Need to report %d touches", numTouches);
for (int i = 0; i < numTouches; i++) {
Touch touch = touches[i];

IOLog("Touch %d at %d,%d", i, touch.x, touch.y);
VoodooI2CDigitiserTransducer* transducer = OSDynamicCast(VoodooI2CDigitiserTransducer, transducers->getObject(i));
transducer->type = kDigitiserTransducerFinger;
if (numTouches == 1) {
Touch touch = touches[0];
// VoodooI2CDigitiserTransducer* transducer = OSDynamicCast(VoodooI2CDigitiserTransducer, transducers->getObject(0));
// UInt32 buttons = transducer->tip_switch.value();

transducer->is_valid = true;
IOFixed x = ((touch.x * 1.0f) / multitouch_interface->logical_max_x) * 65535;
IOFixed y = ((touch.y * 1.0f) / multitouch_interface->logical_max_y) * 65535;

if (multitouch_interface) {
transducer->logical_max_x = multitouch_interface->logical_max_x;
transducer->logical_max_y = multitouch_interface->logical_max_y;
}
dispatchDigitizerEventWithTiltOrientation(timestamp, 0, kDigitiserTransducerFinger, 0x1, 0x1, x, y);
}
else {
// Todo: move the cursor directly to the location between the fingers?

transducer->coordinates.x.update(touch.x, timestamp);
transducer->coordinates.y.update(touch.y, timestamp);
// Send a multitouch event for scrolls, scales, etc
for (int i = 0; i < numTouches; i++) {
Touch touch = touches[i];

// Todo: do something with touch->width to determine if it's a contact?
transducer->tip_switch.update(1, timestamp);
IOLog("Touch %d at %d,%d with max %d,%d", i, touch.x, touch.y, multitouch_interface->logical_max_x, multitouch_interface->logical_max_y);
VoodooI2CDigitiserTransducer* transducer = OSDynamicCast(VoodooI2CDigitiserTransducer, transducers->getObject(i));
transducer->type = kDigitiserTransducerFinger;

transducer->id = i;
transducer->secondary_id = i;
}
transducer->is_valid = true;

VoodooI2CMultitouchEvent event;
event.contact_count = numTouches;
event.transducers = transducers;
if (multitouch_interface) {
multitouch_interface->handleInterruptReport(event, timestamp);
if (multitouch_interface) {
transducer->logical_max_x = multitouch_interface->logical_max_x;
transducer->logical_max_y = multitouch_interface->logical_max_y;
}

transducer->coordinates.x.update(touch.x, timestamp);
transducer->coordinates.y.update(touch.y, timestamp);

// Todo: do something with touch->width to determine if it's a contact?
transducer->tip_switch.update(1, timestamp);

transducer->id = i;
transducer->secondary_id = i;
}

VoodooI2CMultitouchEvent event;
event.contact_count = numTouches;
event.transducers = transducers;
if (multitouch_interface) {
multitouch_interface->handleInterruptReport(event, timestamp);
}
}
}

Expand Down Expand Up @@ -94,6 +110,8 @@ bool VoodooI2CGoodixEventDriver::handleStart(IOService* provider) {
// hid_interface->joinPMtree(this);
// registerPowerDriver(this, VoodooI2CIOPMPowerStates, kVoodooI2CIOPMNumberPowerStates);

multitouch_interface->registerService();

return true;
}

Expand Down
8 changes: 5 additions & 3 deletions VoodooI2CGoodix/VoodooI2CGoodixTouchDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ bool VoodooI2CGoodixTouchDriver::start(IOService* provider) {
ready_for_input = true;
setProperty("VoodooI2CServices Supported", OSBoolean::withBoolean(true));
IOLog("%s::VoodooI2CGoodixTouchDriver has started\n", getName());
registerService();

// Instantiate the event driver
// Todo: how to properly attach to this service?
Expand All @@ -205,6 +204,9 @@ bool VoodooI2CGoodixTouchDriver::start(IOService* provider) {
}

event_driver->initializeMultitouchInterface(ts->abs_x_max, ts->abs_y_max);
event_driver->registerService();

registerService();

return true;
start_exit:
Expand Down Expand Up @@ -421,9 +423,9 @@ void VoodooI2CGoodixTouchDriver::release_resources() {
}
if (event_driver) {
// Todo: how to properly release event_driver?
event_driver->release(); // required?
event_driver->stop(this);
// event_driver->stop(this); // causes crash
event_driver->detach(this);
// event_driver->release(); // required?
OSSafeReleaseNULL(event_driver);
}
}
Expand Down

0 comments on commit 94aea07

Please sign in to comment.