Quantcast

Check for pressing a button twice problem

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Check for pressing a button twice problem

mp3jfast
Hi,

I have this code to check if a button is pressed twice within 6 seconds:

my $A_all_lights_timeout=0.1;
my $timer_A_all_lights              = new Timer ;

my $asleep =  'false';
my $trysleep = 'false';

# pressed twice within 6 seconds then asleep
if (state_now $test_lightsA eq "off" ) {

 if (not expired $timer_A_all_lights and $trysleep eq 'true') {
   $asleep = 'true';
   &alllightsoff; # macro put house a sleep
   $trysleep = 'false';

 } else {

   set $timer_A_all_lights ($A_all_lights_timeout*60);
   $trysleep = 'true';

 }
}



if (expired $timer_A_all_lights) {
 print_log "Too slow ";
 $trysleep = 'false';
}

This code is not working pressing A all lights off, even first time puts
all lights off. My wife is getting annoyed  (so do I).
What is going wrong?

John



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log
files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
________________________________________________________
To unsubscribe from this list, go to:
http://sourceforge.net/mail/?group_id=1365




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Check for pressing a button twice problem

Dave Lounsberry
John,

Not exactly sure what you are trying to do with the code but it appears that you are wanting 2 button presses within 6 seconds before running alllightsoff????

Looking at your code, $trysleep will always be false since you are setting it to false each pass through the code. You might try using a Generic_Item or $Save variable to track the sleep state. There are dozen or more ways to do what you are wanting, here is one of those ways....  to give you some ideas:

----- cut here ------
my $A_all_lights_timeout=0.1;
$house_asleep = new Generic_Item;
$timer_A_all_lights = new Timer;

if (state_now $test_lightsA eq OFF) {
   if (state $house_asleep ne ON and active $timer_A_all_lights ) {   # need to use "ne" to match unset and OFF
         &alllightsoff; # macro put house a sleep
         set $house_asleep ON;
   } else {
          set $timer_A_all_lights ($A_all_lights_timeout*60);
   }
}

if (expired $timer_A_all_lights and state $house_asleep ne ON) {
    print_log "Too slow ";
    set $house_asleep OFF;
}

---- cut here ---

Dave
 
---
Dave Lounsberry
[hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Check for pressing a button twice problem

mp3jfast
Hi,

Indeed that is what I wanted Dave. I tried your code but bad luck.
Mine code is now this:

my $athome = new Generic_Item;
my $house_asleep = new Generic_Item;

if (state_now $test_lightsA eq "off" ) {
  if (active $timer_A_all_lights ) {
    &alllightsoff;
    set $house_asleep ON;
  } else {
    set $timer_A_all_lights ($A_all_lights_timeout*60);
  }
}


if (expired $timer_A_all_lights and state $house_asleep ne ON) {
  print_log "Too slow ";
  set $house_asleep OFF;
}

But also switch all lights off after pushing the button for the first time.

John
Dave Lounsberry wrote:

> John,
>
> Not exactly sure what you are trying to do with the code but it
> appears that you are wanting 2 button presses within 6 seconds before
> running alllightsoff????
>
> Looking at your code, $trysleep will always be false since you are
> setting it to false each pass through the code. You might try using a
> Generic_Item or $Save variable to track the sleep state. There are
> dozen or more ways to do what you are wanting, here is one of those
> ways....  to give you some ideas:
>
> ----- cut here ------
> my $A_all_lights_timeout=0.1;
> $house_asleep = new Generic_Item;
> $timer_A_all_lights = new Timer;
>
> if (state_now $test_lightsA eq OFF) {
>    if (state $house_asleep ne ON and active $timer_A_all_lights ) {  
> # need to use "ne" to match unset and OFF
>          &alllightsoff; # macro put house a sleep
>          set $house_asleep ON;
>    } else {
>           set $timer_A_all_lights ($A_all_lights_timeout*60);
>    }
> }
>
> if (expired $timer_A_all_lights and state $house_asleep ne ON) {
>     print_log "Too slow ";
>     set $house_asleep OFF;
> }
>
> ---- cut here ---
>
> Dave
>  
> ---
> Dave Lounsberry
> [hidden email] <mailto:[hidden email]>



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Check for pressing a button twice problem

Matthew Williams-2
John Ophof wrote:

> Hi,
>
> Indeed that is what I wanted Dave. I tried your code but bad luck.
> Mine code is now this:
>
> my $athome = new Generic_Item;
> my $house_asleep = new Generic_Item;
>
> if (state_now $test_lightsA eq "off" ) {
>  if (active $timer_A_all_lights ) {
>    &alllightsoff;
>    set $house_asleep ON;
>  } else {
>    set $timer_A_all_lights ($A_all_lights_timeout*60);
>  }
> }
>
>
> if (expired $timer_A_all_lights and state $house_asleep ne ON) {
>  print_log "Too slow ";
>  set $house_asleep OFF;
> }
>
> But also switch all lights off after pushing the button for the first time.

You may want to try to reorder your code.  For most objects, a set doesn't
set something immediately, it gets set at the beginning of the next loop.
If other words, your timer will not be set until after your second block is
executed, the next time mh goes through the loop.  Move the "if (expired
..." block to just before the "if (state_now ..." block and see if that helps.

Matt
__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Check for pressing a button twice problem

mp3jfast
Same bad result!
I am not used to misterhouse mine former code was Turbo Pascal
programmed with DOS TW523.

John
Matthew Williams wrote:

> John Ophof wrote:
>  
>> Hi,
>>
>> Indeed that is what I wanted Dave. I tried your code but bad luck.
>> Mine code is now this:
>>
>> my $athome = new Generic_Item;
>> my $house_asleep = new Generic_Item;
>>
>> if (state_now $test_lightsA eq "off" ) {
>>  if (active $timer_A_all_lights ) {
>>    &alllightsoff;
>>    set $house_asleep ON;
>>  } else {
>>    set $timer_A_all_lights ($A_all_lights_timeout*60);
>>  }
>> }
>>
>>
>> if (expired $timer_A_all_lights and state $house_asleep ne ON) {
>>  print_log "Too slow ";
>>  set $house_asleep OFF;
>> }
>>
>> But also switch all lights off after pushing the button for the first time.
>>    
>
> You may want to try to reorder your code.  For most objects, a set doesn't
> set something immediately, it gets set at the beginning of the next loop.
> If other words, your timer will not be set until after your second block is
> executed, the next time mh goes through the loop.  Move the "if (expired
> ..." block to just before the "if (state_now ..." block and see if that helps.
>
> Matt
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com 
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
> ________________________________________________________
> To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365
>
>
>  



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Check for pressing a button twice problem

Dave Lounsberry


On 1/25/06, John Ophof <[hidden email]> wrote:
Same bad result!
I am not used to misterhouse mine former code was Turbo Pascal
programmed with DOS TW523.

John

Can you elaborate on "bad result'? Like what happens. Is the code failing on syntax error or not turning the lights on/off?

You might try putting some print_log statements in the code in various spots to see what is going on to help you debug it.

Dave

--
Dave Lounsberry
[hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Check for pressing a button twice problem

mp3jfast
Dave,

Pressing once on the button puts the house a sleep.

Only want that to happen when pressed twice quickly.

John
Dave Lounsberry wrote:

>
>
> On 1/25/06, *John Ophof* <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Same bad result!
>     I am not used to misterhouse mine former code was Turbo Pascal
>     programmed with DOS TW523.
>
>     John
>
>
> Can you elaborate on "bad result'? Like what happens. Is the code
> failing on syntax error or not turning the lights on/off?
>
> You might try putting some print_log statements in the code in various
> spots to see what is going on to help you debug it.
>
> Dave
>
> --
> Dave Lounsberry
> [hidden email] <mailto:[hidden email]>



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365

Loading...