09b1ec33fe2aad5a253966f2a7e06c889ec40fac
[vuplus_dvbapp] / 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         if (val == 1)
50                 setFastBlank(2);
51 }
52
53 void eAVSwitch::setFastBlank(int val)
54 {
55         int fd;
56         char *fb[] = {"low", "high", "vcr"};
57
58         
59         if((fd = open("/proc/stb/avs/0/fb", O_WRONLY)) < 0) {
60                 printf("cannot open /proc/stb/avs/0/fb\n");
61                 return;
62         }
63
64         write(fd, fb[val], strlen(fb[0]));
65         close(fd);
66 }
67
68 void eAVSwitch::setColorFormat(int format)
69 {
70         /*
71         0-CVBS
72         1-RGB
73         2-S-Video
74         */
75         char *cvbs="cvbs";
76         char *rgb="rgb";
77         char *svideo="svideo";
78         char *yuv="yuv";
79         int fd;
80         
81         if((fd = open("/proc/stb/avs/0/colorformat", O_WRONLY)) < 0) {
82                 printf("cannot open /proc/stb/avs/0/colorformat\n");
83                 return;
84         }
85         switch(format) {
86                 case 0:
87                         write(fd, cvbs, strlen(cvbs));
88                         break;
89                 case 1:
90                         write(fd, rgb, strlen(rgb));
91                         break;
92                 case 2:
93                         write(fd, svideo, strlen(svideo));
94                         break;
95                 case 3:
96                         write(fd, yuv, strlen(yuv));
97                         break;
98         }       
99         close(fd);
100 }
101
102 void eAVSwitch::setAspectRatio(int ratio)
103 {
104         /*
105         0-4:3 Letterbox
106         1-4:3 PanScan
107         2-16:9
108         3-16:9 forced
109         */
110         
111         char *aspect[] = {"4:3", "4:3", "any", "16:9"};
112         char *policy[] = {"letterbox", "panscan", "bestfit", "panscan"};
113
114         int fd;
115         if((fd = open("/proc/stb/video/aspect", O_WRONLY)) < 0) {
116                 printf("cannot open /proc/stb/video/aspect\n");
117                 return;
118         }
119         write(fd, aspect[ratio], strlen(aspect[ratio]));
120         close(fd);
121
122         if((fd = open("/proc/stb/video/policy", O_WRONLY)) < 0) {
123                 printf("cannot open /proc/stb/video/policy\n");
124                 return;
125         }
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         return;
138         //FIXME: bug in driver (cannot set PAL)
139         if((fd = open("/proc/stb/video/videomode", O_WRONLY)) < 0) {
140                 printf("cannot open /proc/stb/video/videomode\n");
141                 return;
142         }
143         switch(mode) {
144                 case 0:
145                         write(fd, pal, strlen(pal));
146                         break;
147                 case 1:
148                         write(fd, ntsc, strlen(ntsc));
149                         break;
150         }       
151         close(fd);
152 }
153
154 //FIXME: correct "run/startlevel"
155 eAutoInitP0<eAVSwitch> init_avswitch(eAutoInitNumbers::rc, "AVSwitch Driver");