shogo sato / SBUS

Files at this revision

API Documentation at this revision

Comitter:
sshogo
Date:
Mon Dec 07 07:41:34 2020 +0000
Parent:
14:481c23f2e4eb
Commit message:
add functions:; - resetall() ; Reset all parameters; - getConnectStatus() ; Get connecting status from receiver to mbed; - connstatus ; Connecting status from receiver to mbed

Changed in this revision

SBUS.cpp Show annotated file Show diff for this revision Revisions of this file
SBUS.h Show annotated file Show diff for this revision Revisions of this file
--- a/SBUS.cpp	Mon Jul 15 09:05:23 2019 +0000
+++ b/SBUS.cpp	Mon Dec 07 07:41:34 2020 +0000
@@ -24,6 +24,7 @@
     switchPositionValue[2] = 0x008F;
     switchFPositionValue[0] = 0x076F;
     switchFPositionValue[1] = 0x0074;
+    connstatus = false;
 }
 
 float SBUS::getStickValue(int tag) {
@@ -38,6 +39,10 @@
     return channel[tag];
 }
 
+bool SBUS::getConnectStatus() {
+    return connstatus;
+}
+
 void SBUS::receiveData() {
     static int count = 0;
     char buf;
@@ -50,6 +55,10 @@
     if(count == 25 && receivedData[0] == 0x0F) {
         decordReceivedData();
         count = 0;
+        connstatus = true;
+    } else {
+        resetall();
+        connstatus = false;
     }
 }
 
@@ -116,3 +125,10 @@
         }
     }
 }
+
+void SBUS::resetall() {
+    for(int i = 0; i < 16; i++) channel[i] = 0;
+    for(int i = 0; i < 50; i++) receivedData[i] = 0;
+    for(int i = 0; i < 4; i++) stickValue[i] = 0.0f;
+    for(int i = 0; i < 12; i++) switchValue[i] = Neutral;
+}
--- a/SBUS.h	Mon Jul 15 09:05:23 2019 +0000
+++ b/SBUS.h	Mon Dec 07 07:41:34 2020 +0000
@@ -44,6 +44,9 @@
         // function of getting channel value
         // @parm    tag 0-25
         int getChannelValue(int tag);
+        
+        // function of getting connecting status
+        bool getConnectStatus();
     
     private:
         Serial com;
@@ -52,6 +55,7 @@
         int stickNeutralValue;
         int stickMinimumValue;
         int stickResolution;
+        bool connstatus;
         
         int channel[16];
         int receivedData[50];
@@ -65,6 +69,8 @@
         void decordReceivedData();
         
         void convertReceivedData();
+        
+        void resetall();
 };
 
 #endif