Skip to content

Commit 8a80cab

Browse files
committed
Attempt at moving event code to EventDriver
1 parent baf81bf commit 8a80cab

File tree

5 files changed

+99
-182
lines changed

5 files changed

+99
-182
lines changed

VoodooI2CGoodix/VoodooI2CGoodixEventDriver.cpp

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,39 @@ bool VoodooI2CGoodixEventDriver::didTerminate(IOService* provider, IOOptionBits
2323
return super::didTerminate(provider, options, defer);
2424
}
2525

26-
void VoodooI2CGoodixEventDriver::forwardReport(VoodooI2CMultitouchEvent event, AbsoluteTime timestamp) {
27-
if (multitouch_interface)
26+
void VoodooI2CGoodixEventDriver::reportTouches(Touch *touches, int touchCount) {
27+
AbsoluteTime timestamp;
28+
clock_get_uptime(&timestamp);
29+
30+
for (int i = 0; i < touchCount; i++) {
31+
Touch touch = touches[i];
32+
33+
VoodooI2CDigitiserTransducer* transducer = OSDynamicCast(VoodooI2CDigitiserTransducer, transducers->getObject(touch.id));
34+
transducer->type = kDigitiserTransducerFinger;
35+
36+
transducer->is_valid = true;
37+
38+
if (multitouch_interface) {
39+
transducer->logical_max_x = multitouch_interface->logical_max_x;
40+
transducer->logical_max_y = multitouch_interface->logical_max_y;
41+
}
42+
43+
transducer->coordinates.x.update(touch.x, timestamp);
44+
transducer->coordinates.y.update(touch.y, timestamp);
45+
46+
// Todo: do something with touch->width to determine if it's a contact?
47+
transducer->tip_switch.update(1, timestamp);
48+
49+
transducer->id = touch.id;
50+
transducer->secondary_id = touch.id;
51+
}
52+
53+
VoodooI2CMultitouchEvent event;
54+
event.contact_count = touchCount;
55+
event.transducers = transducers;
56+
if (multitouch_interface) {
2857
multitouch_interface->handleInterruptReport(event, timestamp);
58+
}
2959
}
3060

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

4777
publishMultitouchInterface();
4878

49-
digitiser.fingers = OSArray::withCapacity(1);
50-
51-
if (!digitiser.fingers)
52-
return false;
53-
54-
digitiser.styluses = OSArray::withCapacity(1);
55-
56-
if (!digitiser.styluses)
57-
return false;
58-
59-
digitiser.transducers = OSArray::withCapacity(1);
60-
61-
if (!digitiser.transducers)
79+
transducers = OSArray::withCapacity(GOODIX_MAX_CONTACTS);
80+
if (!transducers) {
6281
return false;
82+
}
83+
DigitiserTransducerType type = kDigitiserTransducerFinger;
84+
for (int i = 0; i < GOODIX_MAX_CONTACTS; i++) {
85+
VoodooI2CDigitiserTransducer* transducer = VoodooI2CDigitiserTransducer::transducer(type, NULL);
86+
transducers->setObject(transducer);
87+
}
6388

6489
setDigitizerProperties();
6590

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

7398
void VoodooI2CGoodixEventDriver::handleStop(IOService* provider) {
74-
OSSafeReleaseNULL(digitiser.transducers);
75-
OSSafeReleaseNULL(digitiser.wrappers);
76-
OSSafeReleaseNULL(digitiser.styluses);
77-
OSSafeReleaseNULL(digitiser.fingers);
78-
79-
OSSafeReleaseNULL(attached_hid_pointer_devices);
80-
8199
if (multitouch_interface) {
82100
multitouch_interface->stop(this);
83101
multitouch_interface->detach(this);
84102
OSSafeReleaseNULL(multitouch_interface);
85103
}
86104

105+
if (transducers) {
106+
for (int i = 0; i < transducers->getCount(); i++) {
107+
OSObject* object = transducers->getObject(i);
108+
if (object) {
109+
object->release();
110+
}
111+
}
112+
OSSafeReleaseNULL(transducers);
113+
}
114+
87115
PMstop();
88116
super::handleStop(provider);
89117
}
@@ -117,24 +145,14 @@ IOReturn VoodooI2CGoodixEventDriver::publishMultitouchInterface() {
117145
}
118146

119147
void VoodooI2CGoodixEventDriver::setDigitizerProperties() {
120-
OSDictionary* properties = OSDictionary::withCapacity(4);
148+
OSDictionary* properties = OSDictionary::withCapacity(1);
121149

122150
if (!properties)
123151
return;
124152

125-
if (!digitiser.transducers)
126-
goto exit;
127-
128-
properties->setObject("Contact Count Element", digitiser.contact_count);
129-
properties->setObject("Input Mode Element", digitiser.input_mode);
130-
properties->setObject("Contact Count Maximum Element", digitiser.contact_count_maximum);
131-
properties->setObject("Button Element", digitiser.button);
132-
properties->setObject("Transducer Count", OSNumber::withNumber(digitiser.transducers->getCount(), 32));
153+
properties->setObject("Transducer Count", OSNumber::withNumber(GOODIX_MAX_CONTACTS, 32));
133154

134155
setProperty("Digitizer", properties);
135-
136-
exit:
137-
OSSafeReleaseNULL(properties);
138156
}
139157

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

148-
attached_hid_pointer_devices = OSSet::withCapacity(1);
149-
150166
setProperty("VoodooI2CServices Supported", kOSBooleanTrue);
151167

152168
return true;

VoodooI2CGoodix/VoodooI2CGoodixEventDriver.hpp

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "../../../Multitouch Support/MultitouchHelpers.hpp"
2828

2929
#include "../../../Dependencies/helpers.hpp"
30+
#include "goodix.h"
3031

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

3940
public:
40-
struct {
41-
OSArray* fingers = NULL;
42-
OSArray* styluses = NULL;
43-
44-
OSArray* wrappers = NULL;
45-
OSArray*
46-
transducers= NULL;
47-
48-
// report level elements
49-
50-
IOHIDElement* contact_count;
51-
IOHIDElement* input_mode;
52-
IOHIDElement* button;
53-
54-
// collection level elements
55-
56-
IOHIDElement* contact_count_maximum;
57-
58-
59-
UInt8 current_contact_count = 1;
60-
UInt8 report_count = 1;
61-
UInt8 current_report = 1;
62-
} digitiser;
63-
6441
/* Notification that a provider has been terminated, sent after recursing up the stack, in leaf-to-root order.
6542
* @options The terminated provider of this object.
6643
* @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.
@@ -121,13 +98,14 @@ class EXPORT VoodooI2CGoodixEventDriver : public IOHIDEventService {
12198

12299
bool start(IOService* provider);
123100

101+
void reportTouches(Touch *touches, int touchCount);
102+
124103
protected:
125104
const char* name;
126105
bool awake = true;
127106
IOHIDInterface* hid_interface;
128107
VoodooI2CMultitouchInterface* multitouch_interface;
129-
130-
virtual void forwardReport(VoodooI2CMultitouchEvent event, AbsoluteTime timestamp);
108+
OSArray* transducers;
131109

132110
private:
133111
OSSet* attached_hid_pointer_devices;

0 commit comments

Comments
 (0)