VRC1100 Remote control software

Source-code only - please, don't post questions here.
lassar
Posts: 240
Joined: Jan 17, 2006 1:35
Contact:

VRC1100 Remote control software

Postby lassar » Apr 30, 2017 1:18

Linux program for VRC-1100 remote controls.

Should work for other mce remotes. But not tested on any other remotes.
Makes it so the device driver is automatically gotten.
Replaces old keynames with new keynames.

Shells out to ir-keytable to make this work.


Code: Select all

#LANG "fblite"

#include "dir.bi" 'provides constants to use for the attrib_mask parameter

' VRC1100-keytable-auto by Randall Glass
'
' Donated to the public domain.
'
' Linux program for VRC-1100 remote controls.
' Should work for other mce remotes. But not tested on any other remotes.
' Makes it so the device driver is automatically gotten.
' Replaces old keynames with new keynames.
'
' shells out to ir-keytable to make this work.



DECLARE SUB Replaceline(Thisline$)

DIM SHARED NewKey$(), OrgKey$()
DIM SHARED NoFile%, TotalReplaces%

IF COMMAND$ = "--help" THEN
   PRINT
   PRINT "-------------------------------------------------------"
   PRINT
   PRINT "vrc1100-keytable-auto by Randall Glass"
   PRINT
   PRINT "reads /etc/rc_keymaps/replacekeys"
   PRINT "replaces key names in keytable with new key names"
   PRINT
   PRINT "format of file is orginal keyname,New keyname"
   PRINT "all names must be in quotes"
   PRINT
   PRINT "-------------------------------------------------------"
   PRINT
   END
END IF

NoFile% = 1
PRINT
IF DIR$("/etc/rc_keymaps/replacekeys") <> "" THEN
   OPEN "/etc/rc_keymaps/replacekeys" FOR INPUT AS #1
   I% = 0
   DO
      I% = I% + 1
      REDIM Preserve NewKey$(I%), OrgKey$(I%)
      INPUT #1, OrgKey$(I%), NewKey$(I%)
      IF I% = 1 AND OrgKey$(I%) = "" THEN
         NoFile% = 0
         EXIT DO
      END IF      
      OrgKeyLen% = LEN(OrgKey$(I%))
      Counter$ = TRIM$(STR(I%))
      CounterLen% = LEN(Counter$)
      PRINT " ";Counter$;SPACE$(4-CounterLen%);OrgKey$(I%);SPACE$(20-OrgKeyLen%);NewKey$(I%)
   LOOP UNTIL EOF(1)
ELSE
   NoFile% = 0
END IF
CLOSE #1

TotalReplaces% = I%

OPEN "/proc/bus/input/devices" FOR INPUT AS #1

IF DIR$("/etc/rc_keymaps/",fbDirectory) = "" THEN
   MKDIR "/etc/rc_keymaps/"
END IF

OPEN "/etc/rc_keymaps/VRC100_Mapped" FOR OUTPUT AS #2


DO
   LINE INPUT #1,Thisline$
   FoundHid% = INSTR(Thisline$,"N: Name=" + CHR$(34) + "HID ")
   IF FoundHid% > 0 THEN
      DO
         LINE INPUT #1,Thisline$   
         Thisline$ = TRIM$(Thisline$)
         IF INSTR(Thisline$,"H: Handlers=") AND INSTR(Thisline$,"kbd mouse") THEN
            EventPos% = INSTR(Thisline$,"event")
            Device$ = MID$(Thisline$,EventPos%)
            Device$ = TRIM$(Device$)
            EXIT DO,DO
         END IF
      LOOP UNTIL EOF(1) OR Thisline$ = ""
   END IF
LOOP UNTIL EOF(1)
CLOSE #1

PRINT
IF Device$ = "" THEN
   PRINT "HID device not found!"
   END
ELSE
   PRINT "Hid device = ";Device$
   PRINT
END IF


irkeytablecmd$ = "ir-keytable" + " -r" + " --device=/dev/input/" + Device$

ShelledResult% = Open Pipe( irkeytablecmd$, For INPUT, As #1)

IF ShelledResult% = -1 THEN
   PRINT
   PRINT "Cound not run ir-keytable!"
   END
END IF

DO
   LINE INPUT #1,Thisline$
   IF INSTR(Thisline$,"scancode") THEN   
      Replaceline(Thisline$)   
   END IF
LOOP UNTIL EOF(1)
CLOSE 1

IF Device$ = "" THEN
   PRINT
   PRINT "Write HID device not found!"
   END
END IF

irkeytablecmd$ = "ir-keytable --write=/etc/rc_keymaps/VRC100_Mapped --device=/dev/input/" + Device$


CLOSE
ShelledResult% = SHELL(irkeytablecmd$)

IF ShelledResult% = -1 THEN
   PRINT
   PRINT "Cound not run ir-keytable!"
   END
END IF

PRINT
END

SUB Replaceline(Thisline$)
    IF NoFile% THEN
      FOR I% = 1 to TotalReplaces%
         KeyPos% = INSTR(ThisLine$,OrgKey$(I%))
         IF KeyPos%> 0 THEN
            NewLine$ = Left$(ThisLine$,KeyPos%-1) + NewKey$(I%) + "  #" + MID$(ThisLine$,KeyPos%)
         END IF
      NEXT I%
      IF NewLine$ <> "" THEN   
         PRINT #2, NewLine$
      ELSE
         PRINT #2, Thisline$
      END IF
   ELSE
      PRINT #2,Thisline$
   END IF

END SUB
END

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 2 guests