Rev 1.0 4/26/2016 Paul Jaeger - Multitech, Brian Huey - Sprint Changed post interval to 2000ms added temp, analoguv and pressure to http post added alias: TEMP ANALOG-UV PRESSURE concatenated http post, to post all within the same routine and check for error after the post confirmed that data is published to Exosite

Dependencies:   MbedJSONValue mbed mtsas

Fork of UUU_MultiTech_Dragonfly_Sprint by Paul Jaeger

Committer:
mfiore
Date:
Sat Sep 26 22:07:27 2015 +0000
Revision:
5:a946ef74a8c4
Parent:
4:730b61258422
Child:
6:7946b5c2376a
finish http post to AT&T M2X - must configure M2X account properly!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mfiore 0:a44e71488e1f 1 /*************************************************************************
mfiore 0:a44e71488e1f 2 * Dragonfly Example program for 2015 AT&T Government Solutions Hackathon
mfiore 0:a44e71488e1f 3 *
mfiore 0:a44e71488e1f 4 * The following hardware is required to successfully run this program:
mfiore 0:a44e71488e1f 5 * - MultiTech UDK2 (4" square white PCB with Arduino headers, antenna
mfiore 0:a44e71488e1f 6 * connector, micro USB ports, and 40-pin connector for Dragonfly)
mfiore 0:a44e71488e1f 7 * - MultiTech Dragonfly (1"x2" green PCB with Telit radio)
mfiore 0:a44e71488e1f 8 * - Seeed Studio Base Shield
mfiore 0:a44e71488e1f 9 * - Grove moisture sensor (to connect to Base Shield)
mfiore 0:a44e71488e1f 10 * - Grove button (to connect to Base Shield)
mfiore 0:a44e71488e1f 11 * - MEMs Inertial and Environmental Nucleo Expansion board (LSM6DS0
mfiore 0:a44e71488e1f 12 * 3-axis accelerometer + 3-axis gyroscope, LIS3MDL 3-axis
mfiore 0:a44e71488e1f 13 * magnetometer, HTS221 humidity and temperature sensor and LPS25HB
mfiore 0:a44e71488e1f 14 * pressure sensor)
mfiore 0:a44e71488e1f 15 *
mfiore 0:a44e71488e1f 16 * What this program does:
mfiore 0:a44e71488e1f 17 * - reads data from all sensors on MEMs board and moisture sensor on a
mfiore 0:a44e71488e1f 18 * periodic basis
mfiore 0:a44e71488e1f 19 * - prints all sensor data to debug port on a periodic basis
mfiore 0:a44e71488e1f 20 * - optionally send a SMS containing sensor data when the Grove Button
mfiore 5:a946ef74a8c4 21 * is pushed
mfiore 5:a946ef74a8c4 22 * - you need to set the "phone_number" field
mfiore 4:730b61258422 23 * - optionally sends sensor data to AT&T M2X cloud platform (user must
mfiore 4:730b61258422 24 * create own M2X account and configure a device)
mfiore 5:a946ef74a8c4 25 * - you need to set the "m2x_api_key" field and the "m2x_device_id"
mfiore 5:a946ef74a8c4 26 * field based on your M2X account for this to work
mfiore 5:a946ef74a8c4 27 * - you need to set the "do_cloud_post" flag to true for this to
mfiore 5:a946ef74a8c4 28 * work
mfiore 0:a44e71488e1f 29 *
mfiore 0:a44e71488e1f 30 * Setup:
mfiore 0:a44e71488e1f 31 * - Correctly insert SIM card into Dragonfly
mfiore 0:a44e71488e1f 32 * - Seat the Dragonfly on the UDK2 board
mfiore 0:a44e71488e1f 33 * - Connect an antenna to the connector on the Dragonfly labled "M"
mfiore 0:a44e71488e1f 34 * - Stack the Base Shield on the UDK2 Arduino headers
mfiore 0:a44e71488e1f 35 * - Connect the Grove button to the D8 socket on the Base Shield
mfiore 0:a44e71488e1f 36 * - Connect the Grove moisture sensor to the A0 socket on the Base
mfiore 0:a44e71488e1f 37 * Shield
mfiore 3:f6bceb9e5e1a 38 * - Make sure the reference voltage selector switch (next to the A0
mfiore 3:f6bceb9e5e1a 39 * socket) is switched to 5V so you get accurate analog readings
mfiore 0:a44e71488e1f 40 * - Stack the MEMs board on top of the Base Shield
mfiore 0:a44e71488e1f 41 * - Plug in the power cable
mfiore 0:a44e71488e1f 42 * - Plug a micro USB cable into the port below and slightly to the
mfiore 0:a44e71488e1f 43 * left of the Dragonfly (NOT the port on the Dragonfly)
mfiore 0:a44e71488e1f 44 *
mfiore 0:a44e71488e1f 45 * Go have fun and make something cool!
mfiore 0:a44e71488e1f 46 *
mfiore 0:a44e71488e1f 47 ************************************************************************/
mfiore 0:a44e71488e1f 48
mfiore 0:a44e71488e1f 49 #include "mbed.h"
mfiore 0:a44e71488e1f 50 #include "mtsas.h"
mfiore 0:a44e71488e1f 51 #include "x_nucleo_iks01a1.h"
mfiore 0:a44e71488e1f 52 #include "MbedJSONValue.h"
mfiore 5:a946ef74a8c4 53 #include "HTTPJson.h"
mfiore 0:a44e71488e1f 54 #include <string>
mfiore 0:a44e71488e1f 55
mfiore 0:a44e71488e1f 56 // Debug serial port
mfiore 0:a44e71488e1f 57 static Serial debug(USBTX, USBRX);
mfiore 0:a44e71488e1f 58
mfiore 0:a44e71488e1f 59 // MTSSerialFlowControl - serial link between processor and radio
mfiore 1:a049d113e250 60 static MTSSerialFlowControl* io;
mfiore 0:a44e71488e1f 61
mfiore 0:a44e71488e1f 62 // Cellular - radio object for cellular operations (SMS, TCP, etc)
mfiore 0:a44e71488e1f 63 Cellular* radio;
mfiore 0:a44e71488e1f 64
mfiore 0:a44e71488e1f 65 // APN associated with SIM card
mfiore 4:730b61258422 66 // this APN should work for the AT&T SIM that came with your Dragonfly
mfiore 4:730b61258422 67 //static const std::string apn = "";
mfiore 4:730b61258422 68 static const std::string apn = "broadband";
mfiore 0:a44e71488e1f 69
mfiore 0:a44e71488e1f 70 // Phone number to send SMS messages to
mfiore 5:a946ef74a8c4 71 // just change the x digits - the 1 needs to stay!
mfiore 2:955a63247721 72 static const std::string phone_number = "1xxxxxxxxxx";
mfiore 0:a44e71488e1f 73
mfiore 5:a946ef74a8c4 74 // see https://m2x.att.com/developer/documentation/v2/overview for M2X API documentation
mfiore 5:a946ef74a8c4 75 // M2X device ID
mfiore 4:730b61258422 76 static const std::string m2x_device_id = "";
mfiore 5:a946ef74a8c4 77
mfiore 5:a946ef74a8c4 78 // M2X primary API key
mfiore 5:a946ef74a8c4 79 static const std::string m2x_api_key = "";
mfiore 5:a946ef74a8c4 80
mfiore 5:a946ef74a8c4 81 // set to true if you want to post to the cloud
mfiore 5:a946ef74a8c4 82 // you need to have you M2X account set up properly for this to work?
mfiore 5:a946ef74a8c4 83 //bool do_cloud_post = false;
mfiore 5:a946ef74a8c4 84 bool do_cloud_post = true;
mfiore 5:a946ef74a8c4 85
mfiore 5:a946ef74a8c4 86 std::string url = "http://api-m2x.att.com/v2/devices/" + m2x_device_id + "/update";
mfiore 4:730b61258422 87
mfiore 0:a44e71488e1f 88 // handle to MEMs board object
mfiore 0:a44e71488e1f 89 static X_NUCLEO_IKS01A1* mems = X_NUCLEO_IKS01A1::Instance();
mfiore 0:a44e71488e1f 90
mfiore 0:a44e71488e1f 91 // Moisture sensor
mfiore 0:a44e71488e1f 92 AnalogIn moisture_sensor(A0);
mfiore 0:a44e71488e1f 93
mfiore 0:a44e71488e1f 94 // Button
mfiore 2:955a63247721 95 InterruptIn button(D8);
mfiore 1:a049d113e250 96 bool button_pressed = false;
mfiore 0:a44e71488e1f 97
mfiore 0:a44e71488e1f 98 // variables for sensor data
mfiore 0:a44e71488e1f 99 float temp_celsius;
mfiore 0:a44e71488e1f 100 float temp_fahrenheit;
mfiore 0:a44e71488e1f 101 float humidity_percent;
mfiore 0:a44e71488e1f 102 float pressure_mbar;
mfiore 0:a44e71488e1f 103 float moisture_percent;
mfiore 0:a44e71488e1f 104 int32_t mag_mgauss[3];
mfiore 0:a44e71488e1f 105 int32_t acc_mg[3];
mfiore 0:a44e71488e1f 106 int32_t gyro_mdps[3];
mfiore 0:a44e71488e1f 107
mfiore 0:a44e71488e1f 108 // misc variables
mfiore 0:a44e71488e1f 109 static char wall_of_dash[] = "--------------------------------------------------";
mfiore 0:a44e71488e1f 110 bool radio_ok = false;
mfiore 3:f6bceb9e5e1a 111 static int thpm_interval_ms = 2000;
mfiore 0:a44e71488e1f 112 static int motion_interval_ms = 250;
mfiore 5:a946ef74a8c4 113 static int print_interval_ms = 10000;
mfiore 5:a946ef74a8c4 114 static int post_interval_ms = 30000;
mfiore 0:a44e71488e1f 115 int debug_baud = 115200;
mfiore 0:a44e71488e1f 116
mfiore 0:a44e71488e1f 117 // function prototypes
mfiore 0:a44e71488e1f 118 bool init_mtsas();
mfiore 0:a44e71488e1f 119 void read_temperature();
mfiore 0:a44e71488e1f 120 void read_humidity();
mfiore 0:a44e71488e1f 121 void read_pressure();
mfiore 0:a44e71488e1f 122 void read_moisture();
mfiore 0:a44e71488e1f 123 void read_magnetometer();
mfiore 0:a44e71488e1f 124 void read_accelerometer();
mfiore 0:a44e71488e1f 125 void read_gyroscope();
mfiore 0:a44e71488e1f 126 void button_irq();
mfiore 0:a44e71488e1f 127
mfiore 0:a44e71488e1f 128 // main
mfiore 0:a44e71488e1f 129 int main() {
mfiore 0:a44e71488e1f 130 mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL);
mfiore 0:a44e71488e1f 131 debug.baud(debug_baud);
mfiore 0:a44e71488e1f 132 logInfo("starting...");
mfiore 0:a44e71488e1f 133
mfiore 0:a44e71488e1f 134 radio_ok = init_mtsas();
mfiore 0:a44e71488e1f 135 if (! radio_ok)
mfiore 0:a44e71488e1f 136 logError("MTSAS init failed");
mfiore 0:a44e71488e1f 137 else
mfiore 0:a44e71488e1f 138 logInfo("MTSAS is ok");
mfiore 0:a44e71488e1f 139
mfiore 1:a049d113e250 140 button.fall(&button_irq);
mfiore 0:a44e71488e1f 141
mfiore 3:f6bceb9e5e1a 142 Timer thpm_timer;
mfiore 0:a44e71488e1f 143 Timer motion_timer;
mfiore 1:a049d113e250 144 Timer print_timer;
mfiore 4:730b61258422 145 Timer post_timer;
mfiore 0:a44e71488e1f 146
mfiore 3:f6bceb9e5e1a 147 thpm_timer.start();
mfiore 0:a44e71488e1f 148 motion_timer.start();
mfiore 1:a049d113e250 149 print_timer.start();
mfiore 4:730b61258422 150 post_timer.start();
mfiore 1:a049d113e250 151
mfiore 0:a44e71488e1f 152 while (true) {
mfiore 0:a44e71488e1f 153 if (motion_timer.read_ms() > motion_interval_ms) {
mfiore 0:a44e71488e1f 154 read_magnetometer();
mfiore 0:a44e71488e1f 155 read_accelerometer();
mfiore 0:a44e71488e1f 156 read_gyroscope();
mfiore 0:a44e71488e1f 157 motion_timer.reset();
mfiore 0:a44e71488e1f 158 }
mfiore 0:a44e71488e1f 159
mfiore 3:f6bceb9e5e1a 160 if (thpm_timer.read_ms() > thpm_interval_ms) {
mfiore 0:a44e71488e1f 161 read_temperature();
mfiore 0:a44e71488e1f 162 read_humidity();
mfiore 0:a44e71488e1f 163 read_pressure();
mfiore 3:f6bceb9e5e1a 164 read_moisture();
mfiore 3:f6bceb9e5e1a 165 thpm_timer.reset();
mfiore 0:a44e71488e1f 166 }
mfiore 0:a44e71488e1f 167
mfiore 0:a44e71488e1f 168 if (print_timer.read_ms() > print_interval_ms) {
mfiore 0:a44e71488e1f 169 logDebug("%s", wall_of_dash);
mfiore 0:a44e71488e1f 170 logDebug("SENSOR DATA");
mfiore 0:a44e71488e1f 171 logDebug("temperature: %f C\t%f F", temp_celsius, temp_fahrenheit);
mfiore 0:a44e71488e1f 172 logDebug("humidity: %f%%", humidity_percent);
mfiore 0:a44e71488e1f 173 logDebug("pressure: %f mbar", pressure_mbar);
mfiore 0:a44e71488e1f 174 logDebug("moisture: %f%%", moisture_percent);
mfiore 0:a44e71488e1f 175 logDebug("magnetometer:\r\n\tx: %ld\ty: %ld\tz: %ld\tmgauss", mag_mgauss[0], mag_mgauss[1], mag_mgauss[2]);
mfiore 0:a44e71488e1f 176 logDebug("accelerometer:\r\n\tx: %ld\ty: %ld\tz: %ld\tmg", acc_mg[0], acc_mg[1], acc_mg[2]);
mfiore 0:a44e71488e1f 177 logDebug("gyroscope:\r\n\tx: %ld\ty: %ld\tz: %ld\tmdps", gyro_mdps[0], gyro_mdps[1], gyro_mdps[2]);
mfiore 0:a44e71488e1f 178 logDebug("%s", wall_of_dash);
mfiore 0:a44e71488e1f 179 print_timer.reset();
mfiore 0:a44e71488e1f 180 }
mfiore 0:a44e71488e1f 181
mfiore 1:a049d113e250 182 if (button_pressed) {
mfiore 0:a44e71488e1f 183 logInfo("Button was pressed");
mfiore 1:a049d113e250 184 button_pressed = false;
mfiore 0:a44e71488e1f 185 if (radio_ok) {
mfiore 0:a44e71488e1f 186 MbedJSONValue sms_json;
mfiore 0:a44e71488e1f 187 string sms_str;
mfiore 0:a44e71488e1f 188
mfiore 0:a44e71488e1f 189 sms_json["temp_C"] = temp_celsius;
mfiore 0:a44e71488e1f 190 sms_json["temp_F"] = temp_fahrenheit;
mfiore 0:a44e71488e1f 191 sms_json["humidity_percent"] = humidity_percent;
mfiore 0:a44e71488e1f 192 sms_json["pressure_mbar"] = pressure_mbar;
mfiore 0:a44e71488e1f 193 sms_json["moisture_percent"] = moisture_percent;
mfiore 0:a44e71488e1f 194 sms_json["mag_mgauss"]["x"] = mag_mgauss[0];
mfiore 0:a44e71488e1f 195 sms_json["mag_mgauss"]["y"] = mag_mgauss[1];
mfiore 0:a44e71488e1f 196 sms_json["mag_mgauss"]["z"] = mag_mgauss[2];
mfiore 0:a44e71488e1f 197 sms_json["acc_mg"]["x"] = acc_mg[0];
mfiore 0:a44e71488e1f 198 sms_json["acc_mg"]["y"] = acc_mg[1];
mfiore 0:a44e71488e1f 199 sms_json["acc_mg"]["z"] = acc_mg[2];
mfiore 0:a44e71488e1f 200 sms_json["gyro_mdps"]["x"] = gyro_mdps[0];
mfiore 0:a44e71488e1f 201 sms_json["gyro_mdps"]["y"] = gyro_mdps[1];
mfiore 0:a44e71488e1f 202 sms_json["gyro_mdps"]["z"] = gyro_mdps[2];
mfiore 0:a44e71488e1f 203
mfiore 2:955a63247721 204 sms_str = "SENSOR DATA:\n";
mfiore 0:a44e71488e1f 205 sms_str += sms_json.serialize();
mfiore 0:a44e71488e1f 206
mfiore 0:a44e71488e1f 207 logDebug("sending SMS to %s:\r\n%s", phone_number.c_str(), sms_str.c_str());
mfiore 0:a44e71488e1f 208 Code ret = radio->sendSMS(phone_number, sms_str);
mfiore 0:a44e71488e1f 209 if (ret != MTS_SUCCESS)
mfiore 0:a44e71488e1f 210 logError("sending SMS failed");
mfiore 0:a44e71488e1f 211 }
mfiore 0:a44e71488e1f 212 }
mfiore 0:a44e71488e1f 213
mfiore 4:730b61258422 214 if (post_timer.read_ms() > post_interval_ms && do_cloud_post) {
mfiore 4:730b61258422 215 if (radio->connect()) {
mfiore 4:730b61258422 216 logDebug("posting sensor data");
mfiore 5:a946ef74a8c4 217
mfiore 5:a946ef74a8c4 218 HTTPClient http;
mfiore 5:a946ef74a8c4 219 MbedJSONValue http_json_data;
mfiore 5:a946ef74a8c4 220 std::string http_json_str;
mfiore 5:a946ef74a8c4 221 std::string m2x_header = "X-M2X-KEY: " + m2x_api_key + "\r\n";
mfiore 5:a946ef74a8c4 222 int ret;
mfiore 5:a946ef74a8c4 223 char http_response_buf[256];
mfiore 5:a946ef74a8c4 224 HTTPText http_response(http_response_buf, sizeof(http_response_buf));
mfiore 5:a946ef74a8c4 225
mfiore 5:a946ef74a8c4 226 // temp_c, temp_f, humidity, pressure, and moisture are all stream IDs for my device in M2X
mfiore 5:a946ef74a8c4 227 // modify these to match your streams or give your streams the same name
mfiore 5:a946ef74a8c4 228 http_json_data["values"]["temp_c"] = temp_celsius;
mfiore 5:a946ef74a8c4 229 http_json_data["values"]["temp_f"] = temp_fahrenheit;
mfiore 5:a946ef74a8c4 230 http_json_data["values"]["humidity"] = humidity_percent;
mfiore 5:a946ef74a8c4 231 http_json_data["values"]["pressure"] = pressure_mbar;
mfiore 5:a946ef74a8c4 232 http_json_data["values"]["moisture"] = moisture_percent;
mfiore 5:a946ef74a8c4 233 http_json_str = http_json_data.serialize();
mfiore 5:a946ef74a8c4 234
mfiore 5:a946ef74a8c4 235 // add extra header with M2X API key
mfiore 5:a946ef74a8c4 236 http.setHeader(m2x_header.c_str());
mfiore 5:a946ef74a8c4 237
mfiore 5:a946ef74a8c4 238 HTTPJson http_json((char*) http_json_str.c_str());
mfiore 5:a946ef74a8c4 239 ret = http.post(url.c_str(), http_json, &http_response);
mfiore 5:a946ef74a8c4 240 if (ret != HTTP_OK)
mfiore 5:a946ef74a8c4 241 logError("posting data to cloud failed: [%d][%s]", ret, http_response_buf);
mfiore 5:a946ef74a8c4 242 else
mfiore 5:a946ef74a8c4 243 logDebug("post result [%d][%s]", http.getHTTPResponseCode(), http_response_buf);
mfiore 5:a946ef74a8c4 244
mfiore 4:730b61258422 245 radio->disconnect();
mfiore 4:730b61258422 246 } else {
mfiore 4:730b61258422 247 logError("establishing PPP link failed");
mfiore 4:730b61258422 248 }
mfiore 4:730b61258422 249
mfiore 4:730b61258422 250 post_timer.reset();
mfiore 4:730b61258422 251 }
mfiore 4:730b61258422 252
mfiore 1:a049d113e250 253 wait_ms(10);
mfiore 0:a44e71488e1f 254 }
mfiore 0:a44e71488e1f 255 }
mfiore 0:a44e71488e1f 256
mfiore 1:a049d113e250 257 // init functions
mfiore 1:a049d113e250 258 bool init_mtsas() {
mfiore 1:a049d113e250 259 io = new MTSSerialFlowControl(RADIO_TX, RADIO_RX, RADIO_RTS, RADIO_CTS);
mfiore 1:a049d113e250 260 if (! io)
mfiore 1:a049d113e250 261 return false;
mfiore 1:a049d113e250 262
mfiore 1:a049d113e250 263 io->baud(115200);
mfiore 1:a049d113e250 264 radio = CellularFactory::create(io);
mfiore 1:a049d113e250 265 if (! radio)
mfiore 1:a049d113e250 266 return false;
mfiore 1:a049d113e250 267
mfiore 1:a049d113e250 268 Code ret = radio->setApn(apn);
mfiore 1:a049d113e250 269 if (ret != MTS_SUCCESS)
mfiore 1:a049d113e250 270 return false;
mfiore 1:a049d113e250 271
mfiore 5:a946ef74a8c4 272 Transport::setTransport(radio);
mfiore 5:a946ef74a8c4 273
mfiore 1:a049d113e250 274 return true;
mfiore 1:a049d113e250 275 }
mfiore 1:a049d113e250 276
mfiore 0:a44e71488e1f 277 // Sensor data acquisition functions
mfiore 0:a44e71488e1f 278 void read_temperature() {
mfiore 0:a44e71488e1f 279 int ret;
mfiore 0:a44e71488e1f 280
mfiore 0:a44e71488e1f 281 ret = mems->ht_sensor->GetTemperature(&temp_celsius);
mfiore 0:a44e71488e1f 282 if (ret)
mfiore 0:a44e71488e1f 283 logError("reading temp (C) failed");
mfiore 0:a44e71488e1f 284
mfiore 0:a44e71488e1f 285 ret = mems->ht_sensor->GetFahrenheit(&temp_fahrenheit);
mfiore 0:a44e71488e1f 286 if (ret)
mfiore 0:a44e71488e1f 287 logError("reading temp (F) failed");
mfiore 0:a44e71488e1f 288 }
mfiore 0:a44e71488e1f 289
mfiore 0:a44e71488e1f 290 void read_humidity() {
mfiore 0:a44e71488e1f 291 int ret;
mfiore 0:a44e71488e1f 292
mfiore 0:a44e71488e1f 293 ret = mems->ht_sensor->GetHumidity(&humidity_percent);
mfiore 0:a44e71488e1f 294 if (ret)
mfiore 0:a44e71488e1f 295 logError("reading humidity failed");
mfiore 0:a44e71488e1f 296 }
mfiore 0:a44e71488e1f 297
mfiore 0:a44e71488e1f 298 void read_pressure() {
mfiore 0:a44e71488e1f 299 int ret;
mfiore 0:a44e71488e1f 300
mfiore 0:a44e71488e1f 301 ret = mems->pt_sensor->GetPressure(&pressure_mbar);
mfiore 0:a44e71488e1f 302 if (ret)
mfiore 0:a44e71488e1f 303 logError("reading pressure failed");
mfiore 0:a44e71488e1f 304 }
mfiore 0:a44e71488e1f 305
mfiore 0:a44e71488e1f 306 void read_moisture() {
mfiore 3:f6bceb9e5e1a 307 moisture_percent = moisture_sensor * 100.0;
mfiore 0:a44e71488e1f 308 }
mfiore 0:a44e71488e1f 309
mfiore 0:a44e71488e1f 310 void read_magnetometer() {
mfiore 0:a44e71488e1f 311 int ret;
mfiore 0:a44e71488e1f 312
mfiore 0:a44e71488e1f 313 ret = mems->magnetometer->Get_M_Axes(mag_mgauss);
mfiore 0:a44e71488e1f 314 if (ret)
mfiore 0:a44e71488e1f 315 logError("reading magnetometer failed");
mfiore 0:a44e71488e1f 316 }
mfiore 0:a44e71488e1f 317
mfiore 0:a44e71488e1f 318 void read_accelerometer() {
mfiore 0:a44e71488e1f 319 int ret;
mfiore 0:a44e71488e1f 320
mfiore 0:a44e71488e1f 321 ret = mems->GetAccelerometer()->Get_X_Axes(acc_mg);
mfiore 0:a44e71488e1f 322 if (ret)
mfiore 0:a44e71488e1f 323 logError("reading accelerometer failed");
mfiore 0:a44e71488e1f 324 }
mfiore 0:a44e71488e1f 325
mfiore 0:a44e71488e1f 326 void read_gyroscope() {
mfiore 0:a44e71488e1f 327 int ret;
mfiore 0:a44e71488e1f 328
mfiore 0:a44e71488e1f 329 ret = mems->GetGyroscope()->Get_G_Axes(gyro_mdps);
mfiore 0:a44e71488e1f 330 if (ret)
mfiore 0:a44e71488e1f 331 logError("reading gyroscope failed");
mfiore 0:a44e71488e1f 332 }
mfiore 1:a049d113e250 333
mfiore 1:a049d113e250 334 void button_irq() {
mfiore 1:a049d113e250 335 button_pressed = true;
mfiore 1:a049d113e250 336 }