hd44780/serial: Add support for adjustable backlight. Solve some possible
problems that may arise by comparing signed and unsigned char values.
This commit is contained in:
@@ -28,6 +28,7 @@ v0.5dev (ongoing development)
|
||||
+ hd44780: Added 'usb4all' connection type (T. Mohaupt)
|
||||
* Fix RPM init script hanging on recent OS (#3488223)
|
||||
* lcdproc client: Fix build on OpenBSD >= 5.0
|
||||
* hd44780/serial: Add support for adjustable backlight
|
||||
|
||||
v0.5.5
|
||||
+ sed1330 driver: Add support for HG25504 (L. Lagendijk)
|
||||
|
||||
@@ -304,17 +304,26 @@ serial_HD44780_backlight(PrivateData *p, unsigned char state)
|
||||
{
|
||||
unsigned char send;
|
||||
|
||||
if (SERIAL_IF.backlight) {
|
||||
if (SERIAL_IF.backlight_escape) {
|
||||
send = SERIAL_IF.backlight_escape;
|
||||
write(p->fd, &send, 1);
|
||||
}
|
||||
/* If backlight available and escape sequence defined send it */
|
||||
if (SERIAL_IF.backlight && SERIAL_IF.backlight_escape) {
|
||||
send = SERIAL_IF.backlight_escape;
|
||||
write(p->fd, &send, 1);
|
||||
}
|
||||
|
||||
if (SERIAL_IF.backlight == 1) { /* Backlight is just switchable */
|
||||
if (state == BACKLIGHT_ON)
|
||||
send = SERIAL_IF.backlight_on;
|
||||
else
|
||||
send = SERIAL_IF.backlight_off;
|
||||
write(p->fd, &send, 1);
|
||||
}
|
||||
else if (SERIAL_IF.backlight == 2) { /* Backlight is adjustable */
|
||||
int val = (state == BACKLIGHT_ON) ? p->brightness : p->offbrightness;
|
||||
|
||||
/* Map the value to output range (rounding up) */
|
||||
send = (val * (SERIAL_IF.backlight_on - SERIAL_IF.backlight_off) + 999) / 1000 + SERIAL_IF.backlight_off;;
|
||||
write(p->fd, &send, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -330,7 +339,7 @@ serial_HD44780_scankeypad(PrivateData *p)
|
||||
char hangcheck = 100;
|
||||
|
||||
read(p->fd, &buffer, 1);
|
||||
if (buffer == (SERIAL_IF.keypad_escape & 0xFF)) {
|
||||
if (buffer == SERIAL_IF.keypad_escape) {
|
||||
while (hangcheck > 0) {
|
||||
/* Check if I can read another byte */
|
||||
if (read(p->fd, &buffer, 1) == 1) {
|
||||
|
||||
@@ -9,29 +9,55 @@
|
||||
#define SERIALIF_NAME_LENGTH 20
|
||||
#define DEFAULT_DEVICE "/dev/lcd"
|
||||
|
||||
/** Declares one configuration enty in the serial_interfaces table */
|
||||
/** Declares one configuration entry in the serial_interfaces table */
|
||||
struct hd44780_SerialInterface {
|
||||
int connectiontype; /**< Connection type from hd44780 config */
|
||||
/** Command escape character. This is always sent, even if 0x00 */
|
||||
char instruction_escape;
|
||||
/** Data escape character. Only sent if not NUL data is within range
|
||||
* configure by data_escape_min and data_escape_max. */
|
||||
char data_escape;
|
||||
char data_escape_min; /**< Escaped data lower limit (inclusive) */
|
||||
char data_escape_max; /**< Escaped data upper limit (exclusive) */
|
||||
unsigned int default_bitrate; /**< Bitrate device is set to by default */
|
||||
char if_bits; /**< Initialize to 8 or 4 bit interface */
|
||||
char keypad; /**< Flag: keypad available */
|
||||
char keypad_escape; /**< Keys are escaped with this character */
|
||||
char backlight; /**< Flag: backlight available */
|
||||
/** Escape character to send to indicate a backlight state change */
|
||||
char backlight_escape;
|
||||
char backlight_off; /**< Character sent to set display off */
|
||||
char backlight_on; /**< Character sent to set display on */
|
||||
int connectiontype; /**< Connection type from hd44780 config */
|
||||
|
||||
/** \name Instruction / data escape sequence
|
||||
* Determines if escape characters have to be sent for instruction or
|
||||
* data values. The instruction escape character is always sent, even
|
||||
* if its value is 0x00. The data escape character is only sent it it
|
||||
* is not NUL and data is within range set by data_escape_min and
|
||||
* data_escape_max.
|
||||
*@{*/
|
||||
unsigned char instruction_escape; /**< Instruction escape character. */
|
||||
unsigned char data_escape; /**< Data escape character. */
|
||||
unsigned char data_escape_min; /**< Escaped data lower limit (inclusive) */
|
||||
unsigned char data_escape_max; /**< Escaped data upper limit (exclusive) */
|
||||
/**@}*/
|
||||
|
||||
unsigned int default_bitrate; /**< Bitrate device is set to by default */
|
||||
char if_bits; /**< Initialize to 8 or 4 bit interface */
|
||||
|
||||
/** \name Keypad settings
|
||||
*@{*/
|
||||
char keypad; /**< Flag: keypad available */
|
||||
unsigned char keypad_escape; /**< Keys are escaped with this character */
|
||||
/**@}*/
|
||||
|
||||
/** \name Backlight options
|
||||
* The backlight flag determines the type of backlight available.
|
||||
* If the backlight is just switchable, the backlight_off or
|
||||
* backlight_on characters are sent according to backlight state.
|
||||
* If the backlight is switchable, these characters must define a range
|
||||
* of values that are understood as different brightness levels by
|
||||
* the display. The 'brightness' and 'offbrightness' values from config
|
||||
* are used according to the backlight state and mapped to this range.
|
||||
*@{*/
|
||||
char backlight; /**< Flag: backlight available
|
||||
* 0 = none, 1 = switchable, 2 = adjustable */
|
||||
unsigned char backlight_escape; /**< Escape character to send to indicate
|
||||
* a backlight state change */
|
||||
unsigned char backlight_off; /**< Character sent to set display off
|
||||
* or minimum value if adjustable */
|
||||
unsigned char backlight_on; /**< Character sent to set display on
|
||||
* or maximum value if adjustable */
|
||||
/**@}*/
|
||||
|
||||
/** Flag: Device has multiple controllers. If enabled, the displayID
|
||||
* is added to data escape */
|
||||
char multiple_displays;
|
||||
char end_code; /**< Code to send on shutdown */
|
||||
* is added to data_escape and it is always sent. */
|
||||
char multiple_displays;
|
||||
unsigned char end_code; /**< Code to send on shutdown */
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user