maybe I missed it or it is not possible.
I’d like to set up a switch. This switch should have to functions. The first is executed as soon as I push it an release it immediately. The second one should be executed if I push the button and hold it for a given amount of time.
You can do something like this, I didn’t test it, you will maybe have to correct it.
In your App.c
#define BUTT\_PIN\_NUM 0 #define HOLD\_TIME 3000 // in ms cause APP\_SRIO\_ServicePrepare is called every ms u8 butt\_last\_state; u16 butt\_hold\_count; ///////////////////////////////////////////////////////////////////////////// // This hook is called before the shift register chain is scanned ///////////////////////////////////////////////////////////////////////////// void APP\_SRIO\_ServicePrepare(void) { if(butt\_last\_state == 0){ butt\_hold\_count++; if(butt\_hold\_count \>= HOLD\_TIME){//3 second hold time // function#2 here butt\_last\_state = 1; //avoid repetitive Function#2 and Function#1 to be triggered just after Function#2 } }else{ butt\_hold\_count=0; } } ///////////////////////////////////////////////////////////////////////////// // This hook is called when a button has been toggled // pin\_value is 1 when button released, and 0 when button pressed ///////////////////////////////////////////////////////////////////////////// void APP\_DIN\_NotifyToggle(u32 pin, u32 pin\_value) { if(pin == BUTT\_PIN\_NUM){ if(pin\_value == 1 && butt\_last\_state == 0){ if(butt\_hold\_count \< HOLD\_TIME){ // function#1 here } } butt\_last\_state = pin\_value; } }
If you need it in MBNG I don’t know.
Note: If Function#2 need a lot of process you can use a task to do not delay your SRIO Process. tutorial 006_rtos_tasks
if ^section == 1 delay_ms 500 if BUTTON:1 == 127 SEND CC USB1 1 1 127 exit endif if BUTTON:1 == 0 SEND CC USB1 1 2 0 exit endif endif
This code wait’s 500ms and checks if the button is still pressed. If yes it sends on channel 1, if not it sends on channel 2.
You can reduce the time for the short push to only wait the processing when long time press
if ^section == 1 delay\_ms 50 if BUTTON:1 == 0 SEND CC USB1 1 2 0 exit endif delay\_ms 500 if BUTTON:1 == 127 SEND CC USB1 1 1 127 exit endif endif
By this you can handle both situation time in any time respond configuration you want
Note that first condition will in fact be the time you manually release the button (if shorter than second delay) + the first delay as the script will re-trig when button is off ( due to button_mode=onoff)