Welcome! Log In Create A New Profile

Advanced

C++ coding help with Marlin please

Posted by n9jcv 
C++ coding help with Marlin please
April 24, 2019 07:50PM
I am trying to make a change to 1.1.8 to add an E endstop, it will be a 4th axis. Anyway, I have the program endstops.cpp is where I am having a compile issue and I can't seem to figure it out, because I am new to C++.

here is the relevant code
void Endstops::report_state() {
  if (endstop_hit_bits) {
    #if ENABLED(ULTRA_LCD)
      char chrX = ' ', chrY = ' ', chrZ = ' ', chrP = ' ';
      #define _SET_STOP_CHAR(A,C) (chr## A = C)
    #else
      #define _SET_STOP_CHAR(A,C) ;
    #endif

    #define _ENDSTOP_HIT_ECHO(A,C) do{ \
      SERIAL_ECHOPAIR(" " STRINGIFY(A) ":", stepper.triggered_position_mm(A ##_AXIS)); \
      _SET_STOP_CHAR(A,C); }while(0)

    #define _ENDSTOP_HIT_TEST(A,C) \
      if (TEST(endstop_hit_bits, A ##_MIN) || TEST(endstop_hit_bits, A ##_MAX)) \
        _ENDSTOP_HIT_ECHO(A,C)

    #define ENDSTOP_HIT_TEST_hot smiley) _ENDSTOP_HIT_TEST(X,'X')
    #define ENDSTOP_HIT_TEST_Y() _ENDSTOP_HIT_TEST(Y,'Y')
    #define ENDSTOP_HIT_TEST_Z() _ENDSTOP_HIT_TEST(Z,'Z')

    #define ENDSTOP_HIT_TEST_E() _ENDSTOP_HIT_TEST(E,'E')


    SERIAL_ECHO_START();
    SERIAL_ECHOPGM(MSG_ENDSTOPS_HIT);
    ENDSTOP_HIT_TEST_hot smiley);
    ENDSTOP_HIT_TEST_Y();
    ENDSTOP_HIT_TEST_Z();
    ENDSTOP_HIT_TEST_E();

    #if ENABLED(Z_MIN_PROBE_ENDSTOP)
      #define P_AXIS Z_AXIS
      if (TEST(endstop_hit_bits, Z_MIN_PROBE)) _ENDSTOP_HIT_ECHO(P, 'P');
    #endif
    SERIAL_EOL();

    #if ENABLED(ULTRA_LCD)
      lcd_status_printf_P(0, PSTR(MSG_LCD_ENDSTOPS " %c %c %c %c"), chrX, chrY, chrZ, chrP);
    #endif

    hit_on_purpose();

    #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && ENABLED(SDSUPPORT)
      if (stepper.abort_on_endstop_hit) {
        card.sdprinting = false;
        card.closefile();
        quickstop_stepper();
        thermalManager.disable_all_heaters(); // switch off all heaters.
      }
    #endif
  }
} // Endstops::report_state

There are 2 lines I added;
#define ENDSTOP_HIT_TEST_E() _ENDSTOP_HIT_TEST(E,'E')
ENDSTOP_HIT_TEST_E();

The error I have is this;
Marlin\endstops.cpp: In static member function 'static void Endstops::report_state()':
Marlin\endstops.cpp:198:52: error: 'E_MAX' was not declared in this scope

and line 198 is this;
#define ENDSTOP_HIT_TEST_E() _ENDSTOP_HIT_TEST(E,'E')

So I kind of understand that the #define is a preprocessor command to replace all instances of ENDSTOP_HIT_TEST_E() with _ENDSTOP_HIT_TEST(E,'E')

I only have and need the E Min, I do not have nor need a E Max
I believe this line
if (TEST(endstop_hit_bits, A ##_MIN) || TEST(endstop_hit_bits, A ##_MAX)) \
is causing the error but I am not sure.

Any help would be appreciated
Thanks
Re: C++ coding help with Marlin please
April 24, 2019 08:39PM
look in endstops.h

you need to update EndstopEnum

to

enum EndstopEnum : char {
  X_MIN,
  Y_MIN,
  Z_MIN,
  Z_MIN_PROBE,
  X_MAX,
  Y_MAX,
  Z_MAX,
  X2_MIN,
  X2_MAX,
  Y2_MIN,
  Y2_MAX,
  Z2_MIN,
  Z2_MAX,
  E_MIN,
  E_MAX
};

The macros need two endstops for each axis... so regardless if its never going to exist you need to define it

Edited 1 time(s). Last edit at 04/24/2019 08:46PM by Dust.
Re: C++ coding help with Marlin please
April 24, 2019 08:51PM
Thank you Dust, actually for me at 1.1.8 it is in enum.h but with your help I found it, I will give this a try
enum EndstopEnum {
  X_MIN,
  Y_MIN,
  Z_MIN,
  Z_MIN_PROBE,
  X_MAX,
  Y_MAX,
  Z_MAX,
  X2_MIN,
  X2_MAX,
  Y2_MIN,
  Y2_MAX,
  Z2_MIN,
  Z2_MAX,
  E_MIN,
 E_MAX
Sorry, only registered users may post in this forum.

Click here to login