Simple sample that demonstrates reading the FXOS8700CQ accelerometer, convert the data to JSON and send to an Azure IoT Hub.
Dependencies: azure_umqtt_c iothub_mqtt_transport mbed-rtos mbed wolfSSL Socket lwip-eth lwip-sys lwip
SingletonFXOS8700CQ.h@0:6c46c366f500, 2016-10-14 (annotated)
- Committer:
- markrad
- Date:
- Fri Oct 14 21:16:25 2016 +0000
- Revision:
- 0:6c46c366f500
Original commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
markrad | 0:6c46c366f500 | 1 | // Copyright (c) Microsoft. All rights reserved. |
markrad | 0:6c46c366f500 | 2 | // Licensed under the MIT license. See LICENSE file at https://github.com/Azure/azure-iot-sdks/blob/master/LICENSE for full license information. |
markrad | 0:6c46c366f500 | 3 | |
markrad | 0:6c46c366f500 | 4 | #include "mbed.h" |
markrad | 0:6c46c366f500 | 5 | #include "FXOS8700CQ.h" |
markrad | 0:6c46c366f500 | 6 | |
markrad | 0:6c46c366f500 | 7 | typedef struct |
markrad | 0:6c46c366f500 | 8 | { |
markrad | 0:6c46c366f500 | 9 | int16_t x; |
markrad | 0:6c46c366f500 | 10 | int16_t y; |
markrad | 0:6c46c366f500 | 11 | int16_t z; |
markrad | 0:6c46c366f500 | 12 | } AXES; |
markrad | 0:6c46c366f500 | 13 | |
markrad | 0:6c46c366f500 | 14 | typedef struct |
markrad | 0:6c46c366f500 | 15 | { |
markrad | 0:6c46c366f500 | 16 | AXES accelerometer; |
markrad | 0:6c46c366f500 | 17 | AXES magnometer; |
markrad | 0:6c46c366f500 | 18 | } READING; |
markrad | 0:6c46c366f500 | 19 | |
markrad | 0:6c46c366f500 | 20 | class SingletonFXOS8700CQ |
markrad | 0:6c46c366f500 | 21 | { |
markrad | 0:6c46c366f500 | 22 | private: |
markrad | 0:6c46c366f500 | 23 | |
markrad | 0:6c46c366f500 | 24 | SingletonFXOS8700CQ(PinName sda = PTE25, PinName scl = PTE24, int addr = FXOS8700CQ_SLAVE_ADDR1); |
markrad | 0:6c46c366f500 | 25 | SingletonFXOS8700CQ(const SingletonFXOS8700CQ &); |
markrad | 0:6c46c366f500 | 26 | SingletonFXOS8700CQ& operator=(const SingletonFXOS8700CQ&); |
markrad | 0:6c46c366f500 | 27 | |
markrad | 0:6c46c366f500 | 28 | FXOS8700CQ fxos; |
markrad | 0:6c46c366f500 | 29 | InterruptIn fxos_int1; // unused, common with SW2 on FRDM-K64F |
markrad | 0:6c46c366f500 | 30 | InterruptIn fxos_int2; // should just be the Data-Ready interrupt |
markrad | 0:6c46c366f500 | 31 | bool fxos_int1_triggered; |
markrad | 0:6c46c366f500 | 32 | bool fxos_int2_triggered; |
markrad | 0:6c46c366f500 | 33 | |
markrad | 0:6c46c366f500 | 34 | static void trigger_fxos_int1(void) |
markrad | 0:6c46c366f500 | 35 | { |
markrad | 0:6c46c366f500 | 36 | SingletonFXOS8700CQ::getInstance().setInt1Triggered(true); |
markrad | 0:6c46c366f500 | 37 | } |
markrad | 0:6c46c366f500 | 38 | |
markrad | 0:6c46c366f500 | 39 | static void trigger_fxos_int2(void) |
markrad | 0:6c46c366f500 | 40 | { |
markrad | 0:6c46c366f500 | 41 | SingletonFXOS8700CQ::getInstance().setInt2Triggered(true); |
markrad | 0:6c46c366f500 | 42 | //us_ellapsed = t.read_us(); |
markrad | 0:6c46c366f500 | 43 | } |
markrad | 0:6c46c366f500 | 44 | |
markrad | 0:6c46c366f500 | 45 | public: |
markrad | 0:6c46c366f500 | 46 | |
markrad | 0:6c46c366f500 | 47 | static SingletonFXOS8700CQ& getInstance() |
markrad | 0:6c46c366f500 | 48 | { |
markrad | 0:6c46c366f500 | 49 | static SingletonFXOS8700CQ instance; |
markrad | 0:6c46c366f500 | 50 | |
markrad | 0:6c46c366f500 | 51 | return instance; |
markrad | 0:6c46c366f500 | 52 | } |
markrad | 0:6c46c366f500 | 53 | |
markrad | 0:6c46c366f500 | 54 | void enable() { fxos.enable(); } |
markrad | 0:6c46c366f500 | 55 | void disable() { fxos.disable(); } |
markrad | 0:6c46c366f500 | 56 | |
markrad | 0:6c46c366f500 | 57 | uint8_t getData(READING&); |
markrad | 0:6c46c366f500 | 58 | |
markrad | 0:6c46c366f500 | 59 | bool getInt1Triggered() { return fxos_int1_triggered; } |
markrad | 0:6c46c366f500 | 60 | void setInt1Triggered(bool value) { fxos_int1_triggered = value; } |
markrad | 0:6c46c366f500 | 61 | bool getInt2Triggered() { return fxos_int2_triggered; } |
markrad | 0:6c46c366f500 | 62 | void setInt2Triggered(bool value) { fxos_int2_triggered = value; } |
markrad | 0:6c46c366f500 | 63 | uint8_t getWhoAmI() { return fxos.get_whoami(); } |
markrad | 0:6c46c366f500 | 64 | uint8_t getStatus() { return fxos.status(); } |
markrad | 0:6c46c366f500 | 65 | }; |