Robot team project
Dependencies: QEI Motordriver ros_lib_melodic
sensor/Sensor.h@1:d5adc483bce0, 2019-10-22 (annotated)
- Committer:
- florine_van
- Date:
- Tue Oct 22 09:41:35 2019 +0000
- Revision:
- 1:d5adc483bce0
- Parent:
- 0:57855aafa907
- Child:
- 2:c537f1ebad7b
Not working code for two sensors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
florine_van | 0:57855aafa907 | 1 | #ifndef _Sensor_h |
florine_van | 0:57855aafa907 | 2 | #define _Sensor_h |
florine_van | 0:57855aafa907 | 3 | |
florine_van | 0:57855aafa907 | 4 | #include "mbed.h" |
florine_van | 0:57855aafa907 | 5 | |
florine_van | 0:57855aafa907 | 6 | #define DEFAULT_SENSOR_ADDRESS 0x29 |
florine_van | 0:57855aafa907 | 7 | |
florine_van | 0:57855aafa907 | 8 | #define FAILURE_RESET -1 |
florine_van | 0:57855aafa907 | 9 | |
florine_van | 0:57855aafa907 | 10 | #define IDENTIFICATION_MODEL_ID 0x0000 |
florine_van | 0:57855aafa907 | 11 | #define IDENTIFICATION_MODEL_REV_MAJOR 0x0001 |
florine_van | 0:57855aafa907 | 12 | #define IDENTIFICATION_MODEL_REV_MINOR 0x0002 |
florine_van | 0:57855aafa907 | 13 | #define IDENTIFICATION_MODULE_REV_MAJOR 0x0003 |
florine_van | 0:57855aafa907 | 14 | #define IDENTIFICATION_MODULE_REV_MINOR 0x0004 |
florine_van | 0:57855aafa907 | 15 | #define IDENTIFICATION_DATE 0x0006 //16bit value |
florine_van | 0:57855aafa907 | 16 | #define IDENTIFICATION_TIME 0x0008 //16bit value |
florine_van | 0:57855aafa907 | 17 | |
florine_van | 0:57855aafa907 | 18 | #define SYSTEM_MODE_GPIO0 0x0010 |
florine_van | 0:57855aafa907 | 19 | #define SYSTEM_MODE_GPIO1 0x0011 |
florine_van | 0:57855aafa907 | 20 | #define SYSTEM_HISTORY_CTRL 0x0012 |
florine_van | 0:57855aafa907 | 21 | #define SYSTEM_INTERRUPT_CONFIG_GPIO 0x0014 |
florine_van | 0:57855aafa907 | 22 | #define SYSTEM_INTERRUPT_CLEAR 0x0015 |
florine_van | 0:57855aafa907 | 23 | #define SYSTEM_FRESH_OUT_OF_RESET 0x0016 |
florine_van | 0:57855aafa907 | 24 | #define SYSTEM_GROUPED_PARAMETER_HOLD 0x0017 |
florine_van | 0:57855aafa907 | 25 | |
florine_van | 0:57855aafa907 | 26 | #define SYSRANGE_START 0x0018 |
florine_van | 0:57855aafa907 | 27 | #define SYSRANGE_THRESH_HIGH 0x0019 |
florine_van | 0:57855aafa907 | 28 | #define SYSRANGE_THRESH_LOW 0x001A |
florine_van | 0:57855aafa907 | 29 | #define SYSRANGE_INTERMEASUREMENT_PERIOD 0x001B |
florine_van | 0:57855aafa907 | 30 | #define SYSRANGE_MAX_CONVERGENCE_TIME 0x001C |
florine_van | 0:57855aafa907 | 31 | #define SYSRANGE_CROSSTALK_COMPENSATION_RATE 0x001E |
florine_van | 0:57855aafa907 | 32 | #define SYSRANGE_CROSSTALK_VALID_HEIGHT 0x0021 |
florine_van | 0:57855aafa907 | 33 | #define SYSRANGE_EARLY_CONVERGENCE_ESTIMATE 0x0022 |
florine_van | 0:57855aafa907 | 34 | #define SYSRANGE_PART_TO_PART_RANGE_OFFSET 0x0024 |
florine_van | 0:57855aafa907 | 35 | #define SYSRANGE_RANGE_IGNORE_VALID_HEIGHT 0x0025 |
florine_van | 0:57855aafa907 | 36 | #define SYSRANGE_RANGE_IGNORE_THRESHOLD 0x0026 |
florine_van | 0:57855aafa907 | 37 | #define SYSRANGE_MAX_AMBIENT_LEVEL_MULT 0x002C |
florine_van | 0:57855aafa907 | 38 | #define SYSRANGE_RANGE_CHECK_ENABLES 0x002D |
florine_van | 0:57855aafa907 | 39 | #define SYSRANGE_VHV_RECALIBRATE 0x002E |
florine_van | 0:57855aafa907 | 40 | #define SYSRANGE_VHV_REPEAT_RATE 0x0031 |
florine_van | 0:57855aafa907 | 41 | |
florine_van | 0:57855aafa907 | 42 | #define SYSALS_START 0x0038 |
florine_van | 0:57855aafa907 | 43 | #define SYSALS_THRESH_HIGH 0x003A |
florine_van | 0:57855aafa907 | 44 | #define SYSALS_THRESH_LOW 0x003C |
florine_van | 0:57855aafa907 | 45 | #define SYSALS_INTERMEASUREMENT_PERIOD 0x003E |
florine_van | 0:57855aafa907 | 46 | #define SYSALS_ANALOGUE_GAIN 0x003F |
florine_van | 0:57855aafa907 | 47 | #define SYSALS_INTEGRATION_PERIOD 0x0040 |
florine_van | 0:57855aafa907 | 48 | |
florine_van | 0:57855aafa907 | 49 | #define RESULT_RANGE_STATUS 0x004D |
florine_van | 0:57855aafa907 | 50 | #define RESULT_ALS_STATUS 0x004E |
florine_van | 0:57855aafa907 | 51 | #define RESULT_INTERRUPT_STATUS_GPIO 0x004F |
florine_van | 0:57855aafa907 | 52 | #define RESULT_ALS_VAL 0x0050 |
florine_van | 0:57855aafa907 | 53 | #define RESULT_HISTORY_BUFFER 0x0052 |
florine_van | 0:57855aafa907 | 54 | #define RESULT_RANGE_VAL 0x0062 |
florine_van | 0:57855aafa907 | 55 | #define RESULT_RANGE_RAW 0x0064 |
florine_van | 0:57855aafa907 | 56 | #define RESULT_RANGE_RETURN_RATE 0x0066 |
florine_van | 0:57855aafa907 | 57 | #define RESULT_RANGE_REFERENCE_RATE 0x0068 |
florine_van | 0:57855aafa907 | 58 | #define RESULT_RANGE_RETURN_SIGNAL_COUNT 0x006C |
florine_van | 0:57855aafa907 | 59 | #define RESULT_RANGE_REFERENCE_SIGNAL_COUNT 0x0070 |
florine_van | 0:57855aafa907 | 60 | #define RESULT_RANGE_RETURN_AMB_COUNT 0x0074 |
florine_van | 0:57855aafa907 | 61 | #define RESULT_RANGE_REFERENCE_AMB_COUNT 0x0078 |
florine_van | 0:57855aafa907 | 62 | #define RESULT_RANGE_RETURN_CONV_TIME 0x007C |
florine_van | 0:57855aafa907 | 63 | #define RESULT_RANGE_REFERENCE_CONV_TIME 0x0080 |
florine_van | 0:57855aafa907 | 64 | |
florine_van | 0:57855aafa907 | 65 | #define READOUT_AVERAGING_SAMPLE_PERIOD 0x010A |
florine_van | 0:57855aafa907 | 66 | #define FIRMWARE_BOOTUP 0x0119 |
florine_van | 0:57855aafa907 | 67 | #define FIRMWARE_RESULT_SCALER 0x0120 |
florine_van | 0:57855aafa907 | 68 | #define I2C_SLAVE_DEVICE_ADDRESS 0x0212 |
florine_van | 0:57855aafa907 | 69 | #define INTERLEAVED_MODE_ENABLE 0x02A3 |
florine_van | 0:57855aafa907 | 70 | |
florine_van | 0:57855aafa907 | 71 | class Sensor{ |
florine_van | 0:57855aafa907 | 72 | |
florine_van | 0:57855aafa907 | 73 | public: |
florine_van | 0:57855aafa907 | 74 | /** Create a VL6180 object at I2C specified address (7 bit). |
florine_van | 0:57855aafa907 | 75 | * |
florine_van | 0:57855aafa907 | 76 | * @param sda I2C sda pin number |
florine_van | 0:57855aafa907 | 77 | * @param scl I2C scl pin number |
florine_van | 0:57855aafa907 | 78 | * @param shdn I2C shdn pin number |
florine_van | 0:57855aafa907 | 79 | */ |
florine_van | 1:d5adc483bce0 | 80 | Sensor(PinName sda, PinName scl, PinName shdn); |
florine_van | 0:57855aafa907 | 81 | |
florine_van | 0:57855aafa907 | 82 | /** Init the sensor |
florine_van | 0:57855aafa907 | 83 | * |
florine_van | 0:57855aafa907 | 84 | */ |
florine_van | 0:57855aafa907 | 85 | int init(); |
florine_van | 0:57855aafa907 | 86 | |
florine_van | 0:57855aafa907 | 87 | /** Make a range reading |
florine_van | 0:57855aafa907 | 88 | * |
florine_van | 0:57855aafa907 | 89 | */ |
florine_van | 0:57855aafa907 | 90 | int read(); |
florine_van | 1:d5adc483bce0 | 91 | |
florine_van | 1:d5adc483bce0 | 92 | void changeAddress(char address); |
florine_van | 1:d5adc483bce0 | 93 | void turnOff(); |
florine_van | 1:d5adc483bce0 | 94 | void turnOn(); |
florine_van | 0:57855aafa907 | 95 | |
florine_van | 0:57855aafa907 | 96 | private: |
florine_van | 0:57855aafa907 | 97 | char addr; |
florine_van | 0:57855aafa907 | 98 | I2C i2c; |
florine_van | 0:57855aafa907 | 99 | DigitalOut SHDN; |
florine_van | 0:57855aafa907 | 100 | void startRange(); |
florine_van | 0:57855aafa907 | 101 | void pollRange(); |
florine_van | 0:57855aafa907 | 102 | int readRange(); |
florine_van | 0:57855aafa907 | 103 | void clearInterrupts(); |
florine_van | 0:57855aafa907 | 104 | void setRegister(wchar_t reg, char data); |
florine_van | 0:57855aafa907 | 105 | void writeByte(wchar_t reg,char data); |
florine_van | 0:57855aafa907 | 106 | char readByte(wchar_t reg); |
florine_van | 0:57855aafa907 | 107 | |
florine_van | 0:57855aafa907 | 108 | }; |
florine_van | 0:57855aafa907 | 109 | #endif |