Skip to content

Commit

Permalink
Fix handling change USB mode gcode command
Browse files Browse the repository at this point in the history
  • Loading branch information
rechrtb committed Jun 14, 2024
1 parent a3740a7 commit 5f0853d
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/GCodes/GCodes2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3793,21 +3793,34 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
const size_t chan = gb.GetLimitedUIValue('P', NumSerialChannels);
bool hostMode = false;
bool seen = false;
#if SUPPORT_USB_DRIVE
if (chan == 0 && gb.TryGetBValue('H', hostMode, seen)) // switch modes first

// Check if a USB mode change is requested through the 'H' parameter on channel 0.
// If not on channel 0, short-circuit evaluation means TryGetBValue is not performed
// and hostMode == false, result == GCodeResult:ok is unchanged.
if (chan == 0 && gb.TryGetBValue('H', hostMode, seen))
{
#if SUPPORT_USB_DRIVE
if (!platform.SetUsbHostMode(hostMode, reply))
{
reply.printf("Unable to set to %s mode", hostMode ? "host" : "device");
reply.printf("Unable to set to USB %s mode", hostMode ? "host" : "device");
result = GCodeResult::error;
}
}
#else
reply.printf("USB host mode unsupported");
result = GCodeResult::error;
// No support for changing to host mode; changing to device mode is ignored.
if (hostMode)
{
reply.printf("USB host mode unsupported");
result = GCodeResult::error;
}
#endif
if (result == GCodeResult::ok && !hostMode) // switched to device mode with no error, handle other device mode args
}

// Handle the other parameters if specified along with the change to USB device mode,
// no USB mode change requested, or communication parameter configuration on other channels.
if (result == GCodeResult::ok && !hostMode)
{
seen = false;

GCodeBuffer * const gbp = (chan == 0) ? UsbGCode() : (chan == 1) ? AuxGCode() : Aux2GCode();
if (gb.Seen('B'))
{
Expand Down

0 comments on commit 5f0853d

Please sign in to comment.