X-Git-Url: http://git.openpandora.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fpnd_device.c;h=65ea1768963d24acf7cc020aab3c9dd3140fae88;hb=dce16882dd2c3468fb9d61680d89b22d3c59f07b;hp=42a17caf33bf24ea901f0e025edd73c445cf9a8d;hpb=7c3c5d7878000b103ab779f0d811d663914731f8;p=pandora-libraries.git diff --git a/lib/pnd_device.c b/lib/pnd_device.c index 42a17ca..65ea176 100644 --- a/lib/pnd_device.c +++ b/lib/pnd_device.c @@ -7,17 +7,19 @@ #include #include #include +#include #include "pnd_device.h" unsigned char pnd_device_open_write_close ( char *name, char *v ) { int f; - if ( ( f = open ( PND_DEVICE_PROC_CLOCK, O_WRONLY /*O_RDONLY*/ ) ) < 0 ) { + if ( ( f = open ( name, O_WRONLY /*O_RDONLY*/ ) ) < 0 ) { return ( 0 ); } - if ( write ( f, buffer, strlen ( buffer ) ) < strlen ( buffer ) ) { + if ( write ( f, v, strlen ( v ) ) < strlen ( v ) ) { + close ( f ); return ( 0 ); } @@ -48,7 +50,7 @@ unsigned char pnd_device_open_read_close ( char *name, char *r_buffer, unsigned unsigned char pnd_device_set_clock ( unsigned int c ) { char buffer [ 100 ]; - sprint ( buffer, "%u", c ); + sprintf ( buffer, "%u", c ); return ( pnd_device_open_write_close ( PND_DEVICE_PROC_CLOCK, buffer ) ); } @@ -66,7 +68,7 @@ unsigned int pnd_device_get_clock ( void ) { unsigned char pnd_device_set_backlight ( unsigned int c ) { char buffer [ 100 ]; - sprint ( buffer, "%u", c ); + sprintf ( buffer, "%u", c ); return ( pnd_device_open_write_close ( PND_DEVICE_SYS_BACKLIGHT_BRIGHTNESS, buffer ) ); } @@ -80,3 +82,85 @@ unsigned int pnd_device_get_backlight ( void ) { return ( 0 ); } + +int pnd_device_get_battery_gauge_perc ( void ) { + char buffer [ 100 ]; + + if ( pnd_device_open_read_close ( PND_DEVICE_BATTERY_GAUGE_PERC, buffer, 100 ) ) { + return ( atoi ( buffer ) ); + } + + return ( -1 ); +} + +unsigned char pnd_device_get_charge_current ( int *result ) { + char buffer [ 100 ]; + + if ( pnd_device_open_read_close ( PND_DEVICE_CHARGE_CURRENT, buffer, 100 ) ) { + *result = atoi ( buffer ); + return ( 1 ); + } + + return ( 0 ); +} + +int pnd_device_get_charger_enable ( const char *devices ) { + char fullname [ 100 ]; + char buffer [ 100 ]; + + while ( 1 ) { + if ( sscanf ( devices, "%99s", buffer ) != 1 ) { + break; + } + + while ( isspace ( *devices ) ) + devices++; + devices += strlen ( buffer ); + snprintf ( fullname, sizeof ( fullname ), PND_DEVICE_POWER_BASE "/%s/enable", buffer ); + + /* XXX: only ckecks first good device, but that should be enough for our needs */ + if ( pnd_device_open_read_close ( fullname, buffer, 100 ) ) { + return ( atoi ( buffer ) ); + } + } + + return ( -1 ); +} + +unsigned char pnd_device_set_charger_enable ( const char *devices, unsigned char v ) { + char fullname [ 100 ]; + char buffer [ 100 ]; + int ret = 0; + + while ( 1 ) { + if ( sscanf ( devices, "%99s", buffer ) != 1 ) { + break; + } + + while ( isspace ( *devices ) ) + devices++; + devices += strlen ( buffer ); + snprintf ( fullname, sizeof ( fullname ), PND_DEVICE_POWER_BASE "/%s/enable", buffer ); + + sprintf ( buffer, "%u", v ); + ret |= pnd_device_open_write_close ( fullname, buffer ); + } + + return ( ret ); +} + +unsigned char pnd_device_set_led_power_brightness ( unsigned char v ) { + char buffer [ 100 ]; + + sprintf ( buffer, "%u", v ); + + return ( pnd_device_open_write_close ( PND_DEVICE_LED_POWER PND_DEVICE_LED_SUFFIX_BRIGHTNESS, buffer ) ); +} + +unsigned char pnd_device_set_led_charger_brightness ( unsigned char v ) { + char buffer [ 100 ]; + + sprintf ( buffer, "%u", v ); + + return ( pnd_device_open_write_close ( PND_DEVICE_LED_CHARGER PND_DEVICE_LED_SUFFIX_BRIGHTNESS, buffer ) ); +}