@@ -73,6 +73,7 @@ uint8_t pin_linkLED = 255;
7373uint8_t pin_activityLED = 255 ;
7474uint8_t pin_txLED = 255 ;
7575uint8_t pin_rxLED = 255 ;
76+ uint8_t pin_setupButton = 255 ;
7677
7778uint8_t pin_trigger = 255 ;
7879// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
@@ -117,6 +118,15 @@ WDTZero myWatchDog;
117118#endif
118119// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
119120
121+ // Buttons - Interrupt driven and debounce
122+ // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
123+ #include < JC_Button.h> // http://librarymanager/All#JC_Button
124+ Button *trainBtn = NULL ; // We can't instantiate the button here because we don't yet know what pin number to use
125+
126+ const int trainButtonTime = 4000 ; // ms press and hold before entering training
127+ const int trainWithDefaultsButtonTime = 10000 ; // ms press and hold before entering training
128+ // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
129+
120130// Global variables - Serial
121131// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
122132// Buffer to store bytes incoming from serial before broadcasting over LoRa
@@ -169,6 +179,8 @@ bool expectingAck = false; //Used by various send packet functions
169179
170180float frequencyCorrection = 0 ; // Adjust receive freq based on the last packet received freqError
171181
182+ unsigned long lastTrainBlink = 0 ; // Controls LED during training
183+
172184Settings originalSettings; // Create a duplicate of settings during training so that we can resort as needed
173185uint8_t trainNetID; // New netID passed during training
174186uint8_t trainEncryptionKey[16 ]; // New AES key passed during training
@@ -183,9 +195,7 @@ long stopTime = 0;
183195
184196void setup ()
185197{
186- // eepromErase();
187-
188- Serial.begin (57600 );
198+ Serial.begin (57600 ); // Default for debug messages before board begins
189199
190200#if defined(ENABLE_DEVELOPER)
191201 // Wait for serial to come online for debug printing
@@ -206,18 +216,12 @@ void setup()
206216 beginBoard (); // Determine what hardware platform we are running on
207217
208218 // settings.airSpeed = 19200;
209- // settings.maxDwellTime = 400;
210- // settings.frequencyHop = true;
211219 // settings.debug = true; //Enable trigger pin events
212- // //settings.heartbeatTimeout = 2000;
213- // settings.displayPacketQuality = false;
214- // settings.autoTuneFrequency = false;
215- // settings.encryptData = false; //No ecrypt, no scramble works
216- // settings.dataScrambling = false; //Encrypt, no scramble works
217- // settings.pointToPoint = false; //Encrypt, scramble works
218220
219221 beginLoRa (); // Start radio
220222
223+ beginButton (); // Start watching the train button
224+
221225 beginWDT (); // Start watchdog timer
222226
223227 Serial.println (F (" LRS" ));
@@ -230,21 +234,9 @@ void loop()
230234{
231235 petWDT ();
232236
233- // updateSerial(); //Store incoming and print outgoing
234-
235- if (Serial.available ())
236- {
237- byte incoming = Serial.read ();
238-
239- if (incoming == ' t' )
240- {
241- beginTraining ();
242- }
243- else if (incoming == ' r' )
244- {
245- beginDefaultTraining ();
246- }
247- }
237+ updateButton ();
238+
239+ updateSerial (); // Store incoming and print outgoing
248240
249241 updateRadioState (); // Ping/ack/send packets as needed
250242}
0 commit comments