Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
Diff: ak9750ctrl.cpp
- Revision:
- 29:b488d2c89fba
- Parent:
- 27:41aa9fb23a2f
- Child:
- 39:3821886c902e
--- a/ak9750ctrl.cpp Sat Mar 11 02:08:32 2017 +0000 +++ b/ak9750ctrl.cpp Fri Mar 17 23:29:20 2017 +0000 @@ -9,7 +9,7 @@ */ Ak9750Ctrl::Ak9750Ctrl() : AkmSensor(){ ak9750 = NULL; - interrupt = NULL; +// interrupt = NULL; } /** @@ -18,14 +18,14 @@ */ Ak9750Ctrl::~Ak9750Ctrl(){ if (ak9750) delete ak9750; - if (interrupt) delete interrupt; +// if (interrupt) delete interrupt; } AkmSensor::Status Ak9750Ctrl::init(const uint8_t id, const uint8_t subid){ primaryId = id; subId = subid; - interrupt = new InterruptIn(I2C_DRDY); +// interrupt = new InterruptIn(I2C_DRDY); I2C* i2c = new I2C(I2C_SDA,I2C_SCL); i2c->frequency(I2C_SPEED_100KHZ); @@ -132,8 +132,9 @@ return AkmSensor::SUCCESS; } -void Ak9750Ctrl::detectINT(){ - event = true; +void Ak9750Ctrl::setEvent(){ + AK9750::Status status = ak9750->isDataReady(); + if( status == AK9750::DATA_READY ) base::setEvent(); } AkmSensor::Status Ak9750Ctrl::startSensor(){ @@ -142,26 +143,27 @@ ak9750->getSensorData(&data); // enable interrupt - interrupt->fall(callback(this, &Ak9750Ctrl::detectINT)); +// interrupt->fall(callback(this, &Ak9750Ctrl::detectINT)); // set operation mode if(ak9750->setOperationMode(mode,filter) != AK9750::SUCCESS) { - MSG("#Start sensor failed.\r\n"); + MSG("#Start sensor failed %s\r\n", sensorName); return AkmSensor::ERROR; } - MSG("#Start sensor succceeded.\r\n"); + MSG("#Start sensor %s.\r\n",sensorName); return AkmSensor::SUCCESS; } AkmSensor::Status Ak9750Ctrl::startSensor(const float sec){ - interrupt->fall(callback(this, &Ak9750Ctrl::detectINT)); +// interrupt->fall(callback(this, &Ak9750Ctrl::detectINT)); return AkmSensor::ERROR; } AkmSensor::Status Ak9750Ctrl::stopSensor(){ - event = false; - interrupt->fall(NULL); + AkmSensor::clearEvent(); + +// interrupt->fall(NULL); if(ak9750->setOperationMode(AK9750::MODE_STANDBY, filter) != AK9750::SUCCESS) { MSG("#Error setOperationMode. AK9750.\r\n"); return AkmSensor::ERROR; @@ -175,7 +177,7 @@ } AkmSensor::Status Ak9750Ctrl::readSensorData(Message* msg){ - event = false; + AkmSensor::clearEvent(); AK9750::SensorData data; AK9750::Status status = ak9750->getSensorData(&data);