2 #include <stdio.h> /* for FILE etc */
3 #include <stdlib.h> /* for malloc */
6 #include <sys/types.h> /* for open */
12 #include "pnd_device.h"
14 unsigned char pnd_device_open_write_close ( char *name, char *v ) {
17 if ( ( f = open ( name, O_WRONLY /*O_RDONLY*/ ) ) < 0 ) {
21 if ( write ( f, v, strlen ( v ) ) < strlen ( v ) ) {
31 unsigned char pnd_device_open_read_close ( char *name, char *r_buffer, unsigned int buffer_len ) {
34 f = fopen ( name, "r" );
40 if ( ! fgets ( r_buffer, buffer_len, f ) ) {
50 unsigned char pnd_device_set_clock ( unsigned int c ) {
53 sprintf ( buffer, "%u", c );
55 return ( pnd_device_open_write_close ( PND_DEVICE_PROC_CLOCK, buffer ) );
58 unsigned int pnd_device_get_clock ( void ) {
61 if ( pnd_device_open_read_close ( PND_DEVICE_PROC_CLOCK, buffer, 100 ) ) {
62 return ( atoi ( buffer ) );
68 unsigned char pnd_device_set_backlight ( unsigned int c ) {
71 sprintf ( buffer, "%u", c );
73 return ( pnd_device_open_write_close ( PND_DEVICE_SYS_BACKLIGHT_BRIGHTNESS, buffer ) );
76 unsigned int pnd_device_get_backlight ( void ) {
79 if ( pnd_device_open_read_close ( PND_DEVICE_SYS_BACKLIGHT_BRIGHTNESS, buffer, 100 ) ) {
80 return ( atoi ( buffer ) );
86 int pnd_device_get_battery_gauge_perc ( void ) {
89 if ( pnd_device_open_read_close ( PND_DEVICE_BATTERY_GAUGE_PERC, buffer, 100 ) ) {
90 return ( atoi ( buffer ) );
96 unsigned char pnd_device_get_charge_current ( int *result ) {
99 if ( pnd_device_open_read_close ( PND_DEVICE_CHARGE_CURRENT, buffer, 100 ) ) {
100 *result = atoi ( buffer );
107 int pnd_device_get_charger_enable ( const char *devices ) {
108 char fullname [ 100 ];
112 if ( sscanf ( devices, "%99s", buffer ) != 1 ) {
116 while ( isspace ( *devices ) )
118 devices += strlen ( buffer );
119 snprintf ( fullname, sizeof ( fullname ), PND_DEVICE_POWER_BASE "/%s/enable", buffer );
121 /* XXX: only ckecks first good device, but that should be enough for our needs */
122 if ( pnd_device_open_read_close ( fullname, buffer, 100 ) ) {
123 return ( atoi ( buffer ) );
130 unsigned char pnd_device_set_charger_enable ( const char *devices, unsigned char v ) {
131 char fullname [ 100 ];
136 if ( sscanf ( devices, "%99s", buffer ) != 1 ) {
140 while ( isspace ( *devices ) )
142 devices += strlen ( buffer );
143 snprintf ( fullname, sizeof ( fullname ), PND_DEVICE_POWER_BASE "/%s/enable", buffer );
145 sprintf ( buffer, "%u", v );
146 ret |= pnd_device_open_write_close ( fullname, buffer );
152 unsigned char pnd_device_set_led_power_brightness ( unsigned char v ) {
155 sprintf ( buffer, "%u", v );
157 return ( pnd_device_open_write_close ( PND_DEVICE_LED_POWER PND_DEVICE_LED_SUFFIX_BRIGHTNESS, buffer ) );
160 unsigned char pnd_device_set_led_charger_brightness ( unsigned char v ) {
163 sprintf ( buffer, "%u", v );
165 return ( pnd_device_open_write_close ( PND_DEVICE_LED_CHARGER PND_DEVICE_LED_SUFFIX_BRIGHTNESS, buffer ) );