Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
Diff: ak9752ctrl.cpp
- Revision:
- 11:cef8dc1cf010
- Parent:
- 10:5c69b067d88a
- Child:
- 13:d008249f0359
--- a/ak9752ctrl.cpp Fri Jul 08 22:26:26 2016 +0000 +++ b/ak9752ctrl.cpp Fri Jul 22 22:54:11 2016 +0000 @@ -56,10 +56,10 @@ // reset if (ak9752->reset() != AK9752::SUCCESS) { - MSG("#Failed to reset AK9752.\n"); + MSG("#Failed to reset AK9752.\r\n"); } - MSG("#Init success AK9752.\n"); + MSG("#Init success AK9752.\r\n"); return AkmSensor::SUCCESS; } @@ -72,13 +72,20 @@ } AkmSensor::Status Ak9752Ctrl::startSensor(){ + // read one data to clear INT pin + AK9752::SensorData data; + ak9752->getSensorData(&data); + + // enable interrupt + interrupt->fall(this, &Ak9752Ctrl::detectINT); + + // set operation mode if(ak9752->setOperationMode(mode,fc_tmp, fc_ir) != AK9752::SUCCESS) { - MSG("#Error setOperationMode. AK9752.\n"); + MSG("#Start sensor failed.\r\n"); return AkmSensor::ERROR; } - interrupt->fall(this, &Ak9752Ctrl::detectINT); - MSG("#Start Sensor success AK9752.\n"); + MSG("#Start sensor succceeded.\r\n"); return AkmSensor::SUCCESS; } @@ -89,15 +96,15 @@ AkmSensor::Status Ak9752Ctrl::stopSensor(){ event = false; - interrupt->fall(0); + interrupt->fall(NULL); if(ak9752->setOperationMode(AK9752::MODE_STANDBY, fc_tmp, fc_ir) != AK9752::SUCCESS) { - MSG("#Error setOperationMode. AK9752.\n"); + MSG("#Error setOperationMode. AK9752.\r\n"); return AkmSensor::ERROR; } // read one data to clear INT pin - Message msg; - Ak9752Ctrl::readSensorData(&msg); + AK9752::SensorData data; + ak9752->getSensorData(&data); return AkmSensor::SUCCESS; } @@ -108,7 +115,7 @@ AK9752::SensorData data; AK9752::Status status = ak9752->getSensorData(&data); if( status != AK9752::SUCCESS){ - MSG("#Error getSensorData. AK9752.\n"); + MSG("#Error getSensorData. AK9752.\r\n"); return AkmSensor::ERROR; } msg->setCommand(Message::CMD_START_MEASUREMENT); @@ -139,7 +146,7 @@ { if (ak9752->getThreshold(&th) != AK9752::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Failed to set threshold to AK9752.\n"); + MSG("#Failed to set threshold to AK9752.\r\n"); } out->setArgument(0,(char)((int32_t)(th.thirh) >> 8)); out->setArgument(1,(char)((int32_t)(th.thirh) & 0x00FF)); @@ -159,7 +166,7 @@ th.thtmpl = CONV16I(in->getArgument(6), in->getArgument(7)); if (ak9752->setThreshold(&th) != AK9752::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Failed to set threshold to AK9752.\n"); + MSG("#Failed to set threshold to AK9752.\r\n"); } out->setArgument(0,(char)status); break; @@ -168,7 +175,7 @@ { if (ak9752->getInterruptEnable(&interrupt) != AK9752::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Failed to set hysteresis to AK9752.\n"); + MSG("#Failed to set hysteresis to AK9752.\r\n"); } out->setArgument(0, interrupt.irh); out->setArgument(1, interrupt.irl); @@ -186,7 +193,7 @@ interrupt.dr = in->getArgument(4); if (ak9752->setInterruptEnable(&interrupt) != AK9752::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Failed to set hysteresis to AK9752.\n"); + MSG("#Failed to set hysteresis to AK9752.\r\n"); } out->setArgument(0,(char)status); break; @@ -195,7 +202,7 @@ { if(ak9752->getOperationMode(&mode, &fc_tmp, &fc_ir) != AK9752::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Error setOperationMode. AK9752.\n"); + MSG("#Error setOperationMode. AK9752.\r\n"); } out->setArgument(0,(char)mode); out->setArgument(1,(char)fc_tmp); @@ -209,7 +216,7 @@ fc_ir = (AK9752::FcIr)in->getArgument(2); if(ak9752->setOperationMode(mode, fc_tmp, fc_ir) != AK9752::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Error setOperationMode. AK9752.\n"); + MSG("#Error setOperationMode. AK9752.\r\n"); } out->setArgument(0,(char)status); break; @@ -221,7 +228,7 @@ const char data = in->getArgument(2); if( ak9752->write(address, &data, len) != AK9752::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Error register write.\n"); + MSG("#Error register write.\r\n"); } out->setArgument(0,(char)status); break; @@ -236,7 +243,7 @@ } if( ak9752->write(address, data, len) != AK9752::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Error register write.\n"); + MSG("#Error register write.\r\n"); } out->setArgument(0,(char)status); break; @@ -248,7 +255,7 @@ char data; if( ak9752->read(address, &data, len) != AK9752::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Error register read.\n"); + MSG("#Error register read.\r\n"); } out->setArgument(0,data); break; @@ -260,7 +267,7 @@ char data[len]; if( ak9752->read(address, data, len) != AK9752::SUCCESS) { status = AkmSensor::ERROR; - MSG("#Error register read.\n"); + MSG("#Error register read.\r\n"); } for(int i=0; i<len; i++){ out->setArgument(i, data[i]); @@ -269,7 +276,7 @@ } default: { - MSG("#Error no command.\n"); + MSG("#Error no command.\r\n"); status = AkmSensor::ERROR; break; }