Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
ak9752ctrl.cpp@40:42e48427e4b7, 2017-07-19 (annotated)
- Committer:
- masahikofukasawa
- Date:
- Wed Jul 19 23:30:22 2017 +0000
- Revision:
- 40:42e48427e4b7
- Parent:
- 39:3821886c902e
- Child:
- 43:45225713cd58
Changed I2C speed:100kHz --> 400kHz, Serial baud-rate: 115200bps --> 460800bps for faster sampling.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
masahikofukasawa | 10:5c69b067d88a | 1 | #include "ak9752ctrl.h" |
masahikofukasawa | 10:5c69b067d88a | 2 | #include "debug.h" |
masahikofukasawa | 10:5c69b067d88a | 3 | |
masahikofukasawa | 10:5c69b067d88a | 4 | #define CONV16I(high,low) ((int16_t)(((high) << 8) | (low))) |
masahikofukasawa | 10:5c69b067d88a | 5 | |
masahikofukasawa | 10:5c69b067d88a | 6 | /** |
masahikofukasawa | 10:5c69b067d88a | 7 | * Constructor. |
masahikofukasawa | 10:5c69b067d88a | 8 | * |
masahikofukasawa | 10:5c69b067d88a | 9 | */ |
masahikofukasawa | 27:41aa9fb23a2f | 10 | Ak9752Ctrl::Ak9752Ctrl() : AkmSensor(){ |
masahikofukasawa | 10:5c69b067d88a | 11 | ak9752 = NULL; |
masahikofukasawa | 10:5c69b067d88a | 12 | } |
masahikofukasawa | 10:5c69b067d88a | 13 | |
masahikofukasawa | 10:5c69b067d88a | 14 | /** |
masahikofukasawa | 10:5c69b067d88a | 15 | * Destructor. |
masahikofukasawa | 10:5c69b067d88a | 16 | * |
masahikofukasawa | 10:5c69b067d88a | 17 | */ |
masahikofukasawa | 10:5c69b067d88a | 18 | Ak9752Ctrl::~Ak9752Ctrl(){ |
masahikofukasawa | 10:5c69b067d88a | 19 | if (ak9752) delete ak9752; |
masahikofukasawa | 10:5c69b067d88a | 20 | } |
masahikofukasawa | 10:5c69b067d88a | 21 | |
masahikofukasawa | 10:5c69b067d88a | 22 | AkmSensor::Status Ak9752Ctrl::init(const uint8_t id, const uint8_t subid){ |
masahikofukasawa | 10:5c69b067d88a | 23 | primaryId = id; |
masahikofukasawa | 10:5c69b067d88a | 24 | subId = subid; |
masahikofukasawa | 10:5c69b067d88a | 25 | |
masahikofukasawa | 10:5c69b067d88a | 26 | I2C* i2c = new I2C(I2C_SDA,I2C_SCL); |
masahikofukasawa | 40:42e48427e4b7 | 27 | i2c->frequency(I2C_SPEED); |
masahikofukasawa | 10:5c69b067d88a | 28 | |
masahikofukasawa | 10:5c69b067d88a | 29 | if(subId == SUB_ID_AK9752){ |
masahikofukasawa | 10:5c69b067d88a | 30 | ak9752 = new AK9752(); |
masahikofukasawa | 13:d008249f0359 | 31 | sensorName = "AK9752"; |
masahikofukasawa | 10:5c69b067d88a | 32 | } |
masahikofukasawa | 10:5c69b067d88a | 33 | else{ |
masahikofukasawa | 10:5c69b067d88a | 34 | return AkmSensor::ERROR; |
masahikofukasawa | 10:5c69b067d88a | 35 | } |
masahikofukasawa | 10:5c69b067d88a | 36 | |
masahikofukasawa | 10:5c69b067d88a | 37 | bool foundSensor = false; |
masahikofukasawa | 10:5c69b067d88a | 38 | |
masahikofukasawa | 10:5c69b067d88a | 39 | AK9752::SlaveAddress slaveAddr[] |
masahikofukasawa | 10:5c69b067d88a | 40 | = { AK9752::SLAVE_ADDR_1 }; |
masahikofukasawa | 10:5c69b067d88a | 41 | |
masahikofukasawa | 10:5c69b067d88a | 42 | for(int i=0; i<sizeof(slaveAddr); i++) |
masahikofukasawa | 10:5c69b067d88a | 43 | { |
masahikofukasawa | 10:5c69b067d88a | 44 | ak9752->init(i2c, slaveAddr[i]); |
masahikofukasawa | 10:5c69b067d88a | 45 | // Checks connectivity |
masahikofukasawa | 29:b488d2c89fba | 46 | if(ak9752->checkConnection() == AK9752::SUCCESS) { |
masahikofukasawa | 10:5c69b067d88a | 47 | // found |
masahikofukasawa | 10:5c69b067d88a | 48 | foundSensor = true; |
masahikofukasawa | 10:5c69b067d88a | 49 | break; |
masahikofukasawa | 10:5c69b067d88a | 50 | } |
masahikofukasawa | 10:5c69b067d88a | 51 | } |
masahikofukasawa | 10:5c69b067d88a | 52 | if(foundSensor != true) return AkmSensor::ERROR; |
masahikofukasawa | 10:5c69b067d88a | 53 | |
masahikofukasawa | 10:5c69b067d88a | 54 | // reset |
masahikofukasawa | 10:5c69b067d88a | 55 | if (ak9752->reset() != AK9752::SUCCESS) { |
masahikofukasawa | 39:3821886c902e | 56 | MSG("#Error: Failed to reset AK9752.\r\n"); |
masahikofukasawa | 10:5c69b067d88a | 57 | } |
masahikofukasawa | 10:5c69b067d88a | 58 | |
masahikofukasawa | 11:cef8dc1cf010 | 59 | MSG("#Init success AK9752.\r\n"); |
masahikofukasawa | 10:5c69b067d88a | 60 | return AkmSensor::SUCCESS; |
masahikofukasawa | 10:5c69b067d88a | 61 | } |
masahikofukasawa | 10:5c69b067d88a | 62 | |
masahikofukasawa | 29:b488d2c89fba | 63 | void Ak9752Ctrl::setEvent(){ |
masahikofukasawa | 29:b488d2c89fba | 64 | // MSG("#setEvent() in %s.\r\n",sensorName); |
masahikofukasawa | 29:b488d2c89fba | 65 | AK9752::Status status = ak9752->isDataReady(); |
masahikofukasawa | 29:b488d2c89fba | 66 | if( status == AK9752::DATA_READY ) base::setEvent(); |
masahikofukasawa | 10:5c69b067d88a | 67 | } |
masahikofukasawa | 10:5c69b067d88a | 68 | |
masahikofukasawa | 10:5c69b067d88a | 69 | AkmSensor::Status Ak9752Ctrl::startSensor(){ |
masahikofukasawa | 11:cef8dc1cf010 | 70 | // read one data to clear INT pin |
masahikofukasawa | 11:cef8dc1cf010 | 71 | AK9752::SensorData data; |
masahikofukasawa | 11:cef8dc1cf010 | 72 | ak9752->getSensorData(&data); |
masahikofukasawa | 11:cef8dc1cf010 | 73 | |
masahikofukasawa | 11:cef8dc1cf010 | 74 | // set operation mode |
masahikofukasawa | 10:5c69b067d88a | 75 | if(ak9752->setOperationMode(mode,fc_tmp, fc_ir) != AK9752::SUCCESS) { |
masahikofukasawa | 39:3821886c902e | 76 | MSG("#Error: Start sensor failed %s\r\n", sensorName); |
masahikofukasawa | 10:5c69b067d88a | 77 | return AkmSensor::ERROR; |
masahikofukasawa | 10:5c69b067d88a | 78 | } |
masahikofukasawa | 10:5c69b067d88a | 79 | |
masahikofukasawa | 29:b488d2c89fba | 80 | MSG("#Start sensor %s.\r\n",sensorName); |
masahikofukasawa | 10:5c69b067d88a | 81 | return AkmSensor::SUCCESS; |
masahikofukasawa | 10:5c69b067d88a | 82 | } |
masahikofukasawa | 10:5c69b067d88a | 83 | |
masahikofukasawa | 10:5c69b067d88a | 84 | AkmSensor::Status Ak9752Ctrl::startSensor(const float sec){ |
masahikofukasawa | 10:5c69b067d88a | 85 | return AkmSensor::ERROR; |
masahikofukasawa | 10:5c69b067d88a | 86 | } |
masahikofukasawa | 10:5c69b067d88a | 87 | |
masahikofukasawa | 10:5c69b067d88a | 88 | AkmSensor::Status Ak9752Ctrl::stopSensor(){ |
masahikofukasawa | 29:b488d2c89fba | 89 | AkmSensor::clearEvent(); |
masahikofukasawa | 29:b488d2c89fba | 90 | |
masahikofukasawa | 10:5c69b067d88a | 91 | if(ak9752->setOperationMode(AK9752::MODE_STANDBY, fc_tmp, fc_ir) != AK9752::SUCCESS) { |
masahikofukasawa | 39:3821886c902e | 92 | MSG("#Error: setOperationMode. AK9752.\r\n"); |
masahikofukasawa | 10:5c69b067d88a | 93 | return AkmSensor::ERROR; |
masahikofukasawa | 10:5c69b067d88a | 94 | } |
masahikofukasawa | 10:5c69b067d88a | 95 | |
masahikofukasawa | 10:5c69b067d88a | 96 | // read one data to clear INT pin |
masahikofukasawa | 11:cef8dc1cf010 | 97 | AK9752::SensorData data; |
masahikofukasawa | 11:cef8dc1cf010 | 98 | ak9752->getSensorData(&data); |
masahikofukasawa | 10:5c69b067d88a | 99 | |
masahikofukasawa | 10:5c69b067d88a | 100 | return AkmSensor::SUCCESS; |
masahikofukasawa | 10:5c69b067d88a | 101 | } |
masahikofukasawa | 10:5c69b067d88a | 102 | |
masahikofukasawa | 10:5c69b067d88a | 103 | AkmSensor::Status Ak9752Ctrl::readSensorData(Message* msg){ |
masahikofukasawa | 29:b488d2c89fba | 104 | AkmSensor::clearEvent(); |
masahikofukasawa | 10:5c69b067d88a | 105 | |
masahikofukasawa | 10:5c69b067d88a | 106 | AK9752::SensorData data; |
masahikofukasawa | 10:5c69b067d88a | 107 | AK9752::Status status = ak9752->getSensorData(&data); |
masahikofukasawa | 10:5c69b067d88a | 108 | if( status != AK9752::SUCCESS){ |
masahikofukasawa | 39:3821886c902e | 109 | MSG("#Error: getSensorData. AK9752.\r\n"); |
masahikofukasawa | 10:5c69b067d88a | 110 | return AkmSensor::ERROR; |
masahikofukasawa | 10:5c69b067d88a | 111 | } |
masahikofukasawa | 10:5c69b067d88a | 112 | msg->setCommand(Message::CMD_START_MEASUREMENT); |
masahikofukasawa | 10:5c69b067d88a | 113 | msg->setArgument( 0, data.intStatus.irh); |
masahikofukasawa | 10:5c69b067d88a | 114 | msg->setArgument( 1, data.intStatus.irl); |
masahikofukasawa | 10:5c69b067d88a | 115 | msg->setArgument( 2, data.intStatus.tmph); |
masahikofukasawa | 10:5c69b067d88a | 116 | msg->setArgument( 3, data.intStatus.tmpl); |
masahikofukasawa | 10:5c69b067d88a | 117 | msg->setArgument( 4, data.intStatus.dr); |
masahikofukasawa | 10:5c69b067d88a | 118 | msg->setArgument( 5,(char)((int32_t)(data.ir) >> 8)); |
masahikofukasawa | 10:5c69b067d88a | 119 | msg->setArgument( 6, (char)((int32_t)(data.ir) & 0x00FF) ); |
masahikofukasawa | 10:5c69b067d88a | 120 | msg->setArgument( 7,(char)((int32_t)(data.temperature) >> 8)); |
masahikofukasawa | 10:5c69b067d88a | 121 | msg->setArgument( 8, (char)((int32_t)(data.temperature) & 0x00FF) ); |
masahikofukasawa | 10:5c69b067d88a | 122 | msg->setArgument( 9, data.dor); |
masahikofukasawa | 10:5c69b067d88a | 123 | |
masahikofukasawa | 10:5c69b067d88a | 124 | return AkmSensor::SUCCESS; |
masahikofukasawa | 10:5c69b067d88a | 125 | } |
masahikofukasawa | 10:5c69b067d88a | 126 | |
masahikofukasawa | 10:5c69b067d88a | 127 | AkmSensor::Status Ak9752Ctrl::requestCommand(Message* in, Message* out){ |
masahikofukasawa | 10:5c69b067d88a | 128 | AkmSensor::Status status = AkmSensor::SUCCESS; |
masahikofukasawa | 10:5c69b067d88a | 129 | Message::Command cmd = in->getCommand(); |
masahikofukasawa | 10:5c69b067d88a | 130 | AK9752::Threshold th; |
masahikofukasawa | 29:b488d2c89fba | 131 | AK9752::InterruptStatus interruptStatus; |
masahikofukasawa | 10:5c69b067d88a | 132 | |
masahikofukasawa | 10:5c69b067d88a | 133 | out->setCommand(cmd); |
masahikofukasawa | 10:5c69b067d88a | 134 | |
masahikofukasawa | 10:5c69b067d88a | 135 | switch(cmd){ |
masahikofukasawa | 10:5c69b067d88a | 136 | case Message::CMD_IR_GET_THRESHOLD: |
masahikofukasawa | 10:5c69b067d88a | 137 | { |
masahikofukasawa | 10:5c69b067d88a | 138 | if (ak9752->getThreshold(&th) != AK9752::SUCCESS) { |
masahikofukasawa | 39:3821886c902e | 139 | MSG("#Error: Failed to set threshold to AK9752.\r\n"); |
masahikofukasawa | 15:1238993fd75f | 140 | return AkmSensor::ERROR; |
masahikofukasawa | 10:5c69b067d88a | 141 | } |
masahikofukasawa | 10:5c69b067d88a | 142 | out->setArgument(0,(char)((int32_t)(th.thirh) >> 8)); |
masahikofukasawa | 10:5c69b067d88a | 143 | out->setArgument(1,(char)((int32_t)(th.thirh) & 0x00FF)); |
masahikofukasawa | 10:5c69b067d88a | 144 | out->setArgument(2,(char)((int32_t)(th.thirl) >> 8)); |
masahikofukasawa | 10:5c69b067d88a | 145 | out->setArgument(3,(char)((int32_t)(th.thirl) & 0x00FF)); |
masahikofukasawa | 10:5c69b067d88a | 146 | out->setArgument(4,(char)((int32_t)(th.thtmph) >> 8)); |
masahikofukasawa | 10:5c69b067d88a | 147 | out->setArgument(5,(char)((int32_t)(th.thtmph) & 0x00FF)); |
masahikofukasawa | 10:5c69b067d88a | 148 | out->setArgument(6,(char)((int32_t)(th.thtmpl) >> 8)); |
masahikofukasawa | 10:5c69b067d88a | 149 | out->setArgument(7,(char)((int32_t)(th.thtmpl) & 0x00FF)); |
masahikofukasawa | 10:5c69b067d88a | 150 | break; |
masahikofukasawa | 10:5c69b067d88a | 151 | } |
masahikofukasawa | 10:5c69b067d88a | 152 | case Message::CMD_IR_SET_THRESHOLD: |
masahikofukasawa | 10:5c69b067d88a | 153 | { |
masahikofukasawa | 10:5c69b067d88a | 154 | th.thirh = CONV16I(in->getArgument(0), in->getArgument(1)); |
masahikofukasawa | 10:5c69b067d88a | 155 | th.thirl = CONV16I(in->getArgument(2), in->getArgument(3)); |
masahikofukasawa | 10:5c69b067d88a | 156 | th.thtmph = CONV16I(in->getArgument(4), in->getArgument(5)); |
masahikofukasawa | 10:5c69b067d88a | 157 | th.thtmpl = CONV16I(in->getArgument(6), in->getArgument(7)); |
masahikofukasawa | 10:5c69b067d88a | 158 | if (ak9752->setThreshold(&th) != AK9752::SUCCESS) { |
masahikofukasawa | 10:5c69b067d88a | 159 | status = AkmSensor::ERROR; |
masahikofukasawa | 39:3821886c902e | 160 | MSG("#Error: Failed to set threshold to AK9752.\r\n"); |
masahikofukasawa | 10:5c69b067d88a | 161 | } |
masahikofukasawa | 10:5c69b067d88a | 162 | out->setArgument(0,(char)status); |
masahikofukasawa | 10:5c69b067d88a | 163 | break; |
masahikofukasawa | 10:5c69b067d88a | 164 | } |
masahikofukasawa | 10:5c69b067d88a | 165 | case Message::CMD_IR_GET_INTERRUPT: |
masahikofukasawa | 10:5c69b067d88a | 166 | { |
masahikofukasawa | 29:b488d2c89fba | 167 | if (ak9752->getInterruptEnable(&interruptStatus) != AK9752::SUCCESS) { |
masahikofukasawa | 39:3821886c902e | 168 | MSG("#Error: Failed to set hysteresis to AK9752.\r\n"); |
masahikofukasawa | 15:1238993fd75f | 169 | return AkmSensor::ERROR; |
masahikofukasawa | 10:5c69b067d88a | 170 | } |
masahikofukasawa | 29:b488d2c89fba | 171 | out->setArgument(0, interruptStatus.irh); |
masahikofukasawa | 29:b488d2c89fba | 172 | out->setArgument(1, interruptStatus.irl); |
masahikofukasawa | 29:b488d2c89fba | 173 | out->setArgument(2, interruptStatus.tmph); |
masahikofukasawa | 29:b488d2c89fba | 174 | out->setArgument(3, interruptStatus.tmpl); |
masahikofukasawa | 29:b488d2c89fba | 175 | out->setArgument(4, interruptStatus.dr); |
masahikofukasawa | 10:5c69b067d88a | 176 | break; |
masahikofukasawa | 10:5c69b067d88a | 177 | } |
masahikofukasawa | 10:5c69b067d88a | 178 | case Message::CMD_IR_SET_INTERRUPT: |
masahikofukasawa | 10:5c69b067d88a | 179 | { |
masahikofukasawa | 29:b488d2c89fba | 180 | interruptStatus.irh = in->getArgument(0); |
masahikofukasawa | 29:b488d2c89fba | 181 | interruptStatus.irl = in->getArgument(1); |
masahikofukasawa | 29:b488d2c89fba | 182 | interruptStatus.tmph = in->getArgument(2); |
masahikofukasawa | 29:b488d2c89fba | 183 | interruptStatus.tmpl = in->getArgument(3); |
masahikofukasawa | 29:b488d2c89fba | 184 | interruptStatus.dr = in->getArgument(4); |
masahikofukasawa | 29:b488d2c89fba | 185 | if (ak9752->setInterruptEnable(&interruptStatus) != AK9752::SUCCESS) { |
masahikofukasawa | 10:5c69b067d88a | 186 | status = AkmSensor::ERROR; |
masahikofukasawa | 39:3821886c902e | 187 | MSG("#Error: Failed to set hysteresis to AK9752.\r\n"); |
masahikofukasawa | 10:5c69b067d88a | 188 | } |
masahikofukasawa | 10:5c69b067d88a | 189 | out->setArgument(0,(char)status); |
masahikofukasawa | 10:5c69b067d88a | 190 | break; |
masahikofukasawa | 10:5c69b067d88a | 191 | } |
masahikofukasawa | 10:5c69b067d88a | 192 | case Message::CMD_IR_GET_OPERATION_MODE: |
masahikofukasawa | 10:5c69b067d88a | 193 | { |
masahikofukasawa | 10:5c69b067d88a | 194 | if(ak9752->getOperationMode(&mode, &fc_tmp, &fc_ir) != AK9752::SUCCESS) { |
masahikofukasawa | 39:3821886c902e | 195 | MSG("#Error: getOperationMode. AK9752.\r\n"); |
masahikofukasawa | 15:1238993fd75f | 196 | return AkmSensor::ERROR; |
masahikofukasawa | 10:5c69b067d88a | 197 | } |
masahikofukasawa | 10:5c69b067d88a | 198 | out->setArgument(0,(char)mode); |
masahikofukasawa | 10:5c69b067d88a | 199 | out->setArgument(1,(char)fc_tmp); |
masahikofukasawa | 10:5c69b067d88a | 200 | out->setArgument(2,(char)fc_ir); |
masahikofukasawa | 10:5c69b067d88a | 201 | break; |
masahikofukasawa | 10:5c69b067d88a | 202 | } |
masahikofukasawa | 10:5c69b067d88a | 203 | case Message::CMD_IR_SET_OPERATION_MODE: |
masahikofukasawa | 10:5c69b067d88a | 204 | { |
masahikofukasawa | 10:5c69b067d88a | 205 | mode = (AK9752::OperationMode)in->getArgument(0); |
masahikofukasawa | 10:5c69b067d88a | 206 | fc_tmp = (AK9752::FcTmp)in->getArgument(1); |
masahikofukasawa | 10:5c69b067d88a | 207 | fc_ir = (AK9752::FcIr)in->getArgument(2); |
masahikofukasawa | 10:5c69b067d88a | 208 | if(ak9752->setOperationMode(mode, fc_tmp, fc_ir) != AK9752::SUCCESS) { |
masahikofukasawa | 10:5c69b067d88a | 209 | status = AkmSensor::ERROR; |
masahikofukasawa | 39:3821886c902e | 210 | MSG("#Error: setOperationMode. AK9752.\r\n"); |
masahikofukasawa | 10:5c69b067d88a | 211 | } |
masahikofukasawa | 10:5c69b067d88a | 212 | out->setArgument(0,(char)status); |
masahikofukasawa | 10:5c69b067d88a | 213 | break; |
masahikofukasawa | 10:5c69b067d88a | 214 | } |
masahikofukasawa | 10:5c69b067d88a | 215 | case Message::CMD_REG_WRITE: |
masahikofukasawa | 10:5c69b067d88a | 216 | case Message::CMD_REG_WRITEN: |
masahikofukasawa | 10:5c69b067d88a | 217 | { |
masahikofukasawa | 10:5c69b067d88a | 218 | char address = in->getArgument(0); |
masahikofukasawa | 10:5c69b067d88a | 219 | int len = (int)in->getArgument(1); |
masahikofukasawa | 15:1238993fd75f | 220 | if(in->getArgNum() != len+2){ |
masahikofukasawa | 39:3821886c902e | 221 | MSG("#Error: argument num. Args=%d\r\n",in->getArgNum()); |
masahikofukasawa | 15:1238993fd75f | 222 | status = AkmSensor::ERROR; |
masahikofukasawa | 15:1238993fd75f | 223 | out->setArgument(0,(char)status); |
masahikofukasawa | 15:1238993fd75f | 224 | return status; |
masahikofukasawa | 15:1238993fd75f | 225 | } |
masahikofukasawa | 15:1238993fd75f | 226 | |
masahikofukasawa | 10:5c69b067d88a | 227 | char data[len]; |
masahikofukasawa | 10:5c69b067d88a | 228 | for(int i=0; i<len; i++){ |
masahikofukasawa | 15:1238993fd75f | 229 | data[i] = in->getArgument(i+2); |
masahikofukasawa | 10:5c69b067d88a | 230 | } |
masahikofukasawa | 10:5c69b067d88a | 231 | if( ak9752->write(address, data, len) != AK9752::SUCCESS) { |
masahikofukasawa | 10:5c69b067d88a | 232 | status = AkmSensor::ERROR; |
masahikofukasawa | 39:3821886c902e | 233 | MSG("#Error: register write.\r\n"); |
masahikofukasawa | 10:5c69b067d88a | 234 | } |
masahikofukasawa | 10:5c69b067d88a | 235 | out->setArgument(0,(char)status); |
masahikofukasawa | 10:5c69b067d88a | 236 | break; |
masahikofukasawa | 10:5c69b067d88a | 237 | } |
masahikofukasawa | 10:5c69b067d88a | 238 | case Message::CMD_REG_READ: |
masahikofukasawa | 10:5c69b067d88a | 239 | case Message::CMD_REG_READN: |
masahikofukasawa | 10:5c69b067d88a | 240 | { |
masahikofukasawa | 15:1238993fd75f | 241 | if(in->getArgNum() != 2){ |
masahikofukasawa | 39:3821886c902e | 242 | MSG("#Error: argument num. Args=%d\r\n",in->getArgNum()); |
masahikofukasawa | 15:1238993fd75f | 243 | return AkmSensor::ERROR; |
masahikofukasawa | 15:1238993fd75f | 244 | } |
masahikofukasawa | 15:1238993fd75f | 245 | |
masahikofukasawa | 10:5c69b067d88a | 246 | char address = in->getArgument(0); |
masahikofukasawa | 10:5c69b067d88a | 247 | int len = (int)in->getArgument(1); |
masahikofukasawa | 10:5c69b067d88a | 248 | char data[len]; |
masahikofukasawa | 10:5c69b067d88a | 249 | if( ak9752->read(address, data, len) != AK9752::SUCCESS) { |
masahikofukasawa | 39:3821886c902e | 250 | MSG("#Error: register read.\r\n"); |
masahikofukasawa | 15:1238993fd75f | 251 | return AkmSensor::ERROR; |
masahikofukasawa | 10:5c69b067d88a | 252 | } |
masahikofukasawa | 10:5c69b067d88a | 253 | for(int i=0; i<len; i++){ |
masahikofukasawa | 10:5c69b067d88a | 254 | out->setArgument(i, data[i]); |
masahikofukasawa | 10:5c69b067d88a | 255 | } |
masahikofukasawa | 10:5c69b067d88a | 256 | break; |
masahikofukasawa | 10:5c69b067d88a | 257 | } |
masahikofukasawa | 10:5c69b067d88a | 258 | default: |
masahikofukasawa | 10:5c69b067d88a | 259 | { |
masahikofukasawa | 39:3821886c902e | 260 | MSG("#Error: No command.\r\n"); |
masahikofukasawa | 10:5c69b067d88a | 261 | status = AkmSensor::ERROR; |
masahikofukasawa | 10:5c69b067d88a | 262 | break; |
masahikofukasawa | 10:5c69b067d88a | 263 | } |
masahikofukasawa | 10:5c69b067d88a | 264 | } |
masahikofukasawa | 10:5c69b067d88a | 265 | return status; |
masahikofukasawa | 10:5c69b067d88a | 266 | } |