From: Gregg L. <gr...@li...> - 2008-08-04 03:12:26
|
Jacob Strandlien wrote: > Sure, if you could send me the new code off-list I'll even help you do > testing on it if you'd like. Sounds good. I'm testing now and will forward on when I think it's ok. > Here's the test case I was trying to run while exploring using a while > loop with insteon commands: > > if (state_now $go_crazy_key eq ON) { > while (state_now $go_crazy_key eq ON){ > sleep(5); > $entry_light->set(ON); > sleep(5); > $entry_light->set(OFF); > } > } > > The first $entry_light->set(ON); seems to go through, but then > MisterHouse seems to freeze up. Can't figure out why for the life of me. All user code is evaluated once per "mh loop". Loops are scheduled via the main program and run in accordance w/ the ini parms: sleep_time and sleep_count. Further, only one item has state_now true for a given loop. Likewise, state_now remains true for the entire loop evaluation. So, to simulate your above... if ($go_crazy_key_is_set_on_now) { while ($go_crazy_key_is_set_on_now){ # uh-oh--endless loop. # unless we supplement the monotony w/ pointless sleeps: sleep(5); # which gives us winks w/i the endless loop } } Possibly, an alternative is to key up your command stream on $go_crazy_key: my @crazy_stuff = (); if ($go_crazy_key->state_now eq ON) { @crazy_stuff = (); # init in case we jump in line unshift @crazy_stuff, "$entry_light->set(ON)"; unshift @crazy_stuff, "$entry_light->set(OFF)"; # the above seems quite pointless, but ... unshift @crazy_stuff, "speak crazy is, crazy does"; } my $have_crazy_stuff_to_do = @crazy_stuff; if ($have_crazy_stuff_to_do) { my $crazy_skit = pop @crazy_stuff; # yes, with a "k" eval $crazy_skit; # we'll keep doing crazy skits each # mh loop until the well runs dry print ".... not so crazy now as you have error: $@\n" if $@; } |