35df9388a2b3e765382b2ae65cd4fca844c4bb1e
[openblackhole/openblackhole-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         if((fd = open("/proc/stb/avs/0/fb", O_WRONLY)) < 0) {
58                 printf("cannot open /proc/stb/avs/0/fb\n");
59                 return;
60         }
61
62         write(fd, fb[val], strlen(fb[0]));
63         close(fd);
64 }
65
66 void eAVSwitch::setColorFormat(int format)
67 {
68         /*
69         0-CVBS
70         1-RGB
71         2-S-Video
72         */
73         char *cvbs="cvbs";
74         char *rgb="rgb";
75         char *svideo="svideo";
76         char *yuv="yuv";
77         int fd;
78         
79         if((fd = open("/proc/stb/avs/0/colorformat", O_WRONLY)) < 0) {
80                 printf("cannot open /proc/stb/avs/0/colorformat\n");
81                 return;
82         }
83         switch(format) {
84                 case 0:
85                         write(fd, cvbs, strlen(cvbs));
86                         break;
87                 case 1:
88                         write(fd, rgb, strlen(rgb));
89                         break;
90                 case 2:
91                         write(fd, svideo, strlen(svideo));
92                         break;
93                 case 3:
94                         write(fd, yuv, strlen(yuv));
95                         break;
96         }       
97         close(fd);
98 }
99
100 void eAVSwitch::setAspectRatio(int ratio)
101 {
102         /*
103         0-4:3 Letterbox
104         1-4:3 PanScan
105         2-16:9
106         3-16:9 forced
107         */
108         
109         char *aspect[] = {"4:3", "4:3", "any", "16:9"};
110         char *policy[] = {"letterbox", "panscan", "bestfit", "panscan"};
111
112         int fd;
113         if((fd = open("/proc/stb/video/aspect", O_WRONLY)) < 0) {
114                 printf("cannot open /proc/stb/video/aspect\n");
115                 return;
116         }
117 //      eDebug("set aspect to %s", aspect[ratio]);
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 //      eDebug("set ratio to %s", policy[ratio]);
126         write(fd, policy[ratio], strlen(policy[ratio]));
127         close(fd);
128
129 }
130
131 void eAVSwitch::setVideomode(int mode)
132 {
133         char *pal="pal";
134         char *ntsc="ntsc";
135         int fd;
136
137         if((fd = open("/proc/stb/video/videomode", O_WRONLY)) < 0) {
138                 printf("cannot open /proc/stb/video/videomode\n");
139                 return;
140         }
141         switch(mode) {
142                 case 0:
143                         write(fd, pal, strlen(pal));
144                         break;
145                 case 1:
146                         write(fd, ntsc, strlen(ntsc));
147                         break;
148         }
149         close(fd);
150 }
151
152 void eAVSwitch::setWSS(int val) // 0 = auto, 1 = auto(4:3_off)
153 {
154         int fd;
155         if((fd = open("/proc/stb/denc/0/wss", O_WRONLY)) < 0) {
156                 printf("cannot open /proc/stb/denc/0/wss\n");
157                 return;
158         }
159         char *wss[] = {
160                 "off", "auto", "auto(4:3_off)", "4:3_full_format", "16:9_full_format",
161                 "14:9_letterbox_center", "14:9_letterbox_top", "16:9_letterbox_center",
162                 "16:9_letterbox_top", ">16:9_letterbox_center", "14:9_full_format"
163         };
164         write(fd, wss[val], strlen(wss[val]));
165 //      eDebug("set wss to %s", wss[val]);
166         close(fd);
167 }
168
169 void eAVSwitch::setSlowblank(int val)
170 {
171         int fd;
172         if((fd = open("/proc/stb/avs/0/sb", O_WRONLY)) < 0) {
173                 printf("cannot open /proc/stb/avs/0/sb\n");
174                 return;
175         }
176         char *sb[] = {"0", "6", "12", "vcr", "auto"};
177         write(fd, sb[val], strlen(sb[val]));
178 //      eDebug("set slow blanking to %s", sb[val]);
179         close(fd);
180 }
181
182 //FIXME: correct "run/startlevel"
183 eAutoInitP0<eAVSwitch> init_avswitch(eAutoInitNumbers::rc, "AVSwitch Driver");