Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BufferedSerial SX1276GenericLib USBDeviceHT mbed Crypto X_NUCLEO_IKS01A2
Fork of STM32L0_LoRa by
Diff: main.cpp
- Revision:
- 25:18a57be7bb17
- Parent:
- 24:bb733d746bda
- Child:
- 26:d93f1206909c
--- a/main.cpp Fri May 25 15:13:25 2018 +0000 +++ b/main.cpp Fri May 25 16:21:57 2018 +0000 @@ -13,23 +13,11 @@ XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5); volatile int mems_event = 0; volatile int notification = 0; -InterruptIn mybutton(USER_BUTTON); /* Sensor initialization */ HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor; LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro; -/* User button callback. */ -void pressed_cb() { - notification = 0; -} - - -/* Interrupt 1 callback. */ -void int1_cb() { - mems_event = 1; -} - int main() { #ifdef HELTEC_STM32L4 DigitalOut vext(POWER_VEXT); @@ -44,15 +32,10 @@ InitSerial(30*1000, &myled); hum_temp->enable(); - /* Attach callback to LSM6DSL INT1 */ - acc_gyro->attach_int1_irq(&int1_cb); /* Enable LSM6DSL accelerometer */ acc_gyro->enable_x(); - /* Enable Tilt Detection. */ - acc_gyro->enable_free_fall_detection(); - - /* Attach callback to User button press */ - mybutton.fall(&pressed_cb); + /* Enable 6D Orientation. */ + acc_gyro->enable_6d_orientation(); print_stuff(); bool empty = true; @@ -62,17 +45,7 @@ char distance[4], empty_distance[4], temperature[4];//Message to be sent get_distance(distance); get_temperature(temperature); - - - if (mems_event) { - mems_event = 0; - LSM6DSL_Event_Status_t status; - acc_gyro->get_event_status(&status); - if (status.FreeFallStatus) { - notification = 1; - printf("Tilt Detected!\r\n"); - } - } + notification = send_orientation(); if(empty) { memcpy(empty_distance, distance, 4); @@ -103,4 +76,30 @@ sprintf(message, "%f", value); dprintf(message); +} + +/* Print the orientation. */ +bool send_orientation() { + uint8_t xl = 0; + uint8_t xh = 0; + uint8_t yl = 0; + uint8_t yh = 0; + uint8_t zl = 0; + uint8_t zh = 0; + + acc_gyro->get_6d_orientation_xl(&xl); + acc_gyro->get_6d_orientation_xh(&xh); + acc_gyro->get_6d_orientation_yl(&yl); + acc_gyro->get_6d_orientation_yh(&yh); + acc_gyro->get_6d_orientation_zl(&zl); + acc_gyro->get_6d_orientation_zh(&zh); + + + if ( xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 1 ) { + return false; + } + + else { + return true; + } } \ No newline at end of file