diff --git a/arduino/protocol/platformio.ini b/arduino/protocol/platformio.ini index 46ff784048a7388b5f9d13e53b04d75b8f1d51de..62149f68ec704517da1308e246f87cf293a5c556 100644 --- a/arduino/protocol/platformio.ini +++ b/arduino/protocol/platformio.ini @@ -17,6 +17,7 @@ lib_deps = 5390 ; uCRC16Lib 5418 ; RingBuffer build_flags = -fpermissive -I../common/include/ +lib_extra_dirs = ../common/lib [env:uno] platform = atmelavr diff --git a/arduino/protocol/platformio.pro b/arduino/protocol/platformio.pro index 7aa95f3693275c245c73fbc05683720531233fa4..f85d56595ae90ff70d4bf7e1c6cdda9f488219fc 100644 --- a/arduino/protocol/platformio.pro +++ b/arduino/protocol/platformio.pro @@ -6,7 +6,7 @@ else { } INCLUDEPATH += "$${_PRO_FILE_PWD_}/include" INCLUDEPATH += "$${_PRO_FILE_PWD_}/src" -INCLUDEPATH += "$${_PRO_FILE_PWD_}/lib/commsControl" +INCLUDEPATH += "$${_PRO_FILE_PWD_}/../common/lib/commsControl" INCLUDEPATH += "$${_PRO_FILE_PWD_}/.pio/libdeps/uno/uCRC16Lib_ID5390/src" INCLUDEPATH += "$${_PRO_FILE_PWD_}/.pio/libdeps/uno/RingBuffer_ID5418/src" INCLUDEPATH += "$${HOMEDIR}/.platformio/packages/framework-arduino-avr/cores/arduino" @@ -31,9 +31,9 @@ DEFINES += "__AVR_ATmega328P__" OTHER_FILES += platformio.ini SOURCES += src/protocol.cpp \ - lib/commsControl/commsControl.cpp \ - lib/commsControl/commsFormat.cpp + ../common/lib/commsControl/commsControl.cpp \ + ../common/lib/commsControl/commsFormat.cpp -HEADERS += lib/commsControl/commsConstants.h \ - lib/commsControl/commsControl.h \ - lib/commsControl/commsFormat.h +HEADERS += ../common/lib/commsControl/commsConstants.h \ + ../common/lib/commsControl/commsControl.h \ + ../common/lib/commsControl/commsFormat.h diff --git a/arduino/protocol/src/protocol.cpp b/arduino/protocol/src/protocol.cpp index 3b94233029e10c58fa7698e42781c8af40e63a32..5bcb36863fd42ffdeaa6e2b6780167ab0c917a0f 100644 --- a/arduino/protocol/src/protocol.cpp +++ b/arduino/protocol/src/protocol.cpp @@ -21,6 +21,11 @@ bool blue_ = false; bool green_ = false; bool red_ = false; +bool enabled_ = false; + +uint32_t lastTime_ = 0; + +uint32_t offset_ = 10; // dirty function to switch one of the LEDs void switchLED(int led) { @@ -76,23 +81,40 @@ void loop() { } previousState_ = currentState_; } -// switchLED(LED_BLUE); - // counter increase on button press -// plSend_.getData()->fsm_state += 1; -// comms_.writePayload(plSend_); + + if (enabled_ & (millis() > (lastTime_ + offset_))) + { + lastTime_ = millis(); + + plSend_.getData()->readback_valve_air_in = static_cast<uint8_t>((lastTime_ >> 24) & 0xFF); + plSend_.getData()->readback_valve_o2_in = static_cast<uint8_t>((lastTime_ >> 16) & 0xFF); + plSend_.getData()->readback_valve_inhale = static_cast<uint8_t>((lastTime_ >> 8 ) & 0xFF); + plSend_.getData()->readback_valve_exhale = static_cast<uint8_t>((lastTime_ >> 0 ) & 0xFF); + + switchLED(LED_BLUE); + plSend_.setType(payloadType::payloadData); + plSend_.getData()->fsm_state += 1; + comms_.writePayload(plSend_); + } // per cycle sender comms_.sender(); // per cycle receiver comms_.receiver(); - // per cycle data checker - the received entry is automatically removed from the buffer if (comms_.readPayload(plReceive_)) { switch (plReceive_.getType()) { case payloadType::payloadCmd: - switchLED(plReceive_.getCmd()->cmdCode); - alarm_.alarmCode = plReceive_.getCmd()->cmdCode + 1; + if (plReceive_.getCmd()->cmdCode % 2 == 0) { + enabled_ = false; + } else { + enabled_ = true; + } + offset_ = plReceive_.getCmd()->param; + + alarm_.alarmCode = plReceive_.getCmd()->cmdCode; + alarm_.param = millis() & 0xFFFFFFFF; plSend_.setAlarm(&alarm_); comms_.writePayload(plSend_); break; @@ -102,5 +124,4 @@ void loop() { plReceive_.setType(payloadType::payloadUnset); } - delay(50); }