c018b43bc333db0cf10cd1b6cd433a3a67ecaa35
[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::setColorFormat(int format)
30 {
31         /*
32         0-CVBS
33         1-RGB
34         2-S-Video
35         */
36         char *cvbs="cvbs";
37         char *rgb="rgb";
38         char *svideo="svideo";
39         int fd;
40         
41         if((fd = open("/proc/stb/avs/0/colorformat", O_WRONLY)) < 0) {
42                 printf("cannot open /proc/stb/avs/0/colorformat\n");
43                 return;
44         }
45         switch(format) {
46                 case 0:
47                         write(fd, cvbs, strlen(cvbs));
48                         break;
49                 case 1:
50                         write(fd, rgb, strlen(rgb));
51                         break;
52                 case 2:
53                         write(fd, svideo, strlen(svideo));
54                         break;
55         }       
56         close(fd);
57 }
58
59 void eAVSwitch::setAspectRatio(int ratio)
60 {
61         /*
62         0-4:3 Letterbox
63         1-4:3 PanScan
64         2-16:9
65         3-16:9 forced
66         */
67         
68         char *any="any";
69         char *norm="4:3";
70         char *wide="16:9";
71         int fd;
72
73         if((fd = open("/proc/stb/video/aspect", O_WRONLY)) < 0) {
74                 printf("cannot open /proc/stb/video/aspect\n");
75                 return;
76         }
77         switch(ratio) {
78                 case 0:
79                         write(fd, any, strlen(any));
80                         break;
81                 case 1:
82                         write(fd, norm, strlen(norm));
83                         break;
84                 case 2:
85                 case 3:
86                         write(fd, wide, strlen(wide));
87                         break;
88         }       
89         close(fd);
90 }
91
92 void eAVSwitch::setVideomode(int mode)
93 {
94         char *pal="pal";
95         char *ntsc="ntsc";
96         int fd;
97         
98         return;
99         //FIXME: bug in driver (cannot set PAL)
100         if((fd = open("/proc/stb/video/videomode", O_WRONLY)) < 0) {
101                 printf("cannot open /proc/stb/video/videomode\n");
102                 return;
103         }
104         switch(mode) {
105                 case 0:
106                         write(fd, pal, strlen(pal));
107                         break;
108                 case 1:
109                         write(fd, ntsc, strlen(ntsc));
110                         break;
111         }       
112         close(fd);
113 }
114
115 //FIXME: correct "run/startlevel"
116 eAutoInitP0<eAVSwitch> init_avswitch(eAutoInitNumbers::rc, "AVSwitch Driver");