Smartage application
Dependencies: BufferedSerial SX1276GenericLib USBDeviceHT mbed Crypto X_NUCLEO_IKS01A2
Fork of STM32L0_LoRa by
main.cpp
00001 #include "main.h" 00002 00003 DigitalOut myled(LED); 00004 //D12 TRIGGER D11 ECHO 00005 HCSR04 sensor(D12, D11); 00006 /* Instantiate the expansion board */ 00007 XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5); 00008 volatile int mems_event = 0; 00009 volatile int notification = 0; 00010 00011 /* Sensor initialization */ 00012 HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor; 00013 LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro; 00014 00015 int main() { 00016 /* 00017 * inits the Serial or USBSerial when available (230400 baud). 00018 * If the serial uart is not is not connected it swiches to USB Serial 00019 * blinking LED means USBSerial detected, waiting for a connect. 00020 * It waits up to 30 seconds for a USB terminal connections 00021 */ 00022 InitSerial(30*1000, &myled); 00023 hum_temp->enable(); 00024 00025 /* Enable LSM6DSL accelerometer */ 00026 acc_gyro->enable_x(); 00027 /* Enable 6D Orientation. */ 00028 acc_gyro->enable_6d_orientation(); 00029 00030 print_stuff(); 00031 bool empty = true; 00032 //WAIT 00033 wait(30.0f); 00034 while(1){ 00035 00036 char distance[4], empty_distance[4], temperature[4];//Message to be sent 00037 get_distance(distance); 00038 get_temperature(temperature); 00039 notification = send_orientation(); 00040 00041 if(empty) { 00042 memcpy(empty_distance, distance, 4); 00043 SendAndBack((uint8_t*)distance, (uint8_t*)empty_distance, (uint8_t*)temperature, notification); //invia due volte 00044 empty = false; 00045 } 00046 else{ 00047 SendAndBack((uint8_t*)distance, (uint8_t*)empty_distance, (uint8_t*)temperature, notification); 00048 } 00049 00050 } 00051 } 00052 00053 void get_distance(char message[]){ 00054 //Ultrasonic measurement 00055 long distance = 401; 00056 while (distance >= 400) distance = sensor.distance(); 00057 dprintf("distance %d \n",distance); 00058 00059 sprintf(message, "%d", distance); 00060 } 00061 00062 void get_temperature(char message[]){ 00063 float value; 00064 hum_temp->get_temperature(&value); 00065 dprintf("temperature %f", value); 00066 00067 sprintf(message, "%f", value); 00068 dprintf(message); 00069 00070 } 00071 00072 /* Print the orientation. */ 00073 bool send_orientation() { 00074 uint8_t xl = 0; 00075 uint8_t xh = 0; 00076 uint8_t yl = 0; 00077 uint8_t yh = 0; 00078 uint8_t zl = 0; 00079 uint8_t zh = 0; 00080 00081 acc_gyro->get_6d_orientation_xl(&xl); 00082 acc_gyro->get_6d_orientation_xh(&xh); 00083 acc_gyro->get_6d_orientation_yl(&yl); 00084 acc_gyro->get_6d_orientation_yh(&yh); 00085 acc_gyro->get_6d_orientation_zl(&zl); 00086 acc_gyro->get_6d_orientation_zh(&zh); 00087 00088 00089 if ( xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 1 ) { 00090 return false; 00091 } 00092 00093 else { 00094 return true; 00095 } 00096 }
Generated on Thu Jul 14 2022 21:27:01 by
1.7.2
