Smartage application
Dependencies: BufferedSerial SX1276GenericLib USBDeviceHT mbed Crypto X_NUCLEO_IKS01A2
Fork of STM32L0_LoRa by
main.cpp
- Committer:
- marcozecchini
- Date:
- 2018-05-25
- Revision:
- 24:bb733d746bda
- Parent:
- 22:2c1359292de1
- Child:
- 25:18a57be7bb17
File content as of revision 24:bb733d746bda:
/* * Copyright (c) 2018 HELIOS Software GmbH * 30826 Garbsen (Hannover) Germany * Licensed under the Apache License, Version 2.0); */ #include "main.h" DigitalOut myled(LED); //D12 TRIGGER D11 ECHO HCSR04 sensor(D12, D11); /* Instantiate the expansion board */ 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); vext = POWER_VEXT_ON; #endif /* * inits the Serial or USBSerial when available (230400 baud). * If the serial uart is not is not connected it swiches to USB Serial * blinking LED means USBSerial detected, waiting for a connect. * It waits up to 30 seconds for a USB terminal connections */ 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); print_stuff(); bool empty = true; //ADD THE WAIT while(1){ 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"); } } if(empty) { memcpy(empty_distance, distance, 4); SendAndBack((uint8_t*)distance, (uint8_t*)empty_distance, (uint8_t*)temperature, notification); //invia due volte empty = false; } else{ SendAndBack((uint8_t*)distance, (uint8_t*)empty_distance, (uint8_t*)temperature, notification); } } } void get_distance(char message[]){ //Ultrasonic measurement long distance = 401; while (distance >= 400) distance = sensor.distance(); dprintf("distance %d \n",distance); sprintf(message, "%d", distance); } void get_temperature(char message[]){ float value; hum_temp->get_temperature(&value); dprintf("temperature %f", value); sprintf(message, "%f", value); dprintf(message); }