12a8f7d9b9848139025b8cdce8eef52be4356f2c
[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 }
18
19 eAVSwitch::~eAVSwitch()
20 {
21 }
22
23 eAVSwitch *eAVSwitch::getInstance()
24 {
25         return instance;
26 }
27
28 void eAVSwitch::setInput(int val)
29 {
30         /*
31         0-encoder
32         1-scart
33         2-aux
34         */
35
36         char *input[] = {"encoder", "scart", "aux"};
37
38         int fd;
39         
40         if((fd = open("/proc/stb/avs/0/input", O_WRONLY)) < 0) {
41                 printf("cannot open /proc/stb/avs/0/input\n");
42                 return;
43         }
44
45         write(fd, input[val], strlen(input[val]));
46         close(fd);
47         
48         if (val == 1)
49                 setFastBlank(2);
50 }
51
52 void eAVSwitch::setFastBlank(int val)
53 {
54         int fd;
55         char *fb[] = {"low", "high", "vcr"};
56
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         */
109         
110         char *aspect[] = {"4:3", "4:3", "any", "16:9"};
111         char *policy[] = {"letterbox", "panscan", "bestfit", "panscan"};
112
113         int fd;
114         if((fd = open("/proc/stb/video/aspect", O_WRONLY)) < 0) {
115                 printf("cannot open /proc/stb/video/aspect\n");
116                 return;
117         }
118         write(fd, aspect[ratio], strlen(aspect[ratio]));
119         close(fd);
120
121         if((fd = open("/proc/stb/video/policy", O_WRONLY)) < 0) {
122                 printf("cannot open /proc/stb/video/policy\n");
123                 return;
124         }
125         write(fd, policy[ratio], strlen(policy[ratio]));
126         close(fd);
127
128 }
129
130 void eAVSwitch::setVideomode(int mode)
131 {
132         char *pal="pal";
133         char *ntsc="ntsc";
134         int fd;
135         
136         return;
137         //FIXME: bug in driver (cannot set PAL)
138         if((fd = open("/proc/stb/video/videomode", O_WRONLY)) < 0) {
139                 printf("cannot open /proc/stb/video/videomode\n");
140                 return;
141         }
142         switch(mode) {
143                 case 0:
144                         write(fd, pal, strlen(pal));
145                         break;
146                 case 1:
147                         write(fd, ntsc, strlen(ntsc));
148                         break;
149         }       
150         close(fd);
151 }
152
153 void eAVSwitch::setSlowblank(int val)
154 {
155         int fd;
156         if((fd = open("/proc/stb/avs/0/sb", O_WRONLY)) < 0) {
157                 printf("cannot open /proc/stb/avs/0/sb\n");
158                 return;
159         }
160         const char *s = val ? "auto" : "vcr";
161         write(fd, s, strlen(s));
162         close(fd);
163 }
164
165 //FIXME: correct "run/startlevel"
166 eAutoInitP0<eAVSwitch> init_avswitch(eAutoInitNumbers::rc, "AVSwitch Driver");