Ejemplo n.º 1
0
ALSSensorChannel::ALSSensorChannel(const QString& id) :
    AbstractSensorChannel(id),
    DataEmitter<TimedUnsigned>(1),
    previousValue_(0,0)
#ifdef PROVIDE_CONTEXT_INFO
    ,service(QDBusConnection::systemBus()),
    isDarkProperty(service, "Environment.IsDark"),
    isBrightProperty(service, "Environment.IsBright")
#endif
{
    SensorManager& sm = SensorManager::instance();

    alsAdaptor_ = sm.requestDeviceAdaptor("alsadaptor");
    Q_ASSERT( alsAdaptor_ );

    alsReader_ = new BufferReader<TimedUnsigned>(1);

    outputBuffer_ = new RingBuffer<TimedUnsigned>(1);

    // Create buffers for filter chain
    filterBin_ = new Bin;

    filterBin_->add(alsReader_, "als");
    filterBin_->add(outputBuffer_, "buffer");

    filterBin_->join("als", "source", "buffer", "sink");

    // Join datasources to the chain
    connectToSource(alsAdaptor_, "als", alsReader_);

    marshallingBin_ = new Bin;
    marshallingBin_->add(this, "sensorchannel");

    outputBuffer_->join(this);

#ifdef PROVIDE_CONTEXT_INFO
    // Start listening to context clients. When a client comes, we
    // start the sensor channel, and when we no more have clients, we
    // stop it.
    propertyGroup.add(isDarkProperty);
    propertyGroup.add(isBrightProperty);
    connect(&propertyGroup, SIGNAL(firstSubscriberAppeared()), this, SLOT(start()));
    connect(&propertyGroup, SIGNAL(lastSubscriberDisappeared()), this, SLOT(stop()));
    // Note: We should combine this "service needed / not needed"
    // information from Context FW with information from other
    // sources. This doesn't do it yet.

#endif

    setDescription("ambient light intensity in lux");
    setRangeSource(alsAdaptor_);
    addStandbyOverrideSource(alsAdaptor_);
    setIntervalSource(alsAdaptor_);

    setValid(true);
}
Ejemplo n.º 2
0
GyroscopeSensorChannel::GyroscopeSensorChannel(const QString& id) :
        AbstractSensorChannel(id),
        DataEmitter<TimedXyzData>(10),
        previousSample_()
{
    SensorManager& sm = SensorManager::instance();

    gyroscopeAdaptor_ = sm.requestDeviceAdaptor("gyroscopeadaptor");
    Q_ASSERT( gyroscopeAdaptor_ );

    gyroscopeReader_ = new BufferReader<TimedXyzData>(1);

    outputBuffer_ = new RingBuffer<TimedXyzData>(1);

    // Create buffers for filter chain
    filterBin_ = new Bin;
    filterBin_->add(gyroscopeReader_, "gyroscope");
    filterBin_->add(outputBuffer_, "output");

    filterBin_->join("gyroscope", "source", "output", "sink");

    // Join datasources to the chain
    connectToSource(gyroscopeAdaptor_, "gyroscope", gyroscopeReader_);

    marshallingBin_ = new Bin;
    marshallingBin_->add(this, "sensorchannel");

    outputBuffer_->join(this);

    // Set MetaData
    setDescription("x, y, and z axes angular velocity in mdps");
    setRangeSource(gyroscopeAdaptor_);
    addStandbyOverrideSource(gyroscopeAdaptor_);
    setIntervalSource(gyroscopeAdaptor_);

    setValid(true);
}
 StreamReader(QObject *parent, const Phonon::MediaSource &source) :
     m_seekable(false), m_pos(0), m_size(-1)
 {
     Q_UNUSED(parent);
     connectToSource(source);
 }
Ejemplo n.º 4
0
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);
    }
}
Ejemplo n.º 5
0
MagCalibrationChain::MagCalibrationChain(const QString& id) :
    AbstractChain(id)
{
    setMatrixFromString("1,0,0,\
                         0,1,0,\
                         0,0,1");
    SensorManager& sm = SensorManager::instance();

    magAdaptor = sm.requestDeviceAdaptor("magnetometeradaptor");
    setValid(magAdaptor->isValid());

// Config::configuration()->value<int>("magnetometer/interval_compensation", 16);
    // Get the transformation matrix from config file
    QString aconvString = Config::configuration()->value<QString>("magnetometer/transformation_matrix", "");
    if (aconvString.size() > 0) {
        if (!setMatrixFromString(aconvString)) {
            sensordLogW() << "Failed to parse 'transformation_matrix' configuration key. Coordinate alignment may be invalid";
        }
    }

    needsCalibration = Config::configuration()->value<bool>("magnetometer/needs_calibration", true);

    calibratedMagnetometerData = new RingBuffer<CalibratedMagneticFieldData>(1);
    nameOutputBuffer("calibratedmagnetometerdata", calibratedMagnetometerData);

    // Create buffers for filter chain
    filterBin = new Bin;
    //formationsink
    magReader = new BufferReader<CalibratedMagneticFieldData>(1);

    // Join filterchain buffers
    filterBin->add(magReader, "calibratedmagneticfield");

    filterBin->add(calibratedMagnetometerData, "calibratedmagnetometerdata"); //calibration

    if (sm.getAdaptorTypes().contains("orientationadaptor")) {
        DeviceAdaptor *orientAdaptor = sm.requestDeviceAdaptor("orientationadaptor");
        if (orientAdaptor && orientAdaptor->isValid()) {
            needsCalibration = false;
        }
    }
    magCoordinateAlignFilter_ = sm.instantiateFilter("magcoordinatealignfilter");
    Q_ASSERT(magCoordinateAlignFilter_);
    filterBin->add(magCoordinateAlignFilter_, "magcoordinatealigner");

    if (needsCalibration) {
        magCalFilter = sm.instantiateFilter("calibrationfilter");

        ((MagCoordinateAlignFilter*)magCoordinateAlignFilter_)->setMatrix(TMagMatrix(aconv_));

        filterBin->add(magCalFilter, "calibration");

        if (!filterBin->join("calibratedmagneticfield", "source", "magcoordinatealigner", "sink"))
            qDebug() << Q_FUNC_INFO << "calibratedmagneticfield/magcoordinatealigner join failed";

        if (!filterBin->join("magcoordinatealigner", "source", "calibration", "magsink"))
            qDebug() << Q_FUNC_INFO << "magcoordinatealigner/calibration join failed";

        if (!filterBin->join("calibration", "source", "calibratedmagnetometerdata", "sink"))
            qDebug() << Q_FUNC_INFO << "calibration/calibratedmagnetometerdata join failed";
    } else {
        if (!filterBin->join("calibratedmagneticfield", "source", "magcoordinatealigner", "sink"))
            qDebug() << Q_FUNC_INFO << "calibratedmagneticfield/magcoordinatealigner join failed";

        if (!filterBin->join("magcoordinatealigner", "source", "calibratedmagnetometerdata", "sink"))
            qDebug() << Q_FUNC_INFO << "magcoordinatealigner/calibratedmagnetometerdata join failed";
    }

    // Join datasources to the chain
    connectToSource(magAdaptor, "calibratedmagneticfield", magReader);

    setDescription("Calibrated Mag values"); //Magnetometer calibration
    setRangeSource(magAdaptor);
    addStandbyOverrideSource(magAdaptor);
    setIntervalSource(magAdaptor);
}
Ejemplo n.º 6
0
 StreamReader(QBaseFilter *parent, const Phonon::MediaSource &source, const MediaGraph *mg) : 
   QAsyncReader(parent, getMediaTypes()),
       m_seekable(false), m_pos(0), m_size(-1), m_mediaGraph(mg)
   {
       connectToSource(source);
   }