test sending sensor results over lora radio. Accelerometer and temp/pressure.
Serial terminal operates at 115200.
This project provides a text-based menu over serial port.
Operating the program only requires using the arrow keys, enter key to activate a control, or entering numbers.
Two sensors provided:
LIS12DH12
accelerometer operates in a continuous sampling mode. Enable control for accelerometer enables this continuous sampling, approx every 3 seconds.
LPS22HH temperature / pressure sensor operates as single shot, where pressing the control button on terminal causes single sample to be performed.
poll rate
control will enable repeated reading of pressure/temperature-sensor or photo-sensor when poll rate is greater than zero.
target must be: DISCO_L072CZ_LRWAN1
c_demo/demo.c@0:e1e70da93044, 2019-04-24 (annotated)
- Committer:
- Wayne Roberts
- Date:
- Wed Apr 24 10:11:06 2019 -0700
- Revision:
- 0:e1e70da93044
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wayne Roberts |
0:e1e70da93044 | 1 | #include "mbed_wait_api.h" |
Wayne Roberts |
0:e1e70da93044 | 2 | #include "demo.h" |
Wayne Roberts |
0:e1e70da93044 | 3 | #include <math.h> /* trunc */ |
Wayne Roberts |
0:e1e70da93044 | 4 | |
Wayne Roberts |
0:e1e70da93044 | 5 | |
Wayne Roberts |
0:e1e70da93044 | 6 | #define SAMPLE_ODR ODR_LOW /*!< Accelerometer samples Output Data Rate */ |
Wayne Roberts |
0:e1e70da93044 | 7 | |
Wayne Roberts |
0:e1e70da93044 | 8 | static uint8_t verbose = 1; /* Verbose output to UART terminal ON/OFF. */ |
Wayne Roberts |
0:e1e70da93044 | 9 | |
Wayne Roberts |
0:e1e70da93044 | 10 | |
Wayne Roberts |
0:e1e70da93044 | 11 | /** |
Wayne Roberts |
0:e1e70da93044 | 12 | * @brief Handle DEMO State Machine |
Wayne Roberts |
0:e1e70da93044 | 13 | */ |
Wayne Roberts |
0:e1e70da93044 | 14 | typedef enum |
Wayne Roberts |
0:e1e70da93044 | 15 | { |
Wayne Roberts |
0:e1e70da93044 | 16 | STATUS_MEMS_INT1_DETECTED, |
Wayne Roberts |
0:e1e70da93044 | 17 | STATUS_FIFO_DOWNLOAD, |
Wayne Roberts |
0:e1e70da93044 | 18 | STATUS_SLEEP |
Wayne Roberts |
0:e1e70da93044 | 19 | } DEMO_FIFO_STATUS; |
Wayne Roberts |
0:e1e70da93044 | 20 | |
Wayne Roberts |
0:e1e70da93044 | 21 | static void *LIS2DH12_0_handle = NULL; |
Wayne Roberts |
0:e1e70da93044 | 22 | static volatile DEMO_FIFO_STATUS demoFifoStatus; |
Wayne Roberts |
0:e1e70da93044 | 23 | |
Wayne Roberts |
0:e1e70da93044 | 24 | static volatile uint8_t LPS22HH_DIL24_PRESENT = 0; |
Wayne Roberts |
0:e1e70da93044 | 25 | static void *LPS22HH_P_0_handle = NULL; |
Wayne Roberts |
0:e1e70da93044 | 26 | static void *LPS22HH_T_0_handle = NULL; |
Wayne Roberts |
0:e1e70da93044 | 27 | |
Wayne Roberts |
0:e1e70da93044 | 28 | uint8_t accel_get_num_samples(void) |
Wayne Roberts |
0:e1e70da93044 | 29 | { |
Wayne Roberts |
0:e1e70da93044 | 30 | uint16_t samplesToRead = 0; |
Wayne Roberts |
0:e1e70da93044 | 31 | |
Wayne Roberts |
0:e1e70da93044 | 32 | /* Get num of unread FIFO samples before reading data */ |
Wayne Roberts |
0:e1e70da93044 | 33 | if (BSP_ACCELERO_FIFO_Get_Num_Of_Samples_Ext(LIS2DH12_0_handle, &samplesToRead) == COMPONENT_ERROR) |
Wayne Roberts |
0:e1e70da93044 | 34 | { |
Wayne Roberts |
0:e1e70da93044 | 35 | return 0; |
Wayne Roberts |
0:e1e70da93044 | 36 | } |
Wayne Roberts |
0:e1e70da93044 | 37 | |
Wayne Roberts |
0:e1e70da93044 | 38 | return samplesToRead; |
Wayne Roberts |
0:e1e70da93044 | 39 | } |
Wayne Roberts |
0:e1e70da93044 | 40 | |
Wayne Roberts |
0:e1e70da93044 | 41 | static DrvStatusTypeDef Init_All_Sensors(void) |
Wayne Roberts |
0:e1e70da93044 | 42 | { |
Wayne Roberts |
0:e1e70da93044 | 43 | DrvStatusTypeDef ret; |
Wayne Roberts |
0:e1e70da93044 | 44 | |
Wayne Roberts |
0:e1e70da93044 | 45 | ret = BSP_ACCELERO_Init(LIS2DH12_0, &LIS2DH12_0_handle); |
Wayne Roberts |
0:e1e70da93044 | 46 | |
Wayne Roberts |
0:e1e70da93044 | 47 | if (BSP_TEMPERATURE_Init(LPS22HH_T_0, &LPS22HH_T_0_handle) == COMPONENT_OK) |
Wayne Roberts |
0:e1e70da93044 | 48 | { |
Wayne Roberts |
0:e1e70da93044 | 49 | LPS22HH_DIL24_PRESENT = 1; |
Wayne Roberts |
0:e1e70da93044 | 50 | } else { |
Wayne Roberts |
0:e1e70da93044 | 51 | c_log_printf("\e[31mlps22hh temp fail\e[0m\r\n"); |
Wayne Roberts |
0:e1e70da93044 | 52 | ret = COMPONENT_ERROR; |
Wayne Roberts |
0:e1e70da93044 | 53 | } |
Wayne Roberts |
0:e1e70da93044 | 54 | |
Wayne Roberts |
0:e1e70da93044 | 55 | if (BSP_PRESSURE_Init(LPS22HH_P_0, &LPS22HH_P_0_handle) == COMPONENT_OK) |
Wayne Roberts |
0:e1e70da93044 | 56 | { |
Wayne Roberts |
0:e1e70da93044 | 57 | LPS22HH_DIL24_PRESENT = 1; |
Wayne Roberts |
0:e1e70da93044 | 58 | } else { |
Wayne Roberts |
0:e1e70da93044 | 59 | c_log_printf("\e[31mlps22hh pres fail\e[0m\r\n"); |
Wayne Roberts |
0:e1e70da93044 | 60 | ret = COMPONENT_ERROR; |
Wayne Roberts |
0:e1e70da93044 | 61 | } |
Wayne Roberts |
0:e1e70da93044 | 62 | |
Wayne Roberts |
0:e1e70da93044 | 63 | return ret; |
Wayne Roberts |
0:e1e70da93044 | 64 | } |
Wayne Roberts |
0:e1e70da93044 | 65 | |
Wayne Roberts |
0:e1e70da93044 | 66 | int accel_is_enabled(uint8_t* status) |
Wayne Roberts |
0:e1e70da93044 | 67 | { |
Wayne Roberts |
0:e1e70da93044 | 68 | DrvStatusTypeDef ret = BSP_ACCELERO_IsEnabled(LIS2DH12_0_handle, status); |
Wayne Roberts |
0:e1e70da93044 | 69 | if (ret == COMPONENT_OK) |
Wayne Roberts |
0:e1e70da93044 | 70 | return 0; |
Wayne Roberts |
0:e1e70da93044 | 71 | else |
Wayne Roberts |
0:e1e70da93044 | 72 | return -1; |
Wayne Roberts |
0:e1e70da93044 | 73 | } |
Wayne Roberts |
0:e1e70da93044 | 74 | |
Wayne Roberts |
0:e1e70da93044 | 75 | int accel_enable(uint8_t en) |
Wayne Roberts |
0:e1e70da93044 | 76 | { |
Wayne Roberts |
0:e1e70da93044 | 77 | DrvStatusTypeDef ret; |
Wayne Roberts |
0:e1e70da93044 | 78 | if (en) |
Wayne Roberts |
0:e1e70da93044 | 79 | ret = BSP_ACCELERO_Sensor_Enable(LIS2DH12_0_handle); |
Wayne Roberts |
0:e1e70da93044 | 80 | else |
Wayne Roberts |
0:e1e70da93044 | 81 | ret = BSP_ACCELERO_Sensor_Disable(LIS2DH12_0_handle); |
Wayne Roberts |
0:e1e70da93044 | 82 | |
Wayne Roberts |
0:e1e70da93044 | 83 | if (ret == COMPONENT_OK) |
Wayne Roberts |
0:e1e70da93044 | 84 | return 0; |
Wayne Roberts |
0:e1e70da93044 | 85 | else |
Wayne Roberts |
0:e1e70da93044 | 86 | return -1; |
Wayne Roberts |
0:e1e70da93044 | 87 | } |
Wayne Roberts |
0:e1e70da93044 | 88 | |
Wayne Roberts |
0:e1e70da93044 | 89 | static DrvStatusTypeDef Enable_All_Sensors(void) |
Wayne Roberts |
0:e1e70da93044 | 90 | { |
Wayne Roberts |
0:e1e70da93044 | 91 | DrvStatusTypeDef ret = COMPONENT_NOT_IMPLEMENTED; |
Wayne Roberts |
0:e1e70da93044 | 92 | |
Wayne Roberts |
0:e1e70da93044 | 93 | if (LPS22HH_DIL24_PRESENT == 1) |
Wayne Roberts |
0:e1e70da93044 | 94 | { |
Wayne Roberts |
0:e1e70da93044 | 95 | BSP_TEMPERATURE_Sensor_Enable(LPS22HH_T_0_handle); |
Wayne Roberts |
0:e1e70da93044 | 96 | ret = COMPONENT_OK; |
Wayne Roberts |
0:e1e70da93044 | 97 | } |
Wayne Roberts |
0:e1e70da93044 | 98 | if (LPS22HH_DIL24_PRESENT == 1) |
Wayne Roberts |
0:e1e70da93044 | 99 | { |
Wayne Roberts |
0:e1e70da93044 | 100 | BSP_PRESSURE_Sensor_Enable(LPS22HH_P_0_handle); |
Wayne Roberts |
0:e1e70da93044 | 101 | ret = COMPONENT_OK; |
Wayne Roberts |
0:e1e70da93044 | 102 | } |
Wayne Roberts |
0:e1e70da93044 | 103 | |
Wayne Roberts |
0:e1e70da93044 | 104 | return ret; |
Wayne Roberts |
0:e1e70da93044 | 105 | } |
Wayne Roberts |
0:e1e70da93044 | 106 | |
Wayne Roberts |
0:e1e70da93044 | 107 | int demo_start() |
Wayne Roberts |
0:e1e70da93044 | 108 | { |
Wayne Roberts |
0:e1e70da93044 | 109 | if (Init_All_Sensors() == COMPONENT_ERROR) |
Wayne Roberts |
0:e1e70da93044 | 110 | { |
Wayne Roberts |
0:e1e70da93044 | 111 | c_log_printf("Init_All_Sensors fail\r\n"); |
Wayne Roberts |
0:e1e70da93044 | 112 | return -1; |
Wayne Roberts |
0:e1e70da93044 | 113 | } |
Wayne Roberts |
0:e1e70da93044 | 114 | |
Wayne Roberts |
0:e1e70da93044 | 115 | if (Enable_All_Sensors() == COMPONENT_ERROR) |
Wayne Roberts |
0:e1e70da93044 | 116 | { |
Wayne Roberts |
0:e1e70da93044 | 117 | c_log_printf("Enable_All_Sensors fail\r\n"); |
Wayne Roberts |
0:e1e70da93044 | 118 | return -1; |
Wayne Roberts |
0:e1e70da93044 | 119 | } |
Wayne Roberts |
0:e1e70da93044 | 120 | |
Wayne Roberts |
0:e1e70da93044 | 121 | /* Configure LIS2DH12 Sensor for the DEMO application */ |
Wayne Roberts |
0:e1e70da93044 | 122 | if (BSP_ACCELERO_Set_ODR(LIS2DH12_0_handle, SAMPLE_ODR) == COMPONENT_ERROR) |
Wayne Roberts |
0:e1e70da93044 | 123 | { |
Wayne Roberts |
0:e1e70da93044 | 124 | c_log_printf("Set_ODR fail\r\n"); |
Wayne Roberts |
0:e1e70da93044 | 125 | return -1; |
Wayne Roberts |
0:e1e70da93044 | 126 | } |
Wayne Roberts |
0:e1e70da93044 | 127 | |
Wayne Roberts |
0:e1e70da93044 | 128 | /* Set FIFO_OVR on INT1 */ |
Wayne Roberts |
0:e1e70da93044 | 129 | if (BSP_ACCELERO_FIFO_Set_INT1_FIFO_Overrun_Ext(LIS2DH12_0_handle, LIS2DH12_ENABLE) == COMPONENT_ERROR) |
Wayne Roberts |
0:e1e70da93044 | 130 | { |
Wayne Roberts |
0:e1e70da93044 | 131 | c_log_printf("Set_INT1 fail\r\n"); |
Wayne Roberts |
0:e1e70da93044 | 132 | return -1; |
Wayne Roberts |
0:e1e70da93044 | 133 | } |
Wayne Roberts |
0:e1e70da93044 | 134 | |
Wayne Roberts |
0:e1e70da93044 | 135 | demoFifoStatus = STATUS_SLEEP; |
Wayne Roberts |
0:e1e70da93044 | 136 | |
Wayne Roberts |
0:e1e70da93044 | 137 | return 0; |
Wayne Roberts |
0:e1e70da93044 | 138 | } |
Wayne Roberts |
0:e1e70da93044 | 139 | |
Wayne Roberts |
0:e1e70da93044 | 140 | int lis2dh_mainloop() |
Wayne Roberts |
0:e1e70da93044 | 141 | { |
Wayne Roberts |
0:e1e70da93044 | 142 | uint8_t fifo_overrun_status; |
Wayne Roberts |
0:e1e70da93044 | 143 | |
Wayne Roberts |
0:e1e70da93044 | 144 | /* Handle DEMO State Machine */ |
Wayne Roberts |
0:e1e70da93044 | 145 | switch (demoFifoStatus) |
Wayne Roberts |
0:e1e70da93044 | 146 | { |
Wayne Roberts |
0:e1e70da93044 | 147 | case STATUS_MEMS_INT1_DETECTED: |
Wayne Roberts |
0:e1e70da93044 | 148 | |
Wayne Roberts |
0:e1e70da93044 | 149 | /* Check if FIFO is full */ |
Wayne Roberts |
0:e1e70da93044 | 150 | if (BSP_ACCELERO_FIFO_Get_Overrun_Status_Ext(LIS2DH12_0_handle, &fifo_overrun_status) == COMPONENT_ERROR) |
Wayne Roberts |
0:e1e70da93044 | 151 | { |
Wayne Roberts |
0:e1e70da93044 | 152 | c_log_printf("get_overrun_status fail\r\n"); |
Wayne Roberts |
0:e1e70da93044 | 153 | |
Wayne Roberts |
0:e1e70da93044 | 154 | return LIS2DH_BSP_FAIL; |
Wayne Roberts |
0:e1e70da93044 | 155 | } |
Wayne Roberts |
0:e1e70da93044 | 156 | |
Wayne Roberts |
0:e1e70da93044 | 157 | if (fifo_overrun_status == 1) |
Wayne Roberts |
0:e1e70da93044 | 158 | { |
Wayne Roberts |
0:e1e70da93044 | 159 | demoFifoStatus = STATUS_FIFO_DOWNLOAD; |
Wayne Roberts |
0:e1e70da93044 | 160 | } |
Wayne Roberts |
0:e1e70da93044 | 161 | else |
Wayne Roberts |
0:e1e70da93044 | 162 | { |
Wayne Roberts |
0:e1e70da93044 | 163 | demoFifoStatus = STATUS_SLEEP; |
Wayne Roberts |
0:e1e70da93044 | 164 | } |
Wayne Roberts |
0:e1e70da93044 | 165 | break; |
Wayne Roberts |
0:e1e70da93044 | 166 | |
Wayne Roberts |
0:e1e70da93044 | 167 | case STATUS_FIFO_DOWNLOAD: |
Wayne Roberts |
0:e1e70da93044 | 168 | demoFifoStatus = STATUS_SLEEP; |
Wayne Roberts |
0:e1e70da93044 | 169 | return LIS2DH_MAIN_READ_FIFO; |
Wayne Roberts |
0:e1e70da93044 | 170 | |
Wayne Roberts |
0:e1e70da93044 | 171 | case STATUS_SLEEP: |
Wayne Roberts |
0:e1e70da93044 | 172 | /* Enter sleep mode */ |
Wayne Roberts |
0:e1e70da93044 | 173 | return LIS2DH_MAIN_SLEEP; |
Wayne Roberts |
0:e1e70da93044 | 174 | |
Wayne Roberts |
0:e1e70da93044 | 175 | default: |
Wayne Roberts |
0:e1e70da93044 | 176 | return LIS2DH_FAIL_STATE; |
Wayne Roberts |
0:e1e70da93044 | 177 | } // ..switch (demoFifoStatus) |
Wayne Roberts |
0:e1e70da93044 | 178 | |
Wayne Roberts |
0:e1e70da93044 | 179 | return LIS2DH_MAIN_NONE; |
Wayne Roberts |
0:e1e70da93044 | 180 | } |
Wayne Roberts |
0:e1e70da93044 | 181 | |
Wayne Roberts |
0:e1e70da93044 | 182 | int lis2dh_set_fifo_mode() |
Wayne Roberts |
0:e1e70da93044 | 183 | { |
Wayne Roberts |
0:e1e70da93044 | 184 | /* Set FIFO mode to FIFO */ |
Wayne Roberts |
0:e1e70da93044 | 185 | if (BSP_ACCELERO_FIFO_Set_Mode_Ext(LIS2DH12_0_handle, LIS2DH12_FIFO_MODE) == COMPONENT_ERROR) |
Wayne Roberts |
0:e1e70da93044 | 186 | { |
Wayne Roberts |
0:e1e70da93044 | 187 | return -1; |
Wayne Roberts |
0:e1e70da93044 | 188 | } |
Wayne Roberts |
0:e1e70da93044 | 189 | return 0; |
Wayne Roberts |
0:e1e70da93044 | 190 | } |
Wayne Roberts |
0:e1e70da93044 | 191 | |
Wayne Roberts |
0:e1e70da93044 | 192 | int lis2dh_set_fifo_bypass() |
Wayne Roberts |
0:e1e70da93044 | 193 | { |
Wayne Roberts |
0:e1e70da93044 | 194 | if (BSP_ACCELERO_FIFO_Set_Mode_Ext(LIS2DH12_0_handle, LIS2DH12_FIFO_BYPASS_MODE) == COMPONENT_ERROR) |
Wayne Roberts |
0:e1e70da93044 | 195 | return -1; |
Wayne Roberts |
0:e1e70da93044 | 196 | |
Wayne Roberts |
0:e1e70da93044 | 197 | return 0; |
Wayne Roberts |
0:e1e70da93044 | 198 | } |
Wayne Roberts |
0:e1e70da93044 | 199 | |
Wayne Roberts |
0:e1e70da93044 | 200 | void EXTI4_15_IRQHandler() |
Wayne Roberts |
0:e1e70da93044 | 201 | { |
Wayne Roberts |
0:e1e70da93044 | 202 | HAL_GPIO_EXTI_IRQHandler(M_INT1_O_PIN); |
Wayne Roberts |
0:e1e70da93044 | 203 | //HAL_GPIO_EXTI_IRQHandler(M_INT2_O_PIN); |
Wayne Roberts |
0:e1e70da93044 | 204 | } |
Wayne Roberts |
0:e1e70da93044 | 205 | |
Wayne Roberts |
0:e1e70da93044 | 206 | void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) |
Wayne Roberts |
0:e1e70da93044 | 207 | { |
Wayne Roberts |
0:e1e70da93044 | 208 | if (GPIO_Pin == M_INT1_O_PIN) { |
Wayne Roberts |
0:e1e70da93044 | 209 | lis2dh_int1(); |
Wayne Roberts |
0:e1e70da93044 | 210 | demoFifoStatus = STATUS_MEMS_INT1_DETECTED; |
Wayne Roberts |
0:e1e70da93044 | 211 | } |
Wayne Roberts |
0:e1e70da93044 | 212 | } |
Wayne Roberts |
0:e1e70da93044 | 213 | |
Wayne Roberts |
0:e1e70da93044 | 214 | DrvStatusTypeDef lis2dh12_get_axes(SensorAxes_t *acceleration) |
Wayne Roberts |
0:e1e70da93044 | 215 | { |
Wayne Roberts |
0:e1e70da93044 | 216 | /* Read single FIFO data (acceleration in 3 axes) */ |
Wayne Roberts |
0:e1e70da93044 | 217 | return BSP_ACCELERO_Get_Axes(LIS2DH12_0_handle, acceleration); |
Wayne Roberts |
0:e1e70da93044 | 218 | } |
Wayne Roberts |
0:e1e70da93044 | 219 | |
Wayne Roberts |
0:e1e70da93044 | 220 | static void FloatToInt(float in, displayFloatToInt_t *out_value, int32_t dec_prec) |
Wayne Roberts |
0:e1e70da93044 | 221 | { |
Wayne Roberts |
0:e1e70da93044 | 222 | if (in >= 0.0f) |
Wayne Roberts |
0:e1e70da93044 | 223 | { |
Wayne Roberts |
0:e1e70da93044 | 224 | out_value->sign = 0; |
Wayne Roberts |
0:e1e70da93044 | 225 | } |
Wayne Roberts |
0:e1e70da93044 | 226 | else |
Wayne Roberts |
0:e1e70da93044 | 227 | { |
Wayne Roberts |
0:e1e70da93044 | 228 | out_value->sign = 1; |
Wayne Roberts |
0:e1e70da93044 | 229 | in = -in; |
Wayne Roberts |
0:e1e70da93044 | 230 | } |
Wayne Roberts |
0:e1e70da93044 | 231 | |
Wayne Roberts |
0:e1e70da93044 | 232 | out_value->out_int = (int32_t)in; |
Wayne Roberts |
0:e1e70da93044 | 233 | in = in - (float)(out_value->out_int); |
Wayne Roberts |
0:e1e70da93044 | 234 | out_value->out_dec = (int32_t)trunc(in * pow(10, dec_prec)); |
Wayne Roberts |
0:e1e70da93044 | 235 | } |
Wayne Roberts |
0:e1e70da93044 | 236 | |
Wayne Roberts |
0:e1e70da93044 | 237 | static void Temperature_Sensor_Handler(void *handle, displayFloatToInt_t* outValue) |
Wayne Roberts |
0:e1e70da93044 | 238 | { |
Wayne Roberts |
0:e1e70da93044 | 239 | uint8_t who_am_i; |
Wayne Roberts |
0:e1e70da93044 | 240 | float odr; |
Wayne Roberts |
0:e1e70da93044 | 241 | uint8_t id; |
Wayne Roberts |
0:e1e70da93044 | 242 | float temperature; |
Wayne Roberts |
0:e1e70da93044 | 243 | uint8_t status; |
Wayne Roberts |
0:e1e70da93044 | 244 | |
Wayne Roberts |
0:e1e70da93044 | 245 | BSP_TEMPERATURE_Get_Instance(handle, &id); |
Wayne Roberts |
0:e1e70da93044 | 246 | |
Wayne Roberts |
0:e1e70da93044 | 247 | BSP_TEMPERATURE_IsInitialized(handle, &status); |
Wayne Roberts |
0:e1e70da93044 | 248 | |
Wayne Roberts |
0:e1e70da93044 | 249 | if (status == 1) |
Wayne Roberts |
0:e1e70da93044 | 250 | { |
Wayne Roberts |
0:e1e70da93044 | 251 | if (BSP_TEMPERATURE_Get_Temp(handle, &temperature) == COMPONENT_ERROR) |
Wayne Roberts |
0:e1e70da93044 | 252 | { |
Wayne Roberts |
0:e1e70da93044 | 253 | temperature = 0.0f; |
Wayne Roberts |
0:e1e70da93044 | 254 | } |
Wayne Roberts |
0:e1e70da93044 | 255 | |
Wayne Roberts |
0:e1e70da93044 | 256 | //displayFloatToInt_t out_value; |
Wayne Roberts |
0:e1e70da93044 | 257 | FloatToInt(temperature, outValue, 2); |
Wayne Roberts |
0:e1e70da93044 | 258 | c_log_printf("TEMP[%d]: %c%d.%02d\r\n", (int)id, ((outValue->sign) ? '-' : '+'), |
Wayne Roberts |
0:e1e70da93044 | 259 | (int)outValue->out_int, (int)outValue->out_dec); |
Wayne Roberts |
0:e1e70da93044 | 260 | |
Wayne Roberts |
0:e1e70da93044 | 261 | if (verbose == 1) |
Wayne Roberts |
0:e1e70da93044 | 262 | { |
Wayne Roberts |
0:e1e70da93044 | 263 | if (BSP_TEMPERATURE_Get_WhoAmI(handle, &who_am_i) == COMPONENT_ERROR) |
Wayne Roberts |
0:e1e70da93044 | 264 | { |
Wayne Roberts |
0:e1e70da93044 | 265 | c_log_printf("\e[31mtemp-WHO AM I address[%d]: ERROR\e[0m\r\n", id); |
Wayne Roberts |
0:e1e70da93044 | 266 | } |
Wayne Roberts |
0:e1e70da93044 | 267 | else |
Wayne Roberts |
0:e1e70da93044 | 268 | { |
Wayne Roberts |
0:e1e70da93044 | 269 | c_log_printf("temp-WHO AM I address[%d]: 0x%02X\r\n", id, who_am_i); |
Wayne Roberts |
0:e1e70da93044 | 270 | } |
Wayne Roberts |
0:e1e70da93044 | 271 | |
Wayne Roberts |
0:e1e70da93044 | 272 | if (BSP_TEMPERATURE_Get_ODR(handle, &odr) == COMPONENT_ERROR) |
Wayne Roberts |
0:e1e70da93044 | 273 | { |
Wayne Roberts |
0:e1e70da93044 | 274 | c_log_printf("\e[31mtemp-ODR[%d]: ERROR\e[0m\r\n", id); |
Wayne Roberts |
0:e1e70da93044 | 275 | } |
Wayne Roberts |
0:e1e70da93044 | 276 | else |
Wayne Roberts |
0:e1e70da93044 | 277 | { |
Wayne Roberts |
0:e1e70da93044 | 278 | displayFloatToInt_t out_value; |
Wayne Roberts |
0:e1e70da93044 | 279 | FloatToInt(odr, &out_value, 3); |
Wayne Roberts |
0:e1e70da93044 | 280 | c_log_printf("ODR[%d]: %c%d.%03d Hz\r\n", (int)id, ((out_value.sign) ? '-' : '+'), |
Wayne Roberts |
0:e1e70da93044 | 281 | (int)out_value.out_int, (int)out_value.out_dec); |
Wayne Roberts |
0:e1e70da93044 | 282 | } |
Wayne Roberts |
0:e1e70da93044 | 283 | } |
Wayne Roberts |
0:e1e70da93044 | 284 | } |
Wayne Roberts |
0:e1e70da93044 | 285 | } |
Wayne Roberts |
0:e1e70da93044 | 286 | |
Wayne Roberts |
0:e1e70da93044 | 287 | static void Pressure_Sensor_Handler(void *handle, displayFloatToInt_t* val) |
Wayne Roberts |
0:e1e70da93044 | 288 | { |
Wayne Roberts |
0:e1e70da93044 | 289 | uint8_t who_am_i; |
Wayne Roberts |
0:e1e70da93044 | 290 | float odr; |
Wayne Roberts |
0:e1e70da93044 | 291 | uint8_t id; |
Wayne Roberts |
0:e1e70da93044 | 292 | float pressure; |
Wayne Roberts |
0:e1e70da93044 | 293 | uint8_t status; |
Wayne Roberts |
0:e1e70da93044 | 294 | |
Wayne Roberts |
0:e1e70da93044 | 295 | BSP_PRESSURE_Get_Instance(handle, &id); |
Wayne Roberts |
0:e1e70da93044 | 296 | |
Wayne Roberts |
0:e1e70da93044 | 297 | BSP_PRESSURE_IsInitialized(handle, &status); |
Wayne Roberts |
0:e1e70da93044 | 298 | |
Wayne Roberts |
0:e1e70da93044 | 299 | if (status == 1) |
Wayne Roberts |
0:e1e70da93044 | 300 | { |
Wayne Roberts |
0:e1e70da93044 | 301 | if (BSP_PRESSURE_Get_Press(handle, &pressure) == COMPONENT_ERROR) |
Wayne Roberts |
0:e1e70da93044 | 302 | { |
Wayne Roberts |
0:e1e70da93044 | 303 | |
Wayne Roberts |
0:e1e70da93044 | 304 | c_log_printf("\e[31mGet_Press fail\e[0m\r\n", id); |
Wayne Roberts |
0:e1e70da93044 | 305 | pressure = 0.0f; |
Wayne Roberts |
0:e1e70da93044 | 306 | } |
Wayne Roberts |
0:e1e70da93044 | 307 | |
Wayne Roberts |
0:e1e70da93044 | 308 | //displayFloatToInt_t out_value; |
Wayne Roberts |
0:e1e70da93044 | 309 | FloatToInt(pressure, val, 2); |
Wayne Roberts |
0:e1e70da93044 | 310 | c_log_printf("PRESS[%d]: %c%d.%02d\r\n", (int)id, ((val->sign) ? '-' : '+'), |
Wayne Roberts |
0:e1e70da93044 | 311 | (int)val->out_int, (int)val->out_dec); |
Wayne Roberts |
0:e1e70da93044 | 312 | |
Wayne Roberts |
0:e1e70da93044 | 313 | if (verbose == 1) |
Wayne Roberts |
0:e1e70da93044 | 314 | { |
Wayne Roberts |
0:e1e70da93044 | 315 | if (BSP_PRESSURE_Get_WhoAmI(handle, &who_am_i) == COMPONENT_ERROR) |
Wayne Roberts |
0:e1e70da93044 | 316 | { |
Wayne Roberts |
0:e1e70da93044 | 317 | c_log_printf("\e[31mpres-WHO AM I address[%d]: ERROR\e[0m\r\n", id); |
Wayne Roberts |
0:e1e70da93044 | 318 | } |
Wayne Roberts |
0:e1e70da93044 | 319 | else |
Wayne Roberts |
0:e1e70da93044 | 320 | { |
Wayne Roberts |
0:e1e70da93044 | 321 | c_log_printf("pres-WHO AM I address[%d]: 0x%02X\r\n", id, who_am_i); |
Wayne Roberts |
0:e1e70da93044 | 322 | } |
Wayne Roberts |
0:e1e70da93044 | 323 | |
Wayne Roberts |
0:e1e70da93044 | 324 | if (BSP_PRESSURE_Get_ODR(handle, &odr) == COMPONENT_ERROR) |
Wayne Roberts |
0:e1e70da93044 | 325 | { |
Wayne Roberts |
0:e1e70da93044 | 326 | c_log_printf("\e[31mpres-ODR[%d]: ERROR\e[0m\r\n", id); |
Wayne Roberts |
0:e1e70da93044 | 327 | } |
Wayne Roberts |
0:e1e70da93044 | 328 | else |
Wayne Roberts |
0:e1e70da93044 | 329 | { |
Wayne Roberts |
0:e1e70da93044 | 330 | displayFloatToInt_t out_value; |
Wayne Roberts |
0:e1e70da93044 | 331 | FloatToInt(odr, &out_value, 3); |
Wayne Roberts |
0:e1e70da93044 | 332 | c_log_printf("ODR[%d]: %c%d.%03d Hz\r\n", (int)id, ((out_value.sign) ? '-' : '+'), |
Wayne Roberts |
0:e1e70da93044 | 333 | (int)out_value.out_int, (int)out_value.out_dec); |
Wayne Roberts |
0:e1e70da93044 | 334 | } |
Wayne Roberts |
0:e1e70da93044 | 335 | |
Wayne Roberts |
0:e1e70da93044 | 336 | } |
Wayne Roberts |
0:e1e70da93044 | 337 | } |
Wayne Roberts |
0:e1e70da93044 | 338 | } |
Wayne Roberts |
0:e1e70da93044 | 339 | |
Wayne Roberts |
0:e1e70da93044 | 340 | void demo_sample_pressure(displayFloatToInt_t* x) |
Wayne Roberts |
0:e1e70da93044 | 341 | { |
Wayne Roberts |
0:e1e70da93044 | 342 | Pressure_Sensor_Handler(LPS22HH_P_0_handle, x); |
Wayne Roberts |
0:e1e70da93044 | 343 | } |
Wayne Roberts |
0:e1e70da93044 | 344 | |
Wayne Roberts |
0:e1e70da93044 | 345 | void demo_sample_temp(displayFloatToInt_t* outValue) |
Wayne Roberts |
0:e1e70da93044 | 346 | { |
Wayne Roberts |
0:e1e70da93044 | 347 | Temperature_Sensor_Handler(LPS22HH_T_0_handle, outValue); |
Wayne Roberts |
0:e1e70da93044 | 348 | } |
Wayne Roberts |
0:e1e70da93044 | 349 | |
Wayne Roberts |
0:e1e70da93044 | 350 |