Remote Control 100 Version 2.0 ------------------------------ Introduction Rc converts your HP-100/200LX into a universal remote control. The output of most remote control units can be captured by pointing them from a distance of about 1-2 inches to the plastic opening on the right of the "/" key. The remote control signal can then be sent back to the device to be controlled. Remote control definition files allow you to program complicated interfaces to control a number of devices. 0. Package Contents The package contains the following files. As a minimum only rc.exm needs to be installed on the system (possibly with the rc.icn icon file). readme This file rc.icn Program icon rc.exm Program executable (System Manager compliant) rc.exe Program executable (DOS version) bitconv.exe Recording format conversion program keycode.exe Keyboard scan code program rc.rcf Example definition file (7-bit compatible) rc.rc8 Example definition file (8-bit) eg.pcx Example PCX graphic file 1. Program Usage There are two versions of the program. A DOS version and a System Manager compliant version. The DOS version is to be run from the DOS prompt, while the system manager version is run from within the system manager. In addition there are two ways to represent the remote control signals. One way uses 7-bit characters and is compatible with all ASCII editors (appart from line length problems), while the other method uses a more compact 8-bit representation. The "memo" editor that comes with the 100LX can use both formats, so you will probably want to use the 8 bit representation to save space (8 bit files are about half the size of the 7 bit equivalent files). The program can read both forms without any additional specifications. When recording, the user can specify which recording mode is to be used. An external DOS program is provided to convert betweem the two recording formats. The DOS version of the remote control (rc.exe) is used as follows: rc definition-file [entry-routine ...] rc -r[c] recording-file The first form starts the remote control with a given remote command definition file. The optional arguments can specify the routines to execute. The program will execute the contents of the definition file. The second form starts the remote control program in recording operation. In this mode the program will enter a loop and accept key strokes and associated remote control signals. These will then be recorded in the recording file in the form of a trivial remote control program. Any previous contents of the recording file will be erased. If the -rc option is used in place of the -c, the recording is done using the 7 bit compatible format. In order to use the system manager compliant version (rc.exm) the program is added to the list of programs using the "Application Manager" (&..., File, Application, Add). The program is started using a hot-key, or via the Application Manager. The files used by the program can not be specified, and are hard coded as follows: Definition file:c:\_dat\rc.rcf Recording file: c:\dat_\record.rcf In order to start recording in the system manager compliant version, press ALT-R to generate an 8-bit program or ALT-C to generate a 7-bit compatible file. 1.1 Tips and tricks If you encounter any problems with controling the devices here is a list of things you might try: - Change the distance between the remote control and the HP when recoding. - Remove the plastic protective lid from the LED on playback. - Record longer or shorter sequences. - Some remote controls have an internal mode (e.g. they "remember" if the device they control has been turned on, or whether radio or CD operation has been selected). You need to press the appropriate keys to bring them in the mode you want to record. There is no risk in shortening the remote codes by hand to make them as short as possible. After a code sequence has been sent to the remote control the infrared LED is switched off. I have heard of a hardware hack performed on some HPs whereby a crystal is changed to make them faster (please do not ask me about it, I have no idea how to do it, nor a pointer to someone who does). The the program does not have any timing loops; it simply stores the high and low pulse lengths EXCEPT for a low- pass filter which is used to filter out the 40KHz remote carrier frequency. This filter is implemented as a loop which should kill time between successive high edges of the incoming signal. A faster machine could cause the loop to execute faster and thus make it fall inside a low signal edge. The result would be very long and high frequency remote codes which would fail to correctly modulate the internal carrier used for replay. The constant I am using is 8 and it can be found by loading the program in DEBUG and searching for the sequence "7E FE 08 FC". I have been told that after changing the 8s to 12s (the person who told me did not mention whether 12 was decimal or hexadecimal) the program can be used with the faster machine. Keep in mind that some remote controls may use a very different carrier frequency and different modulation scheme. It may be impossible to record and play back successfully signals from such remotes. The program is HP100/200LX specific. The DOS version may work on the 1000CX (this is an OEM version of the 100LX lacking the system manager software), but no version will work on the 95LX. 1.2 Changes from version 1.0 Version 2.0 enhances the previous version in the following ways: * The program now is 100/200LX system manager compatible. Version 1.0 was running in 95LX compatibility mode. The program now runs in graphics mode and always starts up with an 80*25 character screen. * Procedures can be called based on current date and time * DOS executable accepts multiple commands * Pause command * Image command for loading PCX files * No alarms or task switching allowed when sending IR * New icon * Better documentation based on mail received: * Range enhancement by removing lid * Recording distance * Faster machine hack 2. Definition Files The program's operation is based on the remote control definition files. These files contain commands to draw the screen and key bindings to send the appropriate remote control codes. The following paragraphs contain more details on the definition files. 2.1. Lexical Structure A remote-100 definition file consists of a set of commands. Every command must start on a new line. Blank lines and white-space is ignored. Lines that begin using the '#' character are regarded as comments and are ignored. 2.2. Program Structure The commands inside a remote-100 definition file are organised as procedure definitions. No other commands are allowed outside the scope of a procedure definition. A procedure definition is structured as follows: define ... end This construct defines a procedure named . The commands are executed when the procedure is invoked using the "call " command. The procedure "main" is the starting point for the interpretation of the definition file. A minimal file for the control of a simple on/off device could be the following: # Minimal remote control file define main print 0 0 "+):On -):Off ESC):Quit" key 0x1b exit key '+ send "##'##[##'#%+##'##X##'##X" key '- send "##'##[##'#%+##'##X##'##Y" end A remote control file for controling two devices with a mode change can be implemented as follows: define main cls clkey print 0 0 "t) TV v) Video ESC) Quit" key 't call tv key 'v call video key 0x1b exit end define tv print 0 0 "ESC) Main" cls clkey key 0x1b call main # TV commands are place here end defive video ... The remote control files can be used to create new features that are not available in the original products. As an example the following sequence implements a "zap" command that cycles through three tv stations: define z1 send "##'##[##'#%+##'##X##'##Y" key 'z call z2 end define z2 send "##'##[##'#%+##'##A##'##B" key 'z call z3 end define z3 send "##'##[##'#%+##'##M##'##N" key 'z call z1 end main key 'z call z1 ... A complete, sophisticated control file with mode changes and global key definitions is provided in the file rc.rcf. 2.3. Command Description - define Begins a procedure definition. Following this command other commands except for the "define" command can be placed. - end Terminates a procedure - call Uppon execution of this command control is transfered to the procedure . When the "end" statement is reached in control is transfered back to the command after the "call" command. - clkey Clears all key bindings. The key binding table is entirely cleared. As a minimum a key binding that results in the program's termination (via an "exit" command) should always be defined. - cls Clears the screen contents. - pause Pauses the number of seconds specified. - image Displays the monochrome 640*200 PCX image file specified by filename. From that point onwards and until a "cls" command is executed the screen will be redrawn using the image file. Printing on top of the image is not supported since any strings printed will be lost when the screen is redisplayed after a task switch. Errors when loading the file are printed as a number with the following meanings: Number Error 3 Attempted to load a non-PCX file. 4 Attempted to load a PCX file with an unknown encoding scheme 5 The image contains more than 1 bits per pixel or more than 1 plane 6 End of file encountered while reading the image 7 Compression encoding repeat count spans end of image - print "" Prints a string is the row and column specified. The size of the screen can be changed when the program is started using the Fn-Zoom key combination. Rows and columns are numbered from (0,0). - exit Terminates the program. - key ' key Installs a key binding for the specified key. ASCII keys are specified using the ' notation. Other keys (arrows, ALT combinations etc.) are specified by giving the key's scan code in the top byte of the as in 0x2e00. (The 0x prefix is used to specify hexadecimal numbers). The scan codes can be found using the "keycode" program or in a technical reference manual for PC computers. The scan codes are also automaticaly generated during the record operation. The command specified can be any command appart from "define" and "end". - send "" Sends the code signals specified by the string to the infrared control port. There are two possible string encodings depending on the amount of portability desired. The fully portable 7-bit format encodes 16-bit integers as three ASCII characters with values ranging from 0-63 with 0 represented as '#'. The compact format is represented as follows: Values 0-127 are represented by a single character where 0 is '\x80' up to 126 being '\xfe'. 127 is represented by '~'. Values 128-3711 are represented by two characters using base 128 notation. The value of the first character is given by representing 1 with 'c', while the value of the second character is represented as above. Values 3712 and above are represented using the three byte 7-bit portable encoding. Both kinds of encoding can contain embedded spaces to allow for a bug in the HP 100-LX Memo program which introduces spaces inside very long strings. 2.4. Run-time Semantics Program execution normaly starts from the procedure called "main". Control proceeds serialy from that point transfering control when a "call" command is encountered. When the called procedure has been executed (i.e. the "end" command has been reached) control is transfered back to the command immediately following the "call" command. As the language does not provide any imperative input statements the "main" procedure normaly terminates after some initial processing. After that stage the system enters an event loop (yes they do crop up everywhere) which transfers control based on keyboard input events and the corresponding key definitions. The program terminates when the "exit" command is executed. All execution is performed directly from the file. The file is not read into memory and thus occupies no additional storage. A 16 element cache stores the last 16 procedures that have been used. For this reason any initial slugish performance will smooth as the cache is filled in. Keys are also directly associated with file position. A maximum of 200 key bindings can be stored in the table. The definition file must not be modified while the program is running. A simple way to call procedures based on the current time is implemented in the following way: If the name of a procedure being called starts with a colon (:) then when the procedure is called its name is changed so that the name's first character becomes an underline (_) and the second character a digit based on the current date and time and the following substitution table: Original Substitution D Day of month first digit d Day of month second digit M Month first digit (January is 1) m Month second digit Y Year third digit y Year fourth digit w Day of week (Sunday is 0) H Hour first digit h Hour second digit I Minute first digit i Minute second digit S Second first digit s Second second digit For example if the time is 10:37 calling the procedure :Iset will result in the procedure _3set being called. 3. The Record Format Conversion Program Bitconv converts definition files from the 8-bit format to the 7-bit compatible format. To convert from 8-bit to 7-bit run the program as follows: bitconv -c output_file To convert from 7-bit to 8-bit run the program as follows: bitconv output_file 4. The keyboard scan code program In order to find out the scan code of a key run the "keycode" program. Press any key to see its scan code definition printed out. Terminate the program by pressing CTRL-BREAK. 5. Author Contact The programs have been written by: Diomidis Spinellis Myrsinis 1 GR-145 62 Kifissia GREECE E-mail: dspin@leon.nrcps-ariadne-t.gr Many thanks to Gilles Kohl and Steve Loughran for their assistance. Thanks to the following people who provided feedback and encouriagement for the program's second version: Gardner Cohen Peter Koerner Denis Maugey Kent Peterson Brian Pierce John Seymour Martin Weinstein 6. Copyright and Disclaimer Copyright (c) 1993, 1994 Diomidis Spinellis. All rights reserved. Redistribution and use in binary form, without modification, is permitted provided that the following conditions are met: 1. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 2. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. 3. Redistribution for profit is not allowed. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IN PARTICULAR, NOTE THAT SENDING INCORRECT CODES TO THE REMOTE CONTROL LED OF THE HP-100LX MAY PERMANENTLY DAMAGE THE DEVICE.