I just cant see the answer...

General Discussion on DemoPad or related products
Post Reply
solidelectricalltd
Posts: 4
Joined: Tue Sep 02, 2014 9:57 pm

I just cant see the answer...

Post by solidelectricalltd » Tue Jan 27, 2015 9:54 pm

Its going to be glaringly obvious but I just cant see the solution, looking at it too deep maybe. I want to put a power off button on a press/hold so you press and hold it for say 3 seconds and runs a macro but if you let go before 3 seconds it doesn't do anything.

Come on peeps, I'm tearing my hair out.

Cheers.

Idealhomes
Posts: 144
Joined: Mon Jul 16, 2012 3:35 pm
Location: New Zealand
Contact:

Re: I just cant see the answer...

Post by Idealhomes » Wed Jan 28, 2015 6:28 am

I would do it using a flags based on time.

When a button is pressed, a flag (you could call it 'power off ready') goes on at 2.55 secs and off at 3.20 secs (using a delay for times), then set the button release to execute your commands but only if 'power off ready' is on using the 'Dependent Flag'. This will allow you to execute your macros at the 3 second mark, any earlier and they will not execute but the flag will reset for next time.

Simple but effective. I hope this helps :)
"Setting the Standard in Quality and Commitment"

cv27
Posts: 233
Joined: Sat Nov 24, 2012 10:15 pm
Location: Montréal, QC, Canada

Re: I just cant see the answer...

Post by cv27 » Wed Jan 28, 2015 6:45 pm

Idealhomes wrote:I would do it using a flags based on time.

When a button is pressed, a flag (you could call it 'power off ready') goes on at 2.55 secs and off at 3.20 secs (using a delay for times), then set the button release to execute your commands but only if 'power off ready' is on using the 'Dependent Flag'. This will allow you to execute your macros at the 3 second mark, any earlier and they will not execute but the flag will reset for next time.

Simple but effective. I hope this helps :)
I suspect if I hold the button for more than the Off delay, the actions won't fire?

cv27
Posts: 233
Joined: Sat Nov 24, 2012 10:15 pm
Location: Montréal, QC, Canada

Re: I just cant see the answer...

Post by cv27 » Wed Jan 28, 2015 6:56 pm

solidelectricalltd wrote:Its going to be glaringly obvious but I just cant see the solution, looking at it too deep maybe. I want to put a power off button on a press/hold so you press and hold it for say 3 seconds and runs a macro but if you let go before 3 seconds it doesn't do anything.

Come on peeps, I'm tearing my hair out.

Cheers.
Here's another approach.

1- On the press event of a button, set a flag to OFF (flag name "button_hold" for example)
2- Also in the press event, set flag "button_hold" to On after a delay of 3 seconds
3- On the release event of that button, perform your actions, all being dependent on flag "button_hold" being On

If your list of actions is on the long side, you might want to create those in a macro (number custom actions) and then just set that number to 1 in the release event depending on flag "button_hold" being On.

Idealhomes
Posts: 144
Joined: Mon Jul 16, 2012 3:35 pm
Location: New Zealand
Contact:

Re: I just cant see the answer...

Post by Idealhomes » Wed Jan 28, 2015 7:34 pm

cv27 wrote:
Idealhomes wrote:I would do it using a flags based on time.

When a button is pressed, a flag (you could call it 'power off ready') goes on at 2.55 secs and off at 3.20 secs (using a delay for times), then set the button release to execute your commands but only if 'power off ready' is on using the 'Dependent Flag'. This will allow you to execute your macros at the 3 second mark, any earlier and they will not execute but the flag will reset for next time.

Simple but effective. I hope this helps :)
I suspect if I hold the button for more than the Off delay, the actions won't fire?
Yeah doing it this way will only give you a window of opportunity for the macro to fire, or you can have the flag go off on the release press instead of timed delay.

Press button: Set flag 'power off ready' with delay of 2.55 seconds

Release button: Fire Macro dependant on 'power off ready' being 'On', and then set 'power off ready' flag to 'Off' (making sure this is at the bottom of the list).
"Setting the Standard in Quality and Commitment"

cv27
Posts: 233
Joined: Sat Nov 24, 2012 10:15 pm
Location: Montréal, QC, Canada

Re: I just cant see the answer...

Post by cv27 » Wed Jan 28, 2015 10:04 pm

solidelectricalltd wrote:Its going to be glaringly obvious but I just cant see the solution, looking at it too deep maybe. I want to put a power off button on a press/hold so you press and hold it for say 3 seconds and runs a macro but if you let go before 3 seconds it doesn't do anything.

Come on peeps, I'm tearing my hair out.

Cheers.
The issue with my first proposed approach is that the user sees no feedback until the button is released; he may have pressed & held the button for 5-6 seconds for nothing. So here's a variation:
0- To use this, you need to put all your actions in a macro (custom number actions); let's assume Exec_Off as a number
1- On the press event of a button, set a flag to OFF (flag name "button_hold" for example)
2- Also in the press event, set flag "button_hold" to On after a delay of 3 seconds
3- On the press & hold event of that button, set Exec_Off = 1, dependent on flag "button_hold" being On and set to repeat every 3.1 seconds
4- Nothing on the release event of the button
5- To avoid the user pressing & holding the button for ever and re-engaging the custom number actions more than once, set "button_hold" to Off as the first action in your custom number actions

With this version, the user will see the actions immediately at 3 seconds, so he knows to let go the button.

solidelectricalltd
Posts: 4
Joined: Tue Sep 02, 2014 9:57 pm

Re: I just cant see the answer...

Post by solidelectricalltd » Thu Jan 29, 2015 9:51 am

Thanks a bunch chaps, much appreciated. You are life savers.

Idealhomes
Posts: 144
Joined: Mon Jul 16, 2012 3:35 pm
Location: New Zealand
Contact:

Re: I just cant see the answer...

Post by Idealhomes » Fri Jan 30, 2015 6:40 am

cv27 wrote:
solidelectricalltd wrote:Its going to be glaringly obvious but I just cant see the solution, looking at it too deep maybe. I want to put a power off button on a press/hold so you press and hold it for say 3 seconds and runs a macro but if you let go before 3 seconds it doesn't do anything.

Come on peeps, I'm tearing my hair out.

Cheers.
The issue with my first proposed approach is that the user sees no feedback until the button is released; he may have pressed & held the button for 5-6 seconds for nothing. So here's a variation:
0- To use this, you need to put all your actions in a macro (custom number actions); let's assume Exec_Off as a number
1- On the press event of a button, set a flag to OFF (flag name "button_hold" for example)
2- Also in the press event, set flag "button_hold" to On after a delay of 3 seconds
3- On the press & hold event of that button, set Exec_Off = 1, dependent on flag "button_hold" being On and set to repeat every 3.1 seconds
4- Nothing on the release event of the button
5- To avoid the user pressing & holding the button for ever and re-engaging the custom number actions more than once, set "button_hold" to Off as the first action in your custom number actions

With this version, the user will see the actions immediately at 3 seconds, so he knows to let go the button.
Or....lol, there are many ways to do this....

Press button: sets flag 'Power Off Ready' to 'ON' with no delays, have a delay of 3 seconds that executes your Macros with 'Dependant Flag' 'Power Off Ready' being 'ON'.

Release button: sets flag 'Power Off Ready' to 'OFF'.

Actions will always execute at 3 seconds as long as you do not release the button, you will always see feedback at the 3 second mark even if you hold for 4+ seconds.

Who else has a way to do this..... :lol:
"Setting the Standard in Quality and Commitment"

cv27
Posts: 233
Joined: Sat Nov 24, 2012 10:15 pm
Location: Montréal, QC, Canada

Re: I just cant see the answer...

Post by cv27 » Fri Jan 30, 2015 6:32 pm

Idealhomes wrote:Or....lol, there are many ways to do this....

Press button: sets flag 'Power Off Ready' to 'ON' with no delays, have a delay of 3 seconds that executes your Macros with 'Dependant Flag' 'Power Off Ready' being 'ON'.

Release button: sets flag 'Power Off Ready' to 'OFF'.

Actions will always execute at 3 seconds as long as you do not release the button, you will always see feedback at the 3 second mark even if you hold for 4+ seconds.

Who else has a way to do this..... :lol:
SO funny, reminds me of my early programming days where we had contests for who could code a function with the least amount of code :ugeek:

On this one, Idealhomes, you get the prize

Post Reply