Prometheus / Pixy

Dependents:   PixyTest PixyTest

Committer:
ZHAW_Prometheus
Date:
Fri May 05 12:03:13 2017 +0000
Revision:
0:a2603d7fa0ac
Child:
2:c3a866b20784
Vers-0.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ZHAW_Prometheus 0:a2603d7fa0ac 1 #ifndef TUIASI_PIXYLINKI2C_H
ZHAW_Prometheus 0:a2603d7fa0ac 2 #define TUIASI_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 0:a2603d7fa0ac 11 PixyLink(PIXY_DEFAULT_ADDR), I2C(sda, scl) {
ZHAW_Prometheus 0:a2603d7fa0ac 12 };
ZHAW_Prometheus 0:a2603d7fa0ac 13
ZHAW_Prometheus 0:a2603d7fa0ac 14 virtual uint16_t getWord() {
ZHAW_Prometheus 0:a2603d7fa0ac 15 uint8_t data[2] = {0, 0};
ZHAW_Prometheus 0:a2603d7fa0ac 16 I2C::read((int)m_addr, (char *)data, 2);
ZHAW_Prometheus 0:a2603d7fa0ac 17 return ((uint16_t)data[1] << 8) | data[0];
ZHAW_Prometheus 0:a2603d7fa0ac 18 };
ZHAW_Prometheus 0:a2603d7fa0ac 19
ZHAW_Prometheus 0:a2603d7fa0ac 20 virtual uint8_t getByte() {
ZHAW_Prometheus 0:a2603d7fa0ac 21 uint8_t data = 0;
ZHAW_Prometheus 0:a2603d7fa0ac 22 I2C::read((int)m_addr, (char*)&data, 1);
ZHAW_Prometheus 0:a2603d7fa0ac 23 return data;
ZHAW_Prometheus 0:a2603d7fa0ac 24 };
ZHAW_Prometheus 0:a2603d7fa0ac 25
ZHAW_Prometheus 0:a2603d7fa0ac 26 virtual int8_t send(uint8_t *data, uint8_t len) {
ZHAW_Prometheus 0:a2603d7fa0ac 27 return I2C::write((int)m_addr, (char*)data, len);
ZHAW_Prometheus 0:a2603d7fa0ac 28 };
ZHAW_Prometheus 0:a2603d7fa0ac 29
ZHAW_Prometheus 0:a2603d7fa0ac 30
ZHAW_Prometheus 0:a2603d7fa0ac 31 private:
ZHAW_Prometheus 0:a2603d7fa0ac 32 static const uint8_t PIXY_DEFAULT_ADDR = 0x54;
ZHAW_Prometheus 0:a2603d7fa0ac 33 };
ZHAW_Prometheus 0:a2603d7fa0ac 34
ZHAW_Prometheus 0:a2603d7fa0ac 35 #endif //TUIASI_PIXYLINKI2C_H