diff options
Diffstat (limited to 'modules/sensors/dynamic_sensor/HidRawSensor.h')
-rw-r--r-- | modules/sensors/dynamic_sensor/HidRawSensor.h | 60 |
1 files changed, 56 insertions, 4 deletions
diff --git a/modules/sensors/dynamic_sensor/HidRawSensor.h b/modules/sensors/dynamic_sensor/HidRawSensor.h index 2dd32b61..074482a8 100644 --- a/modules/sensors/dynamic_sensor/HidRawSensor.h +++ b/modules/sensors/dynamic_sensor/HidRawSensor.h @@ -46,6 +46,14 @@ public: // handle input report received void handleInput(uint8_t id, const std::vector<uint8_t> &message); + // get head tracker sensor event data + bool getHeadTrackerEventData(const std::vector<uint8_t> &message, + sensors_event_t *event); + + // get generic sensor event data + bool getSensorEventData(const std::vector<uint8_t> &message, + sensors_event_t *event); + // indicate if the HidRawSensor is a valid one bool isValid() const { return mValid; }; @@ -86,6 +94,7 @@ private: size_t fifoMaxSize; uint32_t reportModeFlag; bool isWakeUp; + bool useUniqueIdForUuid; // dynamic sensor specific std::string uniqueId; @@ -121,6 +130,14 @@ private: // helper function to find sensor control feature usage from packets bool findSensorControlUsage(const std::vector<HidParser::ReportPacket> &packets); + // try to parse sensor description feature value to see if it matches any + // known sensors + void detectSensorFromDescription(const std::string &description); + + // try to parse sensor description feature value to see if it matches the + // Android header tracker sensor + bool detectAndroidHeadTrackerSensor(const std::string &description); + // try to parse sensor description feature value to see if it matches // android specified custom sensor definition. bool detectAndroidCustomSensor(const std::string &description); @@ -132,19 +149,54 @@ private: // process HID snesor spec defined orientation(quaternion) sensor usages. bool processQuaternionUsage(const std::vector<HidParser::ReportPacket> &packets); + // get the value of a report field + template<typename ValueType> + bool getReportFieldValue(const std::vector<uint8_t> &message, + ReportTranslateRecord* rec, ValueType* value) { + bool valid = true; + int64_t v; + + v = (message[rec->byteOffset + rec->byteSize - 1] & 0x80) ? -1 : 0; + for (int i = static_cast<int>(rec->byteSize) - 1; i >= 0; --i) { + v = (v << 8) | message[rec->byteOffset + i]; // HID is little endian + } + if (v > rec->maxValue || v < rec->minValue) { + valid = false; + } + + switch (rec->type) { + case TYPE_FLOAT: + *value = rec->a * (v + rec->b); + break; + case TYPE_INT64: + *value = v + rec->b; + break; + } + + return valid; + } + // dump data for test/debug purpose std::string dump() const; // Features for control sensor int mReportingStateId; - unsigned int mReportingStateOffset; + unsigned int mReportingStateBitOffset; + unsigned int mReportingStateBitSize; + int mReportingStateDisableIndex; + int mReportingStateEnableIndex; int mPowerStateId; - unsigned int mPowerStateOffset; + unsigned int mPowerStateBitOffset; + unsigned int mPowerStateBitSize; + int mPowerStateOffIndex; + int mPowerStateOnIndex; int mReportIntervalId; - unsigned int mReportIntervalOffset; - unsigned int mReportIntervalSize; + unsigned int mReportIntervalBitOffset; + unsigned int mReportIntervalBitSize; + double mReportIntervalScale; + int64_t mReportIntervalOffset; // Input report translate table std::vector<ReportTranslateRecord> mTranslateTable; |