Skip to content

Commit

Permalink
Disallow inaccurate objects, use vertical velocity in top zone
Browse files Browse the repository at this point in the history
  • Loading branch information
1Revenger1 committed Sep 7, 2021
1 parent 78dcbee commit 0b8bc0c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 16 additions & 9 deletions VoodooRMI/RMI_2D_Sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ OSDefineMetaClassAndStructors(RMI2DSensor, IOService)

#define RMI_2D_MAX_Z 140
#define RMI_2D_MIN_ZONE_VEL 10
#define RMI_2D_MIN_ZONE_Y_VEL 6
#define RMI_MT2_MAX_PRESSURE 255
#define cfgToPercent(val) ((double) val / 100.0)

Expand Down Expand Up @@ -135,19 +136,20 @@ bool RMI2DSensor::shouldDiscardReport(AbsoluteTime timestamp)
return !trackpadEnable;
}

bool RMI2DSensor::checkInZone(VoodooInputTransducer &obj) {
// Returns zone that finger is in (or 0 if not in a zone)
size_t RMI2DSensor::checkInZone(VoodooInputTransducer &obj) {
TouchCoordinates &fingerCoords = obj.currentCoordinates;
for (int i = 0; i < 3; i++) {
for (size_t i = 0; i < 3; i++) {
RMI2DSensorZone &zone = rejectZones[i];
if (fingerCoords.x >= zone.x_min &&
fingerCoords.x <= zone.x_max &&
fingerCoords.y >= zone.y_min &&
fingerCoords.y <= zone.y_max) {
return true;
return i+1;
}
}

return false;
return 0;
}

/**
Expand All @@ -173,10 +175,10 @@ void RMI2DSensor::handleReport(RMI2DSensorReport *report)
rmi_2d_sensor_abs_object obj = report->objs[i];

bool isValidObj = obj.type == RMI_2D_OBJECT_FINGER ||
obj.type == RMI_2D_OBJECT_STYLUS ||
obj.type == RMI_2D_OBJECT_STYLUS; /*||*/
// Allow inaccurate objects as they are likely invalid, which we want to track still
// This can be a random finger or one which was lifted up slightly
obj.type == RMI_2D_OBJECT_INACCURATE;
// obj.type == RMI_2D_OBJECT_INACCURATE;

auto& transducer = inputEvent.transducers[i];
transducer.isValid = isValidObj;
Expand Down Expand Up @@ -208,12 +210,17 @@ void RMI2DSensor::handleReport(RMI2DSensorReport *report)

/* fall through */
case RMI_FINGER_STARTED_IN_ZONE: {
if (!checkInZone(transducer)) {
size_t zone = checkInZone(transducer);
if (zone == 0) {
fingerState[i] = RMI_FINGER_VALID;
}

int velocityX = abs((int) transducer.currentCoordinates.x - (int) transducer.previousCoordinates.x);
if (velocityX > RMI_2D_MIN_ZONE_VEL) {
int velocityY = abs((int) transducer.currentCoordinates.y - (int) transducer.previousCoordinates.y);

IOLogDebug("Velocity: %d %d Zone: %ld", velocityX, velocityY, zone);
if (velocityX > RMI_2D_MIN_ZONE_VEL ||
(zone == 3 && velocityY > RMI_2D_MIN_ZONE_Y_VEL)) {
fingerState[i] = RMI_FINGER_VALID;
}
}
Expand Down Expand Up @@ -369,7 +376,7 @@ void RMI2DSensor::invalidateFingers() {
fingerState[i] == RMI_FINGER_INVALID)
continue;

if (checkInZone(finger))
if (checkInZone(finger) > 0)
fingerState[i] = RMI_FINGER_INVALID;
}
}
2 changes: 1 addition & 1 deletion VoodooRMI/RMI_2D_Sensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class RMI2DSensor : public IOService {
uint64_t lastKeyboardTS {0}, lastTrackpointTS {0};

MT2FingerType getFingerType();
bool checkInZone(VoodooInputTransducer &obj);
size_t checkInZone(VoodooInputTransducer &obj);
void setThumbFingerType(size_t fingers, RMI2DSensorReport *report);
void handleReport(RMI2DSensorReport *report);
void invalidateFingers();
Expand Down

0 comments on commit 0b8bc0c

Please sign in to comment.