Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
Diff: akmakd.cpp
- Revision:
- 10:5c69b067d88a
- Parent:
- 9:6fa3e7b17c27
- Child:
- 11:cef8dc1cf010
--- a/akmakd.cpp Thu Jun 16 18:36:26 2016 +0000 +++ b/akmakd.cpp Fri Jul 08 22:26:26 2016 +0000 @@ -52,23 +52,29 @@ compass = ak8963; AkmAkd::sensorName = "AK8963"; break; - case AkmAkd::SUB_ID_AK09911: + case AkmAkd::SUB_ID_AK09911C: type = AkmECompass::AK09911; ak099xx = new AK099XX(); compass = ak099xx; - AkmAkd::sensorName = "AK09911"; + AkmAkd::sensorName = "AK09911C"; break; - case AkmAkd::SUB_ID_AK09912: + case AkmAkd::SUB_ID_AK09912C: type = AkmECompass::AK09912; ak099xx = new AK099XX(); compass = ak099xx; - AkmAkd::sensorName = "AK09912"; + AkmAkd::sensorName = "AK09912C"; break; - case AkmAkd::SUB_ID_AK09915: + case AkmAkd::SUB_ID_AK09915C: type = AkmECompass::AK09915; ak099xx = new AK099XX(); compass = ak099xx; - AkmAkd::sensorName = "AK09915"; + AkmAkd::sensorName = "AK09915C"; + break; + case AkmAkd::SUB_ID_AK09915D: + type = AkmECompass::AK09915; + ak099xx = new AK099XX(); + compass = ak099xx; + AkmAkd::sensorName = "AK09915D"; break; case AkmAkd::SUB_ID_AK09916C: type = AkmECompass::AK09916C; @@ -76,6 +82,12 @@ compass = ak099xx; AkmAkd::sensorName = "AK09916C"; break; + case AkmAkd::SUB_ID_AK09916D: + type = AkmECompass::AK09916D; + ak099xx = new AK099XX(); + compass = ak099xx; + AkmAkd::sensorName = "AK09916D"; + break; default: return AkmSensor::ERROR; // break; @@ -126,27 +138,36 @@ compass = ak8963; AkmAkd::sensorName = "AK8963"; break; - case AkmAkd::SUB_ID_AK09911: + case AkmAkd::SUB_ID_AK09911C: type = AkmECompass::AK09911; - AkmAkd::sensorName = "AK09911"; + AkmAkd::sensorName = "AK09911C"; return AkmSensor::ERROR; - case AkmAkd::SUB_ID_AK09912: + case AkmAkd::SUB_ID_AK09912C: type = AkmECompass::AK09912; ak099xx = new AK099XX(); compass = ak099xx; - AkmAkd::sensorName = "AK09912"; + AkmAkd::sensorName = "AK09912C"; break; - case AkmAkd::SUB_ID_AK09915: + case AkmAkd::SUB_ID_AK09915C: type = AkmECompass::AK09915; ak099xx = new AK099XX(); compass = ak099xx; - AkmAkd::sensorName = "AK09915"; + AkmAkd::sensorName = "AK09915C"; + break; + case AkmAkd::SUB_ID_AK09915D: + type = AkmECompass::AK09915; + AkmAkd::sensorName = "AK09915D"; break; case AkmAkd::SUB_ID_AK09916C: type = AkmECompass::AK09916C; AkmAkd::sensorName = "AK09916C"; // doesn't support SPI return AkmSensor::ERROR; + case AkmAkd::SUB_ID_AK09916D: + type = AkmECompass::AK09916D; + AkmAkd::sensorName = "AK09916D"; + // doesn't support SPI + return AkmSensor::ERROR; default: return AkmSensor::ERROR; // break; @@ -186,17 +207,17 @@ } AkmSensor::Status AkmAkd::startSensor(){ + // read once to clear DRDY pin AkmECompass::MagneticVector mag; AkmECompass::Status status = compass->getMagneticVector(&mag); - // Puts the device into continuous measurement mode. - if(compass->getSensorType() == AkmECompass::AK09915){ + if( subId == AkmAkd::SUB_ID_AK09915C || subId == AkmAkd::SUB_ID_AK09915D ){ if(compass->setOperationMode(mode,nsf,sdr) != AkmECompass::SUCCESS) { return AkmSensor::ERROR; } } - else if(compass->getSensorType() == AkmECompass::AK09912){ + else if( subId == AkmAkd::SUB_ID_AK09912C ){ if(compass->setOperationMode(mode,nsf) != AkmECompass::SUCCESS) { return AkmSensor::ERROR; } @@ -207,14 +228,23 @@ } } - // DRDY interrupt enable for AK8963/AK09912/AK09915 with I2C interface + // DRDY interrupt enable if( primaryId == AKM_PRIMARY_ID_AKD_I2C && - (compass->getSensorType() == AkmECompass::AK8963 || - compass->getSensorType() == AkmECompass::AK09912 || - compass->getSensorType() == AkmECompass::AK09915) ){ + (subId == AkmAkd::SUB_ID_AK8963N || + subId == AkmAkd::SUB_ID_AK8963C || + subId == AkmAkd::SUB_ID_AK09912C || + subId == AkmAkd::SUB_ID_AK09915C ) ){ + // Push-Pull DRDY drdy->rise(this, &AkmAkd::detectDRDY); } + else if( primaryId == AKM_PRIMARY_ID_AKD_I2C && + (subId == AkmAkd::SUB_ID_AK09915D || + subId == AkmAkd::SUB_ID_AK09916D ) ){ + // Open Drain DRDY + drdy->fall(this, &AkmAkd::detectDRDY); + } else{ + // No DRDY ticker.attach(this, &AkmAkd::checkDRDY, 0.005); // 200Hz } return AkmSensor::SUCCESS; @@ -271,7 +301,7 @@ case Message::CMD_COMPASS_SET_OPERATION_MODE: { mode = (AkmECompass::OperationMode)in->getArgument(0); - if(compass->getSensorType() == AkmECompass::AK09915){ + if(subId == AkmAkd::SUB_ID_AK09915C || subId == AkmAkd::SUB_ID_AK09915D){ nsf = (AkmECompass::Nsf)in->getArgument(1); sdr = (AkmECompass::Sdr)in->getArgument(2); if(compass->setOperationMode(mode,nsf,sdr) != AkmECompass::SUCCESS) { @@ -279,7 +309,7 @@ MSG("#Error set operation mode.\n"); } } - else if(compass->getSensorType() == AkmECompass::AK09912){ + else if(subId == AkmAkd::SUB_ID_AK09912C){ nsf = (AkmECompass::Nsf)in->getArgument(1); if(compass->setOperationMode(mode,(AkmECompass::Nsf)nsf) != AkmECompass::SUCCESS) { status = AkmSensor::ERROR;