aboutsummaryrefslogtreecommitdiff
path: root/lib/driver/misc_options.cpp
blob: c567878c7789773bf0984d266642b9a4ed7a868b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <lib/driver/misc_options.h>

#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>

#include <lib/base/init.h>
#include <lib/base/init_num.h>
#include <lib/base/eerror.h>

Misc_Options *Misc_Options::instance = 0;

Misc_Options::Misc_Options()
	:m_12V_output_state(-1)
{
	ASSERT(!instance);
	instance = this;
}

int Misc_Options::set_12V_output(int state)
{
	if (state == m_12V_output_state)
		return 0;
	int fd = open("/proc/stb/misc/12V_output", O_WRONLY);
	if (fd < 0)
	{
		eDebug("couldn't open /proc/stb/misc/12V_output");
		return -1;
	}
	const char *str=0;
	if (state == 0)
		str = "off";
	else if (state == 1)
		str = "on";
	if (str)
		write(fd, str, strlen(str));
	m_12V_output_state = state;
	close(fd);
	return 0;
}

bool Misc_Options::detected_12V_output()
{
	int fd = open("/proc/stb/misc/12V_output", O_WRONLY);
	if (fd < 0)
	{
		eDebug("couldn't open /proc/stb/misc/12V_output");
		return false;
	}
	close(fd);
	return true;
}

Misc_Options *Misc_Options::getInstance()
{
	return instance;
}

//FIXME: correct "run/startlevel"
eAutoInitP0<Misc_Options> init_misc_options(eAutoInitNumbers::rc, "misc options");