Merge branch 'bug_538_ignore_global_actions_in_standby'
[enigma2.git] / lib / driver / misc_options.cpp
1 #include <cstring>
2 #include <lib/driver/misc_options.h>
3
4 #include <unistd.h>
5 #include <fcntl.h>
6 #include <sys/ioctl.h>
7
8 #include <lib/base/init.h>
9 #include <lib/base/init_num.h>
10 #include <lib/base/eerror.h>
11
12 Misc_Options *Misc_Options::instance = 0;
13
14 Misc_Options::Misc_Options()
15         :m_12V_output_state(-1)
16 {
17         ASSERT(!instance);
18         instance = this;
19 }
20
21 int Misc_Options::set_12V_output(int state)
22 {
23         if (state == m_12V_output_state)
24                 return 0;
25         int fd = open("/proc/stb/misc/12V_output", O_WRONLY);
26         if (fd < 0)
27         {
28                 eDebug("couldn't open /proc/stb/misc/12V_output");
29                 return -1;
30         }
31         const char *str=0;
32         if (state == 0)
33                 str = "off";
34         else if (state == 1)
35                 str = "on";
36         if (str)
37                 write(fd, str, strlen(str));
38         m_12V_output_state = state;
39         close(fd);
40         return 0;
41 }
42
43 bool Misc_Options::detected_12V_output()
44 {
45         int fd = open("/proc/stb/misc/12V_output", O_WRONLY);
46         if (fd < 0)
47         {
48                 eDebug("couldn't open /proc/stb/misc/12V_output");
49                 return false;
50         }
51         close(fd);
52         return true;
53 }
54
55 Misc_Options *Misc_Options::getInstance()
56 {
57         return instance;
58 }
59
60 //FIXME: correct "run/startlevel"
61 eAutoInitP0<Misc_Options> init_misc_options(eAutoInitNumbers::rc, "misc options");