Skip to content

Commit

Permalink
M579 implemented. This allows any processor pin to be set or
Browse files Browse the repository at this point in the history
read.  Obviously use setting with extreme caution.

Format:

M579 P31 S0

This sets processor pin 31 (whatever that might be) to a 0. Without the S field the command returns the state of the pin.
  • Loading branch information
Adrian Bowyer committed Jul 21, 2015
1 parent ac78807 commit 3e7f551
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
22 changes: 19 additions & 3 deletions GCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4248,7 +4248,9 @@ bool GCodes::HandleMcode(GCodeBuffer* gb)
}
break;

case 578: // Fire Inkjet bits
// Fire Inkjet bits

case 578:
if (!AllMovesAreFinishedAndMoveBufferIsLoaded())
return false;
if(gb->Seen('S')) // Need to handle the 'P' parameter too; see http://reprap.org/wiki/G-code#M578:_Fire_inkjet_bits
Expand Down Expand Up @@ -4312,8 +4314,8 @@ bool GCodes::HandleMcode(GCodeBuffer* gb)
}
break;

//****************************
// These last are M codes only for the cognoscenti
//****************************
// These last are M codes only for the cognoscenti

case 562: // Reset temperature fault - use with great caution
if (gb->Seen('P'))
Expand Down Expand Up @@ -4361,6 +4363,20 @@ bool GCodes::HandleMcode(GCodeBuffer* gb)
}
break;

// Set or read processor pins directly. Setting should obviously be
// used with extreme caution.

case 579:
if(gb->Seen('P'))
{
int pin = gb->GetIValue();
if(gb->Seen('S'))
platform->SetOutputPin(pin, gb->GetIValue());
else
reply.printf("Pin %d is %s.\n", pin, platform->GetInputPin(pin) ? "high" : "low");
}
break;

case 999: // Restart after being stopped by error
result = DoDwellTime(0.5); // wait half a second to allow the response to be sent back to the web server, otherwise it may retry
if (result)
Expand Down
23 changes: 23 additions & 0 deletions Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,13 @@ class Platform
// So you can test for inkjet presence with if(platform->Inkjet(0))

bool Inkjet(int bitPattern);

// Two functions to set and get any processor pin.
// Only for use by the M579 command with extreme caution. Don't use these
// for anything else.

void SetOutputPin(int pin, bool value);
bool GetInputPin(int pin);

private:
void ResetChannel(size_t chan); // re-initialise a serial channel
Expand Down Expand Up @@ -1302,6 +1309,22 @@ inline void Platform::SetNozzleDiameter(float diameter)
nozzleDiameter = diameter;
}

// Two functions to set and get any processor pin.
// Only for use by the M579 command with extreme caution. Don't use these
// for anything else.

inline void Platform::SetOutputPin(int pin, bool value)
{
pinMode(pin, OUTPUT);
digitalWrite(pin, value);
}

inline bool Platform::GetInputPin(int pin)
{
return digitalRead(pin);
}


//***************************************************************************************

#endif
Expand Down

0 comments on commit 3e7f551

Please sign in to comment.