@@ -17,7 +17,7 @@ void updateRadioState()
1717 hopChannel ();
1818
1919 // Check to see if we need to send a ping
20- else if ( (millis () - packetTimestamp) > (settings.heartbeatTimeout + random (0 , 1000 )) // Avoid pinging each other at same time
20+ else if ( (millis () - packetTimestamp) > (unsigned int )( settings.heartbeatTimeout + random (0 , 1000 )) // Avoid pinging each other at same time
2121 || sentFirstPing == false ) // Immediately send pings at POR
2222 {
2323 if (receiveInProcess () == false )
@@ -46,7 +46,7 @@ void updateRadioState()
4646 // We're done transmitting our ack packet
4747 // Yay! Return to normal communication
4848 packetsLost = 0 ; // Reset, used for linkLost testing
49- digitalWrite (pin_linkLED, HIGH);
49+ updateRSSI (); // Adjust LEDs to RSSI level. We will soon be linked.
5050 returnToReceiving ();
5151 changeState (RADIO_LINKED_RECEIVING_STANDBY);
5252 }
@@ -96,7 +96,7 @@ void updateRadioState()
9696 {
9797 // Yay! Return to normal communication
9898 packetsLost = 0 ; // Reset, used for linkLost testing
99- digitalWrite (pin_linkLED, HIGH);
99+ updateRSSI (); // Adjust LEDs to RSSI level
100100 returnToReceiving ();
101101 changeState (RADIO_LINKED_RECEIVING_STANDBY);
102102 }
@@ -108,11 +108,14 @@ void updateRadioState()
108108 else if (packetType == PACKET_PING)
109109 {
110110 triggerEvent (TRIGGER_NOLINK_IDENT_PACKET);
111+ updateRSSI (); // Adjust LEDs to RSSI level. We will soon be linked.
111112 sendAckPacket (); // Someone is pinging us
112113 changeState (RADIO_NO_LINK_TRANSMITTING);
113114 }
114115 else if (packetType == PACKET_DATA)
116+ {
115117 ; // No data packets allowed when not linked
118+ }
116119 }
117120 break ;
118121
@@ -122,7 +125,7 @@ void updateRadioState()
122125 {
123126 if (linkLost ())
124127 {
125- digitalWrite (pin_linkLED, LOW );
128+ setRSSI ( 0 );
126129
127130 // Return to home channel and begin linking process
128131 returnToReceiving ();
@@ -139,7 +142,7 @@ void updateRadioState()
139142 else if (timeToHop == true ) // If the dio1ISR has fired, move to next frequency
140143 hopChannel ();
141144
142- else if ((millis () - packetTimestamp) > (settings.heartbeatTimeout + random (0 , 1000 ))) // Avoid pinging each other at same time
145+ else if ((millis () - packetTimestamp) > (unsigned int )( settings.heartbeatTimeout + random (0 , 1000 ))) // Avoid pinging each other at same time
143146 {
144147 if (receiveInProcess () == false )
145148 {
@@ -190,7 +193,7 @@ void updateRadioState()
190193 sendCommandDataPacket ();
191194 }
192195
193- if (availableTXCommandBytes () == 0 )
196+ if (availableTXCommandBytes () == 0 )
194197 printerEndpoint = PRINT_TO_SERIAL; // Once the response is received, we need to print it to serial
195198
196199 changeState (RADIO_LINKED_TRANSMITTING);
@@ -285,6 +288,7 @@ void updateRadioState()
285288 systemPrintln ();
286289 }
287290 packetsLost = 0 ; // Reset, used for linkLost testing
291+ updateRSSI (); // Adjust LEDs to RSSI level
288292 frequencyCorrection += radio.getFrequencyError () / 1000000.0 ;
289293 returnToReceiving ();
290294 changeState (RADIO_LINKED_RECEIVING_STANDBY);
@@ -294,6 +298,7 @@ void updateRadioState()
294298 // It's a duplicate. Ack then throw data away.
295299 triggerEvent (TRIGGER_LINK_DUPLICATE_PACKET);
296300 packetsLost = 0 ; // Reset, used for linkLost testing
301+ updateRSSI (); // Adjust LEDs to RSSI level
297302 frequencyCorrection += radio.getFrequencyError () / 1000000.0 ;
298303 sendAckPacket ();
299304 changeState (RADIO_LINKED_TRANSMITTING);
@@ -303,6 +308,7 @@ void updateRadioState()
303308 // Someone is pinging us. Ack back.
304309 triggerEvent (TRIGGER_LINK_CONTROL_PACKET);
305310 packetsLost = 0 ; // Reset, used for linkLost testing
311+ updateRSSI (); // Adjust LEDs to RSSI level
306312 frequencyCorrection += radio.getFrequencyError () / 1000000.0 ;
307313 sendAckPacket ();
308314 changeState (RADIO_LINKED_TRANSMITTING);
@@ -331,6 +337,7 @@ void updateRadioState()
331337 }
332338
333339 packetsLost = 0 ; // Reset, used for linkLost testing
340+ updateRSSI (); // Adjust LEDs to RSSI level
334341 frequencyCorrection += radio.getFrequencyError () / 1000000.0 ;
335342 sendAckPacket (); // Transmit ACK
336343 changeState (RADIO_LINKED_TRANSMITTING);
@@ -351,6 +358,7 @@ void updateRadioState()
351358 }
352359
353360 packetsLost = 0 ; // Reset, used for linkLost testing
361+ updateRSSI (); // Adjust LEDs to RSSI level
354362 frequencyCorrection += radio.getFrequencyError () / 1000000.0 ;
355363 sendCommandAckPacket (); // Transmit ACK
356364 changeState (RADIO_LINKED_TRANSMITTING);
@@ -363,6 +371,7 @@ void updateRadioState()
363371 Serial.write (lastPacket[x]);
364372
365373 packetsLost = 0 ; // Reset, used for linkLost testing
374+ updateRSSI (); // Adjust LEDs to RSSI level
366375 frequencyCorrection += radio.getFrequencyError () / 1000000.0 ;
367376 sendCommandResponseAckPacket (); // Transmit ACK
368377 changeState (RADIO_LINKED_TRANSMITTING);
@@ -378,8 +387,7 @@ void updateRadioState()
378387 generateHopTable (); // Generate freq with new settings
379388 configureRadio (); // Apply any new settings
380389
381- digitalWrite (pin_linkLED, LOW);
382- digitalWrite (pin_activityLED, LOW);
390+ setRSSI (0 ); // Turn off RSSI LEDs
383391 if (settings.pointToPoint == true )
384392 changeState (RADIO_NO_LINK_RECEIVING_STANDBY);
385393 else
@@ -388,6 +396,7 @@ void updateRadioState()
388396 else // It was just an ACK
389397 {
390398 packetsLost = 0 ; // Reset, used for linkLost testing
399+ updateRSSI (); // Adjust LEDs to RSSI level
391400 frequencyCorrection += radio.getFrequencyError () / 1000000.0 ;
392401 returnToReceiving ();
393402 changeState (RADIO_LINKED_RECEIVING_STANDBY);
@@ -440,11 +449,15 @@ void updateRadioState()
440449 if (millis () - lastLinkBlink > 500 ) // Blink at 2Hz
441450 {
442451 lastLinkBlink = millis ();
443- digitalWrite (pin_linkLED, !digitalRead (pin_linkLED)); // Toggle LED
452+ // Toggle all RSSI LEDs
453+ if (digitalRead (pin_rssi1LED) == HIGH)
454+ setRSSI (0 );
455+ else
456+ setRSSI (0b1111 ); // All on
444457 }
445458 }
446459 else
447- digitalWrite (pin_linkLED, LOW ); // No link
460+ setRSSI ( 0 ); // No link
448461 }
449462 break ;
450463
@@ -455,7 +468,7 @@ void updateRadioState()
455468 transactionComplete = false ; // Reset ISR flag
456469 returnToReceiving ();
457470 changeState (RADIO_BROADCASTING_RECEIVING_STANDBY); // No ack response when in broadcasting mode
458- digitalWrite (pin_activityLED, LOW);
471+ setRSSI ( 0 ); // Turn off RSSI LEDs
459472 }
460473
461474 else if (timeToHop == true ) // If the dio1ISR has fired, move to next frequency
@@ -518,14 +531,15 @@ void updateRadioState()
518531 }
519532 break ;
520533
534+ // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
535+
521536 case RADIO_TRAINING_TRANSMITTING:
522537 {
523538 if (transactionComplete == true ) // If dio0ISR has fired, we are done transmitting
524539 {
525540 transactionComplete = false ; // Reset ISR flag
526541 returnToReceiving ();
527542 changeState (RADIO_TRAINING_ACK_WAIT);
528- digitalWrite (pin_activityLED, LOW);
529543 }
530544 }
531545 break ;
@@ -556,6 +570,21 @@ void updateRadioState()
556570 transactionComplete = false ; // Reset ISR flag
557571 changeState (RADIO_TRAINING_RECEIVED_PACKET);
558572 }
573+ else if ( (millis () - lastTrainBlink) > 75 ) // Blink while unit waits in training state
574+ {
575+ lastTrainBlink = millis ();
576+
577+ // Cylon the RSSI LEDs
578+ setRSSI (trainCylonNumber);
579+
580+ if (trainCylonNumber == 0b1000 || trainCylonNumber == 0b0001 )
581+ trainCylonDirection *= -1 ; // Change direction
582+
583+ if (trainCylonDirection > 0 )
584+ trainCylonNumber <<= 1 ;
585+ else
586+ trainCylonNumber >>= 1 ;
587+ }
559588 }
560589 break ;
561590
0 commit comments