Exemple #1
0
bool BbMagnetometer::updateReadingFromEvent(const sensor_event_t &event, QMagnetometerReading *reading)
{
    // TODO: In the future, support returnGeoValues here. Right now, /dev/sensors/mag has no
    //       geomagnatic mode, but will gain it in the future.
    float x = convertValue(event.motion.dsp.x);
    float y = convertValue(event.motion.dsp.y);
    float z = convertValue(event.motion.dsp.z);
    remapAxes(&x, &y, &z);
    reading->setX(x);
    reading->setY(y);
    reading->setZ(z);

    const bool returnGeoValues = sensor()->property("returnGeoValues").toBool();
    if (returnGeoValues) {
        switch (event.accuracy) {
        case SENSOR_ACCURACY_UNRELIABLE: reading->setCalibrationLevel(0.0f); break;
        case SENSOR_ACCURACY_LOW:        reading->setCalibrationLevel(0.1f); break;

        // We determined that MEDIUM should map to 1.0, because existing code samples
        // show users should pop a calibration screen when seeing < 1.0. The MEDIUM accuracy
        // is actually good enough not to require calibration, so we don't want to make it seem
        // like it is required artificially.
        case SENSOR_ACCURACY_MEDIUM:     reading->setCalibrationLevel(1.0f); break;
        case SENSOR_ACCURACY_HIGH:       reading->setCalibrationLevel(1.0f); break;
        }
    } else {
        reading->setCalibrationLevel(1.0f);
    }

    return true;
}
IOReturn XboxOneControllerClass::handleReport(IOMemoryDescriptor * descriptor, IOHIDReportType reportType, IOOptionBits options)
{
    if (descriptor->getLength() >= sizeof(XBOXONE_IN_GUIDE_REPORT)) {
        IOBufferMemoryDescriptor *desc = OSDynamicCast(IOBufferMemoryDescriptor, descriptor);
        if (desc != NULL) {
            XBOXONE_ELITE_IN_REPORT *report=(XBOXONE_ELITE_IN_REPORT*)desc->getBytesNoCopy();
            if ((report->header.command==0x07) && (report->header.size==(sizeof(XBOXONE_IN_GUIDE_REPORT)-4)))
            {
                XBOXONE_IN_GUIDE_REPORT *guideReport=(XBOXONE_IN_GUIDE_REPORT*)report;
                isXboxOneGuideButtonPressed = (bool)guideReport->state;
                XBOX360_IN_REPORT *oldReport = (XBOX360_IN_REPORT*)lastData;
                oldReport->buttons ^= (-isXboxOneGuideButtonPressed ^ oldReport->buttons) & (1 << GetOwner(this)->mapping[10]);
                memcpy(report, lastData, sizeof(XBOX360_IN_REPORT));
            }
            else if (report->header.command==0x20)
            {
                if (report->header.size==0x0e || report->header.size==0x1d || report->header.size==0x1a)
                {
                    convertFromXboxOne(report, report->header.size);
                    XBOX360_IN_REPORT *report360=(XBOX360_IN_REPORT*)report;
                    if (!(GetOwner(this)->noMapping))
                        remapButtons(report360);
                    GetOwner(this)->fiddleReport(report360->left, report360->right);

                    if (GetOwner(this)->swapSticks)
                        remapAxes(report360);

                    memcpy(lastData, report360, sizeof(XBOX360_IN_REPORT));
                }
            }
        }
    }
    IOReturn ret = IOHIDDevice::handleReport(descriptor, reportType, options);
    return ret;
}
bool BbMagnetometer::updateReadingFromEvent(const sensor_event_t &event, QMagnetometerReading *reading)
{
    float x, y, z;

    switch (event.accuracy) {
    case SENSOR_ACCURACY_UNRELIABLE: reading->setCalibrationLevel(0.0f); break;
    case SENSOR_ACCURACY_LOW:        reading->setCalibrationLevel(0.1f); break;

    // We determined that MEDIUM should map to 1.0, because existing code samples
    // show users should pop a calibration screen when seeing < 1.0. The MEDIUM accuracy
    // is actually good enough not to require calibration, so we don't want to make it seem
    // like it is required artificially.
    case SENSOR_ACCURACY_MEDIUM:     reading->setCalibrationLevel(1.0f); break;
    case SENSOR_ACCURACY_HIGH:       reading->setCalibrationLevel(1.0f); break;
    }

    x = convertValue(event.motion.dsp.x);
    y = convertValue(event.motion.dsp.y);
    z = convertValue(event.motion.dsp.z);

    remapAxes(&x, &y, &z);
    reading->setX(x);
    reading->setY(y);
    reading->setZ(z);
    return true;
}
void Wireless360Controller::receivedHIDupdate(unsigned char *data, int length)
{
    fiddleReport(data, length);
//    remapButtons(data);
    if (swapSticks)
        remapAxes(data);
    super::receivedHIDupdate(data, length);
}
bool BbAccelerometer::updateReadingFromEvent(const sensor_event_t &event, QAccelerometerReading *reading)
{
    float x = event.motion.dsp.x;
    float y = event.motion.dsp.y;
    float z = event.motion.dsp.z;
    remapAxes(&x, &y, &z);
    reading->setX(x);
    reading->setY(y);
    reading->setZ(z);
    return true;
}
IOReturn Xbox360ControllerClass::handleReport(IOMemoryDescriptor * descriptor, IOHIDReportType reportType, IOOptionBits options) {
    if (descriptor->getLength() >= sizeof(XBOX360_IN_REPORT)) {
        IOBufferMemoryDescriptor *desc = OSDynamicCast(IOBufferMemoryDescriptor, descriptor);
        if (desc != NULL) {
            XBOX360_IN_REPORT *report=(XBOX360_IN_REPORT*)desc->getBytesNoCopy();
            if ((report->header.command==inReport) && (report->header.size==sizeof(XBOX360_IN_REPORT))) {
                GetOwner(this)->fiddleReport(report->left, report->right);
                if (!(GetOwner(this)->noMapping))
                    remapButtons(report);
                if (GetOwner(this)->swapSticks)
                    remapAxes(report);
            }
        }
    }
    IOReturn ret = IOHIDDevice::handleReport(descriptor, reportType, options);
    return ret;
}
bool BbMagnetometer::updateReadingFromEvent(const sensor_event_t &event, QMagnetometerReading *reading)
{
    float x, y, z;

    QMagnetometer * const magnetometer = qobject_cast<QMagnetometer *>(sensor());
    if (magnetometer && magnetometer->returnGeoValues()) {
        switch (event.accuracy) {
        case SENSOR_ACCURACY_UNRELIABLE: reading->setCalibrationLevel(0.0f); break;
        case SENSOR_ACCURACY_LOW:        reading->setCalibrationLevel(0.1f); break;

        // We determined that MEDIUM should map to 1.0, because existing code samples
        // show users should pop a calibration screen when seeing < 1.0. The MEDIUM accuracy
        // is actually good enough not to require calibration, so we don't want to make it seem
        // like it is required artificially.
        case SENSOR_ACCURACY_MEDIUM:     reading->setCalibrationLevel(1.0f); break;
        case SENSOR_ACCURACY_HIGH:       reading->setCalibrationLevel(1.0f); break;
        }

        x = convertValue(event.motion.dsp.x);
        y = convertValue(event.motion.dsp.y);
        z = convertValue(event.motion.dsp.z);

    } else {
        reading->setCalibrationLevel(1.0f);

#ifndef Q_OS_BLACKBERRY_TABLET
        x = convertValue(event.motion.raw.x);
        y = convertValue(event.motion.raw.y);
        z = convertValue(event.motion.raw.z);
#else
        // Blackberry Tablet OS does not support raw reading values
        x = convertValue(event.motion.dsp.x);
        y = convertValue(event.motion.dsp.y);
        z = convertValue(event.motion.dsp.z);
#endif
    }

    remapAxes(&x, &y, &z);
    reading->setX(x);
    reading->setY(y);
    reading->setZ(z);
    return true;
}