![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Fork to see if I can get working
Dependencies: BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated
Fork of xDotBridge_update_test20180823 by
Diff: xDotBridge/src/main.cpp
- Revision:
- 64:46c8819c07cc
- Parent:
- 63:e1efbe3402d9
- Child:
- 65:d546060aa03d
--- a/xDotBridge/src/main.cpp Tue Mar 14 09:54:04 2017 -0600 +++ b/xDotBridge/src/main.cpp Tue Mar 14 11:53:53 2017 -0600 @@ -49,6 +49,7 @@ dot = mDot::getInstance(); // make sure library logging is turned on +// dot->setLogLevel(mts::MTSLog::WARNING_LEVEL); dot->setLogLevel(mts::MTSLog::WARNING_LEVEL); myLogInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION); @@ -110,6 +111,7 @@ else { myLogInfo("= Baseboard Init Finished with Error =\r\n"); } + LedPatterns ledPatterns(bbio); uint16_t txSeqNum=0; uint16_t rxSeqNum=0; @@ -134,7 +136,7 @@ */ while (true) { std::vector<uint8_t> data; - bbio->ledOff(); + ledPatterns.turnOff(); // Sample IO and update any configuration prevCCNormallyOpen = bbio->isCCNO(); @@ -155,31 +157,36 @@ pairBtnState = PairBtnInterp::read(bbio); if (protocol->isTx()) { if (pairBtnState == pairBtnMediumPress) { - protocol->sampleDLC(); +// protocol->sampleDLC(); protocol->configForPairingNetwork(); protocol->sendPairReq(); myLogInfo("Sent pair request. Waiting %f secs for accept.", TX_ACCEPT_WAIT_TIME); result = protocol->waitForAccept(TX_ACCEPT_WAIT_TIME); if (result == cmdSuccess) { myLogInfo("Got accept"); + ledPatterns.turnOff(); + wait(0.5); + ledPatterns.tripleBlink(); } else { myLogInfo("Did not receive accept"); } protocol->configForSavedNetwork(); protocol->printDotConfig(); + protocol->resetCounters(); } } if (protocol->isRx()) { if (pairBtnState == pairBtnMediumPress) { - protocol->sampleDLC(); +// protocol->sampleDLC(); protocol->configForPairingNetwork(); - bbio->ledOn(); + ledPatterns.turnOn(); myLogInfo("Waiting for pair request for %f seconds", RX_PAIR_WAIT_TIME); result = protocol->waitForPairing(RX_PAIR_WAIT_TIME); - bbio->ledOff(); + ledPatterns.turnOff(); if (result == cmdSuccess) { myLogInfo("Got pair request and responded"); + ledPatterns.tripleBlink(); } else if (result == cmdTimeout) { myLogInfo("Did not receive request"); @@ -189,11 +196,14 @@ } protocol->configForSavedNetwork(); protocol->printDotConfig(); + protocol->resetCounters(); } else if (pairBtnState == pairBtnLongPress) { myLogInfo("Clearing pair values and generating new ones."); protocol->clearPair(); protocol->printDotConfig(); + ledPatterns.tenBlinks(); + protocol->resetCounters(); } } } @@ -207,9 +217,7 @@ bbio->isCCInAlert() || // If closure remains in effect (pairBtnIntFlag && (pairBtnState == pairBtnShortPress))) { ccIntFlag = false; - #if LED_FEEDBACK - bbio->ledOn(); - #endif + ledPatterns.turnOn(); data.clear(); data.push_back((txSeqNum >> 8) & 0xFF); @@ -218,10 +226,10 @@ myLogInfo("Sent msg num: %d, payload: %s", txSeqNum, dataStr.c_str()); protocol->send(data); txSeqNum++; - wait(0.5); // Leave the LED on so a person can see it. + ledPatterns.turnOff(); } - bbio->ledOff(); + ledPatterns.turnOff(); pairBtnIntFlag = false; tamperIntFlag = false; bbio->prepareSleep(); @@ -245,23 +253,22 @@ myLogInfo("Got msg num: %d, payload: %s", rxSeqNum, dataStr.c_str()); bbio->relayAlert(); rxSeqNum++; - #if LED_FEEDBACK - bbio->ledOn(); - #endif + ledPatterns.turnOn(); // Hold time for alert // TODO maybe use sleep instead of wait myLogInfo("Holding alert for %f secs", HoldTimeSetting::rotVal2Sec(bbio->rotarySwitch1())); wait(HoldTimeSetting::rotVal2Sec(bbio->rotarySwitch1())); - bbio->ledOff(); + ledPatterns.turnOff(); bbio->relayNormal(); } myLogInfo("Sleeping. Time %d", us_ticker_read()); - protocol->sampleDLC(); +// protocol->sampleDLC(); bbio->prepareSleep(); dot->sleep(2, mDot::RTC_ALARM_OR_INTERRUPT, false); // Go to sleep until wake button bbio->exitSleep(); } + protocol->resetCounters(); myLogInfo("\r\n================================"); loopCnt++; }