Remove trailing whitespace.
[dockapps.git] / wmpower / src / power_management / compal / compal_lib.c
blob6c2d495f5a2f3da2f0244d2d5846e2a0a5435597
1 /***************************************************************************
2 compal_lib.c - description
3 -------------------
4 begin : Oct 01 2003
5 copyright : (C) 2003 by Francisco Rodrigo Escobedo Robles
6 e-mail : frer@pepix.net
7 ***************************************************************************/
9 /***************************************************************************
10 * *
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. *
15 * *
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. *
20 * *
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. *
25 * *
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 ***************************************************************************/
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <time.h>
37 #include <ctype.h>
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)
48 char *value;
49 char *lastchar;
52 for ( ;
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) ;
62 *--lastchar == ' ' ;
63 *lastchar = '\0')
66 return value;
71 int machine_is_compal (void)
73 FILE *fp = fopen(COMPAL_PROC_FILE_DMI, "r");
74 char buf [COMPAL_MAX_DMI_INFO + 1];
75 char *ptr;
76 char *vendor;
77 char *prodname;
80 if (!fp) return 0;
82 fread (&buf, 1, COMPAL_MAX_DMI_INFO, fp);
83 fclose (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);
91 return 1;
96 int compal_get_fan_status (void)
98 FILE *fp = fopen (COMPAL_PROC_FILE_FAN, "r");
99 char fan_status[3];
101 if (!fp) return PM_Error;
103 if (fscanf (fp, "%*s%*s%2s", fan_status) != 1)
105 fclose (fp);
106 return PM_Error;
108 fclose (fp);
110 if (!strcmp (fan_status, "on")) return 1;
111 return 0;
116 int compal_get_temperature (void)
118 FILE *fp = fopen (COMPAL_PROC_FILE_TEMP, "r");
119 int result;
121 if (!fp) return PM_Error;
123 if (fscanf(fp, "%*s%*s%d", &result) == 1)
125 fclose(fp);
126 return result;
129 fclose(fp);
130 return PM_Error;
135 int compal_get_lcd_brightness (void)
137 FILE *fp = fopen (COMPAL_PROC_FILE_LCD, "r");
138 int brightness;
140 if (!fp) return PM_Error;
142 if (fscanf (fp, "%*s%*s%d", &brightness) == 1)
144 fclose (fp);
145 return brightness;
148 fclose (fp);
149 return PM_Error;
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);
166 fclose (fp);
167 return 0;
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);