Browse Source

Support RSSI over PPM

Dustin Sallings 9 years ago
parent
commit
4e4ada9231
1 changed files with 35 additions and 2 deletions
  1. 35
    2
      frsky_arduino_rx_complete.ino

+ 35
- 2
frsky_arduino_rx_complete.ino View File

@@ -19,6 +19,8 @@
19 19
 //#define DEBUG3
20 20
 //#define DEBUG4
21 21
 //#define DEBUG5
22
+//#define RSSI_OVER_PPM 7
23
+
22 24
 #define FAILSAFE
23 25
 #define SPIBB
24 26
 //#define SPIHW
@@ -26,6 +28,11 @@
26 28
     #include <SPI.h>
27 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 36
 #define chanel_number 8  //set the number of chanels
30 37
 #define SEEK_CHANSKIP   13
31 38
 #define MAX_MISSING_PKT 20
@@ -183,7 +190,30 @@ void setup()
183 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 218
 void loop()
189 219
 {
@@ -237,7 +267,7 @@ void loop()
237 267
                         if ((ccData[1] == txid[0]) && (ccData[2] == txid[1])) { // Only if correct txid
238 268
                             packet = true;
239 269
                             //sei();    ///////////////////////////////////////////////////////////////////////////////////////
240
-                            //int rssi = cc2500_readReg(CC2500_34_RSSI | CC2500_READ_BURST);//check RSSI
270
+                            updateRSSI();
241 271
                             cc2500_strobe(CC2500_SIDLE);
242 272
                             nextChannel(1);
243 273
                             LED_ON;
@@ -272,6 +302,9 @@ void loop()
272 302
             }
273 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 308
         #if defined(DEBUG5)
276 309
                 //Serial.println(rssi);
277 310
         #endif

Loading…
Cancel
Save