Fork to see if I can get working

Dependencies:   BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated

Fork of xDotBridge_update_test20180823 by Matt Briggs

Revision:
48:bab9f747d9ed
Child:
49:18f1354f9e51
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xDotBridge/manualTest/testBaseboardIO/testBaseboardIO.cpp	Mon Feb 13 17:10:59 2017 -0700
@@ -0,0 +1,171 @@
+#include "mbed.h"
+#include <string>
+#include "..\..\config.h"
+#include "BaseboardIO.h"
+
+#ifdef __TEST_BBIO__
+Serial pc(USBTX, USBRX); // Externally defined
+
+char* bool2Str(bool in) {
+    if (in) {
+        return "Asserted\    "; // Extra space for alignment
+    }
+    else {
+        return "Not Asserted";
+    }
+}
+
+uint8_t ccInIntCnt;
+uint8_t tamperIntCnt;
+uint8_t pairBtnIntCnt;
+
+void ccInIntCallback () {
+    ccInIntCnt++;
+}
+void tamperIntCallback () {
+    tamperIntCnt++;
+}
+void pairBtnIntCallback () {
+    pairBtnIntCnt++;
+}
+
+class MenuManager
+{
+private:
+    uint8_t mCurrSel; // Current selection
+    BaseboardIO *mBbio;
+    bool validInput(uint8_t in) {
+        if (in > 0 && in <= 8)
+            return true;
+        else {
+            return false;
+        }
+    }
+public:
+    MenuManager() {
+        mCurrSel = 0;
+        mBbio = NULL;
+    }
+    void regBBIO (BaseboardIO *bbio) {
+        mBbio = bbio;
+    }
+    uint8_t getCurrentSel() {
+        return mCurrSel;
+    }
+    void applyInput(uint8_t in) {
+        if (validInput(in)) {
+//            mCurrSel = in;
+            if (in == 1) {
+                mBbio->ledOn();
+            }
+            else if (in == 2) {
+                mBbio->ledOff();
+            }
+            else if (in == 3) {
+                mBbio->relayNormal();
+            }
+            else if (in == 4) {
+                mBbio->relayAlert();
+            }
+            else if (in == 5) {
+                mBbio->serialRx(true);
+            }
+            else if (in == 6) {
+                mBbio->serialRx(false);
+            }
+            else if (in == 7) {
+                mBbio->serialTx(true);
+            }
+            else if (in == 8) {
+                mBbio->serialTx(false);
+            }
+        }
+    }
+    void printMenu() {
+        mBbio->sampleUserSwitches();
+        pc.printf("\r\n\r\n");
+        pc.printf("===============================================\r\n");
+        pc.printf("= Baseboard I/O Tester                        =\r\n");
+        pc.printf("===============================================\r\n");
+        pc.printf("===============================================\r\n");
+        pc.printf("= Selection Options                           =\r\n");
+        pc.printf("===============================================\r\n");
+        pc.printf("= 0: Just refresh                             =\r\n");
+        pc.printf("= 1: Turn on LED                              =\r\n");
+        pc.printf("= 2: Turn off LED                             =\r\n");
+        pc.printf("= 3: Toggle Relay Normal                      =\r\n");
+        pc.printf("= 4: Toggle Relay Alert                       =\r\n");
+        pc.printf("= 5: Turn on 232 RX                           =\r\n");
+        pc.printf("= 6: Turn off 232 RX                          =\r\n");
+        pc.printf("= 7: Turn on 232 TX (Note RX on as well)      =\r\n");
+        pc.printf("= 8: Turn off 232 TX                          =\r\n");
+        pc.printf("===============================================\r\n");
+        pc.printf("= Status and Counters                         =\r\n");
+        pc.printf("===============================================\r\n");
+        pc.printf("= Pair btn. State: %s  IntCnt: %02d   =\r\n",
+                bool2Str(mBbio->isPairBtn()), 0);
+        pc.printf("= Tamper. State: N/A             IntCnt: %02d   =\r\n",
+                0);
+        pc.printf("= CCIN. State: %s      IntCnt: %02d   =\r\n",
+                bool2Str(0), 0);
+        pc.printf("= Is TX. State: %s                  =\r\n", bool2Str(mBbio->isTx()));
+        pc.printf("= CC Normally Open. State: %s       =\r\n", bool2Str(mBbio->isCCNO()));
+        pc.printf("= Is LoraWAN. State: %s             =\r\n", bool2Str(mBbio->isLoRaWANMode()));
+        pc.printf("= Rotary Switch 1.  Value: %02d                 =\r\n", mBbio->rotarySwitch1());
+        pc.printf("= Rotary Switch 2.  Value: %02d                 =\r\n", mBbio->rotarySwitch2());
+        pc.printf("===============================================\r\n");
+    }
+};
+
+/**
+ * Checks that in idle state all the IOs are pulled up.
+ */
+int main ()
+{
+    MenuManager menuMgr;
+    CmdResult result;
+    ccInIntCnt = 0;
+    tamperIntCnt = 0;
+    pairBtnIntCnt = 0;
+
+    pc.baud(115200);
+
+    wait(1.0);
+
+    pc.printf("===============================================\r\n");
+    pc.printf("= Baseboard Constructor Starting              =\r\n");
+    BaseboardIO bbio;
+    pc.printf("= Baseboard Constructor Finished              =\r\n");
+
+    pc.printf("= Baseboard Init Starting                     =\r\n");
+    result = bbio.init();
+    if (result == cmdSuccess) {
+        pc.printf("= Baseboard Init Finished Successfully    =\r\n");
+    }
+    else {
+        pc.printf("= Baseboard Init Finished with Error      =\r\n");
+    }
+
+    bbio.regCCInInt(&ccInIntCallback);
+    bbio.regTamperInt(&tamperIntCallback);
+    bbio.regPairBtnInt(&pairBtnIntCallback);
+
+    menuMgr.regBBIO(&bbio);
+    menuMgr.printMenu();
+
+    while (true) {
+
+        if (pc.readable()) {
+            char menuInput = pc.getc();
+            menuInput -= '0'; // Convert to raw interger value
+            menuMgr.applyInput(menuInput);
+            menuMgr.printMenu();
+        }
+        else {
+            pc.printf("*");
+        }
+        wait(1.0);
+    }
+    return 0;
+}
+#endif