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