Shrink debug code in TWIBus and disable by default

This commit is contained in:
Scott Lahteine 2016-04-20 12:35:56 -07:00
parent 21a6b66807
commit 1addb50b62
2 changed files with 42 additions and 13 deletions

View file

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

View file

@ -23,6 +23,11 @@
#ifndef TWIBUS_H
#define TWIBUS_H
#include "macros.h"
// Print debug messages with M111 S2 (Uses 236 bytes of PROGMEM)
//#define DEBUG_TWIBUS
/**
* TWIBUS class
*
@ -117,6 +122,16 @@ class TWIBus {
* @param bytes the number of bytes to request
*/
void reqbytes(uint8_t bytes);
#if ENABLED(DEBUG_TWIBUS)
/**
* @brief Prints a debug message
* @details Prints a simple debug message "TWIBus::function: value"
*/
static void debug(const char func[], int32_t val = -1);
#endif
};
#endif //TWIBUS_H