[lcdproc] LEDs

Rene Wagner reenoo@gmx.de
Sat, 08 Sep 2001 21:53:24 +0200


Hi!

Philip Pokorny wrote:

>> But the device expects two 8bit values. So how do I split one 16bit
>> value into two 8bit values?
> 
> 
> Bit shifting and masking is commonly used to divide larger quantities
> into smaller ones.
> 
>   low_8bits = full_16bits & 0xff ;
>   high_8bits = (full_16bits >> 8) & 0xff

OK! Works fine! Thanks!

>  
> 
>> There also is another problem: Why doesn't LCDd accept 0 as an argument
>> for "output"? 
...

> It shouldn't be too hard to fix output_func to accept 0.  Read up on the
> strtol function and the meaning of the second argument to it and see if
> you can patch it to make it more intelligent.  Submit a patch when
> you're done.

This is the patch:

diff -urN lcdproc-0.4.1/server/client_functions.c 
lcdproc-0.4.1b/server/client_functions.c
--- lcdproc-0.4.1/server/client_functions.c	Fri May 25 04:23:21 2001
+++ lcdproc-0.4.1b/server/client_functions.c	Sat Sep  8 20:16:11 2001
@@ -1115,7 +1115,7 @@
  {
  	int rc = 0;
  	if (argc != 2) {
- 
	sock_send_string (c->sock, "huh?  Too many parameters...\n");
+ 
	sock_send_string (c->sock, "huh?  Usage: output [value]\n");
  		rc = 1;
  	} else {
  		if (0 == strcmp (argv[1], "on"))
@@ -1129,13 +1129,20 @@
  	 
	char *endptr;

  	 
	out = strtol(argv[1], &endptr, 0);
- 
		if ( (out == 0) && (errno != 0) ) {
+ 
		if (0 == strcmp (endptr, argv[1])) {
  	 
		sock_send_string (c->sock,
  	 
			 "huh?  invalid parameter...\n");
  	 
		rc = 1;
  	 
	}
  	 
	else {
- 
			output_state = out;
+ 
			if  (errno == ERANGE)  {
+ 
				sock_send_string (c->sock,
+ 
					 "huh?  value is out of range...\n");
+ 
				rc = 1;
+ 
			}
+ 
			else {
+ 
				output_state = out;
+ 
			}
  	 
	}
  		}
  	}

Now it is possible to use "output 0", in order to turn all LEDs off in
my case. Using "output off" is still possible.

If the number of args to output is incorrect LCDd returns "huh? usage:
output [value]" to the client.
If the arg to output is invalid (not a digit) LCDd returns "huh? invalid
  parameter..."
In case the arg is a number but the value is out of range LCDd reports
this, too.
Regards,

Rene



-----------------------------------------------------------
To unsubscribe from this list send a blank message to
lcdproc-unsubscribe@lists.omnipotent.net