GravitySensor::GravitySensor(sensor_t const* list, size_t count)
: mSensorDevice(SensorDevice::getInstance()),
- mEnabled(false), mAccTime(0),
+ mAccTime(0),
mLowPass(M_SQRT1_2, 1.5f),
mX(mLowPass), mY(mLowPass), mZ(mLowPass)
}
return false;
}
-
-bool GravitySensor::isEnabled() const {
- return mEnabled;
-}
-
status_t GravitySensor::activate(void* ident, bool enabled) {
status_t err = mSensorDevice.activate(this, mAccelerometer.getHandle(), enabled);
if (err == NO_ERROR) {
- mEnabled = enabled;
if (enabled) {
mAccTime = 0;
}
class GravitySensor : public SensorInterface {
SensorDevice& mSensorDevice;
Sensor mAccelerometer;
- bool mEnabled;
double mAccTime;
SecondOrderLowPassFilter mLowPass;
GravitySensor(sensor_t const* list, size_t count);
virtual bool process(sensors_event_t* outEvent,
const sensors_event_t& event);
- virtual bool isEnabled() const;
virtual status_t activate(void* ident, bool enabled);
virtual status_t setDelay(void* ident, int handle, int64_t ns);
virtual Sensor getSensor() const;
return result;
}
-bool LinearAccelerationSensor::isEnabled() const {
- return mGravitySensor.isEnabled();
-}
-
status_t LinearAccelerationSensor::activate(void* ident, bool enabled) {
return mGravitySensor.activate(ident, enabled);
}
const sensors_event_t& event);
public:
LinearAccelerationSensor(sensor_t const* list, size_t count);
- virtual bool isEnabled() const;
virtual status_t activate(void* ident, bool enabled);
virtual status_t setDelay(void* ident, int handle, int64_t ns);
virtual Sensor getSensor() const;
RotationVectorSensor::RotationVectorSensor(sensor_t const* list, size_t count)
: mSensorDevice(SensorDevice::getInstance()),
- mEnabled(false),
mALowPass(M_SQRT1_2, 5.0f),
mAX(mALowPass), mAY(mALowPass), mAZ(mALowPass),
mMLowPass(M_SQRT1_2, 2.5f),
return false;
}
-bool RotationVectorSensor::isEnabled() const {
- return mEnabled;
-}
-
status_t RotationVectorSensor::activate(void* ident, bool enabled) {
- if (mEnabled != enabled) {
- mSensorDevice.activate(this, mAcc.getHandle(), enabled);
- mSensorDevice.activate(this, mMag.getHandle(), enabled);
- mEnabled = enabled;
- if (enabled) {
- mMagTime = 0;
- mAccTime = 0;
- }
+ mSensorDevice.activate(this, mAcc.getHandle(), enabled);
+ mSensorDevice.activate(this, mMag.getHandle(), enabled);
+ if (enabled) {
+ mMagTime = 0;
+ mAccTime = 0;
}
return NO_ERROR;
}
SensorDevice& mSensorDevice;
Sensor mAcc;
Sensor mMag;
- bool mEnabled;
float mMagData[3];
double mAccTime;
double mMagTime;
RotationVectorSensor(sensor_t const* list, size_t count);
virtual bool process(sensors_event_t* outEvent,
const sensors_event_t& event);
- virtual bool isEnabled() const;
virtual status_t activate(void* ident, bool enabled);
virtual status_t setDelay(void* ident, int handle, int64_t ns);
virtual Sensor getSensor() const;
Mutex::Autolock _l(mLock);
for (size_t i=0 ; i<size_t(count) ; i++) {
- snprintf(buffer, SIZE, "handle=0x%08x, active-count=%d / %d\n",
+ snprintf(buffer, SIZE, "handle=0x%08x, active-count=%d\n",
list[i].handle,
- mActivationCount.valueFor(list[i].handle).count,
mActivationCount.valueFor(list[i].handle).rates.size());
result.append(buffer);
}
bool actuateHardware = false;
Info& info( mActivationCount.editValueFor(handle) );
- int32_t& count(info.count);
if (enabled) {
- if (android_atomic_inc(&count) == 0) {
- actuateHardware = true;
- }
Mutex::Autolock _l(mLock);
if (info.rates.indexOfKey(ident) < 0) {
info.rates.add(ident, DEFAULT_EVENTS_PERIOD);
- }
- } else {
- if (android_atomic_dec(&count) == 1) {
actuateHardware = true;
+ } else {
+ // sensor was already activated for this ident
}
+ } else {
Mutex::Autolock _l(mLock);
- info.rates.removeItem(ident);
+ if (info.rates.removeItem(ident) >= 0) {
+ if (info.rates.size() == 0) {
+ actuateHardware = true;
+ }
+ } else {
+ // sensor wasn't enabled for this ident
+ }
}
+
if (actuateHardware) {
err = mSensorDevice->activate(mSensorDevice, handle, enabled);
if (enabled) {
Mutex mLock; // protect mActivationCount[].rates
// fixed-size array after construction
struct Info {
- Info() : count(0) { }
- int32_t count;
+ Info() { }
KeyedVector<void*, nsecs_t> rates;
};
DefaultKeyedVector<int, Info> mActivationCount;
HardwareSensor::HardwareSensor(const sensor_t& sensor)
: mSensorDevice(SensorDevice::getInstance()),
- mSensor(&sensor), mEnabled(false)
+ mSensor(&sensor)
{
LOGI("%s", sensor.name);
}
return true;
}
-bool HardwareSensor::isEnabled() const {
- return mEnabled;
-}
-
-status_t HardwareSensor::activate(void* ident,bool enabled) {
- status_t err = mSensorDevice.activate(ident, mSensor.getHandle(), enabled);
- if (err == NO_ERROR)
- mEnabled = enabled;
- return err;
+status_t HardwareSensor::activate(void* ident, bool enabled) {
+ return mSensorDevice.activate(ident, mSensor.getHandle(), enabled);
}
status_t HardwareSensor::setDelay(void* ident, int handle, int64_t ns) {
virtual bool process(sensors_event_t* outEvent,
const sensors_event_t& event) = 0;
- virtual bool isEnabled() const = 0;
virtual status_t activate(void* ident, bool enabled) = 0;
virtual status_t setDelay(void* ident, int handle, int64_t ns) = 0;
virtual Sensor getSensor() const = 0;
{
SensorDevice& mSensorDevice;
Sensor mSensor;
- bool mEnabled;
public:
HardwareSensor(const sensor_t& sensor);
virtual bool process(sensors_event_t* outEvent,
const sensors_event_t& event);
- virtual bool isEnabled() const;
virtual status_t activate(void* ident, bool enabled);
virtual status_t setDelay(void* ident, int handle, int64_t ns);
virtual Sensor getSensor() const;