adapted doc & coding stle a bit more to LCDproc

This commit is contained in:
marschap
2007-03-18 14:53:24 +00:00
parent 2d20fd83c6
commit 4efec0996a
4 changed files with 386 additions and 309 deletions
+222 -130
View File
@@ -1,139 +1,231 @@
<sect1 id="picolcd">
<title>The Mini-Box USB LCD (picoLCD 20x2) Driver (picolcd)</title>
<title>The Mini-Box USB LCD (picoLCD 20x2) Driver (picolcd)</title>
<para>
This section covers the installation and use of the Mini-Box USB LCD (picoLCD
20x2) display.
</para>
<para>
The picoLCD page indicates that the device can be connected via I2C or USART.
This lcdproc driver, however, is limited to the USB connected model.
</para>
<sect2 id="picolcd-setup">
<title>Setting up the picoLCD</title>
<para>
This section covers the installation and use of the Mini-Box USB LCD (picoLCD
20x2) display.
The picoLCD device as used by this driver is USB connected and may be purchased
with an internal USB header connector (5-pin to 5-pin) or an external cable
(Type-A to 5-pin). See: <ulink url="http://www.mini-box.com/picoLCD-20x2-OEM"/>.
It may also come pre-installed on systems like the Mini-Box M300:
<ulink url="http://www.mini-box.com/Mini-Box-M300-LCD"/>.
</para>
<para>
The picoLCD page indicates that the device can be connected via I2C or USART.
This lcdproc driver, however, is limited to the USB connected model.
Using the USB LCD with this driver requires the usblcd library from Mini-box.com
(avaiable at <ulink url="http://www.mini-box.com/picoLCD-20x2-OEM"/>).i
The usblcd library
requires libusb and libhcd. Your distribution may or may not already provide
these libraries. The only kernel driver required is the USB host controller
driver (uhci_hcd on the M300) required to fire up the usb bus to which the LCD is
attached.
</para>
<sect2 id="picolcd-setup">
<title>Setting up the picoLCD</title>
<para>
Lastly, the usbfs file system must be mounted on <filename>/proc/bus/usb</filename>.
<code>mount -t usbfs usbfs /proc/bus/usb</code>
</para>
<para>
Once connected and with libusblcd, libusb and libhid installed, testing the USB LCD
can be done with the <command>usblcd</command> program that comes with the usblcd
library.
You can also change the USB LCD's initial display (what it shows when you
initialize the device) by using the <command>usblcd</command> binary's
<command>splash</command> command.
</para>
<para>
To use the picolcd with lcdproc, add picolcd to the lcdproc configure drivers option
(or use all) and then start LCDd with the "-d picolcd" option. The driver has
sane default options and the options that are user configurable are limited to mostly
simple items, like contrast and which keys to lights up.
</para>
</sect2>
<para>
The picoLCD device as used by this driver is USB connected and may be purchased
with an internal USB header connector (5-pin to 5-pin) or an external cable
(Type-A to 5-pin). See: http://www.mini-box.com/picoLCD-20x2-OEM. It may also
come pre-installed on systems like the Mini-Box M300:
http://www.mini-box.com/Mini-Box-M300-LCD.
</para>
<para>
Using the USB LCD with this driver requires the usblcd library from Mini-box.com
(avaiable at http://www.mini-box.com/picoLCD-20x2-OEM). The usblcd library
requires libusb and libhcd. Your distribution may or may not already provide
these libraries. The only kernel driver required is the USB host controller
driver (uhci_hcd on the M300) required to fire up the usb bus to which the LCD is
attached.
</para>
<para>
Lastly, the usbfs file system must be mounted on /proc/bus/usb.
<code>mount -t usbfs usbfs /proc/bus/usb</code>
</para>
<para>
Once connected and with libusblcd, libusb and libhid installed, testing the USB LCD
can be done with the "usblcd" program that comes with the usblcd library. You can
also change the USB LCD's initial display (what it shows when you initialize the
device) by using the usblcd binary's "splash" command.
</para>
<para>
To use the picolcd with lcdproc, add picolcd to the lcdproc configure drivers option
(or use all) and then start LCDd with the "-d picolcd" option. The driver has
sane default options and the options that are user configurable are limited to mostly
simple items, like contrast and which keys to lights up.
</para>
</sect2>
<sect2 id="picolcd-options">
<para>
Contrast: 0-1000. 0 is visible, and 1000 is not on my M300. Default is 0.
</para>
<para>
Keylights: 0/1. 0 turns off the key LEDs and 1 turns them on. Default is 1.
</para>
</sect2>
<sect2>
<para>
Key0Light: if Keylights is set to 1, you can disable the directional pad LED by
setting this value to 0. Default is 1.
</para>
</sect2>
<sect2>
<para>
Key1Light: if Keylights is set to 1, you can disable the F1 LED by setting this value
to 0. Default is 1.
</para>
</sect2>
<sect2>
<para>
Key2Light: if Keylights is set to 1, you can disable the F2 LED by setting this value
to 0. Default is 1.
</para>
</sect2>
<sect2>
<para>
Key3Light: if Keylights is set to 1, you can disable the F3 LED by setting this value
to 0. Default is 1.
</para>
</sect2>
<sect2>
<para>
Key4Light: if Keylights is set to 1, you can disable the F4 LED by setting this value
to 0. Default is 1.
</para>
</sect2>
<sect2>
<para>
Key5Light: if Keylights is set to 1, you can disable the F5 LED by setting this value
to 0. Default is 1.
</para>
</sect2>
<sect2>
<para>
KeyTimeout: (Advanced) This value controls how long LCDd waits for a key press when
get_key is called. The value represents microseconds and the default is 500 or .5
seconds. Lowering this value will make LCDd more responsive but also causes LCDd to use
more CPU time and, as the timeout grows shorter, key presses become harder to detect.
Larger values make key presses more reliable if somewhat slow to take effect.
</para>
</sect2>
<sect2 id="picolcd-status">
<title>picolcd driver status</title>
<sect2 id="picolcd-config">
<title>Configuration in LCDd.conf</title>
<sect3 id="picolcd-config-section">
<title>[picolcd]</title>
<variablelist>
<varlistentry>
<term>
<command>Contrast=</command>
<arg choice="plain"><replaceable>CONTRAST</replaceable></arg>
</term>
<listitem><para>
Contrast: 0-1000. 0 is visible, and 1000 is not on my M300. Default is 0.
</para></listitem>
</varlistentry>
<varlistentry>
<term>
<command>KeyLights=</command>
<arg choice="plain">
<group choice="req">
<arg choice="plain"><literal><emphasis>yes</emphasis></literal></arg>
<arg choice="plain"><literal>no</literal></arg>
</group>
</arg>
</term>
<listitem><para>
Allow key LEDs to be turned on or off. Default is <literal>yes</literal>.
</para></listitem>
</varlistentry>
<varlistentry>
<term>
<command>Key0Light=</command>
<arg choice="plain">
<group choice="req">
<arg choice="plain"><literal><emphasis>yes</emphasis></literal></arg>
<arg choice="plain"><literal>no</literal></arg>
</group>
</arg>
</term>
<listitem><para>
If Keylights is set, you can disable the directional pad LED by
setting this value to <literal>no</literal>. Default is <literal>yes</literal>.
</para></listitem>
</varlistentry>
<varlistentry>
<term>
<command>Key1Light=</command>
<arg choice="plain">
<group choice="req">
<arg choice="plain"><literal><emphasis>yes</emphasis></literal></arg>
<arg choice="plain"><literal>no</literal></arg>
</group>
</arg>
</term>
<listitem><para>
If Keylights is set, you can disable the F1 LED by setting this value
to <literal>no</literal>. Default is <literal>yes</literal>.
</para></listitem>
</varlistentry>
<varlistentry>
<term>
<command>Key2Light=</command>
<arg choice="plain">
<group choice="req">
<arg choice="plain"><literal><emphasis>yes</emphasis></literal></arg>
<arg choice="plain"><literal>no</literal></arg>
</group>
</arg>
</term>
<listitem><para>
If Keylights is set, you can disable the F2 LED by setting this value
to <literal>no</literal>. Default is <literal>yes</literal>.
</para></listitem>
</varlistentry>
<varlistentry>
<term>
<command>Key3Light=</command>
<arg choice="plain">
<group choice="req">
<arg choice="plain"><literal><emphasis>yes</emphasis></literal></arg>
<arg choice="plain"><literal>no</literal></arg>
</group>
</arg>
</term>
<listitem><para>
If Keylights is set, you can disable the F3 LED by setting this value
to <literal>no</literal>. Default is <literal>yes</literal>.
</para></listitem>
</varlistentry>
<varlistentry>
<term>
<command>Key4Light=</command>
<arg choice="plain">
<group choice="req">
<arg choice="plain"><literal><emphasis>yes</emphasis></literal></arg>
<arg choice="plain"><literal>no</literal></arg>
</group>
</arg>
</term>
<listitem><para>
If Keylights is set, you can disable the F4 LED by setting this value
to <literal>no</literal>. Default is <literal>yes</literal>.
</para></listitem>
</varlistentry>
<varlistentry>
<term>
<command>Key5Light=</command>
<arg choice="plain">
<group choice="req">
<arg choice="plain"><literal><emphasis>yes</emphasis></literal></arg>
<arg choice="plain"><literal>no</literal></arg>
</group>
</arg>
</term>
<listitem><para>
If Keylights is set, you can disable the F5 LED by setting this value
to <literal>no</literal>. Default is <literal>yes</literal>.
</para></listitem>
</varlistentry>
<varlistentry>
<term>
<command>KeyTimeout=</command>
<arg choice="plain"><replaceable>DURATION</replaceable></arg>
</term>
<listitem><para>
(Advanced) This value controls how long LCDd waits for a key press when
get_key() is called. The value represents microseconds and the default is <literal>500</literal>
or .5 seconds. Lowering this value will make LCDd more responsive but also causes LCDd to use
more CPU time and, as the timeout grows shorter, key presses become harder to detect.
Larger values make key presses more reliable if somewhat slow to take effect.
</para></listitem>
</varlistentry>
</variablelist>
</sect3>
</sect2>
<sect2 id="picolcd-status">
<title>picolcd driver status</title>
<para>
The lcdproc picolcd driver relies upon Mini-Box's usblcd library to setup the USB/HID
interface. Unfortunately the usblcd library is very thin and tends to put function
results on stdout/stderr instead of in return values. They (Mini-Box) really had
scripting interfaces in mind.
</para>
<para>
The primary example of this is that I had to write a replacement (get_key_events) for
usblcd's read_events so that I could get the key presses back to the calling function
instead of on stdout. usblcd also has a large number of function shells for which no
code exists yet. I am not an expert on HID and USB coding, but if and as time permits
and hardware is available I will try and improve this drivers access to the hardware in
order to get back data (get_contrast for example) and to potentially drive multiple
pcioLCDs at once (or pick the one we want out of many).
</para>
<para>
To sum up, this driver right now stabs and hopes since response data is lacking.
</para>
<para>
The hardware also reports key-up events. Normally this would be of no issue (they are
usually a 0 or 'no key') except that when keys are used in combonation, the key-up
event may actually come back as multiple events depending on how the user released the
keys. If the key-up event for a multiple key press comes back as two events, the first
up event will actually look like a new key press. The algorithm in get_key tries to
deal with this in a sane way and toss out all key-up events for now. The hardware is
touchy and both combo key-down and key-up actions may be reported as mutiple events if
the user is more than a tenth of a second (maybe less?) off in motions.
</para>
</sect2>
<sect2 id="picolcd-copy">
<title>Copyright</title>
<para>
The lcdproc picolcd driver was written by Gatewood Green (woody@nitrosecurity.com)
or (woody@linif.org) and paid for by NitroSecurity, Inc (nitrosecurity.com).
</para>
</sect2>
<para>
The lcdproc picolcd driver relies upon Mini-Box's usblcd library to setup the USB/HID
interface. Unfortunately the usblcd library is very thin and tends to put function
results on stdout/stderr instead of in return values. They (Mini-Box) really had
scripting interfaces in mind.
</para>
<para>
The primary example of this is that I had to write a replacement (get_key_events) for
usblcd's read_events so that I could get the key presses back to the calling function
instead of on stdout. usblcd also has a large number of function shells for which no
code exists yet. I am not an expert on HID and USB coding, but if and as time permits
and hardware is available I will try and improve this drivers access to the hardware in
order to get back data (get_contrast for example) and to potentially drive multiple
pcioLCDs at once (or pick the one we want out of many).
</para>
<para>
To sum up, this driver right now stabs and hopes since response data is lacking.
</para>
<para>
The hardware also reports key-up events. Normally this would be of no issue (they are
usually a 0 or 'no key') except that when keys are used in combonation, the key-up
event may actually come back as multiple events depending on how the user released the
keys. If the key-up event for a multiple key press comes back as two events, the first
up event will actually look like a new key press. The algorithm in get_key tries to
deal with this in a sane way and toss out all key-up events for now. The hardware is
touchy and both combo key-down and key-up actions may be reported as mutiple events if
the user is more than a tenth of a second (maybe less?) off in motions.
</para>
</sect2>
<sect2 id="picolcd-copy">
<title>Copyright</title>
<para>
The lcdproc picolcd driver was written by Gatewood Green (woody@nitrosecurity.com)
or (woody@linif.org) and paid for by NitroSecurity, Inc (nitrosecurity.com).
</para>
</sect2>
</sect1>
+1
View File
@@ -39,6 +39,7 @@
<!ENTITY mtc_s16209x SYSTEM "drivers/mtc_s16209x.docbook">
<!ENTITY MtxOrb SYSTEM "drivers/mtxorb.docbook">
<!ENTITY NoritakeVFD SYSTEM "drivers/NoritakeVFD.docbook">
<!ENTITY picolcd SYSTEM "drivers/picolcd.docbook">
<!ENTITY pylcd SYSTEM "drivers/pylcd.docbook">
<!ENTITY sed1330 SYSTEM "drivers/sed1330.docbook">
<!ENTITY sed1520 SYSTEM "drivers/sed1520.docbook">
+141 -157
View File
@@ -3,6 +3,7 @@
*
* (c) 2007 NitroSecurity, Inc.
* Written by Gatewood Green <woody@nitrosecurity.com> or <woody@linif.org>
* (c) 2007 Peter Marschall - adapted coding style and reporting to LCDproc
*
* License: GPL (same as usblcd and lcdPROC)
*
@@ -45,8 +46,16 @@
/* lcdPROC includes */
#include "lcd.h"
#include "picolcd.h"
/* Debug mode: un-comment to turn on debugging messages in the server */
/* #define DEBUG 1 */
#include "report.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
/* These three includes are the Mini-box.com libusblcd (usblcd) and company. */
#include <usblcd.h>
#include <widgets.h>
@@ -59,9 +68,6 @@
#include <unistd.h>
#include <stdio.h>
/* This is a hack */
#define API_VERSION "0.5"
/* 12 keys plus a 0 placeholder */
#define KEYPAD_MAX 13
#define KEYPAD_LIGHTS 6
@@ -71,8 +77,6 @@
#define DEFAULT_KEYLIGHTS 1 /* On */
#define DEFAULT_TIMEOUT 500 /* Half second */
/* Set this to 1 and get lots of cruft on stderr when using "LCDd -f 1 -d picolcd" */
#define DEBUG_PICO 0
/* PrivateData struct */
typedef struct pd {
@@ -107,8 +111,8 @@ static char * keymap[KEYPAD_MAX] = {
};
/* Private function definitions */
void get_key_event ( usblcd_operations *self, lcd_packet *packet, int timeout );
void set_key_lights ( usblcd_operations *self, int keys[], int state );
void get_key_event (usblcd_operations *self, lcd_packet *packet, int timeout);
void set_key_lights (usblcd_operations *self, int keys[], int state);
/* lcd_logical_driver Variables */
MODULE_EXPORT char *api_version = API_VERSION;
@@ -117,193 +121,180 @@ MODULE_EXPORT int supports_multiple = 1;
MODULE_EXPORT char *symbol_prefix = "picoLCD_";
/* lcd_logical_driver Manditory functions */
MODULE_EXPORT int picoLCD_init( Driver *drvthis ) {
MODULE_EXPORT int picoLCD_init(Driver *drvthis) {
PrivateData *pd;
int x;
pd = ( PrivateData * ) malloc( sizeof( PrivateData ) );
pd = (PrivateData *) malloc(sizeof(PrivateData));
if ( ! pd )
if (! pd)
return -1;
if ( drvthis->store_private_ptr( drvthis, pd ) )
if (drvthis->store_private_ptr(drvthis, pd))
return -1;
pd->lcd = new_usblcd_operations();
pd->lcd->init( pd->lcd );
pd->lcd->init(pd->lcd);
pd->width = 20; /* hard coded (mfg spec) */
pd->height = 2; /* hard coded (mfg spec) */
pd->info = "picoLCD: Supports the LCD as installed on the M300 (http://www.mini-box.com/Mini-Box-M300-LCD) ";
for ( x = 0; x < KEYPAD_LIGHTS; x++ )
for (x = 0; x < KEYPAD_LIGHTS; x++)
pd->key_light[x] = 1; /* individual lights on */
pd->contrast = drvthis->config_get_int( drvthis->name, "Contrast", 0, DEFAULT_CONTRAST );
pd->backlight = drvthis->config_get_bool( drvthis->name, "BackLight", 0, DEFAULT_BACKLIGHT );
pd->keylights = drvthis->config_get_bool( drvthis->name, "KeyLights", 0, DEFAULT_KEYLIGHTS ); /* key lights with LCD Backlight? */
pd->key_timeout = drvthis->config_get_int( drvthis->name, "KeyTimeout", 0, DEFAULT_TIMEOUT );
pd->contrast = drvthis->config_get_int( drvthis->name, "Contrast", 0, DEFAULT_CONTRAST );
pd->backlight = drvthis->config_get_bool(drvthis->name, "BackLight", 0, DEFAULT_BACKLIGHT);
pd->keylights = drvthis->config_get_bool(drvthis->name, "KeyLights", 0, DEFAULT_KEYLIGHTS); /* key lights with LCD Backlight? */
pd->key_timeout = drvthis->config_get_int( drvthis->name, "KeyTimeout", 0, DEFAULT_TIMEOUT );
/* These allow individual lights to be disabled */
pd->key_light[0] = drvthis->config_get_bool( drvthis->name, "Key0Light", 0, 1 ); /* Directional PAD */
pd->key_light[1] = drvthis->config_get_bool( drvthis->name, "Key1Light", 0, 1 ); /* F1 */
pd->key_light[2] = drvthis->config_get_bool( drvthis->name, "Key2Light", 0, 1 ); /* F2 */
pd->key_light[3] = drvthis->config_get_bool( drvthis->name, "Key3Light", 0, 1 ); /* F3 */
pd->key_light[4] = drvthis->config_get_bool( drvthis->name, "Key4Light", 0, 1 ); /* F4 */
pd->key_light[5] = drvthis->config_get_bool( drvthis->name, "Key5Light", 0, 1 ); /* F5 */
pd->key_light[0] = drvthis->config_get_bool(drvthis->name, "Key0Light", 0, 1); /* Directional PAD */
pd->key_light[1] = drvthis->config_get_bool(drvthis->name, "Key1Light", 0, 1); /* F1 */
pd->key_light[2] = drvthis->config_get_bool(drvthis->name, "Key2Light", 0, 1); /* F2 */
pd->key_light[3] = drvthis->config_get_bool(drvthis->name, "Key3Light", 0, 1); /* F3 */
pd->key_light[4] = drvthis->config_get_bool(drvthis->name, "Key4Light", 0, 1); /* F4 */
pd->key_light[5] = drvthis->config_get_bool(drvthis->name, "Key5Light", 0, 1); /* F5 */
for ( x = 0; x < KEYPAD_MAX; x++ )
for (x = 0; x < KEYPAD_MAX; x++)
pd->key_matrix[x] = keymap[x];
pd->framebuf = ( unsigned char * ) malloc( pd->width * pd->height + 1 );
if ( pd->framebuf == NULL ) {
report( RPT_ERR, "%s: unable to create framebuf.\n", __FUNCTION__ );
pd->framebuf = (unsigned char *) malloc(pd->width * pd->height + 1);
if (pd->framebuf == NULL) {
report(RPT_ERR, "%s: unable to create framebuf.\n", __FUNCTION__);
return -1;
}
memset( pd->framebuf, ' ', pd->width * pd->height );
memset(pd->framebuf, ' ', pd->width * pd->height);
pd->framebuf[pd->width * pd->height] = 0;
pd->lstframe = ( unsigned char * ) malloc( pd->width * pd->height + 1 );
if ( pd->lstframe == NULL ) {
report( RPT_ERR, "%s: unable to create lstframe.\n", __FUNCTION__ );
pd->lstframe = (unsigned char *) malloc(pd->width * pd->height + 1);
if (pd->lstframe == NULL) {
report(RPT_ERR, "%s: unable to create lstframe.\n", __FUNCTION__);
return -1;
}
memset( pd->lstframe, ' ', pd->width * pd->height );
memset(pd->lstframe, ' ', pd->width * pd->height);
pd->lstframe[pd->width * pd->height] = 0;
if ( pd->backlight )
picoLCD_backlight( drvthis, 1 );
if ( ! pd->keylights )
set_key_lights( pd->lcd, pd->key_light, 0 );
if (pd->backlight)
picoLCD_backlight(drvthis, 1);
if (! pd->keylights)
set_key_lights(pd->lcd, pd->key_light, 0);
else
picoLCD_backlight( drvthis, 0 );
picoLCD_backlight(drvthis, 0);
picoLCD_set_contrast( drvthis, pd->contrast );
picoLCD_set_contrast(drvthis, pd->contrast);
report( RPT_INFO, "picolcd: init complete\n", __FUNCTION__ );
if ( DEBUG_PICO )
fprintf( stderr, "picolcd: init complete\n" );
report(RPT_INFO, "picolcd: init complete\n", __FUNCTION__);
return 0;
}
MODULE_EXPORT void picoLCD_close( Driver *drvthis ) {
MODULE_EXPORT void picoLCD_close(Driver *drvthis) {
PrivateData *pd = drvthis->private_data;
pd->lcd->close( pd->lcd ); /* This actually does not do anything in usblcd (yet?) */
pd->lcd->close(pd->lcd); /* This actually does not do anything in usblcd (yet?) */
if ( DEBUG_PICO )
fprintf( stderr, "picolcd: close complete\n" );
debug(RPT_DEBUG, "picolcd: close complete\n");
}
/* lcd_logical_driver Essential output functions */
MODULE_EXPORT int picoLCD_width( Driver *drvthis ) {
MODULE_EXPORT int picoLCD_width(Driver *drvthis) {
PrivateData *pd = drvthis->private_data;
return pd->width;
}
MODULE_EXPORT int picoLCD_height( Driver *drvthis ) {
MODULE_EXPORT int picoLCD_height(Driver *drvthis) {
PrivateData *pd = drvthis->private_data;
return pd->height;
}
MODULE_EXPORT void picoLCD_clear( Driver *drvthis ) {
MODULE_EXPORT void picoLCD_clear(Driver *drvthis) {
PrivateData *pd = drvthis->private_data;
memset( pd->framebuf, ' ', pd->width * pd->height );
memset(pd->framebuf, ' ', pd->width * pd->height);
if ( DEBUG_PICO )
fprintf( stderr, "picolcd: clear complete\n" );
debug(RPT_DEBUG, "picolcd: clear complete\n");
}
MODULE_EXPORT void picoLCD_flush( Driver *drvthis ) {
MODULE_EXPORT void picoLCD_flush(Driver *drvthis) {
PrivateData *pd = drvthis->private_data;
unsigned char *fb = pd->framebuf;
unsigned char *lf = pd->lstframe;
static char text[48];
int i, line, offset;
if ( DEBUG_PICO )
fprintf( stderr, "picolcd: flush started\n" );
debug(RPT_DEBUG, "picolcd: flush started\n");
for ( line = 0; line < pd->height; line++ ) {
memset( text, 0, 48 );
for (line = 0; line < pd->height; line++) {
memset(text, 0, 48);
offset = line * pd->width;
fb = pd->framebuf + offset;
lf = pd->lstframe + offset;
for ( i = 0; i < pd->width; i++ ) {
if ( *fb++ != *lf++ ) {
strncpy( text, pd->framebuf + offset, pd->width );
pd->lcd->settext( pd->lcd, line, 0, text );
memcpy( pd->lstframe + offset, pd->framebuf + offset, pd->width );
for (i = 0; i < pd->width; i++) {
if (*fb++ != *lf++) {
strncpy(text, pd->framebuf + offset, pd->width);
pd->lcd->settext(pd->lcd, line, 0, text);
memcpy(pd->lstframe + offset, pd->framebuf + offset, pd->width);
if ( DEBUG_PICO )
fprintf( stderr, "picolcd: flush wrote line %d (%s)\n", line + 1, text );
debug(RPT_DEBUG, "picolcd: flush wrote line %d (%s)\n", line + 1, text);
break;
}
}
}
if ( DEBUG_PICO )
fprintf( stderr, "picolcd: flush complete\n\t(%s)\n\t(%s)\n", pd->framebuf, pd->lstframe );
debug(RPT_DEBUG, "picolcd: flush complete\n\t(%s)\n\t(%s)\n", pd->framebuf, pd->lstframe);
}
MODULE_EXPORT void picoLCD_string( Driver *drvthis, int x, int y, char *str ) {
MODULE_EXPORT void picoLCD_string(Driver *drvthis, int x, int y, char *str) {
PrivateData *pd = drvthis->private_data;
char *dest;
int len;
if ( DEBUG_PICO )
fprintf( stderr, "picolcd: string start (%s)\n", str );
debug(RPT_DEBUG, "picolcd: string start (%s)\n", str);
if ( y < 1 || y > pd->height )
if (y < 1 || y > pd->height)
return;
if ( x < 1 || x > pd->width )
if (x < 1 || x > pd->width)
return;
len = strlen( str );
if ( len + x > pd->width ) {
if ( DEBUG_PICO )
fprintf( stderr, "picolcd: string overlength (>%d). Start: %d Length: %d (%s)\n", pd->width, x, len ,str );
len = strlen(str);
if (len + x > pd->width) {
debug(RPT_DEBUG, "picolcd: string overlength (>%d). Start: %d Length: %d (%s)\n", pd->width, x, len ,str);
len = pd->width - x; /* Copy what we can */
}
x--; y--; /* Convert 1-based to 0-based */
dest = pd->framebuf + ( y * pd->width + x );
memcpy( dest, str, len * sizeof(char) );
dest = pd->framebuf + (y * pd->width + x);
memcpy(dest, str, len * sizeof(char));
if ( DEBUG_PICO )
fprintf( stderr, "picolcd: string complete (%s)\n", str );
debug(RPT_DEBUG, "picolcd: string complete (%s)\n", str);
}
MODULE_EXPORT void picoLCD_chr( Driver *drvthis, int x, int y, char chr ) {
MODULE_EXPORT void picoLCD_chr(Driver *drvthis, int x, int y, char chr) {
PrivateData *pd = drvthis->private_data;
char *dest;
if ( DEBUG_PICO )
fprintf( stderr, "picolcd: chr start (%c)\n", chr );
debug(RPT_DEBUG, "picolcd: chr start (%c)\n", chr);
if ( y < 1 || y > pd->height )
if (y < 1 || y > pd->height)
return;
if ( x < 1 || x > pd->width )
if (x < 1 || x > pd->width)
return;
x--; y--; /* Convert 1-based to 0-based */
dest = pd->framebuf + ( y * pd->width + x );
memcpy( dest, &chr, sizeof(char) );
dest = pd->framebuf + (y * pd->width + x);
memcpy(dest, &chr, sizeof(char));
if ( DEBUG_PICO )
fprintf( stderr, "picolcd: chr complete (%c)\n", chr );
debug(RPT_DEBUG, "picolcd: chr complete (%c)\n", chr);
}
/* lcd_logical_driver Essential input functions */
MODULE_EXPORT char *picoLCD_get_key( Driver *drvthis ) {
MODULE_EXPORT char *picoLCD_get_key(Driver *drvthis) {
PrivateData *pd = drvthis->private_data;
lcd_packet *keydata;
char *keystr;
@@ -311,51 +302,44 @@ MODULE_EXPORT char *picoLCD_get_key( Driver *drvthis ) {
int key_pass = 0;
int two_keys = 0;
if ( DEBUG_PICO )
fprintf( stderr, "picolcd: get_key start (timeout %d)\n", pd->key_timeout );
debug(RPT_DEBUG, "picolcd: get_key start (timeout %d)\n", pd->key_timeout);
keydata = malloc( sizeof( lcd_packet ) );
keydata = malloc(sizeof(lcd_packet));
while ( ! keys_read ) {
get_key_event( pd->lcd, keydata, pd->key_timeout );
if ( DEBUG_PICO )
fprintf( stderr, "picolcd: get_key got an event\n" );
while (! keys_read) {
get_key_event(pd->lcd, keydata, pd->key_timeout);
debug(RPT_DEBUG, "picolcd: get_key got an event\n");
if ( keydata->type == IN_REPORT_KEY_STATE ) {
if ( ! keydata->data[1] && key_pass ) {
if ( DEBUG_PICO )
fprintf( stderr, "picolcd: get_key got all clear\n" );
if (keydata->type == IN_REPORT_KEY_STATE) {
if (! keydata->data[1] && key_pass) {
debug(RPT_DEBUG, "picolcd: get_key got all clear\n");
/* Got a <0, 0> key-up event after reading a valid key press event */
keys_read++; /* All clear */
} else if ( ! keydata->data[2] && ! two_keys ) {
if ( DEBUG_PICO )
fprintf( stderr, "picolcd: get_key got one key\n" );
} else if (! keydata->data[2] && ! two_keys) {
debug(RPT_DEBUG, "picolcd: get_key got one key\n");
/* We got one key (but not after a two key event and before and all clear) */
keystr = pd->key_matrix[keydata->data[1]];
} else {
/* We got two keys */
if ( DEBUG_PICO )
fprintf( stderr, "picolcd: get_key got two keys\n" );
debug(RPT_DEBUG, "picolcd: get_key got two keys\n");
two_keys++;
sprintf( keystr, "%s+%s", pd->key_matrix[keydata->data[1]], pd->key_matrix[keydata->data[2]] );
sprintf(keystr, "%s+%s", pd->key_matrix[keydata->data[1]], pd->key_matrix[keydata->data[2]]);
}
key_pass++; /* This hack allows us to deal with receiving left over <0,0> first */
} else {
if ( DEBUG_PICO )
fprintf( stderr, "picolcd: get_key got non-key data or timeout\n" );
debug(RPT_DEBUG, "picolcd: get_key got non-key data or timeout\n");
/* We got IR or otherwise bad data */
return NULL;
}
}
free( keydata );
free(keydata);
if ( DEBUG_PICO )
fprintf( stderr, "picolcd: get_key complete (%s)\n", keystr );
debug(RPT_DEBUG, "picolcd: get_key complete (%s)\n", keystr);
if ( ! strlen( keystr ) )
if (! strlen(keystr))
return NULL;
return keystr;
@@ -406,80 +390,80 @@ MODULE_EXPORT char *picoLCD_get_key( Driver *drvthis ) {
/* lcd_logical_driver User-defined character functions */
/* lcd_logical_driver Hardware functions */
/*MODULE_EXPORT int picoLCD_get_contrast( Driver *drvthis ) {
/*MODULE_EXPORT int picoLCD_get_contrast(Driver *drvthis) {
PrivateData *pd = drvthis->private_data;
}*/
MODULE_EXPORT int picoLCD_set_contrast( Driver *drvthis, int promille ) {
MODULE_EXPORT int picoLCD_set_contrast(Driver *drvthis, int promille) {
PrivateData *pd = drvthis->private_data;
int inv; /* The hardware seems to go dark on higher values, so we turn it around */
if ( promille <= 1000 && promille > 0 ) {
if (promille <= 1000 && promille > 0) {
inv = 1000 - promille;
pd->lcd->contrast( pd->lcd, ( int ) ( inv / 1000 * 40 ) );
pd->lcd->contrast(pd->lcd, (int) (inv / 1000 * 40));
return 0;
} else if ( promille > 1000 ) {
pd->lcd->contrast( pd->lcd, 0 );
} else if (promille > 1000) {
pd->lcd->contrast(pd->lcd, 0);
return 0;
} else if ( promille <= 0 ) {
pd->lcd->contrast( pd->lcd, 40 );
} else if (promille <= 0) {
pd->lcd->contrast(pd->lcd, 40);
return 0;
} else {
return -1;
}
}
/*MODULE_EXPORT int picoLCD_get_brightness( Driver *drvthis, int state ) {
/*MODULE_EXPORT int picoLCD_get_brightness(Driver *drvthis, int state) {
PrivateData *pd = drvthis->private_data;
}*/
/*MODULE_EXPORT int picoLCD_set_brightness( Driver *drvthis, int state, int promille ) {
/*MODULE_EXPORT int picoLCD_set_brightness(Driver *drvthis, int state, int promille) {
PrivateData *pd = drvthis->private_data;
}*/
MODULE_EXPORT void picoLCD_backlight( Driver *drvthis, int state ) {
MODULE_EXPORT void picoLCD_backlight(Driver *drvthis, int state) {
PrivateData *pd = drvthis->private_data;
if ( state == 0 ) {
pd->lcd->backlight( pd->lcd, state );
set_key_lights( pd->lcd, pd->key_light, state );
if (state == 0) {
pd->lcd->backlight(pd->lcd, state);
set_key_lights(pd->lcd, pd->key_light, state);
return;
}
if ( state == 1 ) {
pd->lcd->backlight( pd->lcd, state );
if ( pd->keylights )
set_key_lights( pd->lcd, pd->key_light, state );
if (state == 1) {
pd->lcd->backlight(pd->lcd, state);
if (pd->keylights)
set_key_lights(pd->lcd, pd->key_light, state);
return;
}
return;
}
/*MODULE_EXPORT int picoLCD_output( Driver *drvthis, int state ) {
/*MODULE_EXPORT int picoLCD_output(Driver *drvthis, int state) {
PrivateData *pd = drvthis->private_data;
}*/
/* lcd_logical_driver Informational functions */
MODULE_EXPORT char *picoLCD_get_info( Driver *drvthis ) {
MODULE_EXPORT char *picoLCD_get_info(Driver *drvthis) {
PrivateData *pd = drvthis->private_data;
return pd->info;
}
/* Private functions */
void get_key_event ( usblcd_operations *self, lcd_packet *packet, int timeout ) {
void get_key_event (usblcd_operations *self, lcd_packet *packet, int timeout) {
int ret;
memset( packet->data, 0, 255 );
memset(packet->data, 0, 255);
packet->type = 0;
ret = usb_interrupt_read( self->hid->hiddev->handle, USB_ENDPOINT_IN + 1, packet->data, _USBLCD_MAX_DATA_LEN, timeout );
if ( ret > 0 ) {
switch ( packet->data[0] ) {
ret = usb_interrupt_read(self->hid->hiddev->handle, USB_ENDPOINT_IN + 1, packet->data, _USBLCD_MAX_DATA_LEN, timeout);
if (ret > 0) {
switch (packet->data[0]) {
case IN_REPORT_KEY_STATE: {
packet->type = IN_REPORT_KEY_STATE;
} break;
@@ -493,28 +477,28 @@ void get_key_event ( usblcd_operations *self, lcd_packet *packet, int timeout )
}
}
void set_key_lights ( usblcd_operations *self, int keys[], int state ) {
if ( state ) {
void set_key_lights (usblcd_operations *self, int keys[], int state) {
if (state) {
/* Only LEDs we want on */
if ( keys[0] )
self->setled( self, 0, 1 );
if ( keys[1] )
self->setled( self, 1, 1 );
if ( keys[2] )
self->setled( self, 2, 1 );
if ( keys[3] )
self->setled( self, 3, 1 );
if ( keys[4] )
self->setled( self, 4, 1 );
if ( keys[5] )
self->setled( self, 5, 1 );
if (keys[0])
self->setled(self, 0, 1);
if (keys[1])
self->setled(self, 1, 1);
if (keys[2])
self->setled(self, 2, 1);
if (keys[3])
self->setled(self, 3, 1);
if (keys[4])
self->setled(self, 4, 1);
if (keys[5])
self->setled(self, 5, 1);
} else {
/* All LEDs off */
self->setled( self, 0, 0 );
self->setled( self, 1, 0 );
self->setled( self, 2, 0 );
self->setled( self, 3, 0 );
self->setled( self, 4, 0 );
self->setled( self, 5, 0 );
self->setled(self, 0, 0);
self->setled(self, 1, 0);
self->setled(self, 2, 0);
self->setled(self, 3, 0);
self->setled(self, 4, 0);
self->setled(self, 5, 0);
}
}
+22 -22
View File
@@ -26,31 +26,31 @@ struct _lcd_packet {
unsigned int type;
};
MODULE_EXPORT int picoLCD_init ( Driver *drvthis );
MODULE_EXPORT void picoLCD_close ( Driver *drvthis );
MODULE_EXPORT int picoLCD_width ( Driver *drvthis );
MODULE_EXPORT int picoLCD_height ( Driver *drvthis );
MODULE_EXPORT void picoLCD_clear ( Driver *drvthis );
MODULE_EXPORT void picoLCD_flush ( Driver *drvthis );
MODULE_EXPORT void picoLCD_string ( Driver *drvthis, int x, int y, char *str );
MODULE_EXPORT void picoLCD_chr ( Driver *drvthis, int x, int y, char c );
MODULE_EXPORT int picoLCD_init(Driver *drvthis);
MODULE_EXPORT void picoLCD_close(Driver *drvthis);
MODULE_EXPORT int picoLCD_width(Driver *drvthis);
MODULE_EXPORT int picoLCD_height(Driver *drvthis);
MODULE_EXPORT void picoLCD_clear(Driver *drvthis);
MODULE_EXPORT void picoLCD_flush(Driver *drvthis);
MODULE_EXPORT void picoLCD_string(Driver *drvthis, int x, int y, char *str);
MODULE_EXPORT void picoLCD_chr(Driver *drvthis, int x, int y, char c);
MODULE_EXPORT char *picoLCD_get_key ( Driver *drvthis );
MODULE_EXPORT char *picoLCD_get_key(Driver *drvthis);
//MODULE_EXPORT void picoLCD_vbar ( Driver *drvthis, int x, int y, int len, int promille, int options );
//MODULE_EXPORT void picoLCD_hbar ( Driver *drvthis, int x, int y, int len, int promille, int options );
//MODULE_EXPORT void picoLCD_num ( Driver *drvthis, int x, int y, int num );
//MODULE_EXPORT void picoLCD_heartbeat ( Driver *drvthis, int state );
//MODULE_EXPORT void picoLCD_icon ( Driver *drvthis, int x, int y, int icon );
//MODULE_EXPORT void picoLCD_cursor ( Driver *drvthis, int x, int y, int type );
//MODULE_EXPORT void picoLCD_vbar(Driver *drvthis, int x, int y, int len, int promille, int options);
//MODULE_EXPORT void picoLCD_hbar(Driver *drvthis, int x, int y, int len, int promille, int options);
//MODULE_EXPORT void picoLCD_num(Driver *drvthis, int x, int y, int num);
//MODULE_EXPORT void picoLCD_heartbeat(Driver *drvthis, int state);
//MODULE_EXPORT void picoLCD_icon(Driver *drvthis, int x, int y, int icon);
//MODULE_EXPORT void picoLCD_cursor(Driver *drvthis, int x, int y, int type);
//MODULE_EXPORT int picoLCD_get_contrast ( Driver *drvthis );
MODULE_EXPORT int picoLCD_set_contrast ( Driver *drvthis, int promille );
//MODULE_EXPORT int picoLCD_get_brightness ( Driver *drvthis, int state );
//MODULE_EXPORT int picoLCD_set_brightness ( Driver *drvthis, int state, int promille );
MODULE_EXPORT void picoLCD_backlight ( Driver *drvthis, int promille );
//MODULE_EXPORT void picoLCD_output ( Driver *drvthis, int state );
//MODULE_EXPORT int picoLCD_get_contrast(Driver *drvthis);
MODULE_EXPORT int picoLCD_set_contrast(Driver *drvthis, int promille);
//MODULE_EXPORT int picoLCD_get_brightness (Driver *drvthis, int state);
//MODULE_EXPORT int picoLCD_set_brightness (Driver *drvthis, int state, int promille);
MODULE_EXPORT void picoLCD_backlight(Driver *drvthis, int promille);
//MODULE_EXPORT void picoLCD_output(Driver *drvthis, int state);
MODULE_EXPORT char *picoLCD_get_info ( Driver *drvthis );
MODULE_EXPORT char *picoLCD_get_info(Driver *drvthis);
#endif