diff --git a/VortexEngine/src/Menus/MenuList/EditorConnection.cpp b/VortexEngine/src/Menus/MenuList/EditorConnection.cpp index a649449871..43062661dd 100644 --- a/VortexEngine/src/Menus/MenuList/EditorConnection.cpp +++ b/VortexEngine/src/Menus/MenuList/EditorConnection.cpp @@ -165,16 +165,37 @@ Menu::MenuAction EditorConnection::run() SerialComs::write(EDITOR_VERB_CLEAR_DEMO_ACK); m_state = STATE_IDLE; break; - case STATE_SEND_MODE_VL: - if (!VLSender::isSending() || !VLSender::send()) { - m_state = STATE_IDLE; + case STATE_TRANSMIT_MODE_VL: +#if ENABLE_VL_SENDER == 1 + // if still sending and the send command indicated more data + if (VLSender::isSending() && VLSender::send()) { + // then continue sending + break; } - // continue sending +#endif + // othewrise, done, switch to the transmit done state + m_state = STATE_TRANSMIT_MODE_VL_DONE; + break; + case STATE_TRANSMIT_MODE_VL_DONE: + // done transmitting + m_receiveBuffer.clear(); + SerialComs::write(EDITOR_VERB_TRANSMIT_VL_ACK); + m_state = STATE_IDLE; break; } return MENU_CONTINUE; } +void EditorConnection::sendCurModeVL() +{ +#if ENABLE_VL_SENDER == 1 + // immediately load the mode and send it now + VLSender::loadMode(&m_previewMode); + VLSender::send(); +#endif + m_state = STATE_TRANSMIT_MODE_VL; +} + // handlers for clicks void EditorConnection::onShortClick() { @@ -186,9 +207,7 @@ void EditorConnection::onShortClick() void EditorConnection::onShortClick2() { - VLSender::loadMode(&m_previewMode); - VLSender::send(); - m_state = STATE_SEND_MODE_VL; + sendCurModeVL(); } void EditorConnection::onLongClick() @@ -310,5 +329,7 @@ void EditorConnection::handleCommand() m_state = STATE_DEMO_MODE; } else if (receiveMessage(EDITOR_VERB_CLEAR_DEMO)) { m_state = STATE_CLEAR_DEMO; + } else if (receiveMessage(EDITOR_VERB_TRANSMIT_VL)) { + sendCurModeVL(); } } diff --git a/VortexEngine/src/Menus/MenuList/EditorConnection.h b/VortexEngine/src/Menus/MenuList/EditorConnection.h index 771c728b9a..5c6e7b652c 100644 --- a/VortexEngine/src/Menus/MenuList/EditorConnection.h +++ b/VortexEngine/src/Menus/MenuList/EditorConnection.h @@ -15,6 +15,9 @@ class EditorConnection : public Menu bool init() override; MenuAction run() override; + // broadcast the current preview mode over VL + void sendCurModeVL(); + // handlers for clicks void onShortClick() override; void onShortClick2() override; @@ -62,8 +65,9 @@ class EditorConnection : public Menu // engine tells gloves to clear the demo preview, gloves acknowledge STATE_CLEAR_DEMO, - // send the mode over visible light - STATE_SEND_MODE_VL, + // transmit the mode over visible light + STATE_TRANSMIT_MODE_VL, + STATE_TRANSMIT_MODE_VL_DONE, }; // state of the editor diff --git a/VortexEngine/src/VortexConfig.h b/VortexEngine/src/VortexConfig.h index 7358e811eb..60429c36be 100644 --- a/VortexEngine/src/VortexConfig.h +++ b/VortexEngine/src/VortexConfig.h @@ -495,6 +495,12 @@ // that it's no longer listening #define EDITOR_VERB_GOODBYE "l" +// when the computer wants to send a mode to the duo it tells the device +// to transmit over VL and send the current preview mode to the duo +#define EDITOR_VERB_TRANSMIT_VL "m" +// the response from the device when it's done transmitting the mode +#define EDITOR_VERB_TRANSMIT_VL_ACK "n" + // =================================================================== // Manually Configured Sizes //