Mailing List archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[vdr] VDR + lcdproc + keypad
Hello list,
I received yesterday a lcd display from matrix orbital that also supports keypads up to 25 keys.
http://www.matrixorbital.com/products/accessories/kp4X4.jpg
I wrote a small perl script that maps keypad key presses to svdrpsend commands.
I am thinking about changing this into a VDR plugin, but I am going to do it only if it can be useful to other people ... just let me know
Hope it is useful for the community.
Mattia
PS:
I run it in the lcdproc init script just after the LCDd command:
/usr/local/sbin/getkpinput.pl 2>1 >/dev/null &
---- [ begin getkpinput.pl ] ------------------
#! /usr/bin/perl -w
#########################################################################
# getkpinput.pl - freely adapted from Matrix Orbital perl example
# Usage:
# getkpinput.pl
# keypad
# o input is sent to vdr via SVDRP command
# o (optional) input is displayed on your monitor
#
# License: Free as in 'Free beer' ;-)
#########################################################################
#
# How it Works: the lcdproc driver can handle keypads with appropriate hardware. This script maps keypad key presses to
# svdrpsend commands.
#
# Supported Hardware: At the moment only Matrix Orbital serial displays are supported, it should be trivial to add support
# for HD44780 displays connected as described in the lcdproc howtos
#
# Features: Allows the use of a keypad with VDR (http://www.cadsoft.de/people/kls/vdr/). Works by mapping
# keypad entries to svdrp commands
# Due to the limited number of keys present on a tipycal keypad (mine has 16)
# I had to introduce a 'shift' key in order to be able to
# use the full range of (basic) VDR keys
#
# INSTALLATION:
# Requirements :
# A working lcdproc installation (keypad included)
# A running LCDd daemon
# A running vdr instance that listens on port 2001 for svdrp connections
# Once all these conditions are met simply running this perl script will enable the keypad mapping to svdrp commands
# Config variables needed:
# SvdrpSendPath: Location of the svdrpsend.pl perl script
# Shiftkey: Contains the (keypad) character that is used to trigger the shift function (default on my keypad: Back button)
# ShiftKeyNumNeeded: Contains the value that indicates how many times the shift
# key must be pressed in order to enable/disable the shift function
# KeypadKeys: Associative array containing all the possible keypad keys for a given keypad.
# It has to be configured for every different keypad installation
# (key returned depends on the keypad and on the connector position on the lcd keypad interface) .
# Keypad keys are then mapped to vdr standard keys
# KeyPadKeysShifted: Same as Keypadkeys but contains the mappings to use when in shift mode
# SerialFileName : device pointing to lirc comm port
#
#HISTORY:
#29/11/2002: Initial release - basic functionality -
# tested with only one 16 key keypad from Matrix Orbital (http://www.matrixorbital.com/products/accessories/kp4X4.jpg)
# and a 4x20 serial lcd from Matrix Orbital
#
# Here is the current mapping (keypad -> lcdproc -> vdr)
#
# Keypad Layout - Lcdproc Layout - VDR Key
#
# Normal
#
# 1 2 3 A T E J O 1 2 3 Red
# 4 5 6 B S D I N 4 5 6 Green
# 7 8 9 C R C H M 7 8 9 Yellow
# + 0 - D B Q G L Ok 0 Back Blue
#
#
# Shifted (2 Back keypresses)
#
# Keypad Layout - Lcdproc Layout - VDR Key
#
# 1 2 3 A T E J O 1 Up 3 Red
# 4 5 6 B S D I N Left Menu Right Green
# 7 8 9 C R C H M 7 Down 9 Yellow
# + 0 - D B Q G L Ok 0 Back Blue
#
#
use strict;
use diagnostics ;
use POSIX ;
use IO::Select ;
use Fcntl ;
$| = 1 ;
my $SerialFileName = '/dev/lcd' ; # com1 or ttyS0 (com2)
my $Selector = '' ;
my $Shutdown = 0 ;
my $SvdrpSendPath = '/usr/local/bin/svdrpsend.pl';
my $str = '';
my $ShiftKeyPressed = 0;
my $ShiftKey = 'G';
my $ShiftKeyNumPressed = 0;
my $ShiftKeyNumNeeded = 2;
my %KeyPadKeys = (
"T" => "1", # Keypad 1
"E" => "2", # Keypad 2
"J" => "3", # Keypad 3
"S" => "4", # Keypad 4
"D" => "5", # Keypad 5
"I" => "6", # Keypad 6
"R" => "7", # Keypad 7
"C" => "8", # Keypad 8
"H" => "9", # Keypad 9
"B" => "0", # Keypad 0
"Q" => "Ok", # Keypad +
"G" => "Back", # Keypad -
"O" => "Red", # Keypad A
"N" => "Green", # Keypad B
"M" => "Yellow", # Keypad C
"L" => "Blue", # Keypad D
);
my %KeyPadKeysShifted = (
"T" => "1", # Keypad 1
"E" => "Up", # Keypad 2
"J" => "3", # Keypad 3
"S" => "Left", # Keypad 4
"D" => "Menu", # Keypad 5
"I" => "Right", # Keypad 6
"R" => "7", # Keypad 7
"C" => "Down", # Keypad 8
"H" => "9", # Keypad 9
"B" => "0", # Keypad 0
"Q" => "Ok", # Keypad +
"G" => "Back", # Keypad -
"O" => "Red", # Keypad A
"N" => "Green", # Keypad B
"M" => "Yellow", # Keypad C
"L" => "Blue", # Keypad D
);
#--------------------------------------------------------------------------
# initialize
#--------------------------------------------------------------------------
sub initialize
{
my $DisplayFD ;
my $DisplayTermios ;
my $CFlag ;
my $LFlag ;
my $OFlag ;
my $IFlag ;
print STDERR "initialize\n" ;
#
#---- Open display serial device ----#
#
open DisplayIO, "+> $SerialFileName" # open serial (display) device
or die ("Can't open tty: $!") ;
$DisplayFD = fileno (DisplayIO) ;
$DisplayTermios = POSIX::Termios->new () ;
$DisplayTermios->getattr ($DisplayFD) ;
$DisplayTermios->setispeed (B19200) ; # serial input speed (19200bps)
$DisplayTermios->setospeed (B19200) ; # serial output speed (19200bps)
$CFlag = $DisplayTermios->getcflag () ;
$LFlag = $DisplayTermios->getlflag () ;
$OFlag = $DisplayTermios->getoflag () ;
$IFlag = $DisplayTermios->getiflag () ;
$IFlag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON) ; # raw IO
$OFlag &= ~(OPOST) ;
$LFlag &= ~(ECHO|ECHONL|ICANON|ISIG) ;
$CFlag &= ~(CSIZE|PARENB|HUPCL) ;
$CFlag |= (CREAD|CS8|CLOCAL) ;
$DisplayTermios->setcflag ($CFlag) ; # update serial settings
$DisplayTermios->setlflag ($LFlag) ;
$DisplayTermios->setoflag ($OFlag) ;
$DisplayTermios->setiflag ($IFlag) ;
$DisplayTermios->setattr ($DisplayFD, TCSANOW) ; # update serial device
#syswrite DisplayIO, sprintf ("%cX", 0xfe) ; # clear LCD
#
#---- Initialize selector ----#
#
$Selector = new IO::Select (\*DisplayIO) # Create selector
or die ("Selector create") ;
} # initialize #
#--------------------------------------------------------------------------
# process_keypad_input
#--------------------------------------------------------------------------
sub process_keypad_input
{
my $ret ;
my $KeyPadInput ;
print "process_keypad_input\n" ;
$ret = sysread DisplayIO, $KeyPadInput, 1 ; # read keypad
#syswrite DisplayIO, $KeyPadInput ; # write kb input to display
if ($ret <= 0)
{ # keypad IO closed??
print "keypad input: zero\n" ;
return ;
}
# This translation depends on the type of display,
# the type of keypad, and how the keypad is plugged into the display
if ($KeyPadInput eq $ShiftKey){
$ShiftKeyNumPressed ++;
if ($ShiftKeyNumPressed >= $ShiftKeyNumNeeded){
$ShiftKeyPressed = !$ShiftKeyPressed;
$ShiftKeyNumPressed = 0;
}
# print "Shift Key Pressed ". $ShiftKeyNumPressed." times ( ". $ShiftKeyNumNeeded." times needed)\n";
# print "Shift Key pressed : ".($ShiftKeyPressed ? "True" : "False") ."\n";
}
$str = $SvdrpSendPath ." HITK ".($ShiftKeyPressed ? $KeyPadKeysShifted{$KeyPadInput}:$KeyPadKeys{$KeyPadInput}). " \n";
print $str;
system $str;
#$KeyPadInput =~ tr/SAPKBQLCRMFGHIDN/0123456789ABCD+-/ ; # translate keypad input
#print "KeyPad='$KeyPadInput'\n" ; # show keypad input
} # process_keypad_input #
#--------------------------------------------------------------------------
# main
#--------------------------------------------------------------------------
initialize () ;
while (! $Shutdown)
{
my @Hands = $Selector->can_read (10) ; # wait for input or 10 seconds
foreach my $Hand (@Hands)
{
if ($Hand == \*DisplayIO)
{ # display keypad input
process_keypad_input () ;
}
}
}
close (DisplayIO) ;
exit 0 ;
---- [ end getkpinput.pl ] ---------------------
--
Info:
To unsubscribe send a mail to listar@linuxtv.org with "unsubscribe vdr" as subject.
Home |
Main Index |
Thread Index