For coursework of group 3 in SOFT564Z
Dependencies: Motordriver ros_lib_kinetic
VL6180.hpp@10:c752a8d76ee2, 2019-12-17 (annotated)
- Committer:
- Jonathan738
- Date:
- Tue Dec 17 16:33:46 2019 +0000
- Revision:
- 10:c752a8d76ee2
- Child:
- 12:82b8fe254222
Added TOF class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jonathan738 | 10:c752a8d76ee2 | 1 | #include "mbed.h" |
Jonathan738 | 10:c752a8d76ee2 | 2 | #include "General.hpp" |
Jonathan738 | 10:c752a8d76ee2 | 3 | #include "rtos.h" |
Jonathan738 | 10:c752a8d76ee2 | 4 | #include "Pins.h" |
Jonathan738 | 10:c752a8d76ee2 | 5 | |
Jonathan738 | 10:c752a8d76ee2 | 6 | #ifndef Define_ONCE_VL6180 |
Jonathan738 | 10:c752a8d76ee2 | 7 | #define Define_ONCE_VL6180 |
Jonathan738 | 10:c752a8d76ee2 | 8 | |
Jonathan738 | 10:c752a8d76ee2 | 9 | #define num_VL6180 1 |
Jonathan738 | 10:c752a8d76ee2 | 10 | #define SHDN_Pins_Cell {PC_9} //, PC_11, PD_2, PG_3} |
Jonathan738 | 10:c752a8d76ee2 | 11 | #define TOF_Addresses {0x29} //, 0x2A, 0x2B, 0x2C} |
Jonathan738 | 10:c752a8d76ee2 | 12 | #define Shifted_TOF_Addresses {0x82} //, 0x84, 0x86, 0x88} |
Jonathan738 | 10:c752a8d76ee2 | 13 | |
Jonathan738 | 10:c752a8d76ee2 | 14 | // Thread that runs TOF sensors |
Jonathan738 | 10:c752a8d76ee2 | 15 | int TOF_Thread(); |
Jonathan738 | 10:c752a8d76ee2 | 16 | |
Jonathan738 | 10:c752a8d76ee2 | 17 | // Class Terminal expects tx and rx pins and is used for controlling a serialy conected terminal |
Jonathan738 | 10:c752a8d76ee2 | 18 | class VL6180 |
Jonathan738 | 10:c752a8d76ee2 | 19 | { |
Jonathan738 | 10:c752a8d76ee2 | 20 | public: |
Jonathan738 | 10:c752a8d76ee2 | 21 | VL6180(I2C& comm_bus, PinName SHDWN, char Address) : shutdown(SHDWN), i2c(comm_bus){addr = Address;}; |
Jonathan738 | 10:c752a8d76ee2 | 22 | |
Jonathan738 | 10:c752a8d76ee2 | 23 | bool Init(void); |
Jonathan738 | 10:c752a8d76ee2 | 24 | bool TOF_PWR(bool State); |
Jonathan738 | 10:c752a8d76ee2 | 25 | void WriteByte(wchar_t reg, char data); |
Jonathan738 | 10:c752a8d76ee2 | 26 | void WriteByte_Uninitialized(wchar_t reg, char data, char Uninitialized_Address); |
Jonathan738 | 10:c752a8d76ee2 | 27 | int Start_Range(void); |
Jonathan738 | 10:c752a8d76ee2 | 28 | int Poll_Range(void); |
Jonathan738 | 10:c752a8d76ee2 | 29 | int Read_Range(void); |
Jonathan738 | 10:c752a8d76ee2 | 30 | int Clear_Interrupts(void); |
Jonathan738 | 10:c752a8d76ee2 | 31 | |
Jonathan738 | 10:c752a8d76ee2 | 32 | private: |
Jonathan738 | 10:c752a8d76ee2 | 33 | // I2C Bus TOF is connected to |
Jonathan738 | 10:c752a8d76ee2 | 34 | I2C& i2c; |
Jonathan738 | 10:c752a8d76ee2 | 35 | // Private functions |
Jonathan738 | 10:c752a8d76ee2 | 36 | char ReadByte(wchar_t reg); |
Jonathan738 | 10:c752a8d76ee2 | 37 | char ReadByte_Uninitialized(wchar_t reg, char Uninitialized_Address); |
Jonathan738 | 10:c752a8d76ee2 | 38 | void WriteByte_Uninitialized(wchar_t reg, char data); |
Jonathan738 | 10:c752a8d76ee2 | 39 | // Private Variables |
Jonathan738 | 10:c752a8d76ee2 | 40 | char addr; |
Jonathan738 | 10:c752a8d76ee2 | 41 | // IOs |
Jonathan738 | 10:c752a8d76ee2 | 42 | DigitalOut shutdown; |
Jonathan738 | 10:c752a8d76ee2 | 43 | }; |
Jonathan738 | 10:c752a8d76ee2 | 44 | |
Jonathan738 | 10:c752a8d76ee2 | 45 | // TypeDef for pointer to the TOF class (needed for dynamic creation of objects) |
Jonathan738 | 10:c752a8d76ee2 | 46 | typedef VL6180* TOFsPtr; |
Jonathan738 | 10:c752a8d76ee2 | 47 | // Function to Initialise all TOF sensors |
Jonathan738 | 10:c752a8d76ee2 | 48 | bool Init_All_TOFs(TOFsPtr *tof); |
Jonathan738 | 10:c752a8d76ee2 | 49 | #endif |