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.
PixyLinkI2C.h@2:c3a866b20784, 2017-05-17 (annotated)
- Committer:
- ZHAW_Prometheus
- Date:
- Wed May 17 07:37:43 2017 +0000
- Revision:
- 2:c3a866b20784
- Parent:
- 0:a2603d7fa0ac
Vers. 17.05.2017
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ZHAW_Prometheus | 2:c3a866b20784 | 1 | #ifndef PIXYLINKI2C_H |
ZHAW_Prometheus | 2:c3a866b20784 | 2 | #define PIXYLINKI2C_H |
ZHAW_Prometheus | 0:a2603d7fa0ac | 3 | |
ZHAW_Prometheus | 0:a2603d7fa0ac | 4 | #include "I2C.h" |
ZHAW_Prometheus | 0:a2603d7fa0ac | 5 | #include "PixyLink.h" |
ZHAW_Prometheus | 0:a2603d7fa0ac | 6 | |
ZHAW_Prometheus | 0:a2603d7fa0ac | 7 | class PixyLinkI2C : public PixyLink, private I2C |
ZHAW_Prometheus | 0:a2603d7fa0ac | 8 | { |
ZHAW_Prometheus | 0:a2603d7fa0ac | 9 | public: |
ZHAW_Prometheus | 0:a2603d7fa0ac | 10 | PixyLinkI2C(PinName sda, PinName scl) : |
ZHAW_Prometheus | 2:c3a866b20784 | 11 | PixyLink(PIXY_DEFAULT_ADDR), I2C(sda, scl){ |
ZHAW_Prometheus | 2:c3a866b20784 | 12 | I2C::frequency(100000); |
ZHAW_Prometheus | 2:c3a866b20784 | 13 | }; |
ZHAW_Prometheus | 0:a2603d7fa0ac | 14 | |
ZHAW_Prometheus | 0:a2603d7fa0ac | 15 | virtual uint16_t getWord() { |
ZHAW_Prometheus | 0:a2603d7fa0ac | 16 | uint8_t data[2] = {0, 0}; |
ZHAW_Prometheus | 0:a2603d7fa0ac | 17 | I2C::read((int)m_addr, (char *)data, 2); |
ZHAW_Prometheus | 0:a2603d7fa0ac | 18 | return ((uint16_t)data[1] << 8) | data[0]; |
ZHAW_Prometheus | 0:a2603d7fa0ac | 19 | }; |
ZHAW_Prometheus | 0:a2603d7fa0ac | 20 | |
ZHAW_Prometheus | 0:a2603d7fa0ac | 21 | virtual uint8_t getByte() { |
ZHAW_Prometheus | 0:a2603d7fa0ac | 22 | uint8_t data = 0; |
ZHAW_Prometheus | 0:a2603d7fa0ac | 23 | I2C::read((int)m_addr, (char*)&data, 1); |
ZHAW_Prometheus | 0:a2603d7fa0ac | 24 | return data; |
ZHAW_Prometheus | 0:a2603d7fa0ac | 25 | }; |
ZHAW_Prometheus | 0:a2603d7fa0ac | 26 | |
ZHAW_Prometheus | 0:a2603d7fa0ac | 27 | virtual int8_t send(uint8_t *data, uint8_t len) { |
ZHAW_Prometheus | 0:a2603d7fa0ac | 28 | return I2C::write((int)m_addr, (char*)data, len); |
ZHAW_Prometheus | 0:a2603d7fa0ac | 29 | }; |
ZHAW_Prometheus | 0:a2603d7fa0ac | 30 | |
ZHAW_Prometheus | 0:a2603d7fa0ac | 31 | |
ZHAW_Prometheus | 0:a2603d7fa0ac | 32 | private: |
ZHAW_Prometheus | 2:c3a866b20784 | 33 | static const uint8_t PIXY_DEFAULT_ADDR = 0xAC; |
ZHAW_Prometheus | 0:a2603d7fa0ac | 34 | }; |
ZHAW_Prometheus | 0:a2603d7fa0ac | 35 | |
ZHAW_Prometheus | 2:c3a866b20784 | 36 | #endif //PIXYLINKI2C_H |