OemtabletMagnetometerAdaptor::OemtabletMagnetometerAdaptor(const QString& id) : SysfsAdaptor(id, SysfsAdaptor::IntervalMode), devId(0) { if (access(SYSFS_MAGNET_PATH, R_OK) < 0) { sensordLogW() << SYSFS_MAGNET_PATH << ": "<< strerror(errno); return; } addPath(SYSFS_MAGNET_PATH, devId); magnetBuffer_ = new DeviceAdaptorRingBuffer<TimedXyzData>(16); addAdaptedSensor("magnetometer", "ak8974 ascii", magnetBuffer_); setDescription("OEM tablet magnetometer"); introduceAvailableDataRange(DataRange(-2048, 2048, 1)); introduceAvailableInterval(DataRange(10, 556, 0)); setDefaultInterval(500); }
PegatronAccelerometerAdaptor::PegatronAccelerometerAdaptor(const QString& id) : InputDevAdaptor(id, 1) { //This was previously in the base class, but it's not //possible call virtual methods from base class constructor. //TODO: find a way to get rid of all child classes calling this //manually. sleep(5); if (!getInputDevices(DEVICE_MATCH_STRING)) { sensordLogW() << "Input device not found."; } accelerometerBuffer_ = new DeviceAdaptorRingBuffer<OrientationData>(128); setAdaptedSensor("accelerometer", "Internal accelerometer coordinates", accelerometerBuffer_); // Set Metadata setDescription("Input device accelerometer adaptor (Pegtron Lucid Tablet)"); introduceAvailableDataRange(DataRange(-512, 512, 1)); introduceAvailableInterval(DataRange(0, 0, 0)); introduceAvailableInterval(DataRange(50, 2000, 0)); // -> [1,100] Hz setDefaultInterval(300); }
TEST(DataRange, DataRangeType) { char buf[] = "foo"; char buf2[] = "barZ"; DataRange dr(buf, buf + sizeof(buf) + -1); DataRange out(nullptr, nullptr); Status status = dr.readInto(&out); ASSERT_OK(status); ASSERT_EQUALS(buf, out.data()); dr = DataRange(buf2, buf2 + sizeof(buf2) + -1); status = dr.write(out); ASSERT_OK(status); ASSERT_EQUALS(std::string("fooZ"), buf2); }
ALSAdaptorAscii::ALSAdaptorAscii(const QString& id) : SysfsAdaptor(id, SysfsAdaptor::IntervalMode) { memset(buf, 0x0, 16); alsBuffer_ = new DeviceAdaptorRingBuffer<TimedUnsigned>(1); setAdaptedSensor("als", "Internal ambient light sensor lux values", alsBuffer_); setDescription("Ambient light"); // Get range from a file, if the path is found in configuration QString rangeFilePath_ = Config::configuration()->value("als/range_file_path",QVariant("")).toString(); if (rangeFilePath_ != "") { QFile sysFile(rangeFilePath_); if (!(sysFile.open(QIODevice::ReadOnly))) { sensordLogW() << "Unable to config ALS range from sysfs"; } else { sysFile.readLine(buf, sizeof(buf)); int range = QString(buf).toInt(); introduceAvailableDataRange(DataRange(0, range, 1)); sensordLogT() << "Ambient light range: " << range; } } }
SteAccelAdaptor::SteAccelAdaptor(const QString& id) : SysfsAdaptor(id, SysfsAdaptor::IntervalMode) { buffer = new DeviceAdaptorRingBuffer<OrientationData>(128); setAdaptedSensor("accelerometer", "ste accelerometer", buffer); introduceAvailableInterval(DataRange(50, 1000, 0)); /* range 0: +/- 2g (1 mg/LSB) 1: +/- 4g (2 mg/LSB) 2: +/- 8g (4 mg/LSB) */ QByteArray rangePath = Config::configuration()->value("accelerometer/range_path").toByteArray(); range = Config::configuration()->value("accelerometer/range_mode").toByteArray(); if(!rangePath.isEmpty()) { writeToFile(rangePath, range); } /* power_state/frequency 0: off 1: 1 Hz 2: 10 Hz 3: 25 Hz 4: 50 Hz 5: 100 Hz 6: 200 Hz 7: 400 Hz */ powerStatePath = Config::configuration()->value("accelerometer/mode_path").toByteArray(); frequency = Config::configuration()->value("accelerometer/frequency_mode").toInt(); setDescription("ste accelerometer"); }
CompassChain::CompassChain(const QString& id) : AbstractChain(id), hasOrientationAdaptor(false) { SensorManager& sm = SensorManager::instance(); orientAdaptor = sm.requestDeviceAdaptor("orientationadaptor"); if (orientAdaptor) { Q_ASSERT(orientAdaptor); hasOrientationAdaptor = true; setValid(orientAdaptor->isValid()); if (orientAdaptor->isValid()) orientationdataReader = new BufferReader<TimedXyzData>(1); orientationFilter = sm.instantiateFilter("orientationfilter"); Q_ASSERT(orientationFilter); declinationFilter = sm.instantiateFilter("declinationfilter"); Q_ASSERT(declinationFilter); //hybris has compass heading in orientation sensor } if (!hasOrientationAdaptor) { magChain = sm.requestChain("magcalibrationchain"); Q_ASSERT(magChain); setValid(magChain->isValid()); accelerometerChain = sm.requestChain("accelerometerchain"); Q_ASSERT(accelerometerChain); setValid(accelerometerChain->isValid()); accelerometerReader = new BufferReader<AccelerationData>(1); magReader = new BufferReader<CalibratedMagneticFieldData>(1); compassFilter = sm.instantiateFilter("compassfilter"); Q_ASSERT(compassFilter); declinationFilter = sm.instantiateFilter("declinationfilter"); Q_ASSERT(declinationFilter); downsampleFilter = sm.instantiateFilter("downsamplefilter"); Q_ASSERT(downsampleFilter); avgaccFilter = sm.instantiateFilter("avgaccfilter"); Q_ASSERT(avgaccFilter); } trueNorthBuffer = new RingBuffer<CompassData>(1); nameOutputBuffer("truenorth", trueNorthBuffer); // magneticNorthBuffer = new RingBuffer<CompassData>(1); nameOutputBuffer("magneticnorth", magneticNorthBuffer); // // Create buffers for filter chain filterBin = new Bin; if (!hasOrientationAdaptor) { filterBin->add(magReader, "magnetometer"); filterBin->add(accelerometerReader, "accelerometer"); filterBin->add(compassFilter, "compass"); filterBin->add(avgaccFilter, "avgaccelerometer"); //normalize to flat ? filterBin->add(downsampleFilter, "downsamplefilter"); } else { //////////////////// filterBin->add(orientationdataReader, "orientation"); filterBin->add(orientationFilter, "orientationfilter"); } filterBin->add(declinationFilter, "declinationcorrection"); filterBin->add(trueNorthBuffer, "truenorth"); filterBin->add(magneticNorthBuffer, "magneticnorth"); if (!hasOrientationAdaptor) { if (!filterBin->join("magnetometer", "source", "compass", "magsink")) qDebug() << Q_FUNC_INFO << "magnetometer join failed"; if (!filterBin->join("accelerometer", "source", "avgaccelerometer", "sink")) qDebug() << Q_FUNC_INFO << "accelerometer join failed"; if (!filterBin->join("avgaccelerometer", "source", "downsamplefilter", "sink")) qDebug() << Q_FUNC_INFO << "avgaccelerometer join failed"; if (!filterBin->join("downsamplefilter", "source", "compass", "accsink")) qDebug() << Q_FUNC_INFO << "downsamplefilter join failed"; if (!filterBin->join("compass", "magnorthangle", "magneticnorth", "sink")) qDebug() << Q_FUNC_INFO << "compass1 join failed"; if (!filterBin->join("compass", "magnorthangle", "declinationcorrection", "sink")) qDebug() << Q_FUNC_INFO << "compass2 join failed"; } else { //////////////////// if (!filterBin->join("orientation", "source", "orientationfilter", "orientsink")) qDebug() << Q_FUNC_INFO << "orientation join failed"; if (!filterBin->join("orientationfilter", "magnorthangle", "magneticnorth", "sink")) qDebug() << Q_FUNC_INFO << "orientation2 join failed"; if (!filterBin->join("orientationfilter", "magnorthangle", "declinationcorrection", "sink")) qDebug() << Q_FUNC_INFO << "orientation3 join failed"; } if (!filterBin->join("declinationcorrection", "source", "truenorth", "sink")) qDebug() << Q_FUNC_INFO << "declinationfilter join failed"; if (!hasOrientationAdaptor) { if (!connectToSource(accelerometerChain, "accelerometer", accelerometerReader)) qDebug() << Q_FUNC_INFO << "accelerometer connect failed"; if (!connectToSource(magChain, "calibratedmagnetometerdata", magReader)) qDebug() << Q_FUNC_INFO << "magnetometer connect failed"; } else { //////////////////// if (!connectToSource(orientAdaptor, "orientation", orientationdataReader)) qDebug() << Q_FUNC_INFO << "orientation connect failed"; } setDescription("Compass direction"); //compass north in degrees introduceAvailableDataRange(DataRange(0, 359, 1)); introduceAvailableInterval(DataRange(50,200,0)); if (!hasOrientationAdaptor) { setRangeSource(magChain); addStandbyOverrideSource(magChain); addStandbyOverrideSource(accelerometerChain); setIntervalSource(accelerometerChain); } }