init
[cpufrequi] / n900.c
1 #include <stdio.h>
2 #include <errno.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <fcntl.h>
6
7 #include "n900.h"
8
9 #define MAX_LINE_LEN 255
10
11 int omap_get_real_temperature()
12 {
13     char buf[MAX_LINE_LEN];
14     int value;
15     char *endp;
16     int fd;
17     size_t numread;
18
19     if ( ( fd = open("/sys/devices/platform/omap34xx_temp/temp1_input", O_RDONLY) ) == -1 )
20             return 0;
21
22     numread = read(fd, buf, MAX_LINE_LEN - 1);
23     if ( numread < 1 )
24     {
25             close(fd);
26             return 0;
27     }
28
29     buf[numread] = '\0';
30     close(fd);
31
32     value = strtol(buf, &endp, 0);
33
34     if ( endp == buf || errno == ERANGE )
35             return 0;
36
37     return value;
38 }
39
40 int omap_get_raw_temperature()
41 {
42     char buf[MAX_LINE_LEN];
43     int value;
44     char *endp;
45     int fd;
46     size_t numread;
47
48     if ( ( fd = open("/sys/devices/platform/omap34xx_temp/temp1_input_raw", O_RDONLY) ) == -1 )
49             return 0;
50
51     numread = read(fd, buf, MAX_LINE_LEN - 1);
52     if ( numread < 1 )
53     {
54             close(fd);
55             return 0;
56     }
57
58     buf[numread] = '\0';
59     close(fd);
60
61     value = strtol(buf, &endp, 0);
62
63     if ( endp == buf || errno == ERANGE )
64             return 0;
65
66     return value;
67 }