X-Git-Url: http://git.openpandora.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fpnd_device.c;h=2e86928afaaa65c93fa77748cb1feb78ec962dd8;hb=b641f303ffacc4445167c760c49230faa6f59be4;hp=42a17caf33bf24ea901f0e025edd73c445cf9a8d;hpb=7c3c5d7878000b103ab779f0d811d663914731f8;p=pandora-libraries.git diff --git a/lib/pnd_device.c b/lib/pnd_device.c index 42a17ca..2e86928 100644 --- a/lib/pnd_device.c +++ b/lib/pnd_device.c @@ -13,11 +13,12 @@ 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 +49,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 +67,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 +81,63 @@ 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 *device ) { + char fullname [ 100 ]; + char buffer [ 100 ]; + + snprintf ( fullname, sizeof ( fullname ), PND_DEVICE_POWER_BASE "/%s/enable", device ); + + if ( pnd_device_open_read_close ( fullname, buffer, 100 ) ) { + return ( atoi ( buffer ) ); + } + + return ( -1 ); +} + +unsigned char pnd_device_set_charger_enable ( const char *device, unsigned char v ) { + char fullname [ 100 ]; + char buffer [ 100 ]; + + snprintf ( fullname, sizeof ( fullname ), PND_DEVICE_POWER_BASE "/%s/enable", device ); + sprintf ( buffer, "%u", v ); + + return ( pnd_device_open_write_close ( fullname, buffer ) ); +} + +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 ) ); +}