|
| 1 | +#include "config/flags.h" |
| 2 | +#if defined NORMAL_BOARD |
| 3 | + |
| 4 | +#include "APDS_Sensor_NanoV2.h" |
| 5 | + |
| 6 | +void APDS_Sensor_NanoV2::start() { |
| 7 | + if (APDS.begin()) { |
| 8 | + available = true; |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +void APDS_Sensor_NanoV2::end() { |
| 13 | + APDS.end(); |
| 14 | + available = false; |
| 15 | +} |
| 16 | + |
| 17 | +void APDS_Sensor_NanoV2::get_data(int sensorID, byte *data) { |
| 18 | + switch (sensorID) { |
| 19 | + case APDS_COLOUR_NANOV2: { |
| 20 | + int r, g, b; |
| 21 | + get_color(r, g, b); |
| 22 | + uint16_t * arr = (uint16_t*)data; |
| 23 | + arr[0] = (uint16_t)r; |
| 24 | + arr[1] = (uint16_t)g; |
| 25 | + arr[2] = (uint16_t)b; |
| 26 | + break; |
| 27 | + } |
| 28 | + case APDS_BRIGHT_NANOV2: { |
| 29 | + uint16_t * arr = (uint16_t*)data; |
| 30 | + arr[0] = get_light(); |
| 31 | + break; |
| 32 | + } |
| 33 | + case APDS_PROX_NANOV2: { |
| 34 | + uint16_t * arr = (uint16_t*)data; |
| 35 | + arr[0] = get_proximity(); |
| 36 | + break; |
| 37 | + } |
| 38 | + case APDS_GEST_NANOV2: { |
| 39 | + int8_t * arr = (int8_t*)data; |
| 40 | + arr[0] = get_gesture(); |
| 41 | + break; |
| 42 | + } |
| 43 | + default: |
| 44 | + break; |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +void APDS_Sensor_NanoV2::get_color(int& r, int& g, int& b) { |
| 49 | + if (!available) { |
| 50 | + return; |
| 51 | + } |
| 52 | + while (! APDS.colorAvailable()) { |
| 53 | + delay(2); |
| 54 | + } |
| 55 | + // In library is only uint16; later converted |
| 56 | + APDS.readColor(r, g, b); |
| 57 | + |
| 58 | +} |
| 59 | + |
| 60 | +uint16_t APDS_Sensor_NanoV2::get_light() { |
| 61 | + if (!available) { |
| 62 | + return 0; |
| 63 | + } |
| 64 | + while (! APDS.colorAvailable()) { |
| 65 | + delay(2); |
| 66 | + } |
| 67 | + |
| 68 | + int r, g, b, c; |
| 69 | + APDS.readColor(r, g, b, c); |
| 70 | + // In library is only uint16 |
| 71 | + return (uint16_t)c; |
| 72 | +} |
| 73 | + |
| 74 | +uint8_t APDS_Sensor_NanoV2::get_proximity() { |
| 75 | + if (!available) { |
| 76 | + return -1; |
| 77 | + } |
| 78 | + while (! APDS.proximityAvailable()) { |
| 79 | + delay(2); |
| 80 | + } |
| 81 | + // In library is only uint8 |
| 82 | + return (uint8_t)APDS.readProximity(); |
| 83 | +} |
| 84 | + |
| 85 | +// Warning if gesture is turned on then it will wait for a gesture!!! |
| 86 | +int8_t APDS_Sensor_NanoV2::get_gesture() { |
| 87 | + if (!available) { |
| 88 | + return -1; |
| 89 | + } |
| 90 | + while (! APDS.gestureAvailable()) { |
| 91 | + delay(2); |
| 92 | + } |
| 93 | + |
| 94 | + // In library is only int8 |
| 95 | + return (int8_t)APDS.readGesture(); |
| 96 | +} |
| 97 | + |
| 98 | +int APDS_Sensor_NanoV2::get_sensor_count() { |
| 99 | + return sensor_count; |
| 100 | +} |
| 101 | + |
| 102 | +#endif |
0 commit comments