Home AMX User Forum AMX General Discussion

IR control - how to deal with a sequence

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:
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.

Comments

  • Try the XCH send command.

    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.
  • jjamesjjames Posts: 2,908
    Pulse bad - SP good

    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!
  • XCH / XCHM was new to me so I went looking and it isn't in the NS2 help file but I did find it in the NIx000 manual. It looks like it does the job.

    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.
    if (sModelName = 'PanasonicTC80V95A') 
    	{
    	
            (*
    	Using the AVT IRL for the Panasonic TC68V80A	
    	Ignoring the VCR commands in the file
    	*)
    	
    	nCTON                                            = 3
    	nCTOF                                            = 3
    	
    	(*                Touchpanel                  IR  Description          Repeats Delay *)
    	IRCommandSetShort(tpDisplayPowerToggle       ,9   ,'Power Toggle'      ,False  ,0      ) (* Not power on *)
    	IRCommandSetShort(tpDisplay0                 ,10  ,'0'                 ,False  ,0      )
    	IRCommandSetShort(tpDisplay1                 ,11  ,'1'                 ,False  ,0      )
    	IRCommandSetShort(tpDisplay2                 ,12  ,'2'                 ,False  ,0      )
    	IRCommandSetShort(tpDisplay3                 ,13  ,'3'                 ,False  ,0      )
    	IRCommandSetShort(tpDisplay4                 ,14  ,'4'                 ,False  ,0      )
    	IRCommandSetShort(tpDisplay5                 ,15  ,'5'                 ,False  ,0      )
    	IRCommandSetShort(tpDisplay6                 ,16  ,'6'                 ,False  ,0      )
    	IRCommandSetShort(tpDisplay7                 ,17  ,'7'                 ,False  ,0      )
    	IRCommandSetShort(tpDisplay8                 ,18  ,'8'                 ,False  ,0      )
    	IRCommandSetShort(tpDisplay9                 ,19  ,'9'                 ,False  ,0      )
    	IRCommandSetShort(tpDisplayDashSlashDashDash ,20  ,'-/--'              ,False  ,0      )
    	IRCommandSetShort(tpDisplayChannelUp         ,22  ,'Channel Up'        ,False  ,0      )
    	IRCommandSetShort(tpDisplayChannelDown       ,23  ,'Channel Down'      ,False  ,0      )
    	IRCommandSetShort(tpDisplayVolumeUp          ,24  ,'Volume Up'         ,True   ,0      )
    	IRCommandSetShort(tpDisplayVolumeDown        ,25  ,'Volume Down'       ,True   ,0      )
    	IRCommandSetShort(tpDisplayAudioMuteToggle   ,26  ,'Mute Toggle'       ,False  ,0      )
    	IRCommandSetShort(tpDisplayAVInput           ,29  ,'AV Input'          ,False  ,0      )
    	IRCommandSetShort(tpDisplayPause1Second      ,6   ,'Pause 1 seconds'   ,False  ,10     ) (* 6 is empty *)
    	IRCommandSetShort(tpDisplayPause2Seconds     ,6   ,'Pause 2 seconds'   ,False  ,20     )
    	IRCommandSetShort(tpDisplayPause3Seconds     ,6   ,'Pause 3 seconds'   ,False  ,30     )
    	(*
    	Not implementing power on cos implicit in av input selection
    	Channel Up and Down always switch on power (off standby)
    	then AVInput goes to AV1
    	*)
    
            (* Power on - input 1 *)
    
    	IRCommandSetStart()
    	(* First guarantee power on but not which channel *)
    	IRCommandSetAdd(tpDisplayChannelUp)
    	IRCommandSetAdd(tpDisplayPause1Second)
    	(* Now guarantee a TV channel *)
    	IRCommandSetAdd(tpDisplayChannelUp)
    	(* Now toggle to first AV input *)
    	IRCommandSetAdd(tpDisplayAVInput)
    	IRCommandSetLong(tpDisplayInput1,nIRCommandTemp,'Power On Input 1')
    
            (* Power off *)
    
    	IRCommandSetStart()  
    	(* First guarantee power on *)
    	IRCommandSetAdd(tpDisplayChannelUp)
    	IRCommandSetAdd(tpDisplayPause1Second)
    	(* Now toggle power off *)
    	IRCommandSetAdd(tpDisplayPowerToggle)
    	IRCommandSetLong(tpDisplayPowerOff,nIRCommandTemp,'Power Off')
      } (* PanasonicTC80V95A *)
    
  • XCH / XCHM was new to me so I went looking and it isn't in the NS2 help file but I did find it in the NIx000 manual. It looks like it does the job.

    The problem is timing, so another solution is to implement your own timing.

    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.
  • DHawthorneDHawthorne Posts: 4,584
    XCH utilizes the CTON/CTOF commands, or you can use the SP command to queue them, which also utilizes them. The problem with any kind of timing queue of your own is that you won't have the fine control the built-in commands have. NetLinx is an interpreted language, and on top of that, it does not process threads concurrently. So any of your code is going to add delays to the output. On a small job, probably not enough to matter, but maybe enough to cause inconsistent behavior if a lot is going on.

    But why re-invent the wheel? They have some very flexible, very customizable built-in commands; use them!
  • jjames wrote:
    There's one that I had posted on here, but can't find it.

    Could it be this one?

    A random Programming Example -- DSS Music Channels

    --John
  • jjamesjjames Posts: 2,908
    Almost, but . . .

    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
  • Pep_SDPep_SD Posts: 106
    Thank you everybody for your help here!

    It also helped understanding the bigger picture .
Sign In or Register to comment.