diff --git a/VortexEngine/src/Menus/MenuList/EditorConnection.cpp b/VortexEngine/src/Menus/MenuList/EditorConnection.cpp index 4a8157fb31..abb6ab7a17 100644 --- a/VortexEngine/src/Menus/MenuList/EditorConnection.cpp +++ b/VortexEngine/src/Menus/MenuList/EditorConnection.cpp @@ -17,7 +17,9 @@ EditorConnection::EditorConnection(const RGBColor &col, bool advanced) : Menu(col, advanced), m_state(STATE_DISCONNECTED), - m_allowReset(true) + m_allowReset(true), + m_previousModeIndex(0), + m_numModesToReceive(0) { } @@ -104,6 +106,11 @@ Menu::MenuAction EditorConnection::run() case STATE_IDLE: // parse the receive buffer for any commands from the editor handleCommand(); + // watch for disconnects + if (!SerialComs::isConnected()) { + Leds::holdAll(RGB_GREEN); + leaveMenu(true); + } break; case STATE_PULL_MODES: // editor requested pull modes, send the modes @@ -257,17 +264,22 @@ Menu::MenuAction EditorConnection::run() if (receiveMode()) { m_receiveBuffer.clear(); SerialComs::write(EDITOR_VERB_PUSH_EACH_MODE_ACK); - if (Modes::numModes() >= m_numModesToReceive) { + if (m_numModesToReceive > 0) { + m_numModesToReceive--; + } + if (!m_numModesToReceive) { // success modes were received send the done m_state = STATE_PUSH_EACH_MODE_DONE; } } break; case STATE_PUSH_EACH_MODE_DONE: - // say we are done - m_receiveBuffer.clear(); - SerialComs::write(EDITOR_VERB_PUSH_EACH_MODE_DONE); - m_state = STATE_IDLE; + //if (receiveMessage(EDITOR_VERB_PUSH_EACH_MODE_DONE)) { + // say we are done + //m_receiveBuffer.clear(); + //SerialComs::write(EDITOR_VERB_PUSH_EACH_MODE_DONE); + m_state = STATE_IDLE; + //} break; } return MENU_CONTINUE; diff --git a/VortexEngine/src/Serial/Serial.cpp b/VortexEngine/src/Serial/Serial.cpp index aedcb2143d..a54b8f93c7 100644 --- a/VortexEngine/src/Serial/Serial.cpp +++ b/VortexEngine/src/Serial/Serial.cpp @@ -19,6 +19,7 @@ bool SerialComs::m_serialConnected = false; uint32_t SerialComs::m_lastCheck = 0; +uint32_t SerialComs::m_lastConnected = 0; // init serial bool SerialComs::init() @@ -39,10 +40,28 @@ bool SerialComs::isConnected() m_serialConnected = false; return false; } + if (!isConnectedReal()) { + return false; + } #endif return m_serialConnected; } +bool SerialComs::isConnectedReal() +{ +#ifdef VORTEX_EMBEDDED + uint32_t now = Time::getCurtime(); + if (!Serial.usb.connected()) { + m_lastConnected = now; + } else { + if (m_lastConnected && (now - m_lastConnected) > 1800) { + return false; + } + } +#endif + return true; +} + // check for any serial connection or messages bool SerialComs::checkSerial() { @@ -51,6 +70,9 @@ bool SerialComs::checkSerial() // already connected return true; } + if (m_serialConnected) { + return isConnectedReal(); + } uint32_t now = Time::getCurtime(); // don't check for serial too fast if (m_lastCheck && (now - m_lastCheck) < MAX_SERIAL_CHECK_INTERVAL) { @@ -71,13 +93,16 @@ bool SerialComs::checkSerial() } // Begin serial communications (turns out this is actually a NO-OP in trinket source) Serial.begin(SERIAL_BAUD_RATE); - // directly open the editor connection menu because we are connected to USB serial - Menus::openMenu(MENU_EDITOR_CONNECTION); + if (Menus::curMenuID() != MENU_EDITOR_CONNECTION) { + // directly open the editor connection menu because we are connected to USB serial + Menus::openMenu(MENU_EDITOR_CONNECTION); + } #endif #endif // serial is now connected m_serialConnected = true; - return true; + // rely on the low level 'real' connection now + return isConnectedReal(); } void SerialComs::write(const char *msg, ...) diff --git a/VortexEngine/src/Serial/Serial.h b/VortexEngine/src/Serial/Serial.h index 0121b5bbb0..7ce393361f 100644 --- a/VortexEngine/src/Serial/Serial.h +++ b/VortexEngine/src/Serial/Serial.h @@ -17,6 +17,9 @@ class SerialComs // whether serial is initialized static bool isConnected(); + // why do I need this + static bool isConnectedReal(); + // check for any serial connection or messages static bool checkSerial(); @@ -36,6 +39,7 @@ class SerialComs // whether serial communications are initialized static bool m_serialConnected; static uint32_t m_lastCheck; + static uint32_t m_lastConnected; }; #endif diff --git a/rewrite_trinket_source.sh b/rewrite_trinket_source.sh index f04e17b804..989304938b 100644 --- a/rewrite_trinket_source.sh +++ b/rewrite_trinket_source.sh @@ -11,11 +11,35 @@ fi CURRENT_LINE=$(sed -n '258p' "$FILE_PATH") if [ "$CURRENT_LINE" != " delay(10);" ]; then - echo "No changes made: line 258 does not match the expected content or has already been modified." - exit 0 + if [ "$CURRENT_LINE" != " \/\/delay(10);" ]; then + echo "No changes made: line 258 does not match the expected content." + exit 1 + fi + echo "No changes made: line 258 has already been modified." +else + # Replace the content of line 258 + sed -i '258s/.*/ \/\/delay(10);/' "$FILE_PATH" + echo "Line 258, a delay(10), has been commented out in: [$FILE_PATH]" fi -# Replace the content of line 258 -sed -i '258s/.*/ \/\/delay(10);/' "$FILE_PATH" +# ============================================================================================= -echo "Line 258, a delay(10), has been commented out in: [$FILE_PATH]" +FILE_PATH2="$HOME/.arduino15/packages/adafruit/hardware/samd/1.7.16/cores/arduino/USB/USBAPI.h" +# Check if the file exists +if [ ! -f "$FILE_PATH2" ]; then + echo "Error: File does not exist." + exit 1 +fi +# Read the specific line and check its content +CURRENT_LINE=$(sed -n '182p' "$FILE_PATH2") +if [ "$CURRENT_LINE" != "private:" ]; then + if [ "$CURRENT_LINE" != "\/\/private:" ]; then + echo "No changes made: line 182 does not match the expected content." + exit 1 + fi + echo "No changes made: line 182 has already been modified." +else + # replace the content of line + sed -i '182s/.*/\/\/private:/' "$FILE_PATH2" + echo "Line 182, private: has been commented out in: [$FILE_PATH2]" +fi