|
|
@ -42,25 +42,26 @@ void TWIBus::reset() {
|
|
|
|
void TWIBus::address(uint8_t addr) {
|
|
|
|
void TWIBus::address(uint8_t addr) {
|
|
|
|
this->addr = addr;
|
|
|
|
this->addr = addr;
|
|
|
|
|
|
|
|
|
|
|
|
if (DEBUGGING(INFO)) {
|
|
|
|
#if ENABLED(DEBUG_TWIBUS)
|
|
|
|
SERIAL_ECHOPAIR("TWIBus::sendto: ", this->addr);
|
|
|
|
debug(PSTR("sendto"), this->addr);
|
|
|
|
SERIAL_EOL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TWIBus::addbyte(char c) {
|
|
|
|
void TWIBus::addbyte(char c) {
|
|
|
|
if (buffer_s >= sizeof(this->buffer)) return;
|
|
|
|
if (buffer_s >= sizeof(this->buffer)) return;
|
|
|
|
this->buffer[this->buffer_s++] = c;
|
|
|
|
this->buffer[this->buffer_s++] = c;
|
|
|
|
|
|
|
|
|
|
|
|
if (DEBUGGING(INFO)) {
|
|
|
|
#if ENABLED(DEBUG_TWIBUS)
|
|
|
|
SERIAL_ECHOPAIR("TWIBus::addbyte: ", this->buffer[this->buffer_s -1]);
|
|
|
|
debug(PSTR("addbyte"), this->buffer[this->buffer_s - 1]);
|
|
|
|
SERIAL_EOL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TWIBus::send() {
|
|
|
|
void TWIBus::send() {
|
|
|
|
if (!this->addr) return;
|
|
|
|
if (!this->addr) return;
|
|
|
|
if (DEBUGGING(INFO)) SERIAL_ECHOLNPGM("TWIBus::send()");
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(DEBUG_TWIBUS)
|
|
|
|
|
|
|
|
debug(PSTR("send()"));
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
Wire.beginTransmission(this->addr);
|
|
|
|
Wire.beginTransmission(this->addr);
|
|
|
|
Wire.write(this->buffer, this->buffer_s);
|
|
|
|
Wire.write(this->buffer, this->buffer_s);
|
|
|
@ -72,10 +73,10 @@ void TWIBus::send() {
|
|
|
|
|
|
|
|
|
|
|
|
void TWIBus::reqbytes(uint8_t bytes) {
|
|
|
|
void TWIBus::reqbytes(uint8_t bytes) {
|
|
|
|
if (!this->addr) return;
|
|
|
|
if (!this->addr) return;
|
|
|
|
if (DEBUGGING(INFO)) {
|
|
|
|
|
|
|
|
SERIAL_ECHOPAIR("TWIBus::reqbytes(): ", bytes);
|
|
|
|
#if ENABLED(DEBUG_TWIBUS)
|
|
|
|
SERIAL_EOL;
|
|
|
|
debug(PSTR("reqbytes"), bytes);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
millis_t t = millis() + this->timeout;
|
|
|
|
millis_t t = millis() + this->timeout;
|
|
|
|
Wire.requestFrom(this->addr, bytes);
|
|
|
|
Wire.requestFrom(this->addr, bytes);
|
|
|
@ -101,4 +102,17 @@ void TWIBus::reqbytes(uint8_t bytes) {
|
|
|
|
this->reset();
|
|
|
|
this->reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(DEBUG_TWIBUS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TWIBus::debug(const char func[], int32_t val/*=-1*/) {
|
|
|
|
|
|
|
|
if (DEBUGGING(INFO)) {
|
|
|
|
|
|
|
|
SERIAL_ECHOPGM("TWIBus::");
|
|
|
|
|
|
|
|
serialprintPGM(func);
|
|
|
|
|
|
|
|
if (val >= 0) SERIAL_ECHOPAIR(": ", val);
|
|
|
|
|
|
|
|
SERIAL_EOL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#endif //EXPERIMENTAL_I2CBUS
|
|
|
|
#endif //EXPERIMENTAL_I2CBUS
|
|
|
|