51 52 with same code
Dependencies: MtSense07
Fork of MtConnect04S_MtSense07 by
Diff: main.cpp
- Revision:
- 0:418880413158
- Child:
- 1:40c18f027e6c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jan 26 03:54:58 2017 +0000 @@ -0,0 +1,96 @@ +/* Copyright (c) 2016 MtM Technology Corporation, MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include "mbed.h" +#include "AK9750.h" +#include "AK09912.h" +#include "AK09970.h" + +Serial pc(p15, p16); + +DigitalOut reset_sensor(p4, 1); // Reset pin for AK09970 (Low active) +I2C i2c(p3, p2); +AK9750 ak9750(i2c); +AK09912 ak09912(i2c); +AK09970 ak09970(i2c); + +int main() { + /* Disable the hardware flow control of Serial, then show the mbed version */ + pc.set_flow_control(SerialBase::Disabled); + pc.printf("\n"); + pc.printf("mbed version(%d.%d.%d)\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); + pc.printf("\n"); + + /* Reset sensor */ + reset_sensor = 1; + wait_ms(10); + reset_sensor = 0; + wait_ms(10); + reset_sensor = 1; + wait_ms(10); + + /* Config device and check device ID */ + uint8_t id; + + ak9750.ConfigDevice(); + ak9750.GetDeviceID(&id); + pc.printf("AK9750_DEVICE_ID(0x%02X)\n", id); + if(id != ak9750.DEVICE_ID){ + pc.printf("Read Device ID fail !\n"); + while(1); + } + + ak09912.ConfigDevice(); + ak09912.GetDeviceID(&id); + pc.printf("AK09912_DEVICE_ID(0x%02X)\n", id); + if(id != ak09912.DEVICE_ID){ + pc.printf("Read Device ID fail !\n"); + while(1); + } + + ak09970.ConfigDevice(); + ak09970.GetDeviceID(&id); + pc.printf("AK09970_DEVICE_ID(0x%02X)\n", id); + if(id != ak09970.DEVICE_ID){ + pc.printf("Read Device ID fail !\n"); + while(1); + } + + /* Main loop */ + AK9750::Data ak9750_data; + AK09912::Data ak09912_data; + AK09970::Data ak09970_data; + int32_t triggered_area; + + while (1) { + ak9750.GetData(&ak9750_data); + triggered_area = ak9750.GetTriggeredAreaNum(&ak9750_data); + pc.printf("AK9750(%5.1fpA, %5.1fpA, %5.1fpA, %5.1fpA, %2.1f'C, Area%d)\n", + ak9750_data.ir1, ak9750_data.ir2, ak9750_data.ir3, ak9750_data.ir4, ak9750_data.tmp, triggered_area); + + ak09912.GetData(&ak09912_data); + pc.printf("AK09912(%5.1fuT/LSB, %5.1fuT/LSB, %5.1fuT/LSB, %2.1f'C)\n", + ak09912_data.x, ak09912_data.y, ak09912_data.z, ak09912_data.t); + + ak09970.GetData(&ak09970_data); + pc.printf("AK09970(%6.1fuT/LSB, %6.1fuT/LSB, %6.1fuT/LSB)\n", + ak09970_data.x, ak09970_data.y, ak09970_data.z); + + pc.printf("\n"); + wait(1); + } +}