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