Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
PixyLinkI2C.h@0:4a23b84b733e, 2017-05-17 (annotated)
- Committer:
- ZHAW_Prometheus
- Date:
- Wed May 17 13:08:18 2017 +0000
- Revision:
- 0:4a23b84b733e
PixyTest2 Vers. 17.05.2017
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ZHAW_Prometheus | 0:4a23b84b733e | 1 | #ifndef TUIASI_PIXYLINKI2C_H |
| ZHAW_Prometheus | 0:4a23b84b733e | 2 | #define TUIASI_PIXYLINKI2C_H |
| ZHAW_Prometheus | 0:4a23b84b733e | 3 | |
| ZHAW_Prometheus | 0:4a23b84b733e | 4 | #include "I2C.h" |
| ZHAW_Prometheus | 0:4a23b84b733e | 5 | #include "PixyLink.h" |
| ZHAW_Prometheus | 0:4a23b84b733e | 6 | |
| ZHAW_Prometheus | 0:4a23b84b733e | 7 | class PixyLinkI2C : public PixyLink, private I2C |
| ZHAW_Prometheus | 0:4a23b84b733e | 8 | { |
| ZHAW_Prometheus | 0:4a23b84b733e | 9 | public: |
| ZHAW_Prometheus | 0:4a23b84b733e | 10 | PixyLinkI2C(PinName sda, PinName scl) : |
| ZHAW_Prometheus | 0:4a23b84b733e | 11 | PixyLink(PIXY_DEFAULT_ADDR), I2C(sda, scl) { |
| ZHAW_Prometheus | 0:4a23b84b733e | 12 | }; |
| ZHAW_Prometheus | 0:4a23b84b733e | 13 | |
| ZHAW_Prometheus | 0:4a23b84b733e | 14 | virtual uint16_t getWord() { |
| ZHAW_Prometheus | 0:4a23b84b733e | 15 | uint8_t data[2] = {0, 0}; |
| ZHAW_Prometheus | 0:4a23b84b733e | 16 | I2C::read((int)m_addr, (char *)data, 2); |
| ZHAW_Prometheus | 0:4a23b84b733e | 17 | return ((uint16_t)data[1] << 8) | data[0]; |
| ZHAW_Prometheus | 0:4a23b84b733e | 18 | }; |
| ZHAW_Prometheus | 0:4a23b84b733e | 19 | |
| ZHAW_Prometheus | 0:4a23b84b733e | 20 | virtual uint8_t getByte() { |
| ZHAW_Prometheus | 0:4a23b84b733e | 21 | uint8_t data = 0; |
| ZHAW_Prometheus | 0:4a23b84b733e | 22 | I2C::read((int)m_addr, (char*)&data, 1); |
| ZHAW_Prometheus | 0:4a23b84b733e | 23 | return data; |
| ZHAW_Prometheus | 0:4a23b84b733e | 24 | }; |
| ZHAW_Prometheus | 0:4a23b84b733e | 25 | |
| ZHAW_Prometheus | 0:4a23b84b733e | 26 | virtual int8_t send(uint8_t *data, uint8_t len) { |
| ZHAW_Prometheus | 0:4a23b84b733e | 27 | return I2C::write((int)m_addr, (char*)data, len); |
| ZHAW_Prometheus | 0:4a23b84b733e | 28 | }; |
| ZHAW_Prometheus | 0:4a23b84b733e | 29 | |
| ZHAW_Prometheus | 0:4a23b84b733e | 30 | |
| ZHAW_Prometheus | 0:4a23b84b733e | 31 | private: |
| ZHAW_Prometheus | 0:4a23b84b733e | 32 | static const uint8_t PIXY_DEFAULT_ADDR = 0x54; |
| ZHAW_Prometheus | 0:4a23b84b733e | 33 | }; |
| ZHAW_Prometheus | 0:4a23b84b733e | 34 | |
| ZHAW_Prometheus | 0:4a23b84b733e | 35 | #endif //TUIASI_PIXYLINKI2C_H |