fix (or hack) scart switching because the value in /proc/stb/avs/0/fb reads low,...
[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         char *fb[] = {"low", "high", "vcr"};
50
51         
52         if((fd = open("/proc/stb/avs/0/fb", O_WRONLY)) < 0) {
53                 printf("cannot open /proc/stb/avs/0/fb\n");
54                 return;
55         }
56
57         write(fd, input[val], strlen(fb[0]));
58         close(fd);
59 }
60
61 void eAVSwitch::setColorFormat(int format)
62 {
63         /*
64         0-CVBS
65         1-RGB
66         2-S-Video
67         */
68         char *cvbs="cvbs";
69         char *rgb="rgb";
70         char *svideo="svideo";
71         int fd;
72         
73         if((fd = open("/proc/stb/avs/0/colorformat", O_WRONLY)) < 0) {
74                 printf("cannot open /proc/stb/avs/0/colorformat\n");
75                 return;
76         }
77         switch(format) {
78                 case 0:
79                         write(fd, cvbs, strlen(cvbs));
80                         break;
81                 case 1:
82                         write(fd, rgb, strlen(rgb));
83                         break;
84                 case 2:
85                         write(fd, svideo, strlen(svideo));
86                         break;
87         }       
88         close(fd);
89 }
90
91 void eAVSwitch::setAspectRatio(int ratio)
92 {
93         /*
94         0-4:3 Letterbox
95         1-4:3 PanScan
96         2-16:9
97         3-16:9 forced
98         */
99         
100         char *aspect[] = {"4:3", "4:3", "any", "16:9"};
101         char *policy[] = {"letterbox", "panscan", "bestfit", "panscan"};
102
103         int fd;
104         if((fd = open("/proc/stb/video/aspect", O_WRONLY)) < 0) {
105                 printf("cannot open /proc/stb/video/aspect\n");
106                 return;
107         }
108         write(fd, aspect[ratio], strlen(aspect[ratio]));
109         close(fd);
110
111         if((fd = open("/proc/stb/video/policy", O_WRONLY)) < 0) {
112                 printf("cannot open /proc/stb/video/policy\n");
113                 return;
114         }
115         write(fd, policy[ratio], strlen(policy[ratio]));
116         close(fd);
117
118 }
119
120 void eAVSwitch::setVideomode(int mode)
121 {
122         char *pal="pal";
123         char *ntsc="ntsc";
124         int fd;
125         
126         return;
127         //FIXME: bug in driver (cannot set PAL)
128         if((fd = open("/proc/stb/video/videomode", O_WRONLY)) < 0) {
129                 printf("cannot open /proc/stb/video/videomode\n");
130                 return;
131         }
132         switch(mode) {
133                 case 0:
134                         write(fd, pal, strlen(pal));
135                         break;
136                 case 1:
137                         write(fd, ntsc, strlen(ntsc));
138                         break;
139         }       
140         close(fd);
141 }
142
143 //FIXME: correct "run/startlevel"
144 eAutoInitP0<eAVSwitch> init_avswitch(eAutoInitNumbers::rc, "AVSwitch Driver");