Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
Diff: ak9750ctrl.cpp
- Revision:
- 39:3821886c902e
- Parent:
- 29:b488d2c89fba
- Child:
- 40:42e48427e4b7
--- a/ak9750ctrl.cpp Thu Jun 08 19:09:18 2017 +0000 +++ b/ak9750ctrl.cpp Tue Jul 18 23:20:26 2017 +0000 @@ -9,7 +9,6 @@ */ Ak9750Ctrl::Ak9750Ctrl() : AkmSensor(){ ak9750 = NULL; -// interrupt = NULL; } /** @@ -18,14 +17,12 @@ */ Ak9750Ctrl::~Ak9750Ctrl(){ if (ak9750) delete ak9750; -// 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); I2C* i2c = new I2C(I2C_SDA,I2C_SCL); i2c->frequency(I2C_SPEED_100KHZ); @@ -59,72 +56,72 @@ } } if(foundSensor != true){ - MSG("#Failed to checkConnection AK9750.\r\n"); + MSG("#Error: Failed to checkConnection AK9750.\r\n"); return AkmSensor::ERROR; } // reset if (ak9750->reset() != AK9750::SUCCESS) { - MSG("#Failed to reset AK9750.\r\n"); + MSG("#Error: Failed to reset AK9750.\r\n"); } /* // Set to EEPROM mode to EEPROM access if(ak9750->setOperationMode(AK9750::MODE_EEPROM_ACCESS, AK9750::DF_0P3HZ) != AK9750::SUCCESS) { - MSG("#Error setOperationMode to EEPROM mode. AK9750.\r\n"); + MSG("#Error: setOperationMode to EEPROM mode. AK9750.\r\n"); return AkmSensor::ERROR; } */ // Gets threshold from EEPROM AK9750::Threshold th; if (ak9750->getThresholdFromEEPROM(&th) != AK9750::SUCCESS) { - MSG("#Failed to get threshold from EEPROM AK9750.\r\n"); + MSG("#Error: Failed to get threshold from EEPROM AK9750.\r\n"); } MSG("#Threshold:(0x%02X,0x%02X,0x%02X,0x%02X)\r\n",th.eth13h,th.eth13l,th.eth24h,th.eth24l); // Gets hysteresis from EEPROM AK9750::Hysteresis hys; if (ak9750->getHysteresisFromEEPROM(&hys) != AK9750::SUCCESS) { - MSG("#Failed to get hysteresis from EEPROM AK9750.\r\n"); + MSG("#Error: Failed to get hysteresis from EEPROM AK9750.\r\n"); } MSG("#Hysteresis:(0x%02X,0x%02X)\r\n",hys.ehys13,hys.ehys24); // Gets interrupt status from EEPROM AK9750::InterruptStatus intStatus; if ((ak9750->getInterruptEnableFromEEPROM(&intStatus)) != AK9750::SUCCESS) { - MSG("#Failed to get interrupts of AK9750 from EEPROM.\r\n"); + MSG("#Error: Failed to get interrupts of AK9750 from EEPROM.\r\n"); } MSG("#Interrupt:(0x%02X,0x%02X,0x%02X,0x%02X,0x%02X)\r\n",intStatus.ir13h,intStatus.ir13l,intStatus.ir24h,intStatus.ir24l,intStatus.drdy); // Gets operation mode from EEPROM if ((ak9750->getOperationModeFromEEPROM(&mode,&filter)) != AK9750::SUCCESS) { - MSG("#Failed to get operation mode of AK9750 from EEPROM.\r\n"); + MSG("#Error: Failed to get operation mode of AK9750 from EEPROM.\r\n"); } MSG("#Operation Mode:(0x%02X,0x%02X)\r\n",mode, filter); /* // Back to Stand-by Mode for register access if(ak9750->setOperationMode(AK9750::MODE_STANDBY, filter) != AK9750::SUCCESS) { - MSG("#Error setOperationMode to stand-by mode of AK9750.\r\n"); + MSG("#Error: setOperationMode to stand-by mode of AK9750.\r\n"); return AkmSensor::ERROR; } */ // Sets threshold from the red EEPROM values if (ak9750->setThreshold(&th) != AK9750::SUCCESS) { - MSG("#Failed to set threshold to AK9750.\r\n"); + MSG("#Error: Failed to set threshold to AK9750.\r\n"); } // Sets hysteresis from the red EEPROM values if (ak9750->setHysteresis(&hys) != AK9750::SUCCESS) { - MSG("#Failed to set hysteresis to AK9750.\r\n"); + MSG("#Error: Failed to set hysteresis to AK9750.\r\n"); } // Sets interruput status from the red EEPROM values AK9750::Status status = ak9750->setInterruptEnable(&intStatus); if (status != AK9750::SUCCESS) { - MSG("#Failed to set interrupts of AK9750. Status = 0x%02X\r\n", status); + MSG("#Error: Failed to set interrupts of AK9750. Status = 0x%02X\r\n", status); } if(ak9750->setOperationMode(mode, filter) != AK9750::SUCCESS) { - MSG("#Error setOperationMode of AK9750.\r\n"); + MSG("#Error: setOperationMode of AK9750.\r\n"); return AkmSensor::ERROR; } @@ -142,12 +139,9 @@ AK9750::SensorData data; ak9750->getSensorData(&data); - // enable interrupt -// interrupt->fall(callback(this, &Ak9750Ctrl::detectINT)); - // set operation mode if(ak9750->setOperationMode(mode,filter) != AK9750::SUCCESS) { - MSG("#Start sensor failed %s\r\n", sensorName); + MSG("#Error: Start sensor failed %s\r\n", sensorName); return AkmSensor::ERROR; } @@ -156,16 +150,14 @@ } AkmSensor::Status Ak9750Ctrl::startSensor(const float sec){ -// interrupt->fall(callback(this, &Ak9750Ctrl::detectINT)); return AkmSensor::ERROR; } AkmSensor::Status Ak9750Ctrl::stopSensor(){ AkmSensor::clearEvent(); -// interrupt->fall(NULL); if(ak9750->setOperationMode(AK9750::MODE_STANDBY, filter) != AK9750::SUCCESS) { - MSG("#Error setOperationMode. AK9750.\r\n"); + MSG("#Error: setOperationMode. AK9750.\r\n"); return AkmSensor::ERROR; } @@ -182,7 +174,7 @@ AK9750::SensorData data; AK9750::Status status = ak9750->getSensorData(&data); if( status != AK9750::SUCCESS){ - MSG("#Error getSensorData. AK9750.\r\n"); + MSG("#Error: getSensorData. AK9750.\r\n"); return AkmSensor::ERROR; } msg->setCommand(Message::CMD_START_MEASUREMENT); @@ -219,7 +211,7 @@ case Message::CMD_IR_GET_THRESHOLD: { if (ak9750->getThreshold(&th) != AK9750::SUCCESS) { - MSG("#Failed to get threshold of AK9750.\r\n"); + MSG("#Error: Failed to get threshold of AK9750.\r\n"); return AkmSensor::ERROR; } out->setArgument(0,(char)((int32_t)(th.eth13h) >> 8)); @@ -240,7 +232,7 @@ th.eth24l = CONV16I(in->getArgument(6), in->getArgument(7)); if (ak9750->setThreshold(&th) != AK9750::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Failed to set threshold to AK9750.\r\n"); + MSG("#Error: Failed to set threshold to AK9750.\r\n"); } out->setArgument(0,(char)status); break; @@ -248,7 +240,7 @@ case Message::CMD_IR_GET_HYSTERESIS: { if (ak9750->getHysteresis(&hys) != AK9750::SUCCESS) { - MSG("#Failed to get hysteresis of AK9750.\r\n"); + MSG("#Error: Failed to get hysteresis of AK9750.\r\n"); return AkmSensor::ERROR; } out->setArgument(0,hys.ehys13); @@ -261,7 +253,7 @@ hys.ehys24 = in->getArgument(1); if (ak9750->setHysteresis(&hys) != AK9750::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Failed to set hysteresis to AK9750.\r\n"); + MSG("#Error: Failed to set hysteresis to AK9750.\r\n"); } out->setArgument(0,(char)status); break; @@ -269,7 +261,7 @@ case Message::CMD_IR_GET_INTERRUPT: { if (ak9750->getInterruptEnable(&interrupt) != AK9750::SUCCESS) { - MSG("#Failed to get interrupt of AK9750.\r\n"); + MSG("#Error: Failed to get interrupt of AK9750.\r\n"); return AkmSensor::ERROR; } out->setArgument(0, interrupt.ir13h); @@ -288,7 +280,7 @@ interrupt.drdy = in->getArgument(4); if (ak9750->setInterruptEnable(&interrupt) != AK9750::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Failed to set interrupt to AK9750.\r\n"); + MSG("#Error: Failed to set interrupt to AK9750.\r\n"); } out->setArgument(0,(char)status); break; @@ -296,7 +288,7 @@ case Message::CMD_IR_GET_OPERATION_MODE: { if(ak9750->getOperationMode(&mode, &filter) != AK9750::SUCCESS) { - MSG("#Error getOperationMode. AK9750.\r\n"); + MSG("#Error: getOperationMode. AK9750.\r\n"); return AkmSensor::ERROR; } out->setArgument(0,(char)mode); @@ -309,7 +301,7 @@ filter = (AK9750::DigitalFilter)in->getArgument(1); if(ak9750->setOperationMode(mode, filter) != AK9750::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Error setOperationMode. AK9750.\r\n"); + MSG("#Error: setOperationMode. AK9750.\r\n"); } out->setArgument(0,(char)status); break; @@ -317,7 +309,7 @@ case Message::CMD_IR_GET_THRESHOLD_EEPROM: { if (ak9750->getThresholdFromEEPROM(&th) != AK9750::SUCCESS) { - MSG("#Failed to get threshold of AK9750(EEPROM).\r\n"); + MSG("#Error: Failed to get threshold of AK9750(EEPROM).\r\n"); return AkmSensor::ERROR; } out->setArgument(0,(char)((int32_t)(th.eth13h) >> 8)); @@ -338,7 +330,7 @@ th.eth24l = CONV16I(in->getArgument(6), in->getArgument(7)); if (ak9750->setThresholdToEEPROM(&th) != AK9750::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Failed to set threshold to AK9750(EEPROM).\r\n"); + MSG("#Error: Failed to set threshold to AK9750(EEPROM).\r\n"); } out->setArgument(0,(char)status); break; @@ -346,7 +338,7 @@ case Message::CMD_IR_GET_HYSTERESIS_EEPROM: { if (ak9750->getHysteresisFromEEPROM(&hys) != AK9750::SUCCESS) { - MSG("#Failed to get hysteresis of AK9750(EEPROM).\r\n"); + MSG("#Error: Failed to get hysteresis of AK9750(EEPROM).\r\n"); return AkmSensor::ERROR; } out->setArgument(0,hys.ehys13); @@ -359,7 +351,7 @@ hys.ehys24 = in->getArgument(1); if (ak9750->setHysteresisToEEPROM(&hys) != AK9750::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Failed to set hysteresis to AK9750(EEPROM).\r\n"); + MSG("#Error: Failed to set hysteresis to AK9750(EEPROM).\r\n"); } out->setArgument(0,(char)status); break; @@ -367,7 +359,7 @@ case Message::CMD_IR_GET_INTERRUPT_EEPROM: { if (ak9750->getInterruptEnableFromEEPROM(&interrupt) != AK9750::SUCCESS) { - MSG("#Failed to get interrupt of AK9750(EEPROM).\r\n"); + MSG("#Error: Failed to get interrupt of AK9750(EEPROM).\r\n"); return AkmSensor::ERROR; } out->setArgument(0, interrupt.ir13h); @@ -386,7 +378,7 @@ interrupt.drdy = in->getArgument(4); if (ak9750->setInterruptEnableToEEPROM(&interrupt) != AK9750::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Failed to set interrupt to AK9750(EEPROM).\r\n"); + MSG("#Error: Failed to set interrupt to AK9750(EEPROM).\r\n"); } out->setArgument(0,(char)status); break; @@ -394,7 +386,7 @@ case Message::CMD_IR_GET_OPERATION_MODE_EEPROM: { if(ak9750->getOperationModeFromEEPROM(&mode, &filter) != AK9750::SUCCESS) { - MSG("#Error getOperationMode. AK9750(EEPROM).\r\n"); + MSG("#Error: getOperationMode. AK9750(EEPROM).\r\n"); return AkmSensor::ERROR; } out->setArgument(0,(char)mode); @@ -407,7 +399,7 @@ filter = (AK9750::DigitalFilter)in->getArgument(1); if(ak9750->setOperationModeToEEPROM(mode, filter) != AK9750::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Error setOperationMode. AK9750(EEPROM).\r\n"); + MSG("#Error: setOperationMode. AK9750(EEPROM).\r\n"); } out->setArgument(0,(char)status); break; @@ -418,7 +410,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; @@ -430,7 +422,7 @@ } if( ak9750->write(address, data, len) != AK9750::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Error register write.\r\n"); + MSG("#Error: register write.\r\n"); } out->setArgument(0,(char)status); break; @@ -439,7 +431,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; } @@ -447,7 +439,7 @@ int len = (int)in->getArgument(1); char data[len]; if( ak9750->read(address, data, len) != AK9750::SUCCESS) { - MSG("#Error register read.\r\n"); + MSG("#Error: register read.\r\n"); return AkmSensor::ERROR; } for(int i=0; i<len; i++){ @@ -457,7 +449,7 @@ } default: { - MSG("#Error no command.\r\n"); + MSG("#Error: no command.\r\n"); status = AkmSensor::ERROR; break; }