2 #include <stdio.h> /* for FILE etc */
3 #include <stdlib.h> /* for malloc */
6 #include <sys/types.h> /* for open */
11 #include "pnd_device.h"
13 unsigned char pnd_device_open_write_close ( char *name, char *v ) {
16 if ( ( f = open ( name, O_WRONLY /*O_RDONLY*/ ) ) < 0 ) {
20 if ( write ( f, v, strlen ( v ) ) < strlen ( v ) ) {
30 unsigned char pnd_device_open_read_close ( char *name, char *r_buffer, unsigned int buffer_len ) {
33 f = fopen ( name, "r" );
39 if ( ! fgets ( r_buffer, buffer_len, f ) ) {
49 unsigned char pnd_device_set_clock ( unsigned int c ) {
52 sprintf ( buffer, "%u", c );
54 return ( pnd_device_open_write_close ( PND_DEVICE_PROC_CLOCK, buffer ) );
57 unsigned int pnd_device_get_clock ( void ) {
60 if ( pnd_device_open_read_close ( PND_DEVICE_PROC_CLOCK, buffer, 100 ) ) {
61 return ( atoi ( buffer ) );
67 unsigned char pnd_device_set_backlight ( unsigned int c ) {
70 sprintf ( buffer, "%u", c );
72 return ( pnd_device_open_write_close ( PND_DEVICE_SYS_BACKLIGHT_BRIGHTNESS, buffer ) );
75 unsigned int pnd_device_get_backlight ( void ) {
78 if ( pnd_device_open_read_close ( PND_DEVICE_SYS_BACKLIGHT_BRIGHTNESS, buffer, 100 ) ) {
79 return ( atoi ( buffer ) );
85 int pnd_device_get_battery_gauge_perc ( void ) {
88 if ( pnd_device_open_read_close ( PND_DEVICE_BATTERY_GAUGE_PERC, buffer, 100 ) ) {
89 return ( atoi ( buffer ) );
95 unsigned char pnd_device_get_charge_current ( int *result ) {
98 if ( pnd_device_open_read_close ( PND_DEVICE_CHARGE_CURRENT, buffer, 100 ) ) {
99 *result = atoi ( buffer );
106 unsigned char pnd_device_set_led_power_brightness ( unsigned char v ) {
109 sprintf ( buffer, "%u", v );
111 return ( pnd_device_open_write_close ( PND_DEVICE_LED_POWER PND_DEVICE_LED_SUFFIX_BRIGHTNESS, buffer ) );
114 unsigned char pnd_device_set_led_charger_brightness ( unsigned char v ) {
117 sprintf ( buffer, "%u", v );
119 return ( pnd_device_open_write_close ( PND_DEVICE_LED_CHARGER PND_DEVICE_LED_SUFFIX_BRIGHTNESS, buffer ) );