Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» M43 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed May 15, 2023
1 parent b364e44 commit d17d86d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Marlin/src/gcode/config/M43.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ void GcodeSuite::M43() {

for (;;) {
LOOP_S_LE_N(i, first_pin, last_pin) {
pin_t pin = GET_PIN_MAP_PIN_M43(i);
const pin_t pin = GET_PIN_MAP_PIN_M43(i);
if (!VALID_PIN(pin)) continue;
if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) continue;
const byte val =
Expand All @@ -383,7 +383,7 @@ void GcodeSuite::M43() {
//*/
extDigitalRead(pin);
if (val != pin_state[i - first_pin]) {
report_pin_state_extended(pin, ignore_protection, false);
report_pin_state_extended(pin, ignore_protection, true);
pin_state[i - first_pin] = val;
}
}
Expand All @@ -401,7 +401,7 @@ void GcodeSuite::M43() {
else {
// Report current state of selected pin(s)
LOOP_S_LE_N(i, first_pin, last_pin) {
pin_t pin = GET_PIN_MAP_PIN_M43(i);
const pin_t pin = GET_PIN_MAP_PIN_M43(i);
if (VALID_PIN(pin)) report_pin_state_extended(pin, ignore_protection, true);
}
}
Expand Down
20 changes: 12 additions & 8 deletions Marlin/src/pins/pinsDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,15 @@ const PinInfo pin_array[] PROGMEM = {
#endif

static void print_input_or_output(const bool isout) {
SERIAL_ECHOPGM_P(isout ? PSTR("Output = ") : PSTR("Input = "));
SERIAL_ECHOF(isout ? F("Output ") : F("Input "));
}

static void print_pin_state(const bool state) {
SERIAL_ECHOF(state ? F("HIGH") : F("LOW"));
}

// pretty report with PWM info
inline void report_pin_state_extended(pin_t pin, const bool ignore, const bool extended=false, FSTR_P const start_string=nullptr) {
inline void report_pin_state_extended(const pin_t pin, const bool ignore, const bool extended=false, FSTR_P const start_string=nullptr) {
char buffer[MAX_NAME_LENGTH + 1]; // for the sprintf statements
bool found = false, multi_name_pin = false;

Expand All @@ -188,12 +192,12 @@ inline void report_pin_state_extended(pin_t pin, const bool ignore, const bool e
// Use FastIO for pins Teensy doesn't expose
if (pin == 46) {
print_input_or_output(IS_OUTPUT(46));
SERIAL_CHAR('0' + READ(46));
print_pin_state(READ(46));
return false;
}
else if (pin == 47) {
print_input_or_output(IS_OUTPUT(47));
SERIAL_CHAR('0' + READ(47));
print_pin_state(READ(47));
return false;
}
#endif
Expand Down Expand Up @@ -230,14 +234,14 @@ inline void report_pin_state_extended(pin_t pin, const bool ignore, const bool e
// because this could interfere with inductive/capacitive
// sensors (high impedance voltage divider) and with Pt100 amplifier
print_input_or_output(false);
SERIAL_ECHO(digitalRead_mod(pin));
print_pin_state(digitalRead_mod(pin));
}
else if (pwm_status(pin)) {
// do nothing
}
else {
print_input_or_output(true);
SERIAL_ECHO(digitalRead_mod(pin));
print_pin_state(digitalRead_mod(pin));
}
}
if (!multi_name_pin && extended) pwm_details(pin); // report PWM capabilities only on the first pass & only if doing an extended report
Expand Down Expand Up @@ -267,7 +271,7 @@ inline void report_pin_state_extended(pin_t pin, const bool ignore, const bool e
else if (GET_PINMODE(pin)) {
SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16);
print_input_or_output(true);
SERIAL_ECHO(digitalRead_mod(pin));
print_pin_state(digitalRead_mod(pin));
}
else {
if (IS_ANALOG(pin)) {
Expand All @@ -279,7 +283,7 @@ inline void report_pin_state_extended(pin_t pin, const bool ignore, const bool e
SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16); // add padding if not an analog pin

print_input_or_output(false);
SERIAL_ECHO(digitalRead_mod(pin));
print_pin_state(digitalRead_mod(pin));
}
//if (!pwm_status(pin)) SERIAL_CHAR(' '); // add padding if it's not a PWM pin
if (extended) {
Expand Down

0 comments on commit d17d86d

Please sign in to comment.