|
33 | 33 |
|
34 | 34 | // TODO - use non-blocking I2C |
35 | 35 | // TODO - support for all-channels sensor read via new command code |
36 | | - // TODO - make dump optional (especially for sensors) |
| 36 | + |
37 | 37 |
|
38 | 38 | enum TrackUnoccupancy |
39 | 39 | { |
|
45 | 45 | // generic class for self-identifying Trainbrains devices |
46 | 46 | class Trainbrains : public IODevice { |
47 | 47 | public: |
48 | | - static void create(VPIN vpin, uint8_t nPins, I2CAddress i2cAddress) { |
49 | | - if (checkNoOverlap(vpin, nPins, i2cAddress)) new Trainbrains(vpin, nPins, i2cAddress); |
| 48 | + static void create(VPIN vpin, uint8_t nPins, I2CAddress i2cAddress,bool debug=false) { |
| 49 | + if (checkNoOverlap(vpin, nPins, i2cAddress)) |
| 50 | + new Trainbrains(vpin, nPins, i2cAddress,debug); |
50 | 51 | } |
51 | 52 |
|
52 | 53 | private: |
53 | 54 | static const byte DT_Unknown=0; |
54 | 55 | static const byte DT_Signal=1; |
55 | 56 | static const byte DT_Turnout=2; |
56 | 57 | static const byte DT_Power=3; |
57 | | - static const byte DT_Track=4; |
| 58 | + static const byte DT_Track=4; |
| 59 | + bool debugme; |
58 | 60 | byte deviceType=0; // 0=none, 1=signal, 2=turnout, 3=power, 4=track |
59 | 61 | uint8_t outputBuffer[10]; |
60 | 62 | uint8_t inputBuffer[10]; |
61 | 63 |
|
62 | 64 | // Constructor |
63 | | - Trainbrains(VPIN vpin, uint8_t nPins, I2CAddress i2cAddress) |
| 65 | + Trainbrains(VPIN vpin, uint8_t nPins, I2CAddress i2cAddress, bool debug) |
64 | 66 | { |
| 67 | + debugme=debug; |
65 | 68 | _firstVpin = vpin; |
66 | 69 | _nPins = nPins; |
67 | 70 | _I2CAddress=i2cAddress; |
@@ -89,17 +92,19 @@ class Trainbrains : public IODevice { |
89 | 92 | DIAG(F("Trainbrains I2C:%s Error:%S"), _I2CAddress.toString(), I2CManager.getErrorMessage(status)); |
90 | 93 | _deviceState = DEVSTATE_FAILED; |
91 | 94 | } |
92 | | - else _dumpBuffers(); |
| 95 | + else { |
| 96 | + if (debugme) _dumpBuffers(); |
| 97 | + } |
93 | 98 | } |
94 | 99 |
|
95 | 100 | void _dumpBuffers() { |
96 | | - StringFormatter::send(&USB_SERIAL,F("<* TB 0x%s\n out:"),_I2CAddress.toString()); |
| 101 | + StringFormatter::send(&USB_SERIAL,F("<* TB %s\n out:"),_I2CAddress.toString()); |
97 | 102 | for (byte i=0;i<sizeof(outputBuffer);i++) { |
98 | | - StringFormatter::send(&USB_SERIAL,F(" %2x"),outputBuffer[i]); |
| 103 | + StringFormatter::send(&USB_SERIAL,F(" %-2x"),outputBuffer[i]); |
99 | 104 | } |
100 | | - StringFormatter::send(&USB_SERIAL,F("\n in:"),_I2CAddress.toString()); |
| 105 | + StringFormatter::send(&USB_SERIAL,F("\n in:")); |
101 | 106 | for (byte i=0;i<sizeof(inputBuffer);i++) { |
102 | | - StringFormatter::send(&USB_SERIAL,F(" %2x"),inputBuffer[i]); |
| 107 | + StringFormatter::send(&USB_SERIAL,F(" %-2x"),inputBuffer[i]); |
103 | 108 | } |
104 | 109 | StringFormatter::send(&USB_SERIAL,F("\n*>\n")); |
105 | 110 | } |
@@ -156,8 +161,8 @@ class Trainbrains : public IODevice { |
156 | 161 | // class retained for backward compatibility. Builds the generic class. |
157 | 162 | class Trainbrains02 { |
158 | 163 | public: |
159 | | - static void create(VPIN vpin, uint8_t nPins, I2CAddress i2cAddress) { |
160 | | - Trainbrains::create(vpin, nPins, i2cAddress); |
| 164 | + static void create(VPIN vpin, uint8_t nPins, I2CAddress i2cAddress, bool debug=false) { |
| 165 | + Trainbrains::create(vpin, nPins, i2cAddress,debug); |
161 | 166 | } |
162 | 167 | }; |
163 | 168 |
|
|
0 commit comments