Custom Event System

edited January 18 in Questions & Answers
Hi,
playing around with Custom Event System i got a "special" Point.
As i´m initializing additional Hardware for example some I2C stuff i also want to start UI Actions.
(let´s say similar the UI Slow Keys also lets say function called "checkI2C(int &action)" returning UIAction)
Initialising, reading etc works perfect , also executing non UI Actions via "GCode::executeFString " works great.
(i placed my function in Timer500ms) but this way i cannot use UI actions

is there a way to do it in Custom events without a modification of  UIDisplay::slowAction
( i added checkI2C(nextaction) similar the original slow keys) in this case i can use the uiactionsand the others without my function in timer500 ms)?

Comments

  • edited January 19 Posts: 344
    May be we should add something like

    #ifdef CustomUI      
            check_Custom_Action(nextAction);
    #endif

    to UIDisplay::slowAction  and the matching defines

    (# define CustomUI ,extern int check_Custom_Action(int &nextAction) etc) to Custom events ?

    what do you think about that?
  • Posts: 0
    I think what you want is already implemented.

    // ok button in wizard page is called
    #define EVENT_UI_OK_WIZARD(action) {}
    #define EVENT_UI_FINISH_ACTION(action) false
    #define EVENT_UI_EXECUTE(action,allowMoves) {}
    #define EVENT_UI_NEXTPREVIOUS(action,allowMoves,increment) {}

    are the 4 types you can trigger with a UI_ACTION. Please see sample systems for felix pro 1 to see how to use it correctly and how to also define new action without conflicting numbers. EVENT_UI_EXECUTE is the most basic one if you click on a action or call it directly from a button.
  • edited January 19 Posts: 344

    I´m not shure if i understand correctly.

    Got it working in Timer500ms as follows:

    ->my function reads from I2C device and returns UIAction

    ->to prevent from hangup i ping watchdog

    ->afterwards i call UI_Execute with that function.

    so i can make it work. but nor shure if that´s a good way to do it



  • Posts: 0
    Ok, I misunderstood you.

    the keys test can be anywhere also outside of slow/fast keys. But you have to encapulate it like the call to fast keys:

    void UIDisplay::fastAction()
    {
    #if UI_HAS_KEYS == 1
        // Check keys
        InterruptProtectedBlock noInts;
        if((flags & (UI_FLAG_KEY_TEST_RUNNING + UI_FLAG_SLOW_KEY_ACTION)) == 0)
        {
            flags |= UI_FLAG_KEY_TEST_RUNNING;
            uint16_t nextAction = 0;
            uiCheckKeys(nextAction);
    //        ui_check_Ukeys(nextAction);
            if(lastButtonAction != nextAction)
            {
                lastButtonStart = HAL::timeInMilliseconds();
                lastButtonAction = nextAction;
                flags |= UI_FLAG_FAST_KEY_ACTION;
            }
            flags &= ~UI_FLAG_KEY_TEST_RUNNING;
        }
    #endif
    }

    so add your test where uiCheckKeys would be called and copy the rest to your function.
  • Posts: 344
    Repetier said:
    Ok, I misunderstood you.

    the keys test can be anywhere also outside of slow/fast keys. But you have to encapulate it like the call to fast keys:

    void UIDisplay::fastAction()
    {
    #if UI_HAS_KEYS == 1
        // Check keys
        InterruptProtectedBlock noInts;
        if((flags & (UI_FLAG_KEY_TEST_RUNNING + UI_FLAG_SLOW_KEY_ACTION)) == 0)
        {
            flags |= UI_FLAG_KEY_TEST_RUNNING;
            uint16_t nextAction = 0;
            uiCheckKeys(nextAction);
    //        ui_check_Ukeys(nextAction);

    #ifdef CustomUI      
            check_Custom_Action(nextAction);
    #endif


            if(lastButtonAction != nextAction)
            {
                lastButtonStart = HAL::timeInMilliseconds();
                lastButtonAction = nextAction;
                flags |= UI_FLAG_FAST_KEY_ACTION;
            }
            flags &= ~UI_FLAG_KEY_TEST_RUNNING;
        }
    #endif
    }

    so add your test where uiCheckKeys would be called and copy the rest to your function.
    Ok so may be it would be more universal to implement it as i inserted in red letters, thats what i ment in second post.
    As i´m using I2C components i prefer inserting in slow_action, but basically it´s the same
  • Posts: 0
    I would rather prefer a extra macro for event system. I will check what I can do. Will add a slow and fast version so you can do I2C in slow variant.
  • Posts: 344

    would be great if you can do that

    Thanks!

  • Posts: 344
    Background for this need for feature is getting a flexible possibility for additional hardware , in my case some i2c stuff.

    i want to implement some external PWM´s , therefore i ordered this:
    https://www.adafruit.com/product/815

    benefit would be free running pwm without need for timers :-)
    so it would be easy to make laser drivers, spindle control etc.

    i also think about fan control , as it´s a mess to combine different sizes of fans on a single control pin.
    especially on low speed´s the bigger ones work, the smaller ones don´t  so there would be a nice gimmick
    to have additional pwms without computation load.

    I´m  also planning a sort of analog controlled laser diode driver controlled by external I2C DAC (might be easier to change reference voltage)

    Lots of ideas but unfortunately not enough time so i think i´ll never finish :-)
  • edited January 22 Posts: 344
    Thanks for implementing the Key Events , just a question :

    in UIDisplay::fast Action()

    are both events ,

    EVENT_CHECK_SLOW_KEYS(nextAction);  (wonder why, typo or wanted?)

    (as expected)

    EVENT_CHECK_FAST_KEYS(nextAction); 

    Thanks again for your help
  • Posts: 0
    Ok, new update is out. Now you should be able to use

    // the following 2 events are equivalent to slow and fast key function and allow adding extra keys in event system.
    // make sure action is called by reference so it can be changed and returned.
    // Set action only if key is hit
    #define EVENT_CHECK_FAST_KEYS(action) {}
    #define EVENT_CHECK_SLOW_KEYS(action) {}

    to add to slow or fast keys.
  • edited January 22 Posts: 344
    ok, i already saw,maybe you overlooked my last post, so


    in UIDisplay::fast Action()

    are both events , so why checking for slow keys in fast action?


  • Posts: 0
    No haven't seen th epost. Had it always open to answer once I finished it.

    You are right. fast should not contain slow call as well. Have removed it for next update.
  • edited January 25 Posts: 344

    Checked it out and works fine, so i saw you indicated some Action Nubers as "reserved"

    // 1500-1699 reserved for custom Actions
    so i think we should reserve some numbers for repeatable Actions also(Number range below 1000) for use in Custom Events.

    so may be from 750 to 900 to leave space to others ?

  • Posts: 0
    Yes, that is a good idea. Just put comment for next release
    // 700-999 reserved for custom events.

    That should be more then enough:-)
  • Posts: 344
    Can you please give me a hint how to shift laserdriver to Custom events?

    is it something like :

    #undef EVENT_INITALIZE_LASER
    #define EVENT_INITALIZE_LASER { "my initialisation" ; return false;}

    #undef EVENT_SET_LASER(intensity)
    #define EVENT_SET_LASER(intensity) {" myroutine(intensity)";return false;}


  • Just add 2 new function that return a boolean like

    bool mySetLaser(uint8_t intensity) {
    ...
    return false;
    }

    extern bool mySetLaser(uint8_t intensity);
    #undef EVENT_SET_LASER(intensity) 
    #define EVENT_SET_LASER(intensity) mySetLaser(intensity)

  • Posts: 344
    Ok , thanks.
    would it be a problem for you to change intensity from uint8_t  to uint16_t ?
    (i´m playing with 12bit external PWM controller  ,looks quite nice :-) )
    so i´ll shift spindle control also to Custom event system with external hardware .


  • I have to check, but since it is just passed from gcode parser I think it should be no problem.
  • Posts: 344
    seems not that simple , next part affected is uint8_t secondspeed 

  • Ok, that is bad. Setting this ti 16 bit increases memory usage and delta users are already are at the limit. While it is easy to change that locally, do you think such a resolution makes a difference? On monitor we also have only 256 shades (ok more bit are coming).
  • Posts: 344
    I´m not shure if it makes that difference,and the more i think about i agree with you so  for now i´ll keep the 256 shades ( just shift that value 4 bits left in my routine to get 4095)
    for first tests with a led and oscilloscope  it looks quite nice , PWM frequency is at 900Hz which should give smooth operation.

    so in the moment there are 23 channels free..., big (sense free) playground
  • edited February 19 Posts: 344
    can you please give me a hint what to change to get the secondspeed work on 16 bit?
    just want to see if i get some visible changes as soon as i receive my 5 Watt Laser

    ok,got it , missed the public uint8 secondspeeed , first just saw the one in queuenonlinearmove
Sign In or Register to comment.