Long push on button

Discuss PC Developer and Web Developer projects and features here.
User avatar
Nico595
Posts: 95
http://meble-kuchenne.info.pl
Joined: Tue Jul 04, 2023 4:17 pm
Has thanked: 18 times
Been thanked: 4 times

Flowcode v10 Long push on button

Post by Nico595 »

Hello,

I need a long push on button function. Have you idea to do the long time push button ?
When I click on the button with long push, I want repeat the execution of the macro. I can't find parameter in the button to do it.

It's like you up the volume of your music player.

I use the same button in the "simple com sender" project. This "button" come from "Creation".
PC Dev Simple USB Sender.fcsx
(30.06 KiB) Downloaded 29 times

Thank you so much.
Last edited by Nico595 on Mon Mar 03, 2025 9:15 am, edited 1 time in total.

medelec35
Matrix Staff
Posts: 1954
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 626 times
Been thanked: 656 times

Re: Long push on button

Post by medelec35 »

What I do for long and short press detection is have a loop with a counter, timeout and a delay that continues all the time the button is pressed.
All the time the button is pressed the loop will continue until the button is released or the loop count is over a certain value i.e. for timeout.
Just after the loop if the loop count over a fixed value then its along press, otherwise it's a short press.
Martin

User avatar
Nico595
Posts: 95
Joined: Tue Jul 04, 2023 4:17 pm
Has thanked: 18 times
Been thanked: 4 times

Re: Long push on button

Post by Nico595 »

Thank you Martin for your fast answer :)

If I understand good, no parameter in the button exist to do it.
I use your method in my embedded project, it work fine with a keyboard interrupt.

With PC App the macro is firstly called by the button and it's very good. We don't need check the state of the button every time in the App.
But with a long push function we must check the state of the button to call the macro.

If the macro of the button is not called by the button, the macro process maybe disconnected by other process. It's again a problem with the priority level. When the macro is called by the button, the macro process is run in first time, probably with the high level priority.

Can you customise proprieties of this button to obtain the long push parameter with repeat the called macro ?

Like this we keep the high level priority of the process for the last pushed button.

User avatar
Nico595
Posts: 95
Joined: Tue Jul 04, 2023 4:17 pm
Has thanked: 18 times
Been thanked: 4 times

Re: Long push on button

Post by Nico595 »

I find a solution in mixing two macro with interrupt on the long push macro. Work fine some minutes and the Interrupt stop without reason.

I added a simple counter on the "Simple Com Sender". Push on "Interrupt" button, you can see the interrupt itself stopped around 1300, 2600 ...
Have you this problem ?

PC Dev Simple USB Sender.fcsx
(37.64 KiB) Downloaded 33 times
Capture_2025-03-04 101027.png
Capture_2025-03-04 101027.png (18.97 KiB) Viewed 8166 times

Thank you for your support.

mnfisher
Valued Contributor
Posts: 1512
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 725 times

Re: Long push on button

Post by mnfisher »

One thing to try:

Move NumericIndicator1:SetValue(compt_test1) to the loop in main. I'm not sure about app developer - but in general you need to keep interrupt handlers as short as possible (if another interrupt occurs before the handler is finished then the code will lock up...)

I cranked up the interrupt rate a bit and it runs for longer (counts to 6000 then resets) - and repeats... If it locks - and it seems to eventually then the code seems to be still running.. I added a simple 'flashing' indicator - and that flashes even after the counter stops being updated (so maybe a bug in the numeric indicator? - or the timer interrupt stops?)

Martin
Attachments
PC Dev Simple USB Sender.fcsx
(40.09 KiB) Downloaded 28 times

User avatar
Nico595
Posts: 95
Joined: Tue Jul 04, 2023 4:17 pm
Has thanked: 18 times
Been thanked: 4 times

Re: Long push on button

Post by Nico595 »

Hi Martin

Thank you so much for your answer, I will try it.
Last edited by Nico595 on Tue Mar 04, 2025 11:10 am, edited 2 times in total.

mnfisher
Valued Contributor
Posts: 1512
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 725 times

Re: Long push on button

Post by mnfisher »

I also tried tying the flash to comp_test1 - in this case the LED stops flashing so it looks like it's a problem with the interrupt code.

Martin

User avatar
Nico595
Posts: 95
Joined: Tue Jul 04, 2023 4:17 pm
Has thanked: 18 times
Been thanked: 4 times

Re: Long push on button

Post by Nico595 »

Your var ".i" is no incremented by the interrupt but by the main. I placed "i" var in the macro started by the interrupt.
Work if you don't push button but when you push a button like "Vol Up" the interrupt is stopped.

I think the delay is also a problem in the main.

medelec35
Matrix Staff
Posts: 1954
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 626 times
Been thanked: 656 times

Re: Long push on button

Post by medelec35 »

I have recently looked into timer interrupts with PC Developer.
Conclusion is mentioned here.
Martin

User avatar
Nico595
Posts: 95
Joined: Tue Jul 04, 2023 4:17 pm
Has thanked: 18 times
Been thanked: 4 times

Re: Long push on button

Post by Nico595 »

Hi Martin,

So, we can't use the Interrupt without your trigger ?

I use successfully the Interrupt in my embedded project, it work fine but because we can set the level priority of the Interrupt in the C code. Without Interrupt we can't design a a big project.

The problem about Interrupt in PC App that we have no priority level, the Interrupt are stopped by push on button or by the main.

I checked the updated project with "i" in counter macro, same problem. Without delay in the main, the Interrupt was not stopped by push on button but stopped in the time without reason.

Post Reply