Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
Diff: akmakd.cpp
- Revision:
- 29:b488d2c89fba
- Parent:
- 27:41aa9fb23a2f
- Child:
- 38:e865dadfe54d
--- a/akmakd.cpp Sat Mar 11 02:08:32 2017 +0000 +++ b/akmakd.cpp Fri Mar 17 23:29:20 2017 +0000 @@ -9,7 +9,7 @@ */ AkmAkd::AkmAkd() : AkmSensor(){ compass = NULL; - drdy = NULL; +// drdy = NULL; } /** @@ -17,9 +17,9 @@ * */ AkmAkd::~AkmAkd(){ - drdy->rise(0); +// drdy->rise(0); if (compass) delete compass; - if (drdy) delete drdy; +// if (drdy) delete drdy; } AkmSensor::Status AkmAkd::checkSensor( const uint8_t primaryid, const uint8_t subid, AkmECompass::DeviceId* devid){ @@ -102,8 +102,8 @@ if(primaryId == AKM_PRIMARY_ID_AKD_I2C){ - drdy = new InterruptIn(I2C_DRDY); - drdy->rise(0); +// drdy = new InterruptIn(I2C_DRDY); +// drdy->rise(0); I2C* i2c = new I2C(I2C_SDA,I2C_SCL); i2c->frequency(I2C_SPEED_100KHZ); @@ -129,8 +129,8 @@ } }else if(primaryId == AKM_PRIMARY_ID_AKD_SPI){ - drdy = new InterruptIn(SPI_DRDY); - drdy->rise(0); +// drdy = new InterruptIn(SPI_DRDY); +// drdy->rise(0); SPI* spi = new SPI(SPI_MOSI, SPI_MISO, SPI_SCK); spi->format(8,3); // 8bit, Mode=3 @@ -151,15 +151,11 @@ return AkmSensor::ERROR; } - -void AkmAkd::checkDRDY(){ +void AkmAkd::setEvent(){ AkmECompass::Status status = compass->isDataReady(); - if( status == AkmECompass::DATA_READY || - status == AkmECompass::DATA_OVER_RUN ) event = true; -} - -void AkmAkd::detectDRDY(){ - event = true; + if( status == AkmECompass::DATA_READY || status == AkmECompass::DATA_OVER_RUN ){ + base::setEvent(); + } } AkmAkd::InterruptMode AkmAkd::getInterrupt(uint8_t primaryId, uint8_t subId){ @@ -193,38 +189,38 @@ // enable interrupt if( int_mode == AkmAkd::INTERRUPT_ENABLED_PP ){ // Push-Pull DRDY - drdy->rise(callback(this, &AkmAkd::detectDRDY)); +// drdy->rise(callback(this, &AkmAkd::detectDRDY)); } else if( int_mode == AkmAkd::INTERRUPT_ENABLED_OD ){ // Open Drain DRDY - drdy->fall(callback(this, &AkmAkd::detectDRDY)); +// drdy->fall(callback(this, &AkmAkd::detectDRDY)); } else{ // No DRDY - ticker.attach(callback(this, &AkmAkd::checkDRDY), 1.0/AKDP_POLLING_FREQUENCY); + ticker.attach(callback(this, &AkmAkd::setEvent), 1.0/AKDP_POLLING_FREQUENCY); } // set operation mode if( subId == AkmAkd::SUB_ID_AK09915C || subId == AkmAkd::SUB_ID_AK09915D ){ if(compass->setOperationMode(mode,nsf,sdr) != AkmECompass::SUCCESS) { - MSG("#Start sensor failed.\r\n"); + MSG("#Start sensor failed %s\r\n", sensorName); return AkmSensor::ERROR; } } else if( subId == AkmAkd::SUB_ID_AK09912C ){ if(compass->setOperationMode(mode,nsf) != AkmECompass::SUCCESS) { - MSG("#Start sensor failed.\r\n"); + MSG("#Start sensor failed %s\r\n", sensorName); return AkmSensor::ERROR; } } else{ if(compass->setOperationMode(mode) != AkmECompass::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; } @@ -234,16 +230,16 @@ AkmSensor::Status AkmAkd::stopSensor(){ ticker.detach(); - event = false; + AkmSensor::clearEvent(); AkmAkd::InterruptMode int_mode = getInterrupt(primaryId,subId); if( int_mode == AkmAkd::INTERRUPT_ENABLED_PP ){ // Push-Pull DRDY - drdy->rise(NULL); +// drdy->rise(NULL); } else if( int_mode == AkmAkd::INTERRUPT_ENABLED_OD ){ // Open Drain DRDY - drdy->fall(NULL); +// drdy->fall(NULL); } else{ // No DRDY @@ -268,7 +264,7 @@ } AkmSensor::Status AkmAkd::readSensorData(Message* msg){ - event = false; + AkmSensor::clearEvent(); AkmECompass::MagneticVector mag; AkmECompass::Status status = compass->getMagneticVector(&mag);