uniconfig.h custom buttons

I would like to add some custom buttons.

1. Button that starts autolevel
2. Button that turns the CASE_LIGHTS_PIN on
3. Button that executes a particular gcode file (not just recently seleced)

with #3 I could just write the gcode to execute whatever for #1 and #2

I have looked at the long list of options at top of ui.h but I just don't see how to do it.

Comments

  • Just assign the action to a button.

    If there is matching action, you need to add your own actions and add them in ui.cpp in the "ok" function I think. Best is to check on a similar function and see how it is done.
  • Ok, UI_ACTION_LIGHTS_ONOFF was there and I made a new 'case' for my custom action:
     case UI_ACTION_AUTOLEVEL_G32S2:

     then I copied everything from "case 32" in commands.cpp and answered all the IF statements by removing the excess.

    --------------------------------------------
    case UI_ACTION_AUTOLEVEL_G32S2:
    {
            Printer::setAutolevelActive(false); // iterate
            Printer::homeAxis(true, true, true);
            Printer::moveTo(IGNORE_COORDINATE, IGNORE_COORDINATE, EEPROM::zProbeBedDistance() + EEPROM::zProbeHeight(), IGNORE_COORDINATE, Printer::homingFeedrate[Z_AXIS]);
            GCode::executeFString(Com::tZProbeStartScript);
            //bool iterate = com->hasP() && com->P>0;
            Printer::coordinateOffset[X_AXIS] = Printer::coordinateOffset[Y_AXIS] = Printer::coordinateOffset[Z_AXIS] = 0;
            float h1,h2,h3,hc,oldFeedrate = Printer::feedrate;
            Printer::moveTo(EEPROM::zProbeX1(),EEPROM::zProbeY1(),IGNORE_COORDINATE,IGNORE_COORDINATE,EEPROM::zProbeXYSpeed());
            h1 = Printer::runZProbe(true,false,Z_PROBE_REPETITIONS,false);
            if(h1 < -1) break;
            Printer::moveTo(EEPROM::zProbeX2(),EEPROM::zProbeY2(),IGNORE_COORDINATE,IGNORE_COORDINATE,EEPROM::zProbeXYSpeed());
            h2 = Printer::runZProbe(false,false);
            if(h2 < -1) break;
            Printer::moveTo(EEPROM::zProbeX3(),EEPROM::zProbeY3(),IGNORE_COORDINATE,IGNORE_COORDINATE,EEPROM::zProbeXYSpeed());
            h3 = Printer::runZProbe(false,true);
            if(h3 < -1) break;

            Printer::buildTransformationMatrix(h1,h2,h3);
            //-(Rxx*Ryz*y-Rxz*Ryx*y+(Rxz*Ryy-Rxy*Ryz)*x)/(Rxy*Ryx-Rxx*Ryy)
            // z = z-deviation from origin due to bed transformation
            float z = -((Printer::autolevelTransformation[0] * Printer::autolevelTransformation[5] -
                         Printer::autolevelTransformation[2] * Printer::autolevelTransformation[3]) *
                        (float)Printer::currentPositionSteps[Y_AXIS] * Printer::invAxisStepsPerMM[Y_AXIS] +
                        (Printer::autolevelTransformation[2] * Printer::autolevelTransformation[4] -
                         Printer::autolevelTransformation[1] * Printer::autolevelTransformation[5]) *
                        (float)Printer::currentPositionSteps[X_AXIS] * Printer::invAxisStepsPerMM[X_AXIS]) /
                      (Printer::autolevelTransformation[1] * Printer::autolevelTransformation[3] - Printer::autolevelTransformation[0] * Printer::autolevelTransformation[4]);
            Printer::zMin = 0;

                Printer::zLength += (h3 + z) - Printer::currentPosition[Z_AXIS];
                Com::printFLN(Com::tZProbePrinterHeight,Printer::zLength);
                Printer::setAutolevelActive(true);
                EEPROM::storeDataIntoEEPROM();
            }

                break;
    ----------------------------------------------

    it seems like a lot of code. but it works (if you are a delta with MAX_HARDWARE_ENDSTOP_Z). Is there a way to just make it execute G32 S2?

     UI_KEYS_BUTTON_LOW(30,UI_ACTION_LIGHTS_ONOFF); // push button, connects gnd to pin
     UI_KEYS_BUTTON_LOW(32,UI_ACTION_AUTOLEVEL_G32S2); // push button, connects gnd to pin


    I'm still working on printing a particular gcode file.



  • You can run any gcode like this

    GCode::executeFString(PSTR("G32 S2"));
  • edited March 2016
    This worked out great (UI.CPP):
            case UI_ACTION_AUTOLEVEL_G32S2:
               GCode::executeFString(PSTR("G32 S2"));
               break;

    Then added line with unique number in UI.H

    #define UI_ACTION_AUTOLEVEL_G32S2        1215



    Most of the other buttons I want to add are already in the list of UI_ACTIONS, or I can look at an existing action and change it easy enough. Except I want to add a button that will change the values stored in EEPROM for Z_PROBE_X1 and Z_PROBE_Y1  to the current positions of X and Y  ( Actually I don't care if they are stored permanently in EEPROM, or just used for the next autolevel G32)

    I figure it will be something like the action for Fan speed up
           case UI_ACTION_FAN_UP:
                Commands::setFanSpeed(Printer::getFanSpeed() + 32, true);
                break;

    or  some combination of M114 and M206 (even though this does not work 'M206 T3 P816 -110.000')
    //EEPROM storage code 
    #define EPR_Z_PROBE_X1            816

    I've found some code-bit relating to current positions, but nothing I can put into a workable syntax

        HAL::eprSetFloat(EPR_Z_PROBE_X1,Z_PROBE_X1);

        writeFloat(EPR_Z_PROBE_X1, Com::tZProbeX1);

     Commands::printCurrentPosition(PSTR("UI_ACTION_YPOSITION "));

    static inline float zProbeX1() {
    #if EEPROM_MODE != 0
            return HAL::eprGetFloat(EPR_Z_PROBE_X1);
            return Z_PROBE_X1;
        }

    Can you point me in the right direction again?


    In case the 'Why' is important.I want to place something on my printbed (glass/mirror/wood) and manually move head over ZP1 and press a button, then do the same for ZP2 and ZP3. Then do an autolevel using the three new points that touch the object, not the print bed.  for doing this to smaller peices
    image
    image
  • Also, is there a way to make an action take two buttons to perform? that way I could use one button as a shift and get more more functions with the same number of buttons
  • Sounds like you want






    uint8_t Printer::moveToReal(float x,float y,float z,float e,float f,bool pathOptimize = true);

    Set coordinates to IGNORE_COORDINATE it you do not want to change.

    One button can only have one function. What you want in this case is a wizard where you switch between wizard pages with "ok" and action is bound to ok. But that is a bit more difficult to program and requires some programming skills to understand the flow. See filament change for an example.







  • finally figured this out. and it really had nothing to do with the moveToReal function. First I found a way to get current position (Printer::currentPosition) and then I used the code from the eeprom.h include to write to the eeprom (HAL::eprSetFloat)

    since I use zprobe autoleveling instead of software leveling, I was able to repurpose setp1-setp3. in hindsight, I probably could have left the prev code in place alongside what I have below and it still would have worked.

    additionally I added a sete1 and sete2 functions to reset the probe points and to change the z probe height between my two tools. 

            case UI_ACTION_SET_P1:
    //Com::printFLN(PSTR("Z-PROBE_X1:"),(int)Printer::currentPosition[X_AXIS]);
    //Com::printFLN(PSTR("Z-PROBE_Y1:"),(int)Printer::currentPosition[Y_AXIS]);
    Com::printF(PSTR("Z-PROBE X1:"),(int)Printer::currentPosition[X_AXIS]);
    Com::printFLN(PSTR(" Y1:"),(int)Printer::currentPosition[Y_AXIS]);
     HAL::eprSetFloat(EPR_Z_PROBE_X1,Printer::currentPosition[X_AXIS]);
     HAL::eprSetFloat(EPR_Z_PROBE_Y1,Printer::currentPosition[Y_AXIS]);
                break;
                
            case UI_ACTION_SET_P2:
    //Com::printFLN(PSTR("Z-PROBE_X2:"),(int)Printer::currentPosition[X_AXIS]);
    //Com::printFLN(PSTR("Z-PROBE_Y2:"),(int)Printer::currentPosition[Y_AXIS]);
    Com::printF(PSTR("Z-PROBE X2:"),(int)Printer::currentPosition[X_AXIS]);
    Com::printFLN(PSTR(" Y2:"),(int)Printer::currentPosition[Y_AXIS]);
     HAL::eprSetFloat(EPR_Z_PROBE_X2,Printer::currentPosition[X_AXIS]);
     HAL::eprSetFloat(EPR_Z_PROBE_Y2,Printer::currentPosition[Y_AXIS]);
                break;
                
            case UI_ACTION_SET_P3:
    //Com::printFLN(PSTR("Z-PROBE_X3:"),(int)Printer::currentPosition[X_AXIS]);
    //Com::printFLN(PSTR("Z-PROBE_Y3:"),(int)Printer::currentPosition[Y_AXIS]);
    Com::printF(PSTR("Z-PROBE X3:"),(int)Printer::currentPosition[X_AXIS]);
    Com::printFLN(PSTR(" Y3:"),(int)Printer::currentPosition[Y_AXIS]);
     HAL::eprSetFloat(EPR_Z_PROBE_X3,Printer::currentPosition[X_AXIS]);
     HAL::eprSetFloat(EPR_Z_PROBE_Y3,Printer::currentPosition[Y_AXIS]);

    //Com::printFLN(PSTR("zLength:"),(int)Printer::zLength);
    //Com::printFLN(PSTR("zHeight:"),(int)Printer::currentPosition[Z_AXIS]);
    Com::printF(PSTR("zLength:"),(int)Printer::zLength);
    Com::printF(PSTR(" - zHeight:"),(int)Printer::currentPosition[Z_AXIS]);
    Com::printFLN(PSTR(" = MaxZ:"),(int)Printer::zLength - Printer::currentPosition[Z_AXIS]);
            
    //Com::printFLN(PSTR("zProbeHeight:"),(int)Printer::zLength - Printer::currentPosition[Z_AXIS]);
     HAL::eprSetFloat(EPR_Z_LENGTH,Printer::zLength - Printer::currentPosition[Z_AXIS]);

                break;

    case UI_ACTION_SET_E1:
    Com::printFLN(PSTR("Tool 1 Settings Loaded:"));

     HAL::eprSetFloat(EPR_Z_PROBE_HEIGHT,6.0);
    //Com::printFLN(PSTR("Z-PROBE_X1:"),(int)-110);
    //Com::printFLN(PSTR("Z-PROBE_Y1:"),(int)-70);
     HAL::eprSetFloat(EPR_Z_PROBE_X1,-110);
     HAL::eprSetFloat(EPR_Z_PROBE_Y1,-70);
    //Com::printFLN(PSTR("Z-PROBE_X2:"),(int)110);
    //Com::printFLN(PSTR("Z-PROBE_Y2:"),(int)-60);
     HAL::eprSetFloat(EPR_Z_PROBE_X2,110);
     HAL::eprSetFloat(EPR_Z_PROBE_Y2,-60);
    //Com::printFLN(PSTR("Z-PROBE_X3:"),(int)0);
    //Com::printFLN(PSTR("Z-PROBE_Y3:"),(int)110);
     HAL::eprSetFloat(EPR_Z_PROBE_X3,0);
     HAL::eprSetFloat(EPR_Z_PROBE_Y3,110);
        break;



  • I take it back, I don't quite have it.

    The buttons to reset Probe points works. and the part at setp3 that changes the MaxZ only half works.

    the maxZ value is written to the eeprom, and if you hit home it reports the new value. however when you home it doesn't stay at the top, it homes and then moves down by the amount you adjusted the zheight. The only way to fix it is to edit the eeprom and manually change the zheight (to the same value) and then rehome and it goes to the top.

    I am changing the maxz to avoid the probe slamming into the workpeice.I think maybe there is a 2nds value I need to set to the new MaxZ?
  • made a video to show my problem..pretty sure I need to set another value when I change the MaxZ

  • Any Advice?
  • Ok I finally got this figured out. After saving all these values into eeprom I then needed to load them back out of eeprom. In the video I did this by opening the eeprom setting in repetier host and then saving after making a small change. In recent testing I found out that if I issue a M501 it serves the same purpose. So I copied some of the code from near "case 501" to the end of UI_ACTION_SET_P3SA after setting the new z height.

    I also made a P123_RESET  UI_ACTION to change all my probe points back to normal. I know I could use the code from M502, but too many other things in the eeprom also get reset with that, and it's not always convenient.  If I wasn't so lazy I would figure out how to make space in the eeprom and store the original data there, that way these values wouldn't have to manually adjusted for each persons printer.

    -------------

      case UI_ACTION_SET_P1SA:
    Com::printF(PSTR("Z-PROBE X1:"),(int)Printer::currentPosition[X_AXIS]);
    Com::printFLN(PSTR(" Y1:"),(int)Printer::currentPosition[Y_AXIS]);
      HAL::eprSetFloat(EPR_Z_PROBE_X1,Printer::currentPosition[X_AXIS]);
    HAL::eprSetFloat(EPR_Z_PROBE_Y1,Printer::currentPosition[Y_AXIS]);
      break;
                
      case UI_ACTION_SET_P2SA:
    Com::printF(PSTR("Z-PROBE X2:"),(int)Printer::currentPosition[X_AXIS]);
    Com::printFLN(PSTR(" Y2:"),(int)Printer::currentPosition[Y_AXIS]);
      HAL::eprSetFloat(EPR_Z_PROBE_X2,Printer::currentPosition[X_AXIS]);
      HAL::eprSetFloat(EPR_Z_PROBE_Y2,Printer::currentPosition[Y_AXIS]);
        break;
                
            case UI_ACTION_SET_P3SA:
    Com::printF(PSTR("Z-PROBE X3:"),(int)Printer::currentPosition[X_AXIS]);
    Com::printFLN(PSTR(" Y3:"),(int)Printer::currentPosition[Y_AXIS]);
      HAL::eprSetFloat(EPR_Z_PROBE_X3,Printer::currentPosition[X_AXIS]);
      HAL::eprSetFloat(EPR_Z_PROBE_Y3,Printer::currentPosition[Y_AXIS]);
    Com::printF(PSTR("zLength:"),(int)Printer::zLength);
    Com::printF(PSTR(" - zHeight:"),(int)Printer::currentPosition[Z_AXIS]);
    Com::printFLN(PSTR(" = MaxZ:"),(int)Printer::zLength - Printer::currentPosition[Z_AXIS]);        
    HAL::eprSetFloat(EPR_Z_LENGTH,Printer::zLength - Printer::currentPosition[Z_AXIS]);
    Printer::zLength = HAL::eprGetFloat(EPR_Z_LENGTH);
    EEPROM::readDataFromEEPROM(true);
            Com::printInfoFLN(Com::tConfigLoadedEEPROM);
      break;

            case UI_ACTION_P123_RESET:
    Com::printFLN(PSTR("All Autolevel Settings Reset"));
      HAL::eprSetFloat(EPR_Z_PROBE_X1,-110);
      HAL::eprSetFloat(EPR_Z_PROBE_Y1,-70);
      HAL::eprSetFloat(EPR_Z_PROBE_X2,110);
      HAL::eprSetFloat(EPR_Z_PROBE_Y2,-60);
      HAL::eprSetFloat(EPR_Z_PROBE_X3,0);
      HAL::eprSetFloat(EPR_Z_PROBE_Y3,110);
      HAL::eprSetFloat(EPR_Z_LENGTH,408);
    EEPROM::readDataFromEEPROM(true);
          Com::printInfoFLN(Com::tConfigLoadedEEPROM);
    break;
  • and since the tittle of this thread is custom buttons, here is another one:

              case UI_ACTION_COUNTER_RESET:
                Com::printFLN(PSTR("Reset All Counters"));
               GCode::executeFString(PSTR("M206 T3 P125 X0"));
               GCode::executeFString(PSTR("M206 T3 P129 X0"));
               break;

    Having a button that resets that "Printing time" and "Filament Printed" counters on the LCD has come in handy. I press it before starting a print and I get accurate counts for that print. The counter for a print usually goes away as soon as it finishes, and I don't usually keep my repetier host connected to monitor the time. Nor can I be relied upon to write down or remember the time a print starts (or notice when it finishes). But I can press a button. ...




  • This has also come in handy Z:

    Z-Probe Servo Deploy and Retract buttons.  Is there a a way to have it toggle between these two function on one button?

              case UI_ACTION_ZPROBE_DEPLOY:
               Com::printFLN(PSTR("ZPROBE Manual Deploy"));
               GCode::executeFString(Com::tZProbeStartScript);
               break;
                case UI_ACTION_ZPROBE_RETRACT:
               Com::printFLN(PSTR("ZPROBE Manual Retract"));
               GCode::executeFString(Com::tZProbeEndScript);
               break;
  • so what do I need to do to be able to make a button that toggles between two functions? UI_ACTION_ZPROBE_DEPLOY and UI_ACTION_ZPROBE_RETRACT ?
  • edited September 2017
    you just need a flag in the switch case of your buttons.
    boolean flag= FALSE ; // at beginning of your custom events, must be global defined

    case x:
    if(!flag) {
    action = action1;
    flag= TRUE;
    }
    else{
    action = action2;
    flag= FALSE;
    }
    break;

    something like this should work
  • typo , FALSE and TRUE have to be lowercase letters

  • Excellent! thanks for coming through again RAyWB! 
Sign In or Register to comment.