Skip to content

Commit

Permalink
Attempt at moving event code to EventDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
lazd committed Jan 6, 2020
1 parent baf81bf commit 8a80cab
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 182 deletions.
88 changes: 52 additions & 36 deletions VoodooI2CGoodix/VoodooI2CGoodixEventDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,39 @@ bool VoodooI2CGoodixEventDriver::didTerminate(IOService* provider, IOOptionBits
return super::didTerminate(provider, options, defer);
}

void VoodooI2CGoodixEventDriver::forwardReport(VoodooI2CMultitouchEvent event, AbsoluteTime timestamp) {
if (multitouch_interface)
void VoodooI2CGoodixEventDriver::reportTouches(Touch *touches, int touchCount) {
AbsoluteTime timestamp;
clock_get_uptime(&timestamp);

for (int i = 0; i < touchCount; i++) {
Touch touch = touches[i];

VoodooI2CDigitiserTransducer* transducer = OSDynamicCast(VoodooI2CDigitiserTransducer, transducers->getObject(touch.id));
transducer->type = kDigitiserTransducerFinger;

transducer->is_valid = true;

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 = touch.id;
transducer->secondary_id = touch.id;
}

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

const char* VoodooI2CGoodixEventDriver::getProductName() {
Expand All @@ -46,20 +76,15 @@ bool VoodooI2CGoodixEventDriver::handleStart(IOService* provider) {

publishMultitouchInterface();

digitiser.fingers = OSArray::withCapacity(1);

if (!digitiser.fingers)
return false;

digitiser.styluses = OSArray::withCapacity(1);

if (!digitiser.styluses)
return false;

digitiser.transducers = OSArray::withCapacity(1);

if (!digitiser.transducers)
transducers = OSArray::withCapacity(GOODIX_MAX_CONTACTS);
if (!transducers) {
return false;
}
DigitiserTransducerType type = kDigitiserTransducerFinger;
for (int i = 0; i < GOODIX_MAX_CONTACTS; i++) {
VoodooI2CDigitiserTransducer* transducer = VoodooI2CDigitiserTransducer::transducer(type, NULL);
transducers->setObject(transducer);
}

setDigitizerProperties();

Expand All @@ -71,19 +96,22 @@ bool VoodooI2CGoodixEventDriver::handleStart(IOService* provider) {
}

void VoodooI2CGoodixEventDriver::handleStop(IOService* provider) {
OSSafeReleaseNULL(digitiser.transducers);
OSSafeReleaseNULL(digitiser.wrappers);
OSSafeReleaseNULL(digitiser.styluses);
OSSafeReleaseNULL(digitiser.fingers);

OSSafeReleaseNULL(attached_hid_pointer_devices);

if (multitouch_interface) {
multitouch_interface->stop(this);
multitouch_interface->detach(this);
OSSafeReleaseNULL(multitouch_interface);
}

if (transducers) {
for (int i = 0; i < transducers->getCount(); i++) {
OSObject* object = transducers->getObject(i);
if (object) {
object->release();
}
}
OSSafeReleaseNULL(transducers);
}

PMstop();
super::handleStop(provider);
}
Expand Down Expand Up @@ -117,24 +145,14 @@ IOReturn VoodooI2CGoodixEventDriver::publishMultitouchInterface() {
}

void VoodooI2CGoodixEventDriver::setDigitizerProperties() {
OSDictionary* properties = OSDictionary::withCapacity(4);
OSDictionary* properties = OSDictionary::withCapacity(1);

if (!properties)
return;

if (!digitiser.transducers)
goto exit;

properties->setObject("Contact Count Element", digitiser.contact_count);
properties->setObject("Input Mode Element", digitiser.input_mode);
properties->setObject("Contact Count Maximum Element", digitiser.contact_count_maximum);
properties->setObject("Button Element", digitiser.button);
properties->setObject("Transducer Count", OSNumber::withNumber(digitiser.transducers->getCount(), 32));
properties->setObject("Transducer Count", OSNumber::withNumber(GOODIX_MAX_CONTACTS, 32));

setProperty("Digitizer", properties);

exit:
OSSafeReleaseNULL(properties);
}

IOReturn VoodooI2CGoodixEventDriver::setPowerState(unsigned long whichState, IOService* whatDevice) {
Expand All @@ -145,8 +163,6 @@ bool VoodooI2CGoodixEventDriver::start(IOService* provider) {
if (!super::start(provider))
return false;

attached_hid_pointer_devices = OSSet::withCapacity(1);

setProperty("VoodooI2CServices Supported", kOSBooleanTrue);

return true;
Expand Down
30 changes: 4 additions & 26 deletions VoodooI2CGoodix/VoodooI2CGoodixEventDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "../../../Multitouch Support/MultitouchHelpers.hpp"

#include "../../../Dependencies/helpers.hpp"
#include "goodix.h"

/* Implements an HID Event Driver for HID devices that expose a digitiser usage page.
*
Expand All @@ -37,30 +38,6 @@ class EXPORT VoodooI2CGoodixEventDriver : public IOHIDEventService {
OSDeclareDefaultStructors(VoodooI2CGoodixEventDriver);

public:
struct {
OSArray* fingers = NULL;
OSArray* styluses = NULL;

OSArray* wrappers = NULL;
OSArray*
transducers= NULL;

// report level elements

IOHIDElement* contact_count;
IOHIDElement* input_mode;
IOHIDElement* button;

// collection level elements

IOHIDElement* contact_count_maximum;


UInt8 current_contact_count = 1;
UInt8 report_count = 1;
UInt8 current_report = 1;
} digitiser;

/* Notification that a provider has been terminated, sent after recursing up the stack, in leaf-to-root order.
* @options The terminated provider of this object.
* @defer If there is pending I/O that requires this object to persist, and the provider is not opened by this object set defer to true and call the IOService::didTerminate() implementation when the I/O completes. Otherwise, leave defer set to its default value of false.
Expand Down Expand Up @@ -121,13 +98,14 @@ class EXPORT VoodooI2CGoodixEventDriver : public IOHIDEventService {

bool start(IOService* provider);

void reportTouches(Touch *touches, int touchCount);

protected:
const char* name;
bool awake = true;
IOHIDInterface* hid_interface;
VoodooI2CMultitouchInterface* multitouch_interface;

virtual void forwardReport(VoodooI2CMultitouchEvent event, AbsoluteTime timestamp);
OSArray* transducers;

private:
OSSet* attached_hid_pointer_devices;
Expand Down
Loading

0 comments on commit 8a80cab

Please sign in to comment.