From 040b482be472996d6aa7b0d5c80ee073bc3c7c6d Mon Sep 17 00:00:00 2001 From: LivingSynthesis Date: Fri, 26 Apr 2024 16:16:09 -0700 Subject: [PATCH] Autoserial :) (#235) --- Makefile | 4 +++- VortexEngine/src/Serial/Serial.cpp | 13 +++++++++++-- VortexEngine/src/VortexEngine.cpp | 3 +++ rewrite_trinket_source.sh | 20 ++++++++++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 rewrite_trinket_source.sh diff --git a/Makefile b/Makefile index 12506733b9..930eb1cab5 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ BUILD_PATH = build CONFIG_FILE = $(HOME)/.arduino15/arduino-cli.yaml # Default target -all: install build +all: build update-index: $(ARDUINO_CLI) core update-index @@ -28,6 +28,8 @@ install: wget https://raw.githubusercontent.com/microsoft/uf2/master/utils/uf2conv.py wget https://raw.githubusercontent.com/microsoft/uf2/master/utils/uf2families.json chmod +x uf2conv.py uf2families.json + chmod +x rewrite_trinket_source.sh + ./rewrite_trinket_source.sh build: $(ARDUINO_CLI) compile --fqbn $(BOARD) $(PROJECT_NAME) --config-file $(CONFIG_FILE) --build-path $(BUILD_PATH) diff --git a/VortexEngine/src/Serial/Serial.cpp b/VortexEngine/src/Serial/Serial.cpp index 871cdffb3e..aedcb2143d 100644 --- a/VortexEngine/src/Serial/Serial.cpp +++ b/VortexEngine/src/Serial/Serial.cpp @@ -3,6 +3,7 @@ #include "../Serial/ByteStream.h" #include "../Time/TimeControl.h" #include "../Time/Timings.h" +#include "../Menus/Menus.h" #include "../Log/Log.h" #include "../VortexEngine.h" @@ -23,7 +24,7 @@ uint32_t SerialComs::m_lastCheck = 0; bool SerialComs::init() { // Try connecting serial ? - //checkSerial(); + checkSerial(); return true; } @@ -33,6 +34,12 @@ void SerialComs::cleanup() bool SerialComs::isConnected() { +#ifdef VORTEX_EMBEDDED + if (!Serial) { + m_serialConnected = false; + return false; + } +#endif return m_serialConnected; } @@ -62,8 +69,10 @@ bool SerialComs::checkSerial() // serial is not connected return false; } - // Begin serial communications + // 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); #endif #endif // serial is now connected diff --git a/VortexEngine/src/VortexEngine.cpp b/VortexEngine/src/VortexEngine.cpp index 53b7f944b8..c703de9322 100644 --- a/VortexEngine/src/VortexEngine.cpp +++ b/VortexEngine/src/VortexEngine.cpp @@ -172,6 +172,9 @@ void VortexEngine::runMainLogic() // the current tick uint32_t now = Time::getCurtime(); + // check if the device has been plugged in + SerialComs::checkSerial(); + // if the menus are open and running then just return if (Menus::run()) { return; diff --git a/rewrite_trinket_source.sh b/rewrite_trinket_source.sh new file mode 100644 index 0000000000..d950ca6211 --- /dev/null +++ b/rewrite_trinket_source.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +FILE_PATH="$HOME/.arduino15/packages/adafruit/hardware/samd/1.7.14/cores/arduino/USB/CDC.cpp" + +# Check if the file exists +if [ ! -f "$FILE_PATH" ]; then + echo "Error: File does not exist." +fi +# Read the specific line and check its content +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 +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]"