fix inverted setting (meaning was inverted too)
[enigma2.git] / lib / driver / avswitch.cpp
1 #include <lib/driver/avswitch.h>
2
3 #include <unistd.h>
4 #include <fcntl.h>
5 #include <sys/ioctl.h>
6
7 #include <lib/base/init.h>
8 #include <lib/base/init_num.h>
9 #include <lib/base/econfig.h>
10 #include <lib/base/eerror.h>
11
12 eAVSwitch *eAVSwitch::instance = 0;
13
14 eAVSwitch::eAVSwitch()
15 {
16         ASSERT(!instance);
17         instance = this;
18 }
19
20 eAVSwitch::~eAVSwitch()
21 {
22 }
23
24 eAVSwitch *eAVSwitch::getInstance()
25 {
26         return instance;
27 }
28
29 void eAVSwitch::setInput(int val)
30 {
31         /*
32         0-encoder
33         1-scart
34         2-aux
35         */
36
37         char *input[] = {"encoder", "scart", "aux"};
38
39         int fd;
40         
41         if((fd = open("/proc/stb/avs/0/input", O_WRONLY)) < 0) {
42                 printf("cannot open /proc/stb/avs/0/input\n");
43                 return;
44         }
45
46         write(fd, input[val], strlen(input[val]));
47         close(fd);
48         
49         if (val == 1)
50                 setFastBlank(2);
51 }
52
53 void eAVSwitch::setFastBlank(int val)
54 {
55         int fd;
56         char *fb[] = {"low", "high", "vcr"};
57
58         
59         if((fd = open("/proc/stb/avs/0/fb", O_WRONLY)) < 0) {
60                 printf("cannot open /proc/stb/avs/0/fb\n");
61                 return;
62         }
63
64         write(fd, fb[val], strlen(fb[0]));
65         close(fd);
66 }
67
68 void eAVSwitch::setColorFormat(int format)
69 {
70         /*
71         0-CVBS
72         1-RGB
73         2-S-Video
74         */
75         char *cvbs="cvbs";
76         char *rgb="rgb";
77         char *svideo="svideo";
78         int fd;
79         
80         if((fd = open("/proc/stb/avs/0/colorformat", O_WRONLY)) < 0) {
81                 printf("cannot open /proc/stb/avs/0/colorformat\n");
82                 return;
83         }
84         switch(format) {
85                 case 0:
86                         write(fd, cvbs, strlen(cvbs));
87                         break;
88                 case 1:
89                         write(fd, rgb, strlen(rgb));
90                         break;
91                 case 2:
92                         write(fd, svideo, strlen(svideo));
93                         break;
94         }       
95         close(fd);
96 }
97
98 void eAVSwitch::setAspectRatio(int ratio)
99 {
100         /*
101         0-4:3 Letterbox
102         1-4:3 PanScan
103         2-16:9
104         3-16:9 forced
105         */
106         
107         char *aspect[] = {"4:3", "4:3", "any", "16:9"};
108         char *policy[] = {"letterbox", "panscan", "bestfit", "panscan"};
109
110         int fd;
111         if((fd = open("/proc/stb/video/aspect", O_WRONLY)) < 0) {
112                 printf("cannot open /proc/stb/video/aspect\n");
113                 return;
114         }
115         write(fd, aspect[ratio], strlen(aspect[ratio]));
116         close(fd);
117
118         if((fd = open("/proc/stb/video/policy", O_WRONLY)) < 0) {
119                 printf("cannot open /proc/stb/video/policy\n");
120                 return;
121         }
122         write(fd, policy[ratio], strlen(policy[ratio]));
123         close(fd);
124
125 }
126
127 void eAVSwitch::setVideomode(int mode)
128 {
129         char *pal="pal";
130         char *ntsc="ntsc";
131         int fd;
132         
133         return;
134         //FIXME: bug in driver (cannot set PAL)
135         if((fd = open("/proc/stb/video/videomode", O_WRONLY)) < 0) {
136                 printf("cannot open /proc/stb/video/videomode\n");
137                 return;
138         }
139         switch(mode) {
140                 case 0:
141                         write(fd, pal, strlen(pal));
142                         break;
143                 case 1:
144                         write(fd, ntsc, strlen(ntsc));
145                         break;
146         }       
147         close(fd);
148 }
149
150 //FIXME: correct "run/startlevel"
151 eAutoInitP0<eAVSwitch> init_avswitch(eAutoInitNumbers::rc, "AVSwitch Driver");