Skip to content

Commit

Permalink
orbit serial fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal-Dan committed Sep 6, 2024
1 parent 461ba57 commit 5e54517
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 14 deletions.
24 changes: 18 additions & 6 deletions VortexEngine/src/Menus/MenuList/EditorConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
31 changes: 28 additions & 3 deletions VortexEngine/src/Serial/Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
{
Expand All @@ -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) {
Expand All @@ -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, ...)
Expand Down
4 changes: 4 additions & 0 deletions VortexEngine/src/Serial/Serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
34 changes: 29 additions & 5 deletions rewrite_trinket_source.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5e54517

Please sign in to comment.