Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
Diff: ak09970ctrl.cpp
- Revision:
- 39:3821886c902e
- Parent:
- 29:b488d2c89fba
- Child:
- 40:42e48427e4b7
--- a/ak09970ctrl.cpp Thu Jun 08 19:09:18 2017 +0000 +++ b/ak09970ctrl.cpp Tue Jul 18 23:20:26 2017 +0000 @@ -20,10 +20,7 @@ * */ Ak09970Ctrl::~Ak09970Ctrl(){ -// interrupt->rise(NULL); -// interrupt->fall(NULL); if (ak09970) delete ak09970; -// if (interrupt) delete interrupt; } AkmSensor::Status Ak09970Ctrl::init(const uint8_t id, const uint8_t subid){ @@ -38,9 +35,6 @@ if(primaryId == AKM_PRIMARY_ID_AKD_I2C){ -// interrupt = new InterruptIn(I2C_DRDY); -// interrupt->rise(0); - I2C* i2c = new I2C(I2C_SDA,I2C_SCL); i2c->frequency(I2C_SPEED_100KHZ); @@ -78,9 +72,6 @@ }else if(primaryId == AKM_PRIMARY_ID_AKD_SPI){ -// interrupt = new InterruptIn(SPI_DRDY); -// sw->rise(0); - SPI* spi = new SPI(SPI_MOSI, SPI_MISO, SPI_SCK); spi->format(8,3); // 8bit, Mode=3 spi->frequency(1000000); @@ -102,7 +93,7 @@ foundSensor = true; } if(foundSensor != true){ - MSG("#failed checkConnetion(SPI). %s\r\n",Ak09970Ctrl::sensorName); + MSG("#Error: Failed checkConnetion(SPI). %s\r\n",Ak09970Ctrl::sensorName); return AkmSensor::ERROR; } @@ -128,41 +119,25 @@ AK09970::SwitchStatus sw_status; ak09970->getSwitchStatus(&sw_status, readConfig); - // enable interrupt - if(switchConfig.enabledINTEN){ -// interrupt->rise(callback(this, &AkmSensor::setEvent)); // Push-pull - MSG("#INT Enable.\r\n"); - } - else if(switchConfig.enabledODINTEN){ -// interrupt->fall(callback(this, &AkmSensor::setEvent)); // Opnen drain - MSG("#ODINT Enable.\r\n"); - } - // set operation mode if(ak09970->setOperationMode(mode,sensorDriveMode,sensorMeasurementRange) != AK09970::SUCCESS) { - MSG("#Start sensor failed.\r\n"); + MSG("#Error: Start sensor %s.\r\n", sensorName); return AkmSensor::ERROR; } - MSG("#Start sensor %s.\r\n", sensorName); return AkmSensor::SUCCESS; } AkmSensor::Status Ak09970Ctrl::startSensor(const float sec){ - MSG("#Start sensor %s.\r\n", sensorName); + MSG("#Error: Start sensor %s.\r\n", sensorName); return AkmSensor::ERROR; } AkmSensor::Status Ak09970Ctrl::stopSensor(){ - if(switchConfig.enabledINTEN){ -// interrupt->rise(NULL); - } - else if(switchConfig.enabledODINTEN){ -// interrupt->fall(NULL); - } AkmSensor::clearEvent(); if(ak09970->setOperationMode(AK09970::MODE_POWER_DOWN, sensorDriveMode, sensorMeasurementRange) != AK09970::SUCCESS) { + MSG("#Error: Stop sensor %s.\r\n", sensorName); return AkmSensor::ERROR; } @@ -192,11 +167,6 @@ msg->setArgument(7, (char)(sw_status.mag.mz>>8)); msg->setArgument(8, (char)(sw_status.mag.mz & 0x00FF)); - // test -// double angle=0; -// angle = atan2((double)sw_status.mag.mx, (double)sw_status.mag.my)*180.0/PI+180.0; -// MSG("#Angle=%3.1f\r\n",angle); - return AkmSensor::SUCCESS; } @@ -209,7 +179,7 @@ case Message::CMD_PROGSW_GET_THRESHOLD: { if(in->getArgNum() != 1){ - MSG("#Error argument num. AK09970. Args=%d\r\n",in->getArgNum()); + MSG("#Error: Argument num. AK09970. Args=%d\r\n",in->getArgNum()); return AkmSensor::ERROR; } @@ -232,7 +202,7 @@ case Message::CMD_PROGSW_SET_THRESHOLD: { if(in->getArgNum() != 9){ - MSG("#Error argument num. AK09970. Args=%d\r\n",in->getArgNum()); + MSG("#Error: Argument num. AK09970. Args=%d\r\n",in->getArgNum()); status = AkmSensor::ERROR; out->setArgument(0,(char)status); return status; @@ -254,7 +224,7 @@ case Message::CMD_PROGSW_GET_READ_COFIGURATION: { if(in->getArgNum() != 0){ - MSG("#Error argument num. AK09970. Args=%d\r\n",in->getArgNum()); + MSG("#Error: Argument num. AK09970. Args=%d\r\n",in->getArgNum()); return AkmSensor::ERROR; } @@ -267,7 +237,7 @@ case Message::CMD_PROGSW_SET_READ_COFIGURATION: { if(in->getArgNum() != 4){ - MSG("#Error argument num. AK09970. Args=%d\r\n",in->getArgNum()); + MSG("#Error: Argument num. AK09970. Args=%d\r\n",in->getArgNum()); status = AkmSensor::ERROR; out->setArgument(0,(char)status); return status; @@ -283,12 +253,12 @@ case Message::CMD_PROGSW_GET_SWITCH_COFIGURATION: { if(in->getArgNum() != 0){ - MSG("#Error argument num. AK09970. Args=%d\r\n",in->getArgNum()); + MSG("#Error: Argument num. AK09970. Args=%d\r\n",in->getArgNum()); return AkmSensor::ERROR; } if(ak09970->getSwitchConfig(&switchConfig) != AK09970::SUCCESS) { - MSG("#Error getSwitchConfig. AK09970.\r\n"); + MSG("#Error: getSwitchConfig. AK09970.\r\n"); return AkmSensor::ERROR; } out->setArgument(0,switchConfig.enabledODINTEN); @@ -307,7 +277,7 @@ case Message::CMD_PROGSW_SET_SWITCH_COFIGURATION: { if(in->getArgNum() != 11){ - MSG("#Error argument num. AK09970. Args=%d\r\n",in->getArgNum()); + MSG("#Error: Argument num. AK09970. Args=%d\r\n",in->getArgNum()); for(int i=0; i<in->getArgNum(); i++){ MSG("#%d = %02X\r\n",i,in->getArgument(i)); } @@ -330,7 +300,7 @@ if(ak09970->setSwitchConfig(switchConfig) != AK09970::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Error setSwitchConfig. AK09970.\r\n"); + MSG("#Error: setSwitchConfig. AK09970.\r\n"); } out->setArgument(0,(char)status); break; @@ -338,12 +308,12 @@ case Message::CMD_PROGSW_GET_OPERATION_MODE: { if(in->getArgNum() != 0){ - MSG("#Error argument num. AK09970. Args=%d\r\n",in->getArgNum()); + MSG("#Error: Argument num. AK09970. Args=%d\r\n",in->getArgNum()); return AkmSensor::ERROR; } if(ak09970->getOperationMode(&mode, &sensorDriveMode, &sensorMeasurementRange) != AK09970::SUCCESS) { - MSG("#Error getOperationMode. AK09970.\r\n"); + MSG("#Error: getOperationMode. AK09970.\r\n"); return AkmSensor::ERROR; } out->setArgument(0,(char)sensorMeasurementRange); @@ -354,7 +324,7 @@ case Message::CMD_PROGSW_SET_OPERATION_MODE: { if(in->getArgNum() != 3){ - MSG("#Error argument num. AK09970. Args=%d\r\n",in->getArgNum()); + MSG("#Error: Argument num. AK09970. Args=%d\r\n",in->getArgNum()); status = AkmSensor::ERROR; out->setArgument(0,(char)status); return status; @@ -365,7 +335,7 @@ mode = (AK09970::OperationMode)(in->getArgument(2)); if(ak09970->setOperationMode(mode, sensorDriveMode, sensorMeasurementRange) != AK09970::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Error setOperationMode. AK09970. %d,%d,%d\r\n",mode,sensorDriveMode,sensorMeasurementRange); + MSG("#Error: setOperationMode. AK09970. %d,%d,%d\r\n",mode,sensorDriveMode,sensorMeasurementRange); } out->setArgument(0,(char)status); break; @@ -376,7 +346,7 @@ char address = in->getArgument(0); int len = (int)in->getArgument(1); if(in->getArgNum() != len+2){ - MSG("#Error argument num. Args=%d\r\n",in->getArgNum()); + MSG("#Error: Argument num. Args=%d\r\n",in->getArgNum()); status = AkmSensor::ERROR; out->setArgument(0,(char)status); return status; @@ -388,7 +358,7 @@ } if( ak09970->write(address, data, len) != AK09970::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Error register write.\r\n"); + MSG("#Error: Register write.\r\n"); } out->setArgument(0,(char)status); break; @@ -397,7 +367,7 @@ case Message::CMD_REG_READN: { if(in->getArgNum() != 2){ - MSG("#Error argument num. Args=%d\r\n",in->getArgNum()); + MSG("#Error: Argument num. Args=%d\r\n",in->getArgNum()); return AkmSensor::ERROR; } @@ -405,7 +375,7 @@ int len = (int)in->getArgument(1); char data[len]; if( ak09970->read(address, data, len) != AK09970::SUCCESS) { - MSG("#Error register read.\r\n"); + MSG("#Error: Register read.\r\n"); return AkmSensor::ERROR; } for(int i=0; i<len; i++){ @@ -415,7 +385,7 @@ } default: { - MSG("#Error no command.\r\n"); + MSG("#Error: No command.\r\n"); status = AkmSensor::ERROR; break; }