27
27
#ifdef ARDUINO
28
28
29
29
30
- uint8_t pinRx = 8 ; // Rx led pin
31
- uint8_t pinTx = 9 ; // Tx led pin
32
- uint8_t pinEr = 7 ; // Err led pin
33
30
uint8_t inclusionTime = 1 ; // Number of minutes inclusion mode is enabled
34
31
uint8_t pinInclusion = 3 ; // Input pin that should trigger inclusion mode
35
32
36
33
#define MAX_RECEIVE_LENGTH 100 // Max buffersize needed for messages coming from controller
37
34
#define MAX_SEND_LENGTH 120 // Max buffersize needed for messages destined for controller
38
35
39
36
volatile boolean buttonTriggeredInclusion ;
40
- volatile uint8_t countRx ;
41
- volatile uint8_t countTx ;
42
- volatile uint8_t countErr ;
43
37
boolean inclusionMode ; // Keeps track on inclusion mode
44
38
void (* serial )(const char * fmt , ... );
45
39
46
40
MyParserSerial parser ;
47
41
48
42
void setInclusionMode (boolean newMode );
49
- void txBlink (uint8_t cnt );
50
- void rxBlink (uint8_t cnt );
51
- void errBlink (uint8_t cnt );
52
43
53
44
char convBuf [MAX_PAYLOAD * 2 + 1 ];
54
45
char serialBuffer [MAX_SEND_LENGTH ]; // Buffer for building string when sending data to vera
55
46
unsigned long inclusionStartTime ;
56
47
57
- void setupGateway (uint8_t _rx , uint8_t _tx , uint8_t _er , uint8_t _inc , uint8_t _incTime , void (* _serial )(const char * , ... )) {
48
+ void setupGateway (uint8_t _inc , uint8_t _incTime , void (* _serial )(const char * , ... )) {
58
49
inclusionMode = 0 ;
59
50
buttonTriggeredInclusion = false;
60
51
serial = _serial ;
61
52
62
- pinRx = _rx ;
63
- pinTx = _tx ;
64
- pinEr = _er ;
65
53
pinInclusion = _inc ;
66
54
inclusionTime = _incTime ;
67
55
68
- countRx = 0 ;
69
- countTx = 0 ;
70
- countErr = 0 ;
71
-
72
-
73
- // Setup led pins
74
- pinMode (pinRx , OUTPUT );
75
- pinMode (pinTx , OUTPUT );
76
- pinMode (pinEr , OUTPUT );
77
- digitalWrite (pinRx , LOW );
78
- digitalWrite (pinTx , LOW );
79
- digitalWrite (pinEr , LOW );
80
-
81
56
// Setup digital in that triggers inclusion mode
82
57
pinMode (pinInclusion , INPUT );
83
58
digitalWrite (pinInclusion , HIGH );
84
-
85
- // Set initial state of leds
86
- digitalWrite (pinRx , HIGH );
87
- digitalWrite (pinTx , HIGH );
88
- digitalWrite (pinEr , HIGH );
89
-
90
59
}
91
60
92
61
@@ -96,11 +65,11 @@ void startInclusionInterrupt() {
96
65
}
97
66
98
67
void incomingMessage (const MyMessage & message ) {
99
- if (mGetCommand (message ) == C_PRESENTATION && inclusionMode ) {
100
- rxBlink (3 );
101
- } else {
102
- rxBlink (1 );
103
- }
68
+ // if (mGetCommand(message) == C_PRESENTATION && inclusionMode) {
69
+ // gw. rxBlink(3);
70
+ // } else {
71
+ // gw. rxBlink(1);
72
+ // }
104
73
// Pass along the message from sensors to serial line
105
74
serial (PSTR ("%d;%d;%d;%d;%d;%s\n" ),message .sender , message .sensor , mGetCommand (message ), mGetAck (message ), message .type , message .getString (convBuf ));
106
75
}
@@ -126,7 +95,7 @@ void checkInclusionFinished() {
126
95
}
127
96
}
128
97
129
- void parseAndSend (MySensor gw , char * commandBuffer ) {
98
+ void parseAndSend (MySensor & gw , char * commandBuffer ) {
130
99
boolean ok ;
131
100
MyMessage & msg = gw .getLastMessage ();
132
101
@@ -143,10 +112,14 @@ void parseAndSend(MySensor gw, char *commandBuffer) {
143
112
setInclusionMode (atoi (msg .data ) == 1 );
144
113
}
145
114
} else {
146
- txBlink (1 );
115
+ #ifdef WITH_LEDS_BLINKING
116
+ gw .txBlink (1 );
117
+ #endif
147
118
ok = gw .sendRoute (msg );
148
119
if (!ok ) {
149
- errBlink (1 );
120
+ #ifdef WITH_LEDS_BLINKING
121
+ gw .errBlink (1 );
122
+ #endif
150
123
}
151
124
}
152
125
}
@@ -165,50 +138,6 @@ void setInclusionMode(boolean newMode) {
165
138
}
166
139
167
140
168
-
169
-
170
- void ledTimersInterrupt () {
171
- if (countRx && countRx != 255 ) {
172
- // switch led on
173
- digitalWrite (pinRx , LOW );
174
- } else if (!countRx ) {
175
- // switching off
176
- digitalWrite (pinRx , HIGH );
177
- }
178
- if (countRx != 255 ) { countRx -- ; }
179
-
180
- if (countTx && countTx != 255 ) {
181
- // switch led on
182
- digitalWrite (pinTx , LOW );
183
- } else if (!countTx ) {
184
- // switching off
185
- digitalWrite (pinTx , HIGH );
186
- }
187
- if (countTx != 255 ) { countTx -- ; }
188
- else if (inclusionMode ) { countTx = 8 ; }
189
-
190
- if (countErr && countErr != 255 ) {
191
- // switch led on
192
- digitalWrite (pinEr , LOW );
193
- } else if (!countErr ) {
194
- // switching off
195
- digitalWrite (pinEr , HIGH );
196
- }
197
- if (countErr != 255 ) { countErr -- ; }
198
- }
199
-
200
- void rxBlink (uint8_t cnt ) {
201
- if (countRx == 255 ) { countRx = cnt ; }
202
- }
203
- void txBlink (uint8_t cnt ) {
204
- if (countTx == 255 && !inclusionMode ) { countTx = cnt ; }
205
- }
206
- void errBlink (uint8_t cnt ) {
207
- if (countErr == 255 ) { countErr = cnt ; }
208
- }
209
-
210
-
211
-
212
141
#else
213
142
#error This example is only for use on Arduino.
214
143
#endif // ARDUINO
0 commit comments