![](/media/cache/group/MFR16-new.png.50x50_q85.jpg)
Sweep a servo according to Proximity sensor measure
Dependencies: Servo X_NUCLEO_6180XA1 mbed
Fork of HelloWorld_6180XA1 by
Diff: main.cpp
- Revision:
- 8:4c05f7a5bb60
- Parent:
- 7:865f0c23a183
- Child:
- 9:1d0e839edee8
--- a/main.cpp Tue Sep 29 15:39:05 2015 +0200 +++ b/main.cpp Tue Oct 06 09:09:03 2015 +0200 @@ -1,87 +1,44 @@ #include "mbed.h" -#include "vl6180x_class.h" -#include "STMPE1600_class.h" +#include "x_nucleo_6180xa1.h" #include <string.h> #include <stdlib.h> #include <stdio.h> +#include <assert.h> + #define VL6180X_I2C_SDA I2C_SDA #define VL6180X_I2C_SCL I2C_SCL - -/* Enable e disable function -------------------------------------------------------*/ -#define EXPANDER_I2C_ADDRESS (0x42*2) -#define GPMR 0x10 -#define GPSR 0x12 -#define GPDR 0x14 +//devo wrappare le funzioni del api.c +//posso creare un`unica funzione che dal main chiama la misura di distanza o luce +//gestisco all`interno della classe sensore con uno switch case e slezionare quindi la modalita di misura +//nel main posso definire con dei define i valori (dello switch case) che permettono di selezionare le varie modalita -#define V2_CHIPEN (1<<12) -#define V2_CHIPEN_B (1<<13) -#define V2_CHIPEN_L (1<<14) -#define V2_CHIPEN_R (1<<15) +#define RANGE_SINGLE_SHOT 1 +#define ALS_SINGLE_SHOT 2 +#define RANGE_CONTINUOUS 3 +#define ALS_CONTINUOUS 4 +#define RANGE_CONTINUOUS_ALS_SINGLE_SHOT 5 +#define RANGE_SINGLE_SHOT_ALS_CONTINUOUS 6 +#define INTERLEAVED MODE 7 -/*----------------------------------------------------------------------------------*/ - void OnErrLog(void){}; void DISP_ExecLoopBody(void){}; +DevI2C device_i2c(VL6180X_I2C_SDA, VL6180X_I2C_SCL); +static X_NUCLEO_6180XA1 *board=X_NUCLEO_6180XA1::Instance(&device_i2c); + int main() { - uint8_t buf[8]={1,1,0,0,0,0,0,0}; - static uint32_t tmp; - + /* + uint8_t buf[8]={1,1,1,0,0,0,0,0}; + uint8_t x=0xFF; uint8_t y=0xF7; uint8_t z=0x80; uint8_t k=0x17; - uint8_t g=0xE7; - - DigitalOut led (LED2); - led=1; - - DevI2C device_i2c(VL6180X_I2C_SDA, VL6180X_I2C_SCL); - - STMPE1600DigiOut gpio0(device_i2c, GPIO_0, STMPE1600_DEF_DEVICE_ADDRESS); - STMPE1600DigiOut gpio1(device_i2c, GPIO_1, STMPE1600_DEF_DEVICE_ADDRESS); - STMPE1600DigiOut gpio2(device_i2c, GPIO_2, STMPE1600_DEF_DEVICE_ADDRESS); - STMPE1600DigiOut gpio3(device_i2c, GPIO_3, STMPE1600_DEF_DEVICE_ADDRESS); - STMPE1600DigiOut gpio4(device_i2c, GPIO_4, STMPE1600_DEF_DEVICE_ADDRESS); - STMPE1600DigiOut gpio5(device_i2c, GPIO_5, STMPE1600_DEF_DEVICE_ADDRESS); - STMPE1600DigiOut gpio6(device_i2c, GPIO_6, STMPE1600_DEF_DEVICE_ADDRESS); - STMPE1600DigiOut gpio7(device_i2c, GPIO_7, STMPE1600_DEF_DEVICE_ADDRESS); - STMPE1600DigiOut gpio8(device_i2c, GPIO_8, STMPE1600_DEF_DEVICE_ADDRESS); - - STMPE1600DigiOut gpio9(device_i2c, GPIO_9, STMPE1600_DEF_DEVICE_ADDRESS); - STMPE1600DigiOut gpio10(device_i2c, GPIO_10, STMPE1600_DEF_DEVICE_ADDRESS); - STMPE1600DigiIn gpio11(device_i2c, GPIO_11, STMPE1600_DEF_DEVICE_ADDRESS); - STMPE1600DigiOut gpio12(device_i2c, GPIO_12, STMPE1600_DEF_DEVICE_ADDRESS); - STMPE1600DigiOut gpio13(device_i2c, GPIO_13, STMPE1600_DEF_DEVICE_ADDRESS); - STMPE1600DigiOut gpio14(device_i2c, GPIO_14, STMPE1600_DEF_DEVICE_ADDRESS); - STMPE1600DigiOut gpio15(device_i2c, GPIO_15, STMPE1600_DEF_DEVICE_ADDRESS); - - - - gpio0 = 0; gpio1 = 1; gpio2 = 1; gpio3 = 1; gpio4 = 1; gpio5 = 1; gpio6 = 1; gpio7 = 0; - gpio8 = 1; gpio9 = 1; gpio10 = 1; gpio12 = 1; gpio13 = 1; gpio14 = 1; gpio15 = 1; - -//STMPE1600DigiOut * p_exp = new STMPE1600DigiOut(device_i2c, GPIO_12, STMPE1600_DEF_DEVICE_ADDRESS); - - VL6180X sensor1(device_i2c, gpio12); - - sensor1.VL6180x_Off(); - sensor1.VL6180x_On(); -// tmp = sensor1.Init(); - - static uint8_t id=0; - id = sensor1.ReadID(); // read id to test - sensor1.VL6180x_SetI2CAddress(sensor1.DevData, 0x10); - id=0; - id = sensor1.ReadID(); // read id to test -// VL6180X sensor1(device_i2c, exp); - - - while (1); + uint8_t g=0xE7; //imposto GPIO di input e output device_i2c.i2c_write(&x, 0x42*2, 0x14, 1); @@ -90,42 +47,16 @@ device_i2c.i2c_write(&z, 0x42*2, 0x12, 1); device_i2c.i2c_write(&g, 0x42*2, 0x13, 1); //spengo gpio0 device_i2c.i2c_write(&k, 0x42*2, 0x13, 1); //accendo gpio0 + */ - //VL6180x_I2CRead(0x29, (uint16_t)0x000, buf, 2); - //VL6180x_I2CRead(0x29, (uint16_t)0x212, buf+1, 2); - //buf[2]=0x32; - //VL6180x_I2CWrite(0x29, (uint16_t)0x0212, buf+2, 1); - //VL6180x_I2CRead(0x32, (uint16_t)0x212, buf+3, 2); - buf[0]=sensor1.Init(); - buf[1]=sensor1.ReadID(); - //buf[2]=sensor1.Prepare(); - //sensor1.~VL6180X(); - - /* - X_NUCLEO_6180XA1 board; - - status=board.vl6180x_top.RdByte(IDENTIFICATION_MODEL_ID, &buffer); - if(!status) - { - board.vl6180x_top.SetPresent(); - board.vl6180x_top.SetDeviceID(i); - if(!(board.vl6180x_top.Init()||board.vl6180x_top.Prepare())) - { - board.vl6180x_top.SetReady(); - status=board.vl6180x_top.SetI2CAddress(final_i2c_address); - if(status) - errore su scrittura indirizzo i2c - } - else - errore su init o prepare - } - i++; + //X_NUCLEO_6180XA1 board(&device_i2c); - //stessa cosa per gli altri sensori (left, bottom e right) - - */ + board->InitBoard(); + board->sensor_top->StartMeasurement(RANGE_SINGLE_SHOT); + + //board.~X_NUCLEO_6180XA1(); }