fix empty expressions in dvb list search
[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/eerror.h>
10
11 eAVSwitch *eAVSwitch::instance = 0;
12
13 eAVSwitch::eAVSwitch()
14 {
15         ASSERT(!instance);
16         instance = this;
17         m_video_mode = 0;
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         if((fd = open("/proc/stb/avs/0/fb", O_WRONLY)) < 0) {
59                 printf("cannot open /proc/stb/avs/0/fb\n");
60                 return;
61         }
62
63         write(fd, fb[val], strlen(fb[0]));
64         close(fd);
65 }
66
67 void eAVSwitch::setColorFormat(int format)
68 {
69         /*
70         0-CVBS
71         1-RGB
72         2-S-Video
73         */
74         char *cvbs="cvbs";
75         char *rgb="rgb";
76         char *svideo="svideo";
77         char *yuv="yuv";
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                 case 3:
95                         write(fd, yuv, strlen(yuv));
96                         break;
97         }       
98         close(fd);
99 }
100
101 void eAVSwitch::setAspectRatio(int ratio)
102 {
103         /*
104         0-4:3 Letterbox
105         1-4:3 PanScan
106         2-16:9
107         3-16:9 forced
108         4-16:9 Letterbox
109         5-16:9 PanScan
110         */
111         
112         char *aspect[] = {"4:3", "4:3", "any", "16:9", "16:10", "16:10"};
113         char *policy[] = {"letterbox", "panscan", "bestfit", "panscan", "letterbox", "panscan"};
114
115         int fd;
116         if((fd = open("/proc/stb/video/aspect", O_WRONLY)) < 0) {
117                 printf("cannot open /proc/stb/video/aspect\n");
118                 return;
119         }
120 //      eDebug("set aspect to %s", aspect[ratio]);
121         write(fd, aspect[ratio], strlen(aspect[ratio]));
122         close(fd);
123
124         if((fd = open("/proc/stb/video/policy", O_WRONLY)) < 0) {
125                 printf("cannot open /proc/stb/video/policy\n");
126                 return;
127         }
128 //      eDebug("set ratio to %s", policy[ratio]);
129         write(fd, policy[ratio], strlen(policy[ratio]));
130         close(fd);
131
132 }
133
134 void eAVSwitch::setVideomode(int mode)
135 {
136         char *pal="pal";
137         char *ntsc="ntsc";
138         
139         if (mode == m_video_mode)
140                 return;
141         
142         int fd;
143
144         if((fd = open("/proc/stb/video/videomode", O_WRONLY)) < 0) {
145                 printf("cannot open /proc/stb/video/videomode\n");
146                 return;
147         }
148         switch(mode) {
149                 case 0:
150                         write(fd, pal, strlen(pal));
151                         break;
152                 case 1:
153                         write(fd, ntsc, strlen(ntsc));
154                         break;
155         }
156         close(fd);
157
158         m_video_mode = mode;
159 }
160
161 void eAVSwitch::setWSS(int val) // 0 = auto, 1 = auto(4:3_off)
162 {
163         int fd;
164         if((fd = open("/proc/stb/denc/0/wss", O_WRONLY)) < 0) {
165                 printf("cannot open /proc/stb/denc/0/wss\n");
166                 return;
167         }
168         char *wss[] = {
169                 "off", "auto", "auto(4:3_off)", "4:3_full_format", "16:9_full_format",
170                 "14:9_letterbox_center", "14:9_letterbox_top", "16:9_letterbox_center",
171                 "16:9_letterbox_top", ">16:9_letterbox_center", "14:9_full_format"
172         };
173         write(fd, wss[val], strlen(wss[val]));
174 //      eDebug("set wss to %s", wss[val]);
175         close(fd);
176 }
177
178 void eAVSwitch::setSlowblank(int val)
179 {
180         int fd;
181         if((fd = open("/proc/stb/avs/0/sb", O_WRONLY)) < 0) {
182                 printf("cannot open /proc/stb/avs/0/sb\n");
183                 return;
184         }
185         char *sb[] = {"0", "6", "12", "vcr", "auto"};
186         write(fd, sb[val], strlen(sb[val]));
187 //      eDebug("set slow blanking to %s", sb[val]);
188         close(fd);
189 }
190
191 //FIXME: correct "run/startlevel"
192 eAutoInitP0<eAVSwitch> init_avswitch(eAutoInitNumbers::rc, "AVSwitch Driver");