Silica Sensor Node board sends custom ble advertising for the Gateway board

Dependencies:   X_NUCLEO_IKS01A2_SPI3W

Fork of sensor-node-ble by Roberto Spelta

Getting started with mbed SensorNode BLE

Information

History project:

  • 26/01/2017 - First Release

This project uses the Bluetooth Low Energy in order to send advertaisments every second. These payloads are read by the Visible Things Gateway board, more about it here . Every advertaisments contains sensors data read form the SensorTile and the Silica Sensor Board. For details please read the document in the MAN folder,

The application:

  • reads sensors data (accelerometer, gyroscope, lux, pressure, temperature, proximity, magnetometer)
  • send these data by BLE

You can compile this project in three ways:

1. Using the Online compiler.

Information

Learn how to use the Online compiler reading https://docs.mbed.com/docs/mbed-os-handbook/en/latest/dev_tools/online_comp/ page.

2. Using the compiler on your PC

Information

Learn how to use the mbed-cli reading https://docs.mbed.com/docs/mbed-os-handbook/en/latest/dev_tools/cli/ page.
The name of the machine is SILICA_SENSOR_NODE.

3. Exporting to 3rd party tools (IDE)

Information

Learn how to use the mbed-cli reading https://docs.mbed.com/docs/mbed-os-handbook/en/latest/dev_tools/third_party/ page. We have exported the project for you, please read here

Warning

This example requires a Visible Things Gateway board. If you don't have this board you can use RF Connect app from an Android phone just to see the raw data sent from the SensorNode.

Committer:
rspelta
Date:
Fri Jan 26 18:26:48 2018 +0100
Revision:
5:26b07c500aa2
Parent:
3:94aee6f716b7
fix comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rspelta 3:94aee6f716b7 1 /**
rspelta 3:94aee6f716b7 2 * @file VL6180x.h
rspelta 3:94aee6f716b7 3 * @brief Library for VL6180x time of flight range finder.
rspelta 3:94aee6f716b7 4 * Casey Kuhns @ SparkFun Electronics
rspelta 3:94aee6f716b7 5 * 10/29/2014
rspelta 3:94aee6f716b7 6 * https://github.com/sparkfun/
rspelta 3:94aee6f716b7 7 *
rspelta 3:94aee6f716b7 8 * The VL6180x by ST micro is a time of flight range finder that
rspelta 3:94aee6f716b7 9 * uses pulsed IR light to determine distances from object at close
rspelta 3:94aee6f716b7 10 * range. The average range of a sensor is between 0-200mm
rspelta 3:94aee6f716b7 11 *
rspelta 3:94aee6f716b7 12 * In this file are the function prototypes in the VL6180x class
rspelta 3:94aee6f716b7 13 *
rspelta 3:94aee6f716b7 14 * Resources:
rspelta 3:94aee6f716b7 15 * This library uses the Arduino Wire.h to complete I2C transactions.
rspelta 3:94aee6f716b7 16 *
rspelta 3:94aee6f716b7 17 * Development environment specifics:
rspelta 3:94aee6f716b7 18 * IDE: Arduino 1.0.5
rspelta 3:94aee6f716b7 19 * Hardware Platform: Arduino Pro 3.3V/8MHz
rspelta 3:94aee6f716b7 20 * VL6180x Breakout Version: 1.0
rspelta 3:94aee6f716b7 21 *
rspelta 3:94aee6f716b7 22 * Some settings and initial values come from code written by Kris Winer
rspelta 3:94aee6f716b7 23 * VL6180X_t3 Basic Example Code
rspelta 3:94aee6f716b7 24 * by: Kris Winer
rspelta 3:94aee6f716b7 25 * date: September 1, 2014
rspelta 3:94aee6f716b7 26 * license: Beerware - Use this code however you'd like. If you
rspelta 3:94aee6f716b7 27 * find it useful you can buy me a beer some time.
rspelta 3:94aee6f716b7 28 *
rspelta 3:94aee6f716b7 29 * This code is beerware. If you see me (or any other SparkFun employee) at the
rspelta 3:94aee6f716b7 30 * local pub, and you've found our code helpful, please buy us a round!
rspelta 3:94aee6f716b7 31 *
rspelta 3:94aee6f716b7 32 * Distributed as-is; no warranty is given.
rspelta 3:94aee6f716b7 33 */
rspelta 3:94aee6f716b7 34 #include "mbed.h"
rspelta 3:94aee6f716b7 35 #ifndef VL6180x_h
rspelta 3:94aee6f716b7 36 #define VL6180x_h
rspelta 3:94aee6f716b7 37
rspelta 3:94aee6f716b7 38 #define PE180_ADDRESS (0x40<<1)
rspelta 3:94aee6f716b7 39 #define GPIO_SET_DIR_LOW 0x19
rspelta 3:94aee6f716b7 40 #define GPIO_SET_DIR_MID 0x1A
rspelta 3:94aee6f716b7 41 #define GPIO_SET_DIR_HIGH 0x1B
rspelta 3:94aee6f716b7 42
rspelta 3:94aee6f716b7 43 #define GPIO_SET_LOW 0x10
rspelta 3:94aee6f716b7 44 #define GPIO_SET_MID 0x11
rspelta 3:94aee6f716b7 45 #define GPIO_SET_HIGH 0x12
rspelta 3:94aee6f716b7 46
rspelta 3:94aee6f716b7 47 #define GPIO_CLR_LOW 0x13
rspelta 3:94aee6f716b7 48 #define GPIO_CLR_MID 0x14
rspelta 3:94aee6f716b7 49 #define GPIO_CLR_HIGH 0x15
rspelta 3:94aee6f716b7 50
rspelta 3:94aee6f716b7 51 #define VL6180X_ADDRESS (0x29<<1)
rspelta 3:94aee6f716b7 52 #define VL6180x_FAILURE_RESET -1
rspelta 3:94aee6f716b7 53
rspelta 3:94aee6f716b7 54 #define VL6180X_IDENTIFICATION_MODEL_ID 0x0000
rspelta 3:94aee6f716b7 55 #define VL6180X_IDENTIFICATION_MODEL_REV_MAJOR 0x0001
rspelta 3:94aee6f716b7 56 #define VL6180X_IDENTIFICATION_MODEL_REV_MINOR 0x0002
rspelta 3:94aee6f716b7 57 #define VL6180X_IDENTIFICATION_MODULE_REV_MAJOR 0x0003
rspelta 3:94aee6f716b7 58 #define VL6180X_IDENTIFICATION_MODULE_REV_MINOR 0x0004
rspelta 3:94aee6f716b7 59 #define VL6180X_IDENTIFICATION_DATE 0x0006 //16bit value
rspelta 3:94aee6f716b7 60 #define VL6180X_IDENTIFICATION_TIME 0x0008 //16bit value
rspelta 3:94aee6f716b7 61
rspelta 3:94aee6f716b7 62 #define VL6180X_SYSTEM_MODE_GPIO0 0x0010
rspelta 3:94aee6f716b7 63 #define VL6180X_SYSTEM_MODE_GPIO1 0x0011
rspelta 3:94aee6f716b7 64 #define VL6180X_SYSTEM_HISTORY_CTRL 0x0012
rspelta 3:94aee6f716b7 65 #define VL6180X_SYSTEM_INTERRUPT_CONFIG_GPIO 0x0014
rspelta 3:94aee6f716b7 66 #define VL6180X_SYSTEM_INTERRUPT_CLEAR 0x0015
rspelta 3:94aee6f716b7 67 #define VL6180X_SYSTEM_FRESH_OUT_OF_RESET 0x0016
rspelta 3:94aee6f716b7 68 #define VL6180X_SYSTEM_GROUPED_PARAMETER_HOLD 0x0017
rspelta 3:94aee6f716b7 69
rspelta 3:94aee6f716b7 70 #define VL6180X_SYSRANGE_START 0x0018
rspelta 3:94aee6f716b7 71 #define VL6180X_SYSRANGE_THRESH_HIGH 0x0019
rspelta 3:94aee6f716b7 72 #define VL6180X_SYSRANGE_THRESH_LOW 0x001A
rspelta 3:94aee6f716b7 73 #define VL6180X_SYSRANGE_INTERMEASUREMENT_PERIOD 0x001B
rspelta 3:94aee6f716b7 74 #define VL6180X_SYSRANGE_MAX_CONVERGENCE_TIME 0x001C
rspelta 3:94aee6f716b7 75 #define VL6180X_SYSRANGE_CROSSTALK_COMPENSATION_RATE 0x001E
rspelta 3:94aee6f716b7 76 #define VL6180X_SYSRANGE_CROSSTALK_VALID_HEIGHT 0x0021
rspelta 3:94aee6f716b7 77 #define VL6180X_SYSRANGE_EARLY_CONVERGENCE_ESTIMATE 0x0022
rspelta 3:94aee6f716b7 78 #define VL6180X_SYSRANGE_PART_TO_PART_RANGE_OFFSET 0x0024
rspelta 3:94aee6f716b7 79 #define VL6180X_SYSRANGE_RANGE_IGNORE_VALID_HEIGHT 0x0025
rspelta 3:94aee6f716b7 80 #define VL6180X_SYSRANGE_RANGE_IGNORE_THRESHOLD 0x0026
rspelta 3:94aee6f716b7 81 #define VL6180X_SYSRANGE_MAX_AMBIENT_LEVEL_MULT 0x002C
rspelta 3:94aee6f716b7 82 #define VL6180X_SYSRANGE_RANGE_CHECK_ENABLES 0x002D
rspelta 3:94aee6f716b7 83 #define VL6180X_SYSRANGE_VHV_RECALIBRATE 0x002E
rspelta 3:94aee6f716b7 84 #define VL6180X_SYSRANGE_VHV_REPEAT_RATE 0x0031
rspelta 3:94aee6f716b7 85
rspelta 3:94aee6f716b7 86 #define VL6180X_SYSALS_START 0x0038
rspelta 3:94aee6f716b7 87 #define VL6180X_SYSALS_THRESH_HIGH 0x003A
rspelta 3:94aee6f716b7 88 #define VL6180X_SYSALS_THRESH_LOW 0x003C
rspelta 3:94aee6f716b7 89 #define VL6180X_SYSALS_INTERMEASUREMENT_PERIOD 0x003E
rspelta 3:94aee6f716b7 90 #define VL6180X_SYSALS_ANALOGUE_GAIN 0x003F
rspelta 3:94aee6f716b7 91 #define VL6180X_SYSALS_INTEGRATION_PERIOD 0x0040
rspelta 3:94aee6f716b7 92
rspelta 3:94aee6f716b7 93 #define VL6180X_RESULT_RANGE_STATUS 0x004D
rspelta 3:94aee6f716b7 94 #define VL6180X_RESULT_ALS_STATUS 0x004E
rspelta 3:94aee6f716b7 95 #define VL6180X_RESULT_INTERRUPT_STATUS_GPIO 0x004F
rspelta 3:94aee6f716b7 96 #define VL6180X_RESULT_ALS_VAL 0x0050
rspelta 3:94aee6f716b7 97 #define VL6180X_RESULT_HISTORY_BUFFER 0x0052
rspelta 3:94aee6f716b7 98 #define VL6180X_RESULT_RANGE_VAL 0x0062
rspelta 3:94aee6f716b7 99 #define VL6180X_RESULT_RANGE_RAW 0x0064
rspelta 3:94aee6f716b7 100 #define VL6180X_RESULT_RANGE_RETURN_RATE 0x0066
rspelta 3:94aee6f716b7 101 #define VL6180X_RESULT_RANGE_REFERENCE_RATE 0x0068
rspelta 3:94aee6f716b7 102 #define VL6180X_RESULT_RANGE_RETURN_SIGNAL_COUNT 0x006C
rspelta 3:94aee6f716b7 103 #define VL6180X_RESULT_RANGE_REFERENCE_SIGNAL_COUNT 0x0070
rspelta 3:94aee6f716b7 104 #define VL6180X_RESULT_RANGE_RETURN_AMB_COUNT 0x0074
rspelta 3:94aee6f716b7 105 #define VL6180X_RESULT_RANGE_REFERENCE_AMB_COUNT 0x0078
rspelta 3:94aee6f716b7 106 #define VL6180X_RESULT_RANGE_RETURN_CONV_TIME 0x007C
rspelta 3:94aee6f716b7 107 #define VL6180X_RESULT_RANGE_REFERENCE_CONV_TIME 0x0080
rspelta 3:94aee6f716b7 108
rspelta 3:94aee6f716b7 109 #define VL6180X_READOUT_AVERAGING_SAMPLE_PERIOD 0x010A
rspelta 3:94aee6f716b7 110 #define VL6180X_FIRMWARE_BOOTUP 0x0119
rspelta 3:94aee6f716b7 111 #define VL6180X_FIRMWARE_RESULT_SCALER 0x0120
rspelta 3:94aee6f716b7 112 #define VL6180X_I2C_SLAVE_DEVICE_ADDRESS 0x0212
rspelta 3:94aee6f716b7 113 #define VL6180X_INTERLEAVED_MODE_ENABLE 0x02A3
rspelta 3:94aee6f716b7 114
rspelta 3:94aee6f716b7 115 /**
rspelta 3:94aee6f716b7 116 * gain settings for ALS
rspelta 3:94aee6f716b7 117 *Data sheet shows gain values as binary list
rspelta 3:94aee6f716b7 118 */
rspelta 3:94aee6f716b7 119 enum vl6180x_als_gain {
rspelta 3:94aee6f716b7 120
rspelta 3:94aee6f716b7 121 GAIN_20 = 0, // Actual ALS Gain of 20
rspelta 3:94aee6f716b7 122 GAIN_10, // Actual ALS Gain of 10.32
rspelta 3:94aee6f716b7 123 GAIN_5, // Actual ALS Gain of 5.21
rspelta 3:94aee6f716b7 124 GAIN_2_5, // Actual ALS Gain of 2.60
rspelta 3:94aee6f716b7 125 GAIN_1_67, // Actual ALS Gain of 1.72
rspelta 3:94aee6f716b7 126 GAIN_1_25, // Actual ALS Gain of 1.28
rspelta 3:94aee6f716b7 127 GAIN_1 , // Actual ALS Gain of 1.01
rspelta 3:94aee6f716b7 128 GAIN_40, // Actual ALS Gain of 40
rspelta 3:94aee6f716b7 129
rspelta 3:94aee6f716b7 130 };
rspelta 3:94aee6f716b7 131 /**
rspelta 3:94aee6f716b7 132 * VL6180xIdentification
rspelta 3:94aee6f716b7 133 * @brief structure to hold module identification
rspelta 3:94aee6f716b7 134 *
rspelta 3:94aee6f716b7 135 * @param idModel Model number
rspelta 3:94aee6f716b7 136 * @param idModelRevMajor Major revision
rspelta 3:94aee6f716b7 137 * @param idModelRevMinor Minor revision
rspelta 3:94aee6f716b7 138 * @param idModuleRevMajor Module Major revision
rspelta 3:94aee6f716b7 139 * @param idModuleRevMinor Module Minor revision
rspelta 3:94aee6f716b7 140 * @param idDate Date of manufacture
rspelta 3:94aee6f716b7 141 * @param idTime Seconds after midnight manufacture
rspelta 3:94aee6f716b7 142 */
rspelta 3:94aee6f716b7 143 struct VL6180xIdentification {
rspelta 3:94aee6f716b7 144 uint8_t idModel;
rspelta 3:94aee6f716b7 145 uint8_t idModelRevMajor;
rspelta 3:94aee6f716b7 146 uint8_t idModelRevMinor;
rspelta 3:94aee6f716b7 147 uint8_t idModuleRevMajor;
rspelta 3:94aee6f716b7 148 uint8_t idModuleRevMinor;
rspelta 3:94aee6f716b7 149 uint16_t idDate;
rspelta 3:94aee6f716b7 150 uint16_t idTime;
rspelta 3:94aee6f716b7 151 };
rspelta 3:94aee6f716b7 152 /**
rspelta 3:94aee6f716b7 153 * VL6180x tof/als sensor example
rspelta 3:94aee6f716b7 154 *
rspelta 3:94aee6f716b7 155 * @code
rspelta 3:94aee6f716b7 156 #include "mbed.h"
rspelta 3:94aee6f716b7 157 #include <VL6180x.h>
rspelta 3:94aee6f716b7 158
rspelta 3:94aee6f716b7 159 const float GAIN_1 = 1.01; // Actual ALS Gain of 1.01
rspelta 3:94aee6f716b7 160 const float GAIN_1_25 = 1.28; // Actual ALS Gain of 1.28
rspelta 3:94aee6f716b7 161 const float GAIN_1_67 = 1.72; // Actual ALS Gain of 1.72
rspelta 3:94aee6f716b7 162 const float GAIN_2_5 = 2.6; // Actual ALS Gain of 2.60
rspelta 3:94aee6f716b7 163 const float GAIN_5 = 5.21; // Actual ALS Gain of 5.21
rspelta 3:94aee6f716b7 164 const float GAIN_10 = 10.32; // Actual ALS Gain of 10.32
rspelta 3:94aee6f716b7 165 const float GAIN_20 = 20; // Actual ALS Gain of 20
rspelta 3:94aee6f716b7 166 const float GAIN_40 = 40; // Actual ALS Gain of 40
rspelta 3:94aee6f716b7 167
rspelta 3:94aee6f716b7 168
rspelta 3:94aee6f716b7 169 #define VL6180X_ADDRESS 0x29
rspelta 3:94aee6f716b7 170
rspelta 3:94aee6f716b7 171 VL6180xIdentification identification;
rspelta 3:94aee6f716b7 172 // mbed uses 8bit addresses shift address by 1 bit left
rspelta 3:94aee6f716b7 173 VL6180x sensor(D14, D15, VL6180X_ADDRESS<<1);
rspelta 3:94aee6f716b7 174
rspelta 3:94aee6f716b7 175 void printIdentification(struct VL6180xIdentification *temp){
rspelta 3:94aee6f716b7 176 printf("Model ID = ");
rspelta 3:94aee6f716b7 177 printf("%d\n",temp->idModel);
rspelta 3:94aee6f716b7 178
rspelta 3:94aee6f716b7 179 printf("Model Rev = ");
rspelta 3:94aee6f716b7 180 printf("%d",temp->idModelRevMajor);
rspelta 3:94aee6f716b7 181 printf(".");
rspelta 3:94aee6f716b7 182 printf("%d\n",temp->idModelRevMinor);
rspelta 3:94aee6f716b7 183
rspelta 3:94aee6f716b7 184 printf("Module Rev = ");
rspelta 3:94aee6f716b7 185 printf("%d",temp->idModuleRevMajor);
rspelta 3:94aee6f716b7 186 printf(".");
rspelta 3:94aee6f716b7 187 printf("%d\n",temp->idModuleRevMinor);
rspelta 3:94aee6f716b7 188
rspelta 3:94aee6f716b7 189 printf("Manufacture Date = ");
rspelta 3:94aee6f716b7 190 printf("%d",((temp->idDate >> 3) & 0x001F));
rspelta 3:94aee6f716b7 191 printf("/");
rspelta 3:94aee6f716b7 192 printf("%d",((temp->idDate >> 8) & 0x000F));
rspelta 3:94aee6f716b7 193 printf("/1");
rspelta 3:94aee6f716b7 194 printf("%d\n",((temp->idDate >> 12) & 0x000F));
rspelta 3:94aee6f716b7 195 printf(" Phase: ");
rspelta 3:94aee6f716b7 196 printf("%d\n",(temp->idDate & 0x0007));
rspelta 3:94aee6f716b7 197
rspelta 3:94aee6f716b7 198 printf("Manufacture Time (s)= ");
rspelta 3:94aee6f716b7 199 printf("%d\n",(temp->idTime * 2));
rspelta 3:94aee6f716b7 200 printf("\n\n");
rspelta 3:94aee6f716b7 201 }
rspelta 3:94aee6f716b7 202 int main() {
rspelta 3:94aee6f716b7 203
rspelta 3:94aee6f716b7 204 wait_ms(100); // delay .1s
rspelta 3:94aee6f716b7 205
rspelta 3:94aee6f716b7 206 sensor.getIdentification(&identification); // Retrieve manufacture info from device memory
rspelta 3:94aee6f716b7 207 printIdentification(&identification); // Helper function to print all the Module information
rspelta 3:94aee6f716b7 208
rspelta 3:94aee6f716b7 209 if(sensor.VL6180xInit() != 0){
rspelta 3:94aee6f716b7 210 printf("FAILED TO INITALIZE\n"); //Initialize device and check for errors
rspelta 3:94aee6f716b7 211 };
rspelta 3:94aee6f716b7 212
rspelta 3:94aee6f716b7 213 sensor.VL6180xDefautSettings(); //Load default settings to get started.
rspelta 3:94aee6f716b7 214
rspelta 3:94aee6f716b7 215 wait_ms(1000); // delay 1s
rspelta 3:94aee6f716b7 216
rspelta 3:94aee6f716b7 217
rspelta 3:94aee6f716b7 218
rspelta 3:94aee6f716b7 219 while(1) {
rspelta 3:94aee6f716b7 220 //Get Ambient Light level and report in LUX
rspelta 3:94aee6f716b7 221 printf("Ambient Light Level (Lux) = ");
rspelta 3:94aee6f716b7 222
rspelta 3:94aee6f716b7 223 //Input GAIN for light levels,
rspelta 3:94aee6f716b7 224 // GAIN_20 // Actual ALS Gain of 20
rspelta 3:94aee6f716b7 225 // GAIN_10 // Actual ALS Gain of 10.32
rspelta 3:94aee6f716b7 226 // GAIN_5 // Actual ALS Gain of 5.21
rspelta 3:94aee6f716b7 227 // GAIN_2_5 // Actual ALS Gain of 2.60
rspelta 3:94aee6f716b7 228 // GAIN_1_67 // Actual ALS Gain of 1.72
rspelta 3:94aee6f716b7 229 // GAIN_1_25 // Actual ALS Gain of 1.28
rspelta 3:94aee6f716b7 230 // GAIN_1 // Actual ALS Gain of 1.01
rspelta 3:94aee6f716b7 231 // GAIN_40 // Actual ALS Gain of 40
rspelta 3:94aee6f716b7 232
rspelta 3:94aee6f716b7 233 printf("%f\n",sensor.getAmbientLight(GAIN_1) );
rspelta 3:94aee6f716b7 234
rspelta 3:94aee6f716b7 235 //Get Distance and report in mm
rspelta 3:94aee6f716b7 236 printf("Distance measured (mm) = ");
rspelta 3:94aee6f716b7 237 printf("%d\n", sensor.getDistance() );
rspelta 3:94aee6f716b7 238
rspelta 3:94aee6f716b7 239 wait_ms(500);
rspelta 3:94aee6f716b7 240 }
rspelta 3:94aee6f716b7 241 }
rspelta 3:94aee6f716b7 242 * @endcode
rspelta 3:94aee6f716b7 243 */
rspelta 3:94aee6f716b7 244 class VL6180x
rspelta 3:94aee6f716b7 245 {
rspelta 3:94aee6f716b7 246 public:
rspelta 3:94aee6f716b7 247 /**
rspelta 3:94aee6f716b7 248 * VL6180x constructor
rspelta 3:94aee6f716b7 249 *
rspelta 3:94aee6f716b7 250 * @param sda SDA pin
rspelta 3:94aee6f716b7 251 * @param sdl SCL pin
rspelta 3:94aee6f716b7 252 * @param addr addr of the I2C peripheral
rspelta 3:94aee6f716b7 253 */
rspelta 3:94aee6f716b7 254 VL6180x(I2C *i2c, uint8_t addr);
rspelta 3:94aee6f716b7 255 /**
rspelta 3:94aee6f716b7 256 * VL6180x destructor
rspelta 3:94aee6f716b7 257 */
rspelta 3:94aee6f716b7 258 ~VL6180x();
rspelta 3:94aee6f716b7 259 /**
rspelta 3:94aee6f716b7 260 * Send mandatory settings as stated in ST datasheet.
rspelta 3:94aee6f716b7 261 * http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00122600.pdf (Section 1.3)
rspelta 3:94aee6f716b7 262 * @returns 0 if ok
rspelta 3:94aee6f716b7 263 * @returns -1 on error*/
rspelta 3:94aee6f716b7 264 int VL6180xInit(void);
rspelta 3:94aee6f716b7 265 /**
rspelta 3:94aee6f716b7 266 * Use default settings from ST data sheet section 9.
rspelta 3:94aee6f716b7 267 *
rspelta 3:94aee6f716b7 268 * http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00122600.pdf
rspelta 3:94aee6f716b7 269 */
rspelta 3:94aee6f716b7 270 void VL6180xDefautSettings(void);
rspelta 3:94aee6f716b7 271 /**
rspelta 3:94aee6f716b7 272 * Get Range distance in (mm)
rspelta 3:94aee6f716b7 273 * @returns TOF distance in mm
rspelta 3:94aee6f716b7 274 */
rspelta 3:94aee6f716b7 275 uint8_t getDistance();
rspelta 3:94aee6f716b7 276 /**
rspelta 3:94aee6f716b7 277 * Get ALS level in Lux
rspelta 3:94aee6f716b7 278 * @param vl6180x_als_gain gain setting for sensor
rspelta 3:94aee6f716b7 279 * @param sdl SCL pin
rspelta 3:94aee6f716b7 280 * @param addr addr of the I2C peripheral
rspelta 3:94aee6f716b7 281 * @returns light level in Lux
rspelta 3:94aee6f716b7 282 */
rspelta 3:94aee6f716b7 283 float getAmbientLight(vl6180x_als_gain VL6180X_ALS_GAIN);
rspelta 3:94aee6f716b7 284 /**
rspelta 3:94aee6f716b7 285 * Load structure provided by the user with identification info
rspelta 3:94aee6f716b7 286 * Structure example:
rspelta 3:94aee6f716b7 287 * struct VL6180xIdentification
rspelta 3:94aee6f716b7 288 */
rspelta 3:94aee6f716b7 289 void getIdentification(struct VL6180xIdentification *temp);
rspelta 3:94aee6f716b7 290
rspelta 3:94aee6f716b7 291 /**
rspelta 3:94aee6f716b7 292 * Change the default address of the device to allow multiple
rspelta 3:94aee6f716b7 293 * sensors on the bus. Can use up to 127 sensors. New address
rspelta 3:94aee6f716b7 294 * is saved in non-volatile device memory.
rspelta 3:94aee6f716b7 295 * @param old_address current address
rspelta 3:94aee6f716b7 296 * @param new_address desired new address
rspelta 3:94aee6f716b7 297 * @returns new address
rspelta 3:94aee6f716b7 298 */
rspelta 3:94aee6f716b7 299 uint8_t changeAddress(uint8_t old_address, uint8_t new_address);
rspelta 3:94aee6f716b7 300
rspelta 3:94aee6f716b7 301
rspelta 3:94aee6f716b7 302 private:
rspelta 3:94aee6f716b7 303 //Store address given when the class is initialized.
rspelta 3:94aee6f716b7 304 //This value can be changed by the changeAddress() function
rspelta 3:94aee6f716b7 305 I2C *m_i2c;
rspelta 3:94aee6f716b7 306 int m_addr;
rspelta 3:94aee6f716b7 307
rspelta 3:94aee6f716b7 308 /**
rspelta 3:94aee6f716b7 309 * read 8 bit register
rspelta 3:94aee6f716b7 310 * @param registerAddr address for register
rspelta 3:94aee6f716b7 311 * @returns contents of register
rspelta 3:94aee6f716b7 312 */
rspelta 3:94aee6f716b7 313 uint8_t VL6180x_getRegister(uint16_t registerAddr);
rspelta 3:94aee6f716b7 314 /**
rspelta 3:94aee6f716b7 315 * read 16 bit register
rspelta 3:94aee6f716b7 316 * @param registerAddr address for register
rspelta 3:94aee6f716b7 317 * @param returns contents of register
rspelta 3:94aee6f716b7 318 */
rspelta 3:94aee6f716b7 319 uint16_t VL6180x_getRegister16bit(uint16_t registerAddr);
rspelta 3:94aee6f716b7 320 /**
rspelta 3:94aee6f716b7 321 * write 8 bit register
rspelta 3:94aee6f716b7 322 * @param registerAddr address for register
rspelta 3:94aee6f716b7 323 * @returns ERROR
rspelta 3:94aee6f716b7 324 */
rspelta 3:94aee6f716b7 325 void VL6180x_setRegister(uint16_t registerAddr, uint8_t data);
rspelta 3:94aee6f716b7 326 /**
rspelta 3:94aee6f716b7 327 * write 16 bit register
rspelta 3:94aee6f716b7 328 * @param registerAddr address for register
rspelta 3:94aee6f716b7 329 * @returns ERROR
rspelta 3:94aee6f716b7 330 */
rspelta 3:94aee6f716b7 331 void VL6180x_setRegister16bit(uint16_t registerAddr, uint16_t data);
rspelta 3:94aee6f716b7 332
rspelta 3:94aee6f716b7 333 void PE1801_setRegister(uint8_t registerAddr, uint8_t data);
rspelta 3:94aee6f716b7 334 };
rspelta 3:94aee6f716b7 335
rspelta 3:94aee6f716b7 336 #endif