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