fix spaces
[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 *aspect[] = {"4:3", "4:3", "any", "16:9"};
69         char *policy[] = {"letterbox", "panscan", "bestfit", "panscan"};
70
71         int fd;
72         if((fd = open("/proc/stb/video/aspect", O_WRONLY)) < 0) {
73                 printf("cannot open /proc/stb/video/aspect\n");
74                 return;
75         }
76         write(fd, aspect[ratio], strlen(aspect[ratio]));
77         close(fd);
78
79         if((fd = open("/proc/stb/video/policy", O_WRONLY)) < 0) {
80                 printf("cannot open /proc/stb/video/policy\n");
81                 return;
82         }
83         write(fd, policy[ratio], strlen(policy[ratio]));
84         close(fd);
85
86 }
87
88 void eAVSwitch::setVideomode(int mode)
89 {
90         char *pal="pal";
91         char *ntsc="ntsc";
92         int fd;
93         
94         return;
95         //FIXME: bug in driver (cannot set PAL)
96         if((fd = open("/proc/stb/video/videomode", O_WRONLY)) < 0) {
97                 printf("cannot open /proc/stb/video/videomode\n");
98                 return;
99         }
100         switch(mode) {
101                 case 0:
102                         write(fd, pal, strlen(pal));
103                         break;
104                 case 1:
105                         write(fd, ntsc, strlen(ntsc));
106                         break;
107         }       
108         close(fd);
109 }
110
111 //FIXME: correct "run/startlevel"
112 eAutoInitP0<eAVSwitch> init_avswitch(eAutoInitNumbers::rc, "AVSwitch Driver");