51 52 with same code
Dependencies: MtSense07
Fork of MtConnect04S_MtSense07 by
main.cpp@1:40c18f027e6c, 2017-02-03 (annotated)
- Committer:
- bcc6
- Date:
- Fri Feb 03 06:51:09 2017 +0000
- Revision:
- 1:40c18f027e6c
- Parent:
- 0:418880413158
- Child:
- 2:87f1b98c0d09
Add configuration for running mode, and baudrate 115200.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcc6 | 0:418880413158 | 1 | /* Copyright (c) 2016 MtM Technology Corporation, MIT License |
bcc6 | 0:418880413158 | 2 | * |
bcc6 | 0:418880413158 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
bcc6 | 0:418880413158 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
bcc6 | 0:418880413158 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
bcc6 | 0:418880413158 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
bcc6 | 0:418880413158 | 7 | * furnished to do so, subject to the following conditions: |
bcc6 | 0:418880413158 | 8 | * |
bcc6 | 0:418880413158 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
bcc6 | 0:418880413158 | 10 | * substantial portions of the Software. |
bcc6 | 0:418880413158 | 11 | * |
bcc6 | 0:418880413158 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
bcc6 | 0:418880413158 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
bcc6 | 0:418880413158 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
bcc6 | 0:418880413158 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
bcc6 | 0:418880413158 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
bcc6 | 0:418880413158 | 17 | */ |
bcc6 | 0:418880413158 | 18 | #include "mbed.h" |
bcc6 | 0:418880413158 | 19 | #include "AK9750.h" |
bcc6 | 0:418880413158 | 20 | #include "AK09912.h" |
bcc6 | 0:418880413158 | 21 | #include "AK09970.h" |
bcc6 | 1:40c18f027e6c | 22 | #include "config.h" |
bcc6 | 1:40c18f027e6c | 23 | |
bcc6 | 0:418880413158 | 24 | Serial pc(p15, p16); |
bcc6 | 0:418880413158 | 25 | |
bcc6 | 0:418880413158 | 26 | DigitalOut reset_sensor(p4, 1); // Reset pin for AK09970 (Low active) |
bcc6 | 0:418880413158 | 27 | I2C i2c(p3, p2); |
bcc6 | 0:418880413158 | 28 | AK9750 ak9750(i2c); |
bcc6 | 0:418880413158 | 29 | AK09912 ak09912(i2c); |
bcc6 | 0:418880413158 | 30 | AK09970 ak09970(i2c); |
bcc6 | 0:418880413158 | 31 | |
bcc6 | 0:418880413158 | 32 | int main() { |
bcc6 | 0:418880413158 | 33 | /* Disable the hardware flow control of Serial, then show the mbed version */ |
bcc6 | 1:40c18f027e6c | 34 | pc.set_flow_control(SerialBase::Disabled); |
bcc6 | 1:40c18f027e6c | 35 | pc.baud(CONFIG_BAUDRATE); |
bcc6 | 0:418880413158 | 36 | pc.printf("\n"); |
bcc6 | 0:418880413158 | 37 | pc.printf("mbed version(%d.%d.%d)\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); |
bcc6 | 0:418880413158 | 38 | pc.printf("\n"); |
bcc6 | 0:418880413158 | 39 | |
bcc6 | 0:418880413158 | 40 | /* Reset sensor */ |
bcc6 | 0:418880413158 | 41 | reset_sensor = 1; |
bcc6 | 0:418880413158 | 42 | wait_ms(10); |
bcc6 | 0:418880413158 | 43 | reset_sensor = 0; |
bcc6 | 0:418880413158 | 44 | wait_ms(10); |
bcc6 | 0:418880413158 | 45 | reset_sensor = 1; |
bcc6 | 0:418880413158 | 46 | wait_ms(10); |
bcc6 | 0:418880413158 | 47 | |
bcc6 | 0:418880413158 | 48 | /* Config device and check device ID */ |
bcc6 | 0:418880413158 | 49 | uint8_t id; |
bcc6 | 0:418880413158 | 50 | |
bcc6 | 0:418880413158 | 51 | ak9750.ConfigDevice(); |
bcc6 | 0:418880413158 | 52 | ak9750.GetDeviceID(&id); |
bcc6 | 0:418880413158 | 53 | pc.printf("AK9750_DEVICE_ID(0x%02X)\n", id); |
bcc6 | 0:418880413158 | 54 | if(id != ak9750.DEVICE_ID){ |
bcc6 | 0:418880413158 | 55 | pc.printf("Read Device ID fail !\n"); |
bcc6 | 0:418880413158 | 56 | while(1); |
bcc6 | 0:418880413158 | 57 | } |
bcc6 | 0:418880413158 | 58 | |
bcc6 | 0:418880413158 | 59 | ak09912.ConfigDevice(); |
bcc6 | 0:418880413158 | 60 | ak09912.GetDeviceID(&id); |
bcc6 | 0:418880413158 | 61 | pc.printf("AK09912_DEVICE_ID(0x%02X)\n", id); |
bcc6 | 0:418880413158 | 62 | if(id != ak09912.DEVICE_ID){ |
bcc6 | 0:418880413158 | 63 | pc.printf("Read Device ID fail !\n"); |
bcc6 | 0:418880413158 | 64 | while(1); |
bcc6 | 0:418880413158 | 65 | } |
bcc6 | 0:418880413158 | 66 | |
bcc6 | 0:418880413158 | 67 | ak09970.ConfigDevice(); |
bcc6 | 0:418880413158 | 68 | ak09970.GetDeviceID(&id); |
bcc6 | 0:418880413158 | 69 | pc.printf("AK09970_DEVICE_ID(0x%02X)\n", id); |
bcc6 | 0:418880413158 | 70 | if(id != ak09970.DEVICE_ID){ |
bcc6 | 0:418880413158 | 71 | pc.printf("Read Device ID fail !\n"); |
bcc6 | 0:418880413158 | 72 | while(1); |
bcc6 | 0:418880413158 | 73 | } |
bcc6 | 0:418880413158 | 74 | |
bcc6 | 0:418880413158 | 75 | /* Main loop */ |
bcc6 | 1:40c18f027e6c | 76 | #if (CONFIG_RUN_MODE == RUN_ALL_SENSOR_COM) |
bcc6 | 0:418880413158 | 77 | AK9750::Data ak9750_data; |
bcc6 | 0:418880413158 | 78 | AK09912::Data ak09912_data; |
bcc6 | 0:418880413158 | 79 | AK09970::Data ak09970_data; |
bcc6 | 0:418880413158 | 80 | int32_t triggered_area; |
bcc6 | 0:418880413158 | 81 | while (1) { |
bcc6 | 0:418880413158 | 82 | ak9750.GetData(&ak9750_data); |
bcc6 | 0:418880413158 | 83 | triggered_area = ak9750.GetTriggeredAreaNum(&ak9750_data); |
bcc6 | 0:418880413158 | 84 | pc.printf("AK9750(%5.1fpA, %5.1fpA, %5.1fpA, %5.1fpA, %2.1f'C, Area%d)\n", |
bcc6 | 0:418880413158 | 85 | ak9750_data.ir1, ak9750_data.ir2, ak9750_data.ir3, ak9750_data.ir4, ak9750_data.tmp, triggered_area); |
bcc6 | 0:418880413158 | 86 | |
bcc6 | 0:418880413158 | 87 | ak09912.GetData(&ak09912_data); |
bcc6 | 0:418880413158 | 88 | pc.printf("AK09912(%5.1fuT/LSB, %5.1fuT/LSB, %5.1fuT/LSB, %2.1f'C)\n", |
bcc6 | 0:418880413158 | 89 | ak09912_data.x, ak09912_data.y, ak09912_data.z, ak09912_data.t); |
bcc6 | 0:418880413158 | 90 | |
bcc6 | 0:418880413158 | 91 | ak09970.GetData(&ak09970_data); |
bcc6 | 0:418880413158 | 92 | pc.printf("AK09970(%6.1fuT/LSB, %6.1fuT/LSB, %6.1fuT/LSB)\n", |
bcc6 | 0:418880413158 | 93 | ak09970_data.x, ak09970_data.y, ak09970_data.z); |
bcc6 | 0:418880413158 | 94 | |
bcc6 | 0:418880413158 | 95 | pc.printf("\n"); |
bcc6 | 0:418880413158 | 96 | wait(1); |
bcc6 | 0:418880413158 | 97 | } |
bcc6 | 1:40c18f027e6c | 98 | #elif (CONFIG_RUN_MODE == RUN_IR_AK9750_APP) |
bcc6 | 1:40c18f027e6c | 99 | AK9750::Data ak9750_data; |
bcc6 | 1:40c18f027e6c | 100 | int32_t count = 0; |
bcc6 | 1:40c18f027e6c | 101 | while (1) { |
bcc6 | 1:40c18f027e6c | 102 | ak9750.GetData(&ak9750_data); |
bcc6 | 1:40c18f027e6c | 103 | pc.printf(" 3:%d,%d,%d,%d,%d,\r", count, (int32_t)ak9750_data.ir1, (int32_t)ak9750_data.ir2, (int32_t)ak9750_data.ir3, (int32_t)ak9750_data.ir4); |
bcc6 | 1:40c18f027e6c | 104 | count++; |
bcc6 | 1:40c18f027e6c | 105 | wait(1); |
bcc6 | 1:40c18f027e6c | 106 | } |
bcc6 | 1:40c18f027e6c | 107 | #elif (CONFIG_RUN_MODE == RUN_COMPASS_AK09912_APP) |
bcc6 | 1:40c18f027e6c | 108 | AK09912::Data ak09912_data; |
bcc6 | 1:40c18f027e6c | 109 | int32_t count = 0; |
bcc6 | 1:40c18f027e6c | 110 | while (1) { |
bcc6 | 1:40c18f027e6c | 111 | ak09912.GetData(&ak09912_data); |
bcc6 | 1:40c18f027e6c | 112 | pc.printf("C:%d,%d,%d,%d\r", count, (int32_t)ak09912_data.x, (int32_t)ak09912_data.y, (int32_t)ak09912_data.z); |
bcc6 | 1:40c18f027e6c | 113 | count++; |
bcc6 | 1:40c18f027e6c | 114 | wait(1); |
bcc6 | 1:40c18f027e6c | 115 | } |
bcc6 | 1:40c18f027e6c | 116 | #elif (CONFIG_RUN_MODE == RUN_MAGNETIC_AK09970_APP) |
bcc6 | 1:40c18f027e6c | 117 | AK09970::Data ak09970_data; |
bcc6 | 1:40c18f027e6c | 118 | int32_t count = 0; |
bcc6 | 1:40c18f027e6c | 119 | while (1) { |
bcc6 | 1:40c18f027e6c | 120 | ak09970.GetData(&ak09970_data); |
bcc6 | 1:40c18f027e6c | 121 | pc.printf("C:%d,%d,%d,%d\r", count, (int32_t)ak09970_data.x, (int32_t)ak09970_data.y, (int32_t)ak09970_data.z); |
bcc6 | 1:40c18f027e6c | 122 | count++; |
bcc6 | 1:40c18f027e6c | 123 | wait(1); |
bcc6 | 1:40c18f027e6c | 124 | } |
bcc6 | 1:40c18f027e6c | 125 | #else |
bcc6 | 1:40c18f027e6c | 126 | #errror "Config run mode ...FAIL" |
bcc6 | 1:40c18f027e6c | 127 | #endif |
bcc6 | 0:418880413158 | 128 | } |