Sweep a servo according to Proximity sensor measure
Dependencies: Servo X_NUCLEO_6180XA1 mbed
Fork of HelloWorld_6180XA1 by
main.cpp@14:946e62f44f4f, 2015-10-27 (annotated)
- Committer:
- gallonm
- Date:
- Tue Oct 27 15:54:05 2015 +0000
- Revision:
- 14:946e62f44f4f
- Parent:
- 11:657dbe7bf245
- Child:
- 15:b94bc967fecd
Updated all files. Added midlewares
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gallonm | 0:83c628a58feb | 1 | #include "mbed.h" |
gallonm | 8:4c05f7a5bb60 | 2 | #include "x_nucleo_6180xa1.h" |
gallonm | 14:946e62f44f4f | 3 | #include "HmiBBGesture.h" |
gallonm | 4:ccd62fd7e137 | 4 | #include <string.h> |
gallonm | 4:ccd62fd7e137 | 5 | #include <stdlib.h> |
gallonm | 4:ccd62fd7e137 | 6 | #include <stdio.h> |
gallonm | 8:4c05f7a5bb60 | 7 | #include <assert.h> |
gallonm | 8:4c05f7a5bb60 | 8 | |
gallonm | 14:946e62f44f4f | 9 | /* Polling operating modes don`t require callback function that handles IRQ |
gallonm | 14:946e62f44f4f | 10 | Callback functions are used only for measure that require interrupt */ |
gallonm | 14:946e62f44f4f | 11 | |
gallonm | 5:fa65d931bd96 | 12 | #define VL6180X_I2C_SDA I2C_SDA |
gallonm | 5:fa65d931bd96 | 13 | #define VL6180X_I2C_SCL I2C_SCL |
gallonm | 5:fa65d931bd96 | 14 | |
gallonm | 10:5319abadb31e | 15 | //#define RANGE_SINGLE_SHOT_POLLING |
gallonm | 10:5319abadb31e | 16 | //#define ALS_SINGLE_SHOT_POLLING |
gallonm | 10:5319abadb31e | 17 | //#define RANGE_CONTINUOUS_POLLING |
gallonm | 10:5319abadb31e | 18 | //#define ALS_CONTINUOUS_POLLING |
gallonm | 10:5319abadb31e | 19 | //#define RANGE_CONTINUOUS_INTERRUPT |
gallonm | 14:946e62f44f4f | 20 | //#define ALS_CONTINUOUS_INTERRUPT |
gallonm | 11:657dbe7bf245 | 21 | //#define INTERLEAVED_MODE_INTERRUPT |
gallonm | 10:5319abadb31e | 22 | //#define RANGE_CONTINUOUS_POLLING_LOW_THRESHOLD |
gallonm | 10:5319abadb31e | 23 | //#define RANGE_CONTINUOUS_POLLING_HIGH_THRESHOLD |
gallonm | 10:5319abadb31e | 24 | //#define RANGE_CONTINUOUS_POLLING_OUT_OF_WINDOW |
gallonm | 10:5319abadb31e | 25 | //#define ALS_CONTINUOUS_POLLING_LOW_THRESHOLD |
gallonm | 10:5319abadb31e | 26 | //#define ALS_CONTINUOUS_POLLING_HIGH_THRESHOLD |
gallonm | 10:5319abadb31e | 27 | //#define ALS_CONTINUOUS_POLLING_OUT_OF_WINDOW |
gallonm | 10:5319abadb31e | 28 | //#define RANGE_CONTINUOUS_INTERRUPT_LOW_THRESHOLD |
gallonm | 10:5319abadb31e | 29 | //#define RANGE_CONTINUOUS_INTERRUPT_HIGH_THRESHOLD |
gallonm | 10:5319abadb31e | 30 | //#define RANGE_CONTINUOUS_INTERRUPT_OUT_OF_WINDOW |
gallonm | 10:5319abadb31e | 31 | //#define ALS_CONTINUOUS_INTERRUPT_LOW_THRESHOLD |
gallonm | 10:5319abadb31e | 32 | //#define ALS_CONTINUOUS_INTERRUPT_HIGH_THRESHOLD |
gallonm | 10:5319abadb31e | 33 | //#define ALS_CONTINUOUS_INTERRUPT_OUT_OF_WINDOW |
gallonm | 14:946e62f44f4f | 34 | #define HAND_GESTURE |
gallonm | 10:5319abadb31e | 35 | |
gallonm | 14:946e62f44f4f | 36 | /* timer and digital out pin used for debugging */ |
gallonm | 14:946e62f44f4f | 37 | //Timer timer; |
gallonm | 14:946e62f44f4f | 38 | //int start, end; |
gallonm | 14:946e62f44f4f | 39 | //DigitalOut pin(PA_15); |
gallonm | 5:fa65d931bd96 | 40 | |
gallonm | 14:946e62f44f4f | 41 | /* Create a serial object */ |
gallonm | 14:946e62f44f4f | 42 | Serial pc(USBTX, USBRX); |
gallonm | 0:83c628a58feb | 43 | |
gallonm | 8:4c05f7a5bb60 | 44 | DevI2C device_i2c(VL6180X_I2C_SDA, VL6180X_I2C_SCL); |
gallonm | 9:1d0e839edee8 | 45 | static X_NUCLEO_6180XA1 *board=X_NUCLEO_6180XA1::Instance(&device_i2c); |
gallonm | 9:1d0e839edee8 | 46 | |
gallonm | 14:946e62f44f4f | 47 | HmiBBGesture gesture_reco; |
gallonm | 9:1d0e839edee8 | 48 | |
gallonm | 14:946e62f44f4f | 49 | MeasureData_t data_sensor_top, data_sensor_bottom, data_sensor_left, data_sensor_right; |
gallonm | 11:657dbe7bf245 | 50 | |
gallonm | 9:1d0e839edee8 | 51 | /* flags that handle the call to HandleIRQ function */ |
gallonm | 9:1d0e839edee8 | 52 | bool flag_sensor_top=false, flag_sensor_bottom=false, flag_sensor_left=false, flag_sensor_right=false; |
gallonm | 9:1d0e839edee8 | 53 | |
gallonm | 9:1d0e839edee8 | 54 | /* callback functions of the sensors */ |
gallonm | 14:946e62f44f4f | 55 | static void SensorTopIRQ(void) |
gallonm | 9:1d0e839edee8 | 56 | { |
gallonm | 11:657dbe7bf245 | 57 | flag_sensor_top=true; |
gallonm | 14:946e62f44f4f | 58 | board->sensor_top->DisableInterruptMeasureDetectionIRQ(); |
gallonm | 9:1d0e839edee8 | 59 | } |
gallonm | 9:1d0e839edee8 | 60 | |
gallonm | 14:946e62f44f4f | 61 | static void SensorBottomIRQ(void) |
gallonm | 11:657dbe7bf245 | 62 | { |
gallonm | 11:657dbe7bf245 | 63 | flag_sensor_bottom=true; |
gallonm | 14:946e62f44f4f | 64 | board->sensor_bottom->DisableInterruptMeasureDetectionIRQ(); |
gallonm | 11:657dbe7bf245 | 65 | } |
gallonm | 11:657dbe7bf245 | 66 | |
gallonm | 14:946e62f44f4f | 67 | static void SensorLeftIRQ(void) |
gallonm | 11:657dbe7bf245 | 68 | { |
gallonm | 11:657dbe7bf245 | 69 | flag_sensor_left=true; |
gallonm | 14:946e62f44f4f | 70 | board->sensor_left->DisableInterruptMeasureDetectionIRQ(); |
gallonm | 11:657dbe7bf245 | 71 | } |
gallonm | 11:657dbe7bf245 | 72 | |
gallonm | 14:946e62f44f4f | 73 | static void SensorRightIRQ(void) |
gallonm | 11:657dbe7bf245 | 74 | { |
gallonm | 11:657dbe7bf245 | 75 | flag_sensor_right=true; |
gallonm | 14:946e62f44f4f | 76 | board->sensor_right->DisableInterruptMeasureDetectionIRQ(); |
gallonm | 11:657dbe7bf245 | 77 | } |
gallonm | 9:1d0e839edee8 | 78 | |
gallonm | 14:946e62f44f4f | 79 | void OnErrLog(void){}; // FIXME sistemare la funzione per stampare il messaggio che gli viene passato |
gallonm | 14:946e62f44f4f | 80 | // posso ridirigere la OnErrLog come pc.printf(__VA_ARGS__), ma deve essere OnErrLog(...) |
gallonm | 14:946e62f44f4f | 81 | void DISP_ExecLoopBody(void){}; //FIXME sistemare questa funzione |
gallonm | 14:946e62f44f4f | 82 | |
gallonm | 4:ccd62fd7e137 | 83 | int main() |
gallonm | 5:fa65d931bd96 | 84 | { |
gallonm | 14:946e62f44f4f | 85 | int status, status_t, status_b, status_l, status_r; |
gallonm | 14:946e62f44f4f | 86 | |
gallonm | 14:946e62f44f4f | 87 | //device_i2c.frequency(300000); //change i2c frequncy from 100kHz to 400kHz |
gallonm | 14:946e62f44f4f | 88 | pc.baud(115200); //change baudrate of the printf |
gallonm | 14:946e62f44f4f | 89 | |
gallonm | 10:5319abadb31e | 90 | status=board->InitBoard(); |
gallonm | 14:946e62f44f4f | 91 | if(status) |
gallonm | 14:946e62f44f4f | 92 | VL6180x_ErrLog("Failed to init the board!\n\r"); |
gallonm | 10:5319abadb31e | 93 | |
gallonm | 10:5319abadb31e | 94 | #ifdef RANGE_SINGLE_SHOT_POLLING |
gallonm | 14:946e62f44f4f | 95 | status_t=board->sensor_top->StartMeasurement(range_single_shot_polling, NULL, &data_sensor_top, NULL, NULL); |
gallonm | 14:946e62f44f4f | 96 | if(!status_t) |
gallonm | 14:946e62f44f4f | 97 | printf("Top Range: %dmm\n\r",data_sensor_top.range_mm); |
gallonm | 14:946e62f44f4f | 98 | else if(status==INVALID_PARAMS) |
gallonm | 14:946e62f44f4f | 99 | printf("Failed to start measurement!\n\r"); |
gallonm | 14:946e62f44f4f | 100 | else |
gallonm | 14:946e62f44f4f | 101 | printf("Invalid range value!\n\r"); |
gallonm | 14:946e62f44f4f | 102 | status_t=board->sensor_top->StopMeasurement(range_single_shot_polling); |
gallonm | 14:946e62f44f4f | 103 | if(status_t) |
gallonm | 14:946e62f44f4f | 104 | printf("Failed to stop measurement!\n\r"); |
gallonm | 10:5319abadb31e | 105 | #endif |
gallonm | 9:1d0e839edee8 | 106 | |
gallonm | 10:5319abadb31e | 107 | #ifdef ALS_SINGLE_SHOT_POLLING |
gallonm | 14:946e62f44f4f | 108 | status_t=board->sensor_top->StartMeasurement(als_single_shot_polling, NULL, &data_sensor_top, NULL, NULL); |
gallonm | 14:946e62f44f4f | 109 | if(!status_t) |
gallonm | 14:946e62f44f4f | 110 | printf("Top Light: %dlux\n\r",data_sensor_top.lux); |
gallonm | 14:946e62f44f4f | 111 | else if(status==INVALID_PARAMS) |
gallonm | 14:946e62f44f4f | 112 | printf("Failed to start measurement!\n\r"); |
gallonm | 14:946e62f44f4f | 113 | else |
gallonm | 14:946e62f44f4f | 114 | printf("Invalid light value!\n\r"); |
gallonm | 14:946e62f44f4f | 115 | status_t=board->sensor_top->StopMeasurement(als_single_shot_polling); |
gallonm | 14:946e62f44f4f | 116 | if(status_t) |
gallonm | 14:946e62f44f4f | 117 | printf("Failed to stop measurement!\n\r"); |
gallonm | 10:5319abadb31e | 118 | #endif |
gallonm | 10:5319abadb31e | 119 | |
gallonm | 10:5319abadb31e | 120 | #ifdef RANGE_CONTINUOUS_POLLING |
gallonm | 14:946e62f44f4f | 121 | status_t=board->sensor_top->StartMeasurement(range_continuous_polling, NULL, &data_sensor_top, NULL, NULL); |
gallonm | 14:946e62f44f4f | 122 | if(!status_t) |
gallonm | 14:946e62f44f4f | 123 | { |
gallonm | 14:946e62f44f4f | 124 | int i; |
gallonm | 14:946e62f44f4f | 125 | for(i=0;i<10;i++) |
gallonm | 14:946e62f44f4f | 126 | { |
gallonm | 14:946e62f44f4f | 127 | status_t=board->sensor_top->GetMeasurement(range_continuous_polling, &data_sensor_top); |
gallonm | 11:657dbe7bf245 | 128 | if(!status_t) |
gallonm | 14:946e62f44f4f | 129 | printf("Top Range measure %d: %dmm\n\r",i+1,data_sensor_top.range_mm); |
gallonm | 14:946e62f44f4f | 130 | else |
gallonm | 14:946e62f44f4f | 131 | printf("Invalid range value!\n\r"); |
gallonm | 14:946e62f44f4f | 132 | } |
gallonm | 10:5319abadb31e | 133 | } |
gallonm | 14:946e62f44f4f | 134 | else |
gallonm | 14:946e62f44f4f | 135 | printf("Failed to start measurement!\n\r"); |
gallonm | 14:946e62f44f4f | 136 | status_t=board->sensor_top->StopMeasurement(range_continuous_polling); |
gallonm | 14:946e62f44f4f | 137 | if(status_t) |
gallonm | 14:946e62f44f4f | 138 | printf("Failed to stop measurement!\n\r"); |
gallonm | 10:5319abadb31e | 139 | #endif |
gallonm | 10:5319abadb31e | 140 | |
gallonm | 10:5319abadb31e | 141 | #ifdef ALS_CONTINUOUS_POLLING |
gallonm | 14:946e62f44f4f | 142 | status_t=board->sensor_top->StartMeasurement(als_continuous_polling, NULL, &data_sensor_top, NULL, NULL); |
gallonm | 14:946e62f44f4f | 143 | if(!status_t) |
gallonm | 14:946e62f44f4f | 144 | { |
gallonm | 14:946e62f44f4f | 145 | int i; |
gallonm | 14:946e62f44f4f | 146 | for(i=0;i<10;i++) |
gallonm | 14:946e62f44f4f | 147 | { |
gallonm | 14:946e62f44f4f | 148 | status=board->sensor_top->GetMeasurement(als_continuous_polling, &data_sensor_top); |
gallonm | 11:657dbe7bf245 | 149 | if(!status_t) |
gallonm | 14:946e62f44f4f | 150 | printf("Top Light measure %d: %dlux\n\r",i,data_sensor_top.lux); |
gallonm | 14:946e62f44f4f | 151 | else |
gallonm | 14:946e62f44f4f | 152 | printf("Invalid light value!\n\r"); |
gallonm | 14:946e62f44f4f | 153 | } |
gallonm | 9:1d0e839edee8 | 154 | } |
gallonm | 14:946e62f44f4f | 155 | else |
gallonm | 14:946e62f44f4f | 156 | printf("Failed to start measurement!\n\r"); |
gallonm | 14:946e62f44f4f | 157 | status_t=board->sensor_top->StopMeasurement(als_continuous_polling); |
gallonm | 14:946e62f44f4f | 158 | if(status_t) |
gallonm | 14:946e62f44f4f | 159 | printf("Failed to stop measurement!\n\r"); |
gallonm | 10:5319abadb31e | 160 | #endif |
gallonm | 11:657dbe7bf245 | 161 | |
gallonm | 11:657dbe7bf245 | 162 | #ifdef RANGE_CONTINUOUS_INTERRUPT |
gallonm | 14:946e62f44f4f | 163 | status=board->sensor_top->StartMeasurement(range_continuous_interrupt, SensorTopIRQ, &data_sensor_top, NULL, NULL); |
gallonm | 14:946e62f44f4f | 164 | if(!status) |
gallonm | 14:946e62f44f4f | 165 | { |
gallonm | 14:946e62f44f4f | 166 | while(1) |
gallonm | 14:946e62f44f4f | 167 | { |
gallonm | 14:946e62f44f4f | 168 | if(flag_sensor_top) |
gallonm | 14:946e62f44f4f | 169 | { |
gallonm | 14:946e62f44f4f | 170 | flag_sensor_top=false; |
gallonm | 14:946e62f44f4f | 171 | status=board->sensor_top->HandleIRQ(range_continuous_interrupt, &data_sensor_top); |
gallonm | 14:946e62f44f4f | 172 | if(!status) |
gallonm | 14:946e62f44f4f | 173 | printf("Range: %dmm\n\r",data_sensor_top.range_mm); |
gallonm | 14:946e62f44f4f | 174 | else |
gallonm | 14:946e62f44f4f | 175 | printf("Invalid range value!\n\r"); |
gallonm | 14:946e62f44f4f | 176 | } |
gallonm | 14:946e62f44f4f | 177 | } |
gallonm | 14:946e62f44f4f | 178 | } |
gallonm | 14:946e62f44f4f | 179 | else |
gallonm | 14:946e62f44f4f | 180 | printf("Failed to start measurement!\n\r"); |
gallonm | 14:946e62f44f4f | 181 | status=board->sensor_top->StopMeasurement(range_continuous_interrupt); //FIXME per questo modo operativo e per i successivi ad interrupt si deve sistemare la funzione di StopMeasurement in quanto il main sta sempre dentro il ciclo while e quindi non viene mai chiamata StopMeasurement |
gallonm | 14:946e62f44f4f | 182 | if(status) |
gallonm | 14:946e62f44f4f | 183 | printf("Failed to stop measurement!\n\r"); |
gallonm | 10:5319abadb31e | 184 | #endif |
gallonm | 10:5319abadb31e | 185 | |
gallonm | 10:5319abadb31e | 186 | #ifdef ALS_CONTINUOUS_INTERRUPT |
gallonm | 14:946e62f44f4f | 187 | status_t=board->sensor_top->StartMeasurement(als_continuous_interrupt, SensorTopIRQ, &data_sensor_top, NULL, NULL); |
gallonm | 11:657dbe7bf245 | 188 | if(!status_t) |
gallonm | 14:946e62f44f4f | 189 | { |
gallonm | 14:946e62f44f4f | 190 | while(1) |
gallonm | 14:946e62f44f4f | 191 | { |
gallonm | 14:946e62f44f4f | 192 | if(flag_sensor_top) |
gallonm | 14:946e62f44f4f | 193 | { |
gallonm | 14:946e62f44f4f | 194 | flag_sensor_top=false; |
gallonm | 14:946e62f44f4f | 195 | status_t=board->sensor_top->HandleIRQ(als_continuous_interrupt, &data_sensor_top); |
gallonm | 14:946e62f44f4f | 196 | if(!status_t) |
gallonm | 14:946e62f44f4f | 197 | printf("Top Light: %dlux\n\r",data_sensor_top.lux); |
gallonm | 14:946e62f44f4f | 198 | else |
gallonm | 14:946e62f44f4f | 199 | printf("Invalid light value!\n\r"); |
gallonm | 10:5319abadb31e | 200 | } |
gallonm | 14:946e62f44f4f | 201 | } |
gallonm | 14:946e62f44f4f | 202 | } |
gallonm | 14:946e62f44f4f | 203 | else |
gallonm | 14:946e62f44f4f | 204 | printf("Failed to stop measurement!\n\r"); |
gallonm | 14:946e62f44f4f | 205 | status_t=board->sensor_top->StopMeasurement(als_continuous_interrupt); |
gallonm | 14:946e62f44f4f | 206 | if(status_t) |
gallonm | 14:946e62f44f4f | 207 | printf("Failed to stop measurement!\n\r"); |
gallonm | 10:5319abadb31e | 208 | #endif |
gallonm | 9:1d0e839edee8 | 209 | |
gallonm | 10:5319abadb31e | 210 | #ifdef INTERLEAVED_MODE_INTERRUPT |
gallonm | 14:946e62f44f4f | 211 | status_t=board->sensor_top->StartMeasurement(interleaved_mode_interrupt, SensorTopIRQ, &data_sensor_top, NULL, NULL); |
gallonm | 14:946e62f44f4f | 212 | if(!status_t) |
gallonm | 14:946e62f44f4f | 213 | { |
gallonm | 14:946e62f44f4f | 214 | while(1) |
gallonm | 14:946e62f44f4f | 215 | { |
gallonm | 14:946e62f44f4f | 216 | if(flag_sensor_top) |
gallonm | 14:946e62f44f4f | 217 | { |
gallonm | 14:946e62f44f4f | 218 | flag_sensor_top=false; |
gallonm | 14:946e62f44f4f | 219 | status_t=board->sensor_top->HandleIRQ(interleaved_mode_interrupt, &data_sensor_top); |
gallonm | 14:946e62f44f4f | 220 | if(!status_t) |
gallonm | 14:946e62f44f4f | 221 | printf("Top Range: %dmm\tTop Light: %dlux\n\r",data_sensor_top.range_mm, data_sensor_top.lux); |
gallonm | 14:946e62f44f4f | 222 | else |
gallonm | 14:946e62f44f4f | 223 | printf("Invalid range or light value!\n\r"); |
gallonm | 9:1d0e839edee8 | 224 | } |
gallonm | 14:946e62f44f4f | 225 | } |
gallonm | 14:946e62f44f4f | 226 | } |
gallonm | 14:946e62f44f4f | 227 | else |
gallonm | 14:946e62f44f4f | 228 | printf("Failed to stop measurement!\n\r"); |
gallonm | 14:946e62f44f4f | 229 | status_t=board->sensor_top->StopMeasurement(interleaved_mode_interrupt); |
gallonm | 14:946e62f44f4f | 230 | if(status_t) |
gallonm | 14:946e62f44f4f | 231 | printf("Failed to stop measurement!\n\r"); |
gallonm | 10:5319abadb31e | 232 | #endif |
gallonm | 10:5319abadb31e | 233 | |
gallonm | 10:5319abadb31e | 234 | #ifdef RANGE_CONTINUOUS_INTERRUPT_LOW_THRESHOLD |
gallonm | 14:946e62f44f4f | 235 | status_t=board->sensor_top->StartMeasurement(range_continuous_interrupt_low_threshold, SensorTopIRQ, &data_sensor_top, 80, NULL); |
gallonm | 14:946e62f44f4f | 236 | if(!status_t) |
gallonm | 14:946e62f44f4f | 237 | { |
gallonm | 14:946e62f44f4f | 238 | while(1) |
gallonm | 14:946e62f44f4f | 239 | { |
gallonm | 14:946e62f44f4f | 240 | if(flag_sensor_top) |
gallonm | 14:946e62f44f4f | 241 | { |
gallonm | 14:946e62f44f4f | 242 | flag_sensor_top=false; |
gallonm | 14:946e62f44f4f | 243 | status_t=board->sensor_top->HandleIRQ(range_continuous_interrupt_low_threshold, &data_sensor_top); |
gallonm | 14:946e62f44f4f | 244 | if(!status_t) |
gallonm | 14:946e62f44f4f | 245 | printf("Range int low threshold: %dmm\n\r",data_sensor_top.range_mm); |
gallonm | 14:946e62f44f4f | 246 | else |
gallonm | 14:946e62f44f4f | 247 | printf("Invalid range value!\n\r"); |
gallonm | 14:946e62f44f4f | 248 | } |
gallonm | 14:946e62f44f4f | 249 | } |
gallonm | 14:946e62f44f4f | 250 | } |
gallonm | 14:946e62f44f4f | 251 | else |
gallonm | 14:946e62f44f4f | 252 | printf("Failed to start measurement!\n\r"); |
gallonm | 14:946e62f44f4f | 253 | status_t=board->sensor_top->StopMeasurement(range_continuous_interrupt_low_threshold); |
gallonm | 14:946e62f44f4f | 254 | if(status_t) |
gallonm | 14:946e62f44f4f | 255 | printf("Failed to stop measurement!\n\r"); |
gallonm | 10:5319abadb31e | 256 | #endif |
gallonm | 5:fa65d931bd96 | 257 | |
gallonm | 14:946e62f44f4f | 258 | /* Test application Hand Gesture */ |
gallonm | 14:946e62f44f4f | 259 | #ifdef HAND_GESTURE |
gallonm | 14:946e62f44f4f | 260 | int gest_code, prev_gest_code, gest_duration; |
gallonm | 14:946e62f44f4f | 261 | char str[5]; |
gallonm | 14:946e62f44f4f | 262 | char valLeft[] = {'E'}; |
gallonm | 14:946e62f44f4f | 263 | char valRight[] = {'3'}; |
gallonm | 14:946e62f44f4f | 264 | char valTap[] = {'0'}; |
gallonm | 14:946e62f44f4f | 265 | status_l=board->sensor_left->StartMeasurement(range_continuous_interrupt, SensorLeftIRQ, &data_sensor_left, NULL, NULL); |
gallonm | 14:946e62f44f4f | 266 | status_r=board->sensor_right->StartMeasurement(range_continuous_interrupt, SensorRightIRQ, &data_sensor_right, NULL, NULL); |
gallonm | 14:946e62f44f4f | 267 | gesture_reco.Init(150, 100, 200, 60, 500); |
gallonm | 14:946e62f44f4f | 268 | if((!status_l)&&(!status_r)) |
gallonm | 14:946e62f44f4f | 269 | { |
gallonm | 14:946e62f44f4f | 270 | while(1) |
gallonm | 14:946e62f44f4f | 271 | { |
gallonm | 14:946e62f44f4f | 272 | if(flag_sensor_left) |
gallonm | 14:946e62f44f4f | 273 | { |
gallonm | 14:946e62f44f4f | 274 | flag_sensor_left=false; |
gallonm | 14:946e62f44f4f | 275 | status_l=board->sensor_left->HandleIRQ(range_continuous_interrupt, &data_sensor_left); |
gallonm | 14:946e62f44f4f | 276 | //printf("Left range=%dmm\n\r",data_sensor_left.range_mm); |
gallonm | 14:946e62f44f4f | 277 | } |
gallonm | 14:946e62f44f4f | 278 | if(flag_sensor_right) |
gallonm | 14:946e62f44f4f | 279 | { |
gallonm | 14:946e62f44f4f | 280 | flag_sensor_right=false; |
gallonm | 14:946e62f44f4f | 281 | status_r=board->sensor_right->HandleIRQ(range_continuous_interrupt, &data_sensor_right); |
gallonm | 14:946e62f44f4f | 282 | //printf("Right range=%dmm\n\r",data_sensor_right.range_mm); |
gallonm | 14:946e62f44f4f | 283 | } |
gallonm | 14:946e62f44f4f | 284 | if(data_sensor_left.range_mm>400) |
gallonm | 14:946e62f44f4f | 285 | data_sensor_left.range_mm=400; |
gallonm | 14:946e62f44f4f | 286 | if(data_sensor_right.range_mm>400) |
gallonm | 14:946e62f44f4f | 287 | data_sensor_right.range_mm=400; |
gallonm | 14:946e62f44f4f | 288 | gest_code=gesture_reco.Update(data_sensor_right.range_mm, data_sensor_left.range_mm, &gest_duration); |
gallonm | 14:946e62f44f4f | 289 | switch(gest_code) |
gallonm | 14:946e62f44f4f | 290 | { |
gallonm | 14:946e62f44f4f | 291 | case -1: |
gallonm | 14:946e62f44f4f | 292 | break; |
gallonm | 14:946e62f44f4f | 293 | case 0: //tap and start timer |
gallonm | 14:946e62f44f4f | 294 | if(gest_code!=prev_gest_code) |
gallonm | 14:946e62f44f4f | 295 | { |
gallonm | 14:946e62f44f4f | 296 | prev_gest_code=gest_code; |
gallonm | 14:946e62f44f4f | 297 | sprintf(str,"%s","0-"); |
gallonm | 14:946e62f44f4f | 298 | board->display->DisplayDigit(valTap, 1); |
gallonm | 14:946e62f44f4f | 299 | } |
gallonm | 14:946e62f44f4f | 300 | else |
gallonm | 14:946e62f44f4f | 301 | { |
gallonm | 14:946e62f44f4f | 302 | if(strcmp(str,"0-")==0) |
gallonm | 14:946e62f44f4f | 303 | { |
gallonm | 14:946e62f44f4f | 304 | sprintf(str,"-0"); |
gallonm | 14:946e62f44f4f | 305 | board->display->DisplayDigit(valTap, 2); |
gallonm | 14:946e62f44f4f | 306 | } |
gallonm | 14:946e62f44f4f | 307 | else |
gallonm | 14:946e62f44f4f | 308 | { |
gallonm | 14:946e62f44f4f | 309 | sprintf(str,"0-"); |
gallonm | 14:946e62f44f4f | 310 | board->display->DisplayDigit(valTap, 1); |
gallonm | 14:946e62f44f4f | 311 | } |
gallonm | 14:946e62f44f4f | 312 | } |
gallonm | 14:946e62f44f4f | 313 | break; |
gallonm | 14:946e62f44f4f | 314 | case 1: //left to right |
gallonm | 14:946e62f44f4f | 315 | board->display->DisplayDigit(valRight, 3); |
gallonm | 14:946e62f44f4f | 316 | break; |
gallonm | 14:946e62f44f4f | 317 | case 2: //right to left |
gallonm | 14:946e62f44f4f | 318 | board->display->DisplayDigit(valLeft, 0); |
gallonm | 14:946e62f44f4f | 319 | break; |
gallonm | 14:946e62f44f4f | 320 | default: |
gallonm | 14:946e62f44f4f | 321 | printf("Errore!\n\r"); |
gallonm | 14:946e62f44f4f | 322 | } |
gallonm | 14:946e62f44f4f | 323 | } |
gallonm | 14:946e62f44f4f | 324 | } |
gallonm | 14:946e62f44f4f | 325 | else |
gallonm | 14:946e62f44f4f | 326 | printf("Failed to start measurement!\n\r"); |
gallonm | 14:946e62f44f4f | 327 | status_t=board->sensor_top->StopMeasurement(range_continuous_interrupt_low_threshold); |
gallonm | 14:946e62f44f4f | 328 | if(status_t) |
gallonm | 14:946e62f44f4f | 329 | printf("Failed to stop measurement!\n\r"); |
gallonm | 14:946e62f44f4f | 330 | status_t=board->sensor_top->StopMeasurement(als_continuous_interrupt); |
gallonm | 14:946e62f44f4f | 331 | if(status_t) |
gallonm | 14:946e62f44f4f | 332 | printf("Failed to stop measurement!\n\r"); |
gallonm | 14:946e62f44f4f | 333 | #endif |
gallonm | 11:657dbe7bf245 | 334 | |
gallonm | 4:ccd62fd7e137 | 335 | } |
gallonm | 5:fa65d931bd96 | 336 | |
gallonm | 5:fa65d931bd96 | 337 |