Change a TP4 button channel dynamically
Dear All,
is there any way and the possibility for a TP4 button channel to be dynamically reassigned through the code ? For example the port 1 channel 100 to be changed to port1 channel 200.
Thanks,
George
is there any way and the possibility for a TP4 button channel to be dynamically reassigned through the code ? For example the port 1 channel 100 to be changed to port1 channel 200.
Thanks,
George
0
Comments
Nope. You can use REBUILD_EVENT to generate a new event table but you can't change the actual channel code of a button to the fly. What are you trying to accomplish?
May I ask why? Without the two letter word, well i dont know what I would do with my life.
? {{<Ctrl>B -or- <RtClick>Show External Controls}}
? Select all the buttons you want to customize (on a per-page scheme)
? Select the [General] Properties Tab
? Change [Override Global Settings] to [yes]
? Now each hard button can be selected per normal TP button & on the [Programming] Properties Tab you can change the [P:C] values
I think this is definitely the more labor intensive way (not only with development, but especially with regards to maintenance/support...) and I agree with [USER="1623"]ericmedley[/USER] and I track a flag & use a conditional expression.
I cannot explain in details, but if statements needed I should use hundreds of "if"...."if"...."if"...."if"...."if"...."if"...."if".... ones.
I'm sorry but this still doesn't change the argument. And the fact that, in any case, you cannot do it, still points you in the same directino: doing it in code. The whole If If If If thing too is not necessary.
Here's a smiple approach. make a variable that tracks the mode of the button. How many modes? Who cares - lets say the one button can do 100 different things. In code as you go along you're tracking what mode the system is in. Cable/Satellite/HVAC/Pop Up Toaster/Coffe Maker/World Wide ThermoNuclear War Engage/etc...
You can even create constants that chagne the numbers into text.
integer Mode_Cable=1;
integer Mode_Satellite-2;
integer Mode_ThermoNuclear_war=55;
etc..
Then in code you just track it
define_function fn_set_North_Korea_status(integer nCrazy_Level)} if(nCrazy_Level>5){ MyMode=Mode_ThermoNuclear_war; }// if }// define_functionso what you end up with is a button event (or a button event that goes off to a function )
Button_Event[MyR4s,The_Button]{ push:{ switch(MyMode){ case Mode_Cable:{ // do the cable thing }// case case Mode_Satellite:{ .// do the satellite thing }// case case Mode_ThermoNuclear_war:{ // do the thermonuclear war thing } }// switch }// push }// button_eventI do this for a lot of both hard and soft buttons. I even deliberately change the button labels on the fly. And if there's hard buttons I even turn on/off little pointers in the UI layout to let the user know the hard button now does something else. this approach is entirely scaleable and allows for almost an endless variety of things a single button can do (or not do for that case) I use the same idea to disable a button if I don't want the user hitting it. I hope this helps.
No and thank goodness there isn't. It would be a mess. Each page on an R4 has a different set of buttons so you can just changes pages to use different channel numbers if need be. Alternatively you can keep the numbers as is, and depending on what's needed, run different code when its triggered. Changing channels dynamically will not make your life easier.
Paul
PROGRAM_NAME='Do_Push_Template' (***********************************************************) (* FILE CREATED ON: 01/28/2018 AT: 17:23:44 *) (***********************************************************) (* FILE_LAST_MODIFIED_ON: 01/28/2018 AT: 18:29:04 *) (***********************************************************) DEFINE_CONSTANT //template constants DO_PUSH_TIMED_5S_MAX = 50; DO_PUSH_TIMED_10S_MAX = 100; DO_PUSH_TIMED_15S_MAX = 150 ; DO_PUSH_TIMED_20S_MAX = 200 ; DO_PUSH_TIMED_30S_MAX = 300; DO_PUSH_TIMED_1M_MAX = 600; DO_PUSH_TIMED_5M_MAX = 3000; CHAR NUM_UIs_IN_SYSTEM = 7; DEFINE_VARIABLE //real UI's VOLATILE DEV dvUI_Arry[NUM_UIs_IN_SYSTEM] = //real UIs { dvUI_1 ,dvUI_2 ,dvUI_3 ,dvUI_4 ,dvUI_5 ,dvUI_6 ,dvUI_7 } DEFINE_VARIABLE //virtual device UI's VOLATILE DEV vUI_DevArry[NUM_DEVs_IN_SYSTEM] = //device virtual UIs { vDev1_UI ,vDev2_UI ,vDev3_UI ,vDev4_UI } DEFINE_VARIABLE //geeneral var's PERSISTENT INTEGER nUI_Active_Dev[NUM_UIs_IN_SYSTEM]; VOLATILE INTEGER nUI_PushedBtn[NUM_UIs_IN_SYSTEM]; DEFINE_EVENT //BUTTON_EVENT[dvUI_Arry,0]//the real UIs to interface with the devices virtual UI BUTTON_EVENT[dvUI_Arry,0] { PUSH : { STACK_VAR INTEGER nBtn; STACK_VAR INTEGER nUI_Indx; nBtn = BUTTON.INPUT.CHANNEL; nUI_Indx = GET_LAST(dvUI_Arry); if(nBtn <= NUM_DEVs_IN_SYSTEM)//let's say button 1-10 are for dev control selection { nUI_Active_Dev[nUI_Indx] = nBtn; } if(nUI_Active_Dev[nUI_Indx]) { nUI_PushedBtn[nUI_Indx] = nBtn; DO_PUSH_TIMED(vUI_DevArry[nUI_Active_Dev[nUI_Indx]],nBtn,DO_PUSH_TIMED_15S_MAX); } //longest possible hold ever needed for any device else { //send 0 error UI has no selected devices....... } } // //HOLD: occurs in the virtual button event not here, you're not running code here // RELEASE: { STACK_VAR INTEGER nBtn; STACK_VAR INTEGER nUI_Indx; nBtn = BUTTON.INPUT.CHANNEL; nUI_Indx = GET_LAST(dvUI_Arry); if(nUI_PushedBtn[nUI_Indx] == nBtn)//don't send a release if we didn't send a push first, not likely { DO_RELEASE(vUI_DevArry[nUI_Active_Dev[nUI_Indx]],nBtn); nUI_PushedBtn[nUI_Indx] = 0; } } } DEFINE_EVENT //BUTTON_EVENT[vDev1_UI,0]//device 1 virtual UI BUTTON_EVENT[vDev1_UI,0] { PUSH : { STACK_VAR INTEGER nBtn; nBtn = BUTTON.INPUT.CHANNEL; if(nBtn <= NUM_DEVs_IN_SYSTEM)//only the index button of this virtual will trigger this { //device selected start up code and send FB to populate UI values, etc } else { //do stuff } } HOLD[2,REPEAT]: { //holds will work up to 10 seconds max since the do_push is timed with a max time of 15 seconds } RELEASE: { //releases work just normally } } DEFINE_EVENT //BUTTON_EVENT[vDev2_UI,0]//device 2 virtual UI BUTTON_EVENT[vDev2_UI,0] { PUSH : { STACK_VAR INTEGER nBtn; nBtn = BUTTON.INPUT.CHANNEL; if(nBtn <= NUM_DEVs_IN_SYSTEM)//only the index button of this virtual will trigger this { //device selected start up code and send FB to populate UI values, etc } else { //do stuff } } HOLD[2,REPEAT]: { //holds will work up to 10 seconds max since the do_push is timed with a max time of 15 seconds } RELEASE: { //releases work just normally } } DEFINE_EVENT //BUTTON_EVENT[vDev3_UI,0]//device 3 virtual UI BUTTON_EVENT[vDev3_UI,0] { PUSH : { STACK_VAR INTEGER nBtn; nBtn = BUTTON.INPUT.CHANNEL; if(nBtn <= NUM_DEVs_IN_SYSTEM)//only the index button of this virtual will trigger this { //device selected start up code and send FB to populate UI values, etc } else { //do stuff } } HOLD[2,REPEAT]: { //holds will work up to 10 seconds max since the do_push is timed with a max time of 15 seconds } RELEASE: { //releases work just normally } } DEFINE_EVENT //BUTTON_EVENT[vDev4_UI,0]//device 4 virtual UI BUTTON_EVENT[vDev4_UI,0] { PUSH : { STACK_VAR INTEGER nBtn; nBtn = BUTTON.INPUT.CHANNEL; if(nBtn <= NUM_DEVs_IN_SYSTEM)//only the index button of this virtual will trigger this { //device selected start up code and send FB to populate UI values, etc } else { //do stuff } } HOLD[2,REPEAT]: { //holds will work up to 10 seconds max since the do_push is timed with a max time of 15 seconds } RELEASE: { //releases work just normally } }Imagine if the core processes had a notion of what was going on, instead of slavishly passing buttons into actions.
Like, if the system knew what source was selected in a particular room, giving context to any UI that was in charge of that room at the moment. So the UI would only every have to say "PLAY" and the system would apply that action to whatever the context demanded, instead of sorting through what page the ui was on and manhandling the hard button input to keep up.
I bet that such an architecture would also be able to easily share what rooms were in use, with what sources, should that matter to a user. Maybe even avoid conflicts automatically. Among other things.
Throw in a database of devices to define what "Play" means to each, and how to reach them (IR? SERIAL? IP? RELAY?) to say that... and gee, you could "reprogram" the system dynamically by just changing pointers to different sources (or system devices) in data. Maybe even without rebooting.
Yeah. A big project. One that sounds familiar to some of us....