IR control - how to deal with a sequence
Pep_SD
Posts: 106
I have a pop-up page on a panel with a list of icons representing the favorite satellite channels (HBO = 9456, TNT=9423 etc.).
I control the sat. box by IR.
When a push happens a button (HBO for instance), I want to send the command to the Sat to switch to HBO.
So far, here is my code:
The problem I have is it's working fine if the channel number is composed of different digits (e.g. 9456), but if there are at least 2 identical digits (e.g. 303) then I don't see the Pulse for the second identical digit: the push on 303 channel/icon produces only the pulses for 3 and 0.
I understand it's a timing issue where the channel on 5001:11:1 is still ON when the pulse for the second identical digit is sent ('3' in this example) - but I don't know how to fix it.
Comments, advice, critics are welcome.
I control the sat. box by IR.
When a push happens a button (HBO for instance), I want to send the command to the Sat to switch to HBO.
So far, here is my code:
DEFINE_DEVICE dvTP = 10001:1:1 //touchpanel dvSat = 5001:11:1 //Sat receiver on IR port 3 = NI4000 port #11 DEFINE_VARIABLE VOLATILE INTEGER nSatChButtons[]={114,119} // Buttons on panel VOLATILE INTEGER nCmdSatChannels[]={9456,303} //Actual Satellite ch number CHAR sCmdSatChannels[5]='' //To store the Sat channel as a string INTEGER nPanelIndex INTEGER nButtonIndex INTEGER i INTEGER cmd DEFINE_EVENT BUTTON_EVENT[dvTP, nSatChButtons] { PUSH: {//Select input SET_PULSE_TIME (1) nButtonIndex = GET_LAST(nSatChButtons) sCmdSatChannels = ITOA(nCmdSatChannels[nButtonIndex]) //Convert number of Sat channel to string FOR(i=1;i<=LENGTH_ARRAY(sCmdSatChannels);i++) { cmd=sCmdSatChannels[i]-48+10 // -48 for implicit conversion ASCII to decimal, // +10 to match the actual channel on dvSat PULSE[dvSat,cmd] } } }
The problem I have is it's working fine if the channel number is composed of different digits (e.g. 9456), but if there are at least 2 identical digits (e.g. 303) then I don't see the Pulse for the second identical digit: the push on 303 channel/icon produces only the pulses for 3 and 0.
I understand it's a timing issue where the channel on 5001:11:1 is still ON when the pulse for the second identical digit is sent ('3' in this example) - but I don't know how to fix it.
Comments, advice, critics are welcome.
0
Comments
SEND_COMMAND dvSAT,"'XCH ',ITOA(BUTTON.INPUT.CHANNEL)"
Where the TP button is the channel you want entered.
You'll have to use the XCHM command to tell the port how to format the XCH. This is all detailed in the master instruction manual and the help file.
There are PLENTY of ways to handle channel commands. Some here use the XCH command that's built in. The basic syntax would be SEND_COMMAND dvSAT,"'XCH-303'" (I think - only used it once.) Then there's a couple of different "functions" or "calls" here on the board.
Check these out - it might point you in the right direction:
http://www.amxforums.com/showthread.php?t=352
http://www.amxforums.com/showthread.php?t=1314
http://www.amxforums.com/showthread.php?t=3268&page=3
There's one that I had posted on here, but can't find it. Should be simple enough to do a search! Good luck!
The problem is timing, so another solution is to implement your own timing. Implement a queue for the IR pulses. Write it once and use it a thousand times - or PM me and I'll send you mine.
Some IR controlled devices are very odd indeed. For example, my TV accepts IR pulses in the usual way for all commands except the AV Input command, which also acts as the power on command in our household, I think because we never use the tuner in the TV. For that to work I have to hold down the button for at least half a second. So a laboriously constructed piece of code which allows you to define at a per-command level thnigs like the pause between pulses and the length of the pulses is worth having if you are in this game for the long haul.
Also consider that you may wish to send a sequence of commands to the TV from your code: Power on - Channel select - Mute off. And each of those commands may involve multiple IR flashes. You can never really know the state of an IR controlled device. IR control is intended to be used with a feedback loop through the user's eyes and ears and we don't have that. I've programmed pulse sequences as long as 13 pulses to achieve a guaranteed outcome.
So your generic code to handle IR flashing needs:
A table-driven approach to describing how to control a device
An incoming high-level command queue "Power On","Select channel 23" etc
Some code to unpack the pulse trains for each command
An outgoing IR pulse queue
Some code in define_program to start and stop flashes at the right times.
Here is my code that fills in the command table for a given model of TV being used as a monitor. The "Short" commands represent the buttons on the remote control. The "Long" commands represent the things that we actually want it to do.
Or you can use:
SEND_COMMAND DATA.DEVICE,"'CTON',2"
SEND_COMMAND DATA.DEVICE,"'CTOF',5"
in the Data_Event and play with those two numbers to get the right timing.
But why re-invent the wheel? They have some very flexible, very customizable built-in commands; use them!
Could it be this one?
A random Programming Example -- DSS Music Channels
--John
Not quite. Here's the piece of code that I use for channels. I got it from someone, who I think got it from someone else - you know how it goes - code blocks get passed around and we forget the true originator. Regardless of who it's from, it's a mighty fine piece of code. You would change the CTON/CTOF to speed up or slow down the sequence.
http://www.amxforums.com/showpost.php?p=21068&postcount=85
It also helped understanding the bigger picture .