Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome General
 PowerHome Messageboard : PowerHome General
Subject Topic: advanced programming qns Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
jeffw_00
Super User
Super User


Joined: June 30 2007
Online Status: Offline
Posts: 929
Posted: November 25 2007 at 13:05 | IP Logged Quote jeffw_00

Hi - I'm realizing the Power part of PowerHome and have some programming questions….

1) I'm wondering if there is any way to selectively cancel stuff in the execution queue. My problem is this: Someone presses a button to turn on an outside light for 10 minutes. This triggers a macro with a 10 minute WAIT in it. 8 minutes later a second person does the same thing. 2 minutes later the light goes off, leaving the second person unsatisfied. Ideally, I'd like the code for the press to look at the execution queue, see if there are any pending requests related to that light, and cancel them. Not sure there is already a way to do this.

I had an idea for a workaround though: If I had a global variable that I incremented every time the button was pressed, then the macro with the delay in it (that is WAITing 10 minutes for the light to go off), could, at the end of the WAIT period, first check the value of this global variable before turning the light off, if the value has changed since the macro was executed, the macro would just die, since there has been later activity. However, this would require the macro, or pending event, (or whatever) to store a local copy of the global variable to later compare with the global one. Not sure how to do this in PH.


2) I'm finding increased reliability in my X-10 commands if they are all triggered as follows:
Wait 2
Send command
Wait 2
Send command again

Right now I'm coding this as 4 lines in a macro. It would be great to create my own function

Send_x10(module_name,val)

If (val==1)
    Wait 2
    Send module_name ON
    Wait 2
    Send module_name ON
End
Else if (val==0)
    Wait 2
    Send module_name OFF
    Wait 2
    Send module_name OFF
End
Endfunction

Then every X-10 command could be a single function call, and if I found a different paradigm worked better in the future, I would have to change it only in one place.

I know I may be pushing it, but I've been pleasantly surprised previously about 'hard' things that were actually very easy to do in PH, so I figured it couldn't hurt to ask.

Thanks!
/j



Back to Top View jeffw_00's Profile Search for other posts by jeffw_00
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: November 25 2007 at 14:52 | IP Logged Quote TonyNo

1. Not really. You can cancel waiting macros, though, with ph_killmacrowait.

2. I believe Dave already pointed out one concept for this in a previous post (your question #3: ph_macroparm). You can simulate "functions" like this.

Create a Macro called Send_x10 and use the Local variables to send the module ID and requested state.

SEND_X10:
10 comment LOCAL1 = ID, LOCAL2 = State
20 formula if [LOCAL2]=0, ph_x10btn( "[LOCAL1]", xoff, 0), ph_x10btn( "[LOCAL1]", xon, 0)
30 wait 2
40 formula if [LOCAL2]=0, ph_x10btn( "[LOCAL1]", xoff, 0), ph_x10btn( "[LOCAL1]", xon, 0)

You can then "call" it with something like ph_macroparm ( "SEND_X10", "BATH LAMP", 1, 0, 0, 0 )

Edited by TonyNo - November 25 2007 at 14:53
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
jbbtex
Senior Member
Senior Member


Joined: February 15 2007
Location: United States
Online Status: Offline
Posts: 181
Posted: November 25 2007 at 14:58 | IP Logged Quote jbbtex

1) ph_killmacrowait



__________________
Brady

"Never tell people how to do things. Tell them what to do and they will surprise you with their ingenuity." - Gen. George S. Patton
Back to Top View jbbtex's Profile Search for other posts by jbbtex
 
jeffw_00
Super User
Super User


Joined: June 30 2007
Online Status: Offline
Posts: 929
Posted: November 25 2007 at 15:02 | IP Logged Quote jeffw_00

1) AWESOME - solves many problems
2) Thanks Tony - saw the other post, hadn't made the connection
/j

Edited by jeffw_00 - November 25 2007 at 15:25
Back to Top View jeffw_00's Profile Search for other posts by jeffw_00
 
bhlonewolf
Senior Member
Senior Member


Joined: March 29 2007
Online Status: Offline
Posts: 198
Posted: November 25 2007 at 15:31 | IP Logged Quote bhlonewolf

Actually for a situation like this, do a few checks at the start of the macro. You can start the macro with ph_ismacrowaiting() to check if the macro is already waiting (meaning, someone hit the button already). You can then choose to either kill the macro, or extend the macro wait time (ph_extendmacrowait).
Back to Top View bhlonewolf's Profile Search for other posts by bhlonewolf
 
jeffw_00
Super User
Super User


Joined: June 30 2007
Online Status: Offline
Posts: 929
Posted: November 25 2007 at 16:03 | IP Logged Quote jeffw_00

Bhlonewolf - what you suggest is definitely more elegant, but I think a simple ph_killmacrowait at the beginning of the macro does the same thing. kills an old one if it exists, and then posts a new one with the right wait time.

Powerhome: "there is more than one way to do it" (just like Perl 8-})
Back to Top View jeffw_00's Profile Search for other posts by jeffw_00
 
bhlonewolf
Senior Member
Senior Member


Joined: March 29 2007
Online Status: Offline
Posts: 198
Posted: November 25 2007 at 17:04 | IP Logged Quote bhlonewolf

Really? I kind of like keeping the same macro running, seems cleaner :) But that's just me.

By the way, the extendmacrowait takes a couple of parameters, one that specifies if the time is _in addition to_ the current macro wait time, or if it just sets a new wait time. In your case, you could do it so it resets it to 10 minutes regardless of the current time.

But what I've done on mine is allow the macro to add cumulative time to that. For example, suppose you want that light to stay on 20 minutes instead of 10. Click it on twice, and 10 minutes gets added to the first 10.
Back to Top View bhlonewolf's Profile Search for other posts by bhlonewolf
 
jeffw_00
Super User
Super User


Joined: June 30 2007
Online Status: Offline
Posts: 929
Posted: November 25 2007 at 18:07 | IP Logged Quote jeffw_00

as I said - your approach is more elegant, but also more code. I like the click-twice to double the time, but I don't have a use for that here
thanks
/j
Back to Top View jeffw_00's Profile Search for other posts by jeffw_00
 
jeffw_00
Super User
Super User


Joined: June 30 2007
Online Status: Offline
Posts: 929
Posted: November 25 2007 at 19:42 | IP Logged Quote jeffw_00

Hi - i implemented 1) and 2) throughout my code. Cool stuff...but, one thing leads to another... 8-}

3) If I have a macro that calls 2 other macros, they get started together. I want the 2nd macro to start only when the first one completes. Is there an easy way to do this? I know there is a "submacro" command but it is undocumented.

4) When I re-init, the buttons in the Control Center revert to their default colors. I use the colors to signify state of global variables. I can create a macro that sets all the buttons to the right state, but how do I cause the macro to run at re-init?

Thanks!

Edited by jeffw_00 - November 25 2007 at 19:52
Back to Top View jeffw_00's Profile Search for other posts by jeffw_00
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: November 25 2007 at 20:00 | IP Logged Quote TonyNo

3. Calling a submacro holds execution in the primary macro until it's completed.

4. Create a macro called STARTUP and call that macro from it.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
jeffw_00
Super User
Super User


Joined: June 30 2007
Online Status: Offline
Posts: 929
Posted: November 25 2007 at 20:07 | IP Logged Quote jeffw_00

Thanks Tony.

3) OOPS - I'm calling macros, but via a FORMULA (to use the SEND_X10 macro mentioned above). I don't see a ph_submacro() or ph_submacroparm() function, maybe I'm out of luck?

4) didn't work. (PH Status doesn't show the STARTUP Macro called after the re-init)

thanks
/j
Back to Top View jeffw_00's Profile Search for other posts by jeffw_00
 
jbbtex
Senior Member
Senior Member


Joined: February 15 2007
Location: United States
Online Status: Offline
Posts: 181
Posted: November 25 2007 at 20:12 | IP Logged Quote jbbtex

4) there is a Trigger Type called System Process there you can set the Trigger ID to Reinitialize and put your macro in the Action field

Edited by jbbtex - November 25 2007 at 20:13


__________________
Brady

"Never tell people how to do things. Tell them what to do and they will surprise you with their ingenuity." - Gen. George S. Patton
Back to Top View jbbtex's Profile Search for other posts by jbbtex
 
jeffw_00
Super User
Super User


Joined: June 30 2007
Online Status: Offline
Posts: 929
Posted: November 25 2007 at 20:17 | IP Logged Quote jeffw_00

4) That did it, thanks!

3) ?

/j
Back to Top View jeffw_00's Profile Search for other posts by jeffw_00
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: November 25 2007 at 20:20 | IP Logged Quote TonyNo

3. Yes, I believe you are out of luck.

4. Ah, yes. Dave just changed this functionality.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
jeffw_00
Super User
Super User


Joined: June 30 2007
Online Status: Offline
Posts: 929
Posted: November 25 2007 at 20:22 | IP Logged Quote jeffw_00

3) I don't believe it until Dave weighs in, PH hasn't disappointed me yet 8-}

4) thanks!
/j
Back to Top View jeffw_00's Profile Search for other posts by jeffw_00
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: November 25 2007 at 22:19 | IP Logged Quote dhoward

3) Well, not completely out of luck, but probably just a little more involved than you were hoping.

The proper command you're going to need is SubMacro. The problem is due to the "Wait" command. As soon as the a macro enters Wait mode, it goes into the Waiting Macros queue and control transfers back to the execution queue (or to the macro that called the macro that is waiting). When a macro waits, it effectively ends so control is transferred back. Since you're wanting the control to NOT transfer back to the calling macro, the only available command to circumvent this behaviour is the Sub Macro command. The Sub Macro command treats a macro as an extension of calling macro. It is essentially the same as the calling macro from an execution perspective.

Now, how to use the Sub Macro command from your context of passing a couple of values in [LOCAL1] and [LOCAL2]. Since the Sub Macro is the same as the calling macro, there is no passing of parameters. We can just set the [LOCAL] variables in the calling macro and then call the Sub Macro, but I understand the desire to do it all in a single line. Below is the formula to properly call Tony's SEND_X10 macro from a Sub Macro all in a single line:

10 Sub Macro ph_rtne(ph_setvar_s(1,1,"BATH LAMP") + ph_setvar_a(1,2,1)) + "SEND_X10"

The Sub Macro command expects the ID of the macro to call in the formula field. What we're doing with this formula is setting the [LOCAL1] variable to "BATH LAMP" and the [LOCAL2] variable to 1. Both of these functions return a numeric which we add together (we're unconcerned with the return value). This return value is then wrapped in the ph_rtne function which takes a numeric and converts it to an empty string. This empty string is combined with "SEND_X10" which will end up being just "SEND_X10" (the ID of the macro for the Sub Macro command).

HTH,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
jeffw_00
Super User
Super User


Joined: June 30 2007
Online Status: Offline
Posts: 929
Posted: November 25 2007 at 23:58 | IP Logged Quote jeffw_00

PH Rules
thanks
/j
Back to Top View jeffw_00's Profile Search for other posts by jeffw_00
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum