1 /***************************************************************************
2 compal_lib.c - description
5 copyright : (C) 2003 by Francisco Rodrigo Escobedo Robles
6 e-mail : frer@pepix.net
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License for more details. *
21 * You should have received a copy of the GNU General Public License *
22 * along with this program; if not, write to the *
23 * Free Software Foundation, Inc., *
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
26 ***************************************************************************/
28 /***************************************************************************
29 Many thanks to Soós Péter <sp@osb.hu> and the omke project team
30 I could never have done this otherwise
31 ***************************************************************************/
39 #include "compal_lib.h"
40 #include "lib_utils.h"
41 #include "power_management.h"
45 /* gets a value from a strtok-ed buffer; for reading from /proc */
46 char *getvaluefromhash (char *key
, char *hash
)
53 NULL
!= hash
&& strcmp (key
, hash
) ;
54 hash
= strtok (NULL
, ":\n"))
57 value
= strtok (NULL
, ":\n");
59 while (*value
== ' ') ++value
;
61 for (lastchar
= value
+ strlen (value
) ;
71 int machine_is_compal (void)
73 FILE *fp
= fopen(COMPAL_PROC_FILE_DMI
, "r");
74 char buf
[COMPAL_MAX_DMI_INFO
+ 1];
82 fread (&buf
, 1, COMPAL_MAX_DMI_INFO
, fp
);
85 /* always get the values in order! */
86 ptr
= strtok (buf
, ":\n");
87 vendor
= getvaluefromhash ("System Vendor", ptr
);
88 prodname
= getvaluefromhash ("Product Name", ptr
);
89 sprintf (compal_model
, "%s %s", vendor
, prodname
);
96 int compal_get_fan_status (void)
98 FILE *fp
= fopen (COMPAL_PROC_FILE_FAN
, "r");
101 if (!fp
) return PM_Error
;
103 if (fscanf (fp
, "%*s%*s%2s", fan_status
) != 1)
110 if (!strcmp (fan_status
, "on")) return 1;
116 int compal_get_temperature (void)
118 FILE *fp
= fopen (COMPAL_PROC_FILE_TEMP
, "r");
121 if (!fp
) return PM_Error
;
123 if (fscanf(fp
, "%*s%*s%d", &result
) == 1)
135 int compal_get_lcd_brightness (void)
137 FILE *fp
= fopen (COMPAL_PROC_FILE_LCD
, "r");
140 if (!fp
) return PM_Error
;
142 if (fscanf (fp
, "%*s%*s%d", &brightness
) == 1)
154 int compal_set_lcd_brightness (int brightness
)
156 FILE *fp
= fopen (COMPAL_PROC_FILE_LCD
, "w");
158 if (!fp
) return PM_Error
;
160 if (brightness
< COMPAL_LCD_MIN
) brightness
= COMPAL_LCD_MIN
;
161 if (brightness
> COMPAL_LCD_MAX
) brightness
= COMPAL_LCD_MAX
;
162 if (maxBrightness
!= -1 && brightness
> maxBrightness
) brightness
= maxBrightness
;
163 if (minBrightness
!= -1 && brightness
< minBrightness
) brightness
= minBrightness
;
165 fprintf (fp
, "%i", brightness
);
172 void Compal_lcdBrightness_UpOneStep (void)
174 compal_set_lcd_brightness (compal_get_lcd_brightness () + 1);
179 void Compal_lcdBrightness_DownOneStep (void)
181 compal_set_lcd_brightness (compal_get_lcd_brightness () - 1);