Browse Source

Merge pull request #1 from dustin/master

Auto binding when uninitialized and RSSI over PPM
readerror67 9 years ago
parent
commit
5811f6a9f3
1 changed files with 40 additions and 2 deletions
  1. 40
    2
      frsky_arduino_rx_complete.ino

+ 40
- 2
frsky_arduino_rx_complete.ino View File

19
 //#define DEBUG3
19
 //#define DEBUG3
20
 //#define DEBUG4
20
 //#define DEBUG4
21
 //#define DEBUG5
21
 //#define DEBUG5
22
+//#define RSSI_OVER_PPM 7
23
+
22
 #define FAILSAFE
24
 #define FAILSAFE
23
 #define SPIBB
25
 #define SPIBB
24
 //#define SPIHW
26
 //#define SPIHW
26
     #include <SPI.h>
28
     #include <SPI.h>
27
 #endif
29
 #endif
28
 
30
 
31
+// Used for RSSI_OVER_PPM
32
+int rssi;
33
+int rssi_min = -114;
34
+int rssi_max = -79;
35
+
29
 #define chanel_number 8  //set the number of chanels
36
 #define chanel_number 8  //set the number of chanels
30
 #define SEEK_CHANSKIP   13
37
 #define SEEK_CHANSKIP   13
31
 #define MAX_MISSING_PKT 20
38
 #define MAX_MISSING_PKT 20
183
     cc2500_strobe(CC2500_SRX);
190
     cc2500_strobe(CC2500_SRX);
184
 }
191
 }
185
 
192
 
186
-
193
+void updateRSSI() {
194
+#if defined(RSSI_OVER_PPM)
195
+    rssi = cc2500_readReg(CC2500_34_RSSI | CC2500_READ_BURST);
196
+    if (rssi < 128) {
197
+        rssi = ((rssi / 2) - 74) & 0x7f;
198
+    } else {
199
+        rssi = (((rssi - 256) / 2)) - 74;
200
+    }
201
+    int old_rssi_min = rssi_min;
202
+    int old_rssi_max = rssi_max;
203
+    rssi_min = min(rssi_min, rssi);
204
+    rssi_max = max(rssi_max, rssi);
205
+  #if defined(DEBUG)
206
+    if (rssi_min != old_rssi_min || rssi_max != old_rssi_max) {
207
+        Serial.print("RSSI: ");
208
+        Serial.print(rssi);
209
+        Serial.print(", min=");
210
+        Serial.print(rssi_min);
211
+        Serial.print(", max=");
212
+        Serial.println(rssi_max);
213
+    }
214
+  #endif
215
+#endif
216
+}
187
 
217
 
188
 void loop()
218
 void loop()
189
 {
219
 {
237
                         if ((ccData[1] == txid[0]) && (ccData[2] == txid[1])) { // Only if correct txid
267
                         if ((ccData[1] == txid[0]) && (ccData[2] == txid[1])) { // Only if correct txid
238
                             packet = true;
268
                             packet = true;
239
                             //sei();    ///////////////////////////////////////////////////////////////////////////////////////
269
                             //sei();    ///////////////////////////////////////////////////////////////////////////////////////
240
-                            //int rssi = cc2500_readReg(CC2500_34_RSSI | CC2500_READ_BURST);//check RSSI
270
+                            updateRSSI();
241
                             cc2500_strobe(CC2500_SIDLE);
271
                             cc2500_strobe(CC2500_SIDLE);
242
                             nextChannel(1);
272
                             nextChannel(1);
243
                             LED_ON;
273
                             LED_ON;
272
             }
302
             }
273
             ppm[i] = Servo_data[i];
303
             ppm[i] = Servo_data[i];
274
         }
304
         }
305
+        #if defined(RSSI_OVER_PPM)
306
+          ppm[RSSI_OVER_PPM] = map(rssi, rssi_min, rssi_max, 1000, 2000);
307
+        #endif
275
         #if defined(DEBUG5)
308
         #if defined(DEBUG5)
276
                 //Serial.println(rssi);
309
                 //Serial.println(rssi);
277
         #endif
310
         #endif
547
             for (i = 0; i < 2; i++) {
580
             for (i = 0; i < 2; i++) {
548
                 txid[i] = EEPROM.read(adr + i);
581
                 txid[i] = EEPROM.read(adr + i);
549
             }
582
             }
583
+            if (txid[0] == 0xff && txid[1] == 0xff) {
584
+                // No valid txid, forcing bind
585
+                jumper2 = 1;
586
+                continue;
587
+            }
550
             for (i = 0; i < sizeof(hopData); i++) {
588
             for (i = 0; i < sizeof(hopData); i++) {
551
                 hopData[i] = EEPROM.read(adr + 10 + i);
589
                 hopData[i] = EEPROM.read(adr + 10 + i);
552
             }
590
             }

Loading…
Cancel
Save