1 | #ifndef CEC_H |
---|
2 | #define CEC_H |
---|
3 | |
---|
4 | int cecon = 0; |
---|
5 | struct stimerthread* hdmiEventthread = NULL; |
---|
6 | |
---|
7 | |
---|
8 | void sendName(unsigned char address) |
---|
9 | { |
---|
10 | unsigned char cmd = 0x47; |
---|
11 | char data[16] = "TitanNit"; |
---|
12 | |
---|
13 | data[8] = '\0'; |
---|
14 | sendMessage(address, cmd, data, strlen(data)); |
---|
15 | |
---|
16 | } |
---|
17 | |
---|
18 | void sendMenuInfo(unsigned char address) |
---|
19 | { |
---|
20 | unsigned char cmd = 0x8e; |
---|
21 | char data[2]; |
---|
22 | |
---|
23 | data[0] = 0x00; |
---|
24 | if(status.standby > 0 || getconfigint("cec_menue", NULL) == 0) |
---|
25 | data[0] = 0x01; |
---|
26 | data[1] = '\0'; |
---|
27 | sendMessage(address, cmd, data, 1); |
---|
28 | } |
---|
29 | |
---|
30 | void sendVendorid(unsigned char address) |
---|
31 | { |
---|
32 | unsigned char cmd = 0x87; |
---|
33 | char data[4]; |
---|
34 | |
---|
35 | data[0] = 0x00; |
---|
36 | data[1] = 0x00; |
---|
37 | data[2] = 0x00; |
---|
38 | data[3] = '\0'; |
---|
39 | sendMessage(address, cmd, data, 3); |
---|
40 | } |
---|
41 | |
---|
42 | void sendSource(unsigned char address) |
---|
43 | { |
---|
44 | unsigned char cmd = 0x82; |
---|
45 | char data[4]; |
---|
46 | |
---|
47 | data[0] = cec_physicalAddress[0]; |
---|
48 | data[1] = cec_physicalAddress[1]; |
---|
49 | data[2] = '\0'; |
---|
50 | sendMessage(address, cmd, data, 2); |
---|
51 | } |
---|
52 | |
---|
53 | void sendVersion(unsigned char address) |
---|
54 | { |
---|
55 | unsigned char cmd = 0x9e; |
---|
56 | char data[4]; |
---|
57 | |
---|
58 | data[0] = 0x01; |
---|
59 | data[1] = '\0'; |
---|
60 | sendMessage(address, cmd, data, 2); |
---|
61 | } |
---|
62 | |
---|
63 | void sendTVon() |
---|
64 | { |
---|
65 | char data[3]; |
---|
66 | unsigned char address = 0x00; |
---|
67 | unsigned char cmd = 0x04; |
---|
68 | data[0] = '\0'; |
---|
69 | sendMessage(address, cmd, data, 0); |
---|
70 | } |
---|
71 | |
---|
72 | void sendswitch() |
---|
73 | { |
---|
74 | char data[3]; |
---|
75 | unsigned char address = 0x0f; |
---|
76 | unsigned char cmd = 0x82; |
---|
77 | data[0] = cec_physicalAddress[0]; |
---|
78 | data[1] = cec_physicalAddress[1]; |
---|
79 | data[2] = '\0'; |
---|
80 | //if(getconfigint("cec_tv_switch", NULL) == 1) |
---|
81 | sendMessage(address, cmd, data, 2); |
---|
82 | } |
---|
83 | |
---|
84 | int translateKey(unsigned char code) |
---|
85 | { |
---|
86 | int key = 0; |
---|
87 | switch (code) |
---|
88 | { |
---|
89 | case 0x09: |
---|
90 | key = 0x8b; |
---|
91 | break; |
---|
92 | case 0x0A: |
---|
93 | key = 0x18e; |
---|
94 | break; |
---|
95 | case 0x0B: |
---|
96 | key = 0x166; |
---|
97 | break; |
---|
98 | case 0x32: |
---|
99 | key = 0x8b; |
---|
100 | break; |
---|
101 | case 0x20: |
---|
102 | key = 0x0b; |
---|
103 | break; |
---|
104 | case 0x21: |
---|
105 | key = 0x02; |
---|
106 | break; |
---|
107 | case 0x22: |
---|
108 | key = 0x03; |
---|
109 | break; |
---|
110 | case 0x23: |
---|
111 | key = 0x04; |
---|
112 | break; |
---|
113 | case 0x24: |
---|
114 | key = 0x05; |
---|
115 | break; |
---|
116 | case 0x25: |
---|
117 | key = 0x06; |
---|
118 | break; |
---|
119 | case 0x26: |
---|
120 | key = 0x07; |
---|
121 | break; |
---|
122 | case 0x27: |
---|
123 | key = 0x08; |
---|
124 | break; |
---|
125 | case 0x28: |
---|
126 | key = 0x09; |
---|
127 | break; |
---|
128 | case 0x29: |
---|
129 | key = 0x0a; |
---|
130 | break; |
---|
131 | case 0x30: |
---|
132 | key = 0x192; |
---|
133 | break; |
---|
134 | case 0x31: |
---|
135 | key = 0x193; |
---|
136 | break; |
---|
137 | case 0x44: |
---|
138 | key = 0xcf; |
---|
139 | break; |
---|
140 | case 0x45: |
---|
141 | key = 0x80; |
---|
142 | break; |
---|
143 | case 0x46: |
---|
144 | key = 0x77; |
---|
145 | break; |
---|
146 | case 0x47: |
---|
147 | key = 0xa7; |
---|
148 | break; |
---|
149 | case 0x48: |
---|
150 | key = 0xa8; |
---|
151 | break; |
---|
152 | case 0x49: |
---|
153 | key = 0xd0; |
---|
154 | break; |
---|
155 | case 0x53: |
---|
156 | key = 0x166; |
---|
157 | break; |
---|
158 | case 0x54: |
---|
159 | key = 0x16a; |
---|
160 | break; |
---|
161 | case 0x60: |
---|
162 | key = 0xcf; |
---|
163 | break; |
---|
164 | case 0x61: |
---|
165 | key = 0xa4; |
---|
166 | break; |
---|
167 | case 0x62: |
---|
168 | key = 0xa7; |
---|
169 | break; |
---|
170 | case 0x64: |
---|
171 | key = 0x80; |
---|
172 | break; |
---|
173 | case 0x00: |
---|
174 | key = 0x160; |
---|
175 | break; |
---|
176 | case 0x03: |
---|
177 | key = 0x69; |
---|
178 | break; |
---|
179 | case 0x04: |
---|
180 | key = 0x6a; |
---|
181 | break; |
---|
182 | case 0x01: |
---|
183 | key = 0x67; |
---|
184 | break; |
---|
185 | case 0x02: |
---|
186 | key = 0x6c; |
---|
187 | break; |
---|
188 | case 0x0d: |
---|
189 | key = 0xae; |
---|
190 | break; |
---|
191 | case 0x72: |
---|
192 | key = 0x18e; |
---|
193 | break; |
---|
194 | case 0x71: |
---|
195 | key = 0x191; |
---|
196 | break; |
---|
197 | case 0x73: |
---|
198 | key = 0x18f; |
---|
199 | break; |
---|
200 | case 0x74: |
---|
201 | key = 0x190; |
---|
202 | break; |
---|
203 | default: |
---|
204 | key = 0x8b; |
---|
205 | break; |
---|
206 | } |
---|
207 | return key; |
---|
208 | } |
---|
209 | |
---|
210 | void setVolumeForward() |
---|
211 | { |
---|
212 | unsigned char address = 0x00; |
---|
213 | unsigned char cmd = 0x7d; |
---|
214 | char data[2]; |
---|
215 | data[0] = '\0'; |
---|
216 | |
---|
217 | addconfiginttmp("ForwardVolume", 1); |
---|
218 | data[0] = '\0'; |
---|
219 | if(getconfigint("cec_volume", NULL) > 0) |
---|
220 | { |
---|
221 | if(getconfigint("cec_volume", NULL) == 1) |
---|
222 | address = 0x05; |
---|
223 | if(getconfigint("cec_volume", NULL) == 2) |
---|
224 | address = 0x00; |
---|
225 | |
---|
226 | //cmd = 0x72; |
---|
227 | //data[0] = 0x01; |
---|
228 | //data[1] = '\0'; |
---|
229 | //m_lock(&status.cecmutex, 26); |
---|
230 | //sendMessage(address, cmd, data, strlen(data)); |
---|
231 | //m_unlock(&status.cecmutex, 26); |
---|
232 | |
---|
233 | //cmd = 0x70; |
---|
234 | //data[0] = 0x02; |
---|
235 | //data[1] = 0x00; |
---|
236 | //data[2] = '\0'; |
---|
237 | //m_lock(&status.cecmutex, 26); |
---|
238 | //sendMessage(address, cmd, data, 2); |
---|
239 | //m_unlock(&status.cecmutex, 26); |
---|
240 | |
---|
241 | cmd = 0x7d; |
---|
242 | data[0] = '\0'; |
---|
243 | sendMessage(address, cmd, data, strlen(data)); |
---|
244 | |
---|
245 | } |
---|
246 | } |
---|
247 | |
---|
248 | void hdmiEvent() |
---|
249 | { |
---|
250 | fd_set rfds; |
---|
251 | struct timeval tv; |
---|
252 | struct cec_rx_message rxmessage; |
---|
253 | int ret = 0; |
---|
254 | int hasdata = 0; |
---|
255 | int keypressed = 0; |
---|
256 | int transkey = 0; |
---|
257 | unsigned char pressedkey = 0x00; |
---|
258 | |
---|
259 | while (hdmiEventthread->aktion != STOP) |
---|
260 | { |
---|
261 | printf("**** start Thread\n"); |
---|
262 | tv.tv_sec = 0x7fffffff; |
---|
263 | tv.tv_usec = 0; |
---|
264 | FD_ZERO(&rfds); |
---|
265 | FD_SET(status.hdmiFd, &rfds); |
---|
266 | |
---|
267 | hasdata = 0; |
---|
268 | |
---|
269 | ret = select(status.hdmiFd + 1, &rfds, NULL, NULL, &tv); |
---|
270 | if(ret > 0) |
---|
271 | { |
---|
272 | if(FD_ISSET(status.hdmiFd, &rfds)) |
---|
273 | { |
---|
274 | #ifdef DREAMBOX |
---|
275 | if (ioctl(status.hdmiFd, 2, &rxmessage) >= 0) |
---|
276 | hasdata = 1; |
---|
277 | |
---|
278 | unsigned int val = 0; |
---|
279 | ioctl(status.hdmiFd, 4, &val); |
---|
280 | #else |
---|
281 | if (read(status.hdmiFd, &rxmessage, 2) == 2) |
---|
282 | { |
---|
283 | if (read(status.hdmiFd, &rxmessage.data, rxmessage.length) == rxmessage.length) |
---|
284 | hasdata = 1; |
---|
285 | } |
---|
286 | #endif |
---|
287 | if(hasdata) |
---|
288 | { |
---|
289 | printf("CEC: rxmessage ->"); |
---|
290 | printf(" %02x ", rxmessage.address); |
---|
291 | for (int i = 0; i < rxmessage.length; i++) |
---|
292 | printf(" %02x", rxmessage.data[i]); |
---|
293 | printf("\n"); |
---|
294 | |
---|
295 | switch (rxmessage.data[0]) |
---|
296 | { |
---|
297 | case 0x7e: |
---|
298 | case 0x72: /* system audio mode status */ |
---|
299 | { |
---|
300 | if(rxmessage.data[1] == 0x01) |
---|
301 | { |
---|
302 | addconfiginttmp("ForwardVolume", 1); |
---|
303 | printf("HDMI_CEC: Volume forward is acticated\n"); |
---|
304 | } |
---|
305 | else |
---|
306 | { |
---|
307 | printf("HDMI_CEC: Volume forward is not supported\n"); |
---|
308 | addconfiginttmp("ForwardVolume", 0); |
---|
309 | } |
---|
310 | break; |
---|
311 | } |
---|
312 | |
---|
313 | case 0x46: /* request name */ |
---|
314 | { |
---|
315 | sendName(rxmessage.address); |
---|
316 | break; |
---|
317 | } |
---|
318 | case 0x8c: /* request vendor id */ |
---|
319 | { |
---|
320 | sendVendorid(rxmessage.address); |
---|
321 | break; |
---|
322 | } |
---|
323 | case 0x8d: /* menu request */ |
---|
324 | { |
---|
325 | //if(rxmessage.data[1] == 0x02) |
---|
326 | sendMenuInfo(rxmessage.address); |
---|
327 | break; |
---|
328 | } |
---|
329 | case 0x82: |
---|
330 | { |
---|
331 | //cecon = 0; |
---|
332 | //sendTVon(); |
---|
333 | if(rxmessage.data[1]== cec_physicalAddress[0] && rxmessage.data[2]== cec_physicalAddress[1]) |
---|
334 | { |
---|
335 | sendswitch(); |
---|
336 | setFixedPhysicalAddress(getconfigint("cec_fixedAddress", NULL)); |
---|
337 | reportPhysicalAddress(0); |
---|
338 | sendMenuInfo(0x00); |
---|
339 | setVolumeForward(); |
---|
340 | } |
---|
341 | break; |
---|
342 | } |
---|
343 | case 0x00: /* feature abort */ |
---|
344 | { |
---|
345 | if(rxmessage.data[1] == 0x44 || rxmessage.data[1] == 0x7d) |
---|
346 | { |
---|
347 | addconfiginttmp("ForwardVolume", 0); |
---|
348 | printf("HdmiCec: volume forwarding not supported by device %02x\n", rxmessage.address); |
---|
349 | } |
---|
350 | break; |
---|
351 | } |
---|
352 | case 0x44: /* key pressed */ |
---|
353 | { |
---|
354 | keypressed = 1; |
---|
355 | pressedkey = rxmessage.data[1]; |
---|
356 | transkey = translateKey(pressedkey); |
---|
357 | writerc(transkey); |
---|
358 | break; |
---|
359 | } |
---|
360 | case 0x45: /* key released */ |
---|
361 | { |
---|
362 | printf("HdmiCec: key received -- %02x\n", pressedkey); |
---|
363 | transkey = translateKey(pressedkey); |
---|
364 | printf("HdmiCec: key TitanCode -- %i\n", transkey); |
---|
365 | //writerc(transkey); |
---|
366 | keypressed = 0; |
---|
367 | break; |
---|
368 | } |
---|
369 | case 0x83: /* request address */ |
---|
370 | { |
---|
371 | reportPhysicalAddress(1); |
---|
372 | break; |
---|
373 | } |
---|
374 | case 0x85: /* request active source */ |
---|
375 | { |
---|
376 | sendSource(rxmessage.address); |
---|
377 | break; |
---|
378 | } |
---|
379 | case 0x9f: /* request cec version */ |
---|
380 | { |
---|
381 | sendVersion(rxmessage.address); |
---|
382 | break; |
---|
383 | } |
---|
384 | } |
---|
385 | } |
---|
386 | } |
---|
387 | usleep(10000); |
---|
388 | continue; |
---|
389 | } |
---|
390 | else //timeout or error |
---|
391 | { |
---|
392 | printf("read error or timeout if ret is 0: ret=%d\n", ret); |
---|
393 | sleep(1); |
---|
394 | } |
---|
395 | } |
---|
396 | hdmiEventthread = NULL; |
---|
397 | printf("**** stop Thread\n"); |
---|
398 | } |
---|
399 | |
---|
400 | |
---|
401 | int getPhysicalAddress() |
---|
402 | { |
---|
403 | return (cec_physicalAddress[0] << 8) | cec_physicalAddress[1]; |
---|
404 | } |
---|
405 | |
---|
406 | //void sendMessage(struct cec_message &message) |
---|
407 | void sendMessageReal(struct cec_message message) |
---|
408 | { |
---|
409 | int i = 0; |
---|
410 | if (status.hdmiFd >= 0) |
---|
411 | { |
---|
412 | printf("HdmiCEC: send message\n"); |
---|
413 | printf("%02x ", message.address); |
---|
414 | for(i = 0; i < message.length; i++) |
---|
415 | { |
---|
416 | printf(" %02X", message.data[i]); |
---|
417 | } |
---|
418 | printf("\n"); |
---|
419 | int ret = 0; |
---|
420 | #ifdef DREAMBOX |
---|
421 | message.flag = 1; |
---|
422 | ret = ioctl(status.hdmiFd, 3, &message); |
---|
423 | if(ret == 0) |
---|
424 | ret = 1 + message.length; |
---|
425 | #else |
---|
426 | ret = write(status.hdmiFd, &message, 2 + message.length); |
---|
427 | #endif |
---|
428 | printf("%i Bytes wurden gesendet\n", ret); |
---|
429 | } |
---|
430 | } |
---|
431 | |
---|
432 | void sendMessageReal_thread(struct stimerthread* timernode, struct cec_message* message, int flag) |
---|
433 | { |
---|
434 | m_lock(&status.cecmutex, 26); |
---|
435 | int i = 0; |
---|
436 | if (status.hdmiFd >= 0) |
---|
437 | { |
---|
438 | printf("HdmiCEC: send message\n"); |
---|
439 | printf("%02x ", message->address); |
---|
440 | for(i = 0; i < message->length; i++) |
---|
441 | { |
---|
442 | printf(" %02X", message->data[i]); |
---|
443 | } |
---|
444 | printf("\n"); |
---|
445 | int ret = 0; |
---|
446 | #ifdef DREAMBOX |
---|
447 | message->flag = 1; |
---|
448 | ret = ioctl(status.hdmiFd, 3, message); |
---|
449 | if(ret == 0) |
---|
450 | ret = 1 + message->length; |
---|
451 | #else |
---|
452 | ret = write(status.hdmiFd, message, 2 + message->length); |
---|
453 | #endif |
---|
454 | printf("%i Bytes wurden gesendet\n", ret); |
---|
455 | } |
---|
456 | free(message); message=NULL; |
---|
457 | usleep(100000); |
---|
458 | m_unlock(&status.cecmutex, 26); |
---|
459 | } |
---|
460 | |
---|
461 | void sendMessageReal_add(struct cec_message message) |
---|
462 | { |
---|
463 | struct cec_message* smessage; |
---|
464 | smessage = calloc(1, sizeof(struct cec_message)); |
---|
465 | if(smessage == NULL) |
---|
466 | { |
---|
467 | err("no mem"); |
---|
468 | return; |
---|
469 | } |
---|
470 | memcpy(smessage, &message, sizeof(struct cec_message)); |
---|
471 | addtimer(&sendMessageReal_thread, START, 1000, 1, (void*)smessage, NULL, NULL); |
---|
472 | } |
---|
473 | |
---|
474 | |
---|
475 | void sendMessage(unsigned char address, unsigned char cmd, char *data, int length) |
---|
476 | { |
---|
477 | struct cec_message message; |
---|
478 | message.address = address; |
---|
479 | if (length > (int)(sizeof(message.data) - 1)) length = sizeof(message.data) - 1; |
---|
480 | message.length = length + 1; |
---|
481 | message.data[0] = cmd; |
---|
482 | memcpy(&message.data[1], data, length); |
---|
483 | sendMessageReal_add(message); |
---|
484 | } |
---|
485 | |
---|
486 | void reportPhysicalAddress(int flag) |
---|
487 | { |
---|
488 | struct cec_message txmessage; |
---|
489 | txmessage.address = 0x0f; /* broadcast */ |
---|
490 | txmessage.data[0] = 0x84; /* report address */ |
---|
491 | txmessage.data[1] = cec_physicalAddress[0]; |
---|
492 | txmessage.data[2] = cec_physicalAddress[1]; |
---|
493 | txmessage.data[3] = cec_deviceType; |
---|
494 | txmessage.length = 4; |
---|
495 | sendMessageReal_add(txmessage); |
---|
496 | } |
---|
497 | |
---|
498 | |
---|
499 | void getAddressInfo() |
---|
500 | { |
---|
501 | int hasdata = 0; |
---|
502 | |
---|
503 | if (status.hdmiFd >= 0) |
---|
504 | { |
---|
505 | #if DREAMBOX |
---|
506 | struct |
---|
507 | { |
---|
508 | unsigned char physical[2]; |
---|
509 | unsigned char logical; |
---|
510 | unsigned char type; |
---|
511 | } addressinfo; |
---|
512 | |
---|
513 | if (ioctl(status.hdmiFd, 1, &addressinfo) >= 0) |
---|
514 | { |
---|
515 | hasdata = 1; |
---|
516 | /* we do not get the device type, check the logical address to determine the type */ |
---|
517 | switch (addressinfo.logical) |
---|
518 | { |
---|
519 | case 0x1: |
---|
520 | case 0x2: |
---|
521 | case 0x9: |
---|
522 | addressinfo.type = 1; /* recorder */ |
---|
523 | break; |
---|
524 | case 0x3: |
---|
525 | case 0x6: |
---|
526 | case 0x7: |
---|
527 | case 0xa: |
---|
528 | addressinfo.type = 3; /* tuner */ |
---|
529 | break; |
---|
530 | case 0x4: |
---|
531 | case 0x8: |
---|
532 | case 0xb: |
---|
533 | addressinfo.type = 4; /* playback */ |
---|
534 | break; |
---|
535 | } |
---|
536 | } |
---|
537 | #else |
---|
538 | struct |
---|
539 | { |
---|
540 | unsigned char logical; |
---|
541 | unsigned char physical[2]; |
---|
542 | unsigned char type; |
---|
543 | } addressinfo; |
---|
544 | if (ioctl(status.hdmiFd, 1, &addressinfo) < 0) |
---|
545 | { |
---|
546 | printf("ERROR: cec read AddressInfo"); |
---|
547 | return; |
---|
548 | } |
---|
549 | else |
---|
550 | hasdata = 1; |
---|
551 | #endif |
---|
552 | if(hasdata == 1) |
---|
553 | { |
---|
554 | cec_deviceType = addressinfo.type; |
---|
555 | cec_logicalAddress = addressinfo.logical; |
---|
556 | printf("HdmiCEC: detected deviceType: %02X\n", addressinfo.type); |
---|
557 | printf("HdmiCEC: detected logical address: %02X\n", addressinfo.logical); |
---|
558 | printf("HdmiCEC: detected physical address: %02X%02X\n", addressinfo.physical[0], addressinfo.physical[1]); |
---|
559 | if (status.cec_fixedAddress == 0) |
---|
560 | { |
---|
561 | //if(cecon > 0) |
---|
562 | if (memcmp(cec_physicalAddress, addressinfo.physical, sizeof(cec_physicalAddress))) |
---|
563 | { |
---|
564 | printf("HdmiCEC: detected physical address change: %02X%02X --> %02X%02X\n", cec_physicalAddress[0], cec_physicalAddress[1], addressinfo.physical[0], addressinfo.physical[1]); |
---|
565 | memcpy(cec_physicalAddress, addressinfo.physical, sizeof(cec_physicalAddress)); |
---|
566 | reportPhysicalAddress(0); |
---|
567 | /* emit */ //addressChanged((cec_physicalAddress[0] << 8) | cec_physicalAddress[1]); |
---|
568 | } |
---|
569 | } |
---|
570 | } |
---|
571 | } |
---|
572 | } |
---|
573 | |
---|
574 | void screencec() |
---|
575 | { |
---|
576 | struct skin* tmp = NULL; |
---|
577 | struct skin* cec = getscreen("cec"); |
---|
578 | struct skin* listbox = getscreennode(cec, "listbox"); |
---|
579 | struct skin* workpink = getscreennode(cec, "workpink"); |
---|
580 | struct skin* cecon = getscreennode(cec, "cecon"); |
---|
581 | struct skin* alloff = getscreennode(cec, "alloff"); |
---|
582 | struct skin* allon = getscreennode(cec, "allon"); |
---|
583 | struct skin* tvoff = getscreennode(cec, "tvoff"); |
---|
584 | struct skin* tvon = getscreennode(cec, "tvon"); |
---|
585 | struct skin* recoff = getscreennode(cec, "recoff"); |
---|
586 | struct skin* recon = getscreennode(cec, "recon"); |
---|
587 | struct skin* tvswitch = getscreennode(cec, "tvswitch"); |
---|
588 | struct skin* cecfix = getscreennode(cec, "cecfix"); |
---|
589 | struct skin* volume = getscreennode(cec, "volume"); |
---|
590 | struct skin* menue = getscreennode(cec, "menue"); |
---|
591 | int rcret = 0; |
---|
592 | int help = 0; |
---|
593 | |
---|
594 | addchoicebox(workpink, "0", _("off")); |
---|
595 | addchoicebox(workpink, "1", _("on")); |
---|
596 | setchoiceboxselection(workpink, getconfig("workpink", NULL)); |
---|
597 | |
---|
598 | addchoicebox(cecon, "0", _("no")); |
---|
599 | addchoicebox(cecon, "1", _("yes")); |
---|
600 | setchoiceboxselection(cecon, getconfig("cec_on", NULL)); |
---|
601 | |
---|
602 | addchoicebox(alloff, "0", _("no")); |
---|
603 | addchoicebox(alloff, "1", _("yes")); |
---|
604 | setchoiceboxselection(alloff, getconfig("cec_all_off", NULL)); |
---|
605 | |
---|
606 | addchoicebox(allon, "0", _("no")); |
---|
607 | addchoicebox(allon, "1", _("yes")); |
---|
608 | setchoiceboxselection(allon, getconfig("cec_all_on", NULL)); |
---|
609 | |
---|
610 | addchoicebox(tvoff, "0", _("no")); |
---|
611 | addchoicebox(tvoff, "1", _("yes")); |
---|
612 | setchoiceboxselection(tvoff, getconfig("cec_tv_off", NULL)); |
---|
613 | |
---|
614 | addchoicebox(tvon, "0", _("no")); |
---|
615 | addchoicebox(tvon, "1", _("yes")); |
---|
616 | setchoiceboxselection(tvon, getconfig("cec_tv_on", NULL)); |
---|
617 | |
---|
618 | addchoicebox(recoff, "0", _("no")); |
---|
619 | addchoicebox(recoff, "1", _("yes")); |
---|
620 | setchoiceboxselection(recoff, getconfig("cec_rec_off", NULL)); |
---|
621 | |
---|
622 | addchoicebox(recon, "0", _("no")); |
---|
623 | addchoicebox(recon, "1", _("yes")); |
---|
624 | setchoiceboxselection(recon, getconfig("cec_rec_on", NULL)); |
---|
625 | |
---|
626 | addchoicebox(tvswitch, "0", _("no")); |
---|
627 | addchoicebox(tvswitch, "1", _("yes")); |
---|
628 | setchoiceboxselection(tvswitch, getconfig("cec_tv_switch", NULL)); |
---|
629 | |
---|
630 | addchoicebox(cecfix, "0", _("no")); |
---|
631 | addchoicebox(cecfix, "1", _("yes")); |
---|
632 | if(getconfigint("cec_fixedAddress", NULL) == 0) |
---|
633 | setchoiceboxselection(cecfix, "0"); |
---|
634 | else |
---|
635 | setchoiceboxselection(cecfix, "1"); |
---|
636 | |
---|
637 | addchoicebox(volume, "0", _("none")); |
---|
638 | addchoicebox(volume, "1", _("Receiver")); |
---|
639 | addchoicebox(volume, "2", _("TV")); |
---|
640 | setchoiceboxselection(volume, getconfig("cec_volume", NULL)); |
---|
641 | |
---|
642 | addchoicebox(menue, "0", _("off")); |
---|
643 | addchoicebox(menue, "1", _("on")); |
---|
644 | setchoiceboxselection(menue, getconfig("cec_menue", NULL)); |
---|
645 | |
---|
646 | |
---|
647 | if(getconfigint("cec_on", NULL) == 0) |
---|
648 | { |
---|
649 | workpink->hidden = YES; |
---|
650 | alloff->hidden = YES; |
---|
651 | allon->hidden = YES; |
---|
652 | tvoff->hidden = YES; |
---|
653 | tvon->hidden = YES; |
---|
654 | recoff->hidden = YES; |
---|
655 | recon->hidden = YES; |
---|
656 | tvswitch->hidden = YES; |
---|
657 | cecfix->hidden = YES; |
---|
658 | volume->hidden = YES; |
---|
659 | menue->hidden = YES; |
---|
660 | } |
---|
661 | else |
---|
662 | { |
---|
663 | workpink->hidden = NO; |
---|
664 | alloff->hidden = NO; |
---|
665 | allon->hidden = NO; |
---|
666 | tvoff->hidden = NO; |
---|
667 | tvon->hidden = NO; |
---|
668 | recoff->hidden = NO; |
---|
669 | recon->hidden = NO; |
---|
670 | tvswitch->hidden = NO; |
---|
671 | cecfix->hidden = NO; |
---|
672 | volume->hidden = NO; |
---|
673 | menue->hidden = NO; |
---|
674 | } |
---|
675 | |
---|
676 | drawscreen(cec, 0, 0); |
---|
677 | addscreenrc(cec, listbox); |
---|
678 | tmp = listbox->select; |
---|
679 | while(1) |
---|
680 | { |
---|
681 | addscreenrc(cec, tmp); |
---|
682 | rcret = waitrc(cec, 0, 0); |
---|
683 | tmp = listbox->select; |
---|
684 | |
---|
685 | if((rcret == getrcconfigint("rcleft", NULL) || rcret == getrcconfigint("rcright", NULL)) && listbox->select != NULL && ostrcmp(listbox->select->name, "cecon") == 0) |
---|
686 | { |
---|
687 | if(ostrcmp(cecon->ret, "0") == 0) |
---|
688 | { |
---|
689 | workpink->hidden = YES; |
---|
690 | alloff->hidden = YES; |
---|
691 | allon->hidden = YES; |
---|
692 | tvoff->hidden = YES; |
---|
693 | tvon->hidden = YES; |
---|
694 | recoff->hidden = YES; |
---|
695 | recon->hidden = YES; |
---|
696 | tvswitch->hidden = YES; |
---|
697 | cecfix->hidden = YES; |
---|
698 | volume->hidden = YES; |
---|
699 | menue->hidden = YES; |
---|
700 | } |
---|
701 | else |
---|
702 | { |
---|
703 | workpink->hidden = NO; |
---|
704 | alloff->hidden = NO; |
---|
705 | allon->hidden = NO; |
---|
706 | tvoff->hidden = NO; |
---|
707 | tvon->hidden = NO; |
---|
708 | recoff->hidden = NO; |
---|
709 | recon->hidden = NO; |
---|
710 | tvswitch->hidden = NO; |
---|
711 | cecfix->hidden = NO; |
---|
712 | volume->hidden = NO; |
---|
713 | menue->hidden = NO; |
---|
714 | } |
---|
715 | } |
---|
716 | if(rcret == getrcconfigint("rcexit", NULL)) |
---|
717 | break; |
---|
718 | if(rcret == getrcconfigint("rcok", NULL)) |
---|
719 | { |
---|
720 | addconfig("workpink", workpink->ret); |
---|
721 | addconfig("cec_on", cecon->ret); |
---|
722 | addconfig("cec_all_off", alloff->ret); |
---|
723 | addconfig("cec_all_on", allon->ret); |
---|
724 | addconfig("cec_tv_off", tvoff->ret); |
---|
725 | addconfig("cec_tv_on", tvon->ret); |
---|
726 | addconfig("cec_rec_off", recoff->ret); |
---|
727 | addconfig("cec_rec_on", recon->ret); |
---|
728 | addconfig("cec_tv_switch", tvswitch->ret); |
---|
729 | addconfig("cec_volume", volume->ret); |
---|
730 | addconfig("cec_menue", menue->ret); |
---|
731 | if(ostrcmp(cecfix->ret, "0") == 0) |
---|
732 | { |
---|
733 | addconfig("cec_fixedAddress", "0"); |
---|
734 | //setFixedPhysicalAddress(0); |
---|
735 | } |
---|
736 | else |
---|
737 | { |
---|
738 | help = 0; |
---|
739 | help = (cec_physicalAddress[0] << 8) | cec_physicalAddress[1] ; |
---|
740 | addconfigint("cec_fixedAddress", help); |
---|
741 | //setFixedPhysicalAddress(help); |
---|
742 | } |
---|
743 | if(getconfigint("cec_activ", NULL) == 0 || getconfigint("cec_on", NULL) == 0) |
---|
744 | cecinit(); |
---|
745 | break; |
---|
746 | } |
---|
747 | drawscreen(cec, 0, 0); |
---|
748 | } |
---|
749 | delownerrc(cec); |
---|
750 | clearscreen(cec); |
---|
751 | } |
---|
752 | |
---|
753 | void setFixedPhysicalAddress(int address) |
---|
754 | { |
---|
755 | if (address > 0) |
---|
756 | { |
---|
757 | status.cec_fixedAddress = 1; |
---|
758 | cec_physicalAddress[0] = (address >> 8) & 0xff; |
---|
759 | cec_physicalAddress[1] = address & 0xff; |
---|
760 | /* report our (possibly new) address */ |
---|
761 | reportPhysicalAddress(0); |
---|
762 | } |
---|
763 | else |
---|
764 | { |
---|
765 | status.cec_fixedAddress = 0; |
---|
766 | /* get our current address */ |
---|
767 | getAddressInfo(); |
---|
768 | } |
---|
769 | } |
---|
770 | |
---|
771 | void cecinit() |
---|
772 | { |
---|
773 | status.cec_fixedAddress = 0; |
---|
774 | status.hdmiFd = -1; |
---|
775 | cec_physicalAddress[0] = 0x10; |
---|
776 | cec_physicalAddress[1] = 0x00; |
---|
777 | cec_logicalAddress = 1; |
---|
778 | cec_deviceType = 1; /* default: recorder */ |
---|
779 | |
---|
780 | if(getconfigint("cec_on", NULL) == 0) |
---|
781 | { |
---|
782 | addconfiginttmp("cec_activ", 0); |
---|
783 | if(hdmiEventthread != NULL) |
---|
784 | hdmiEventthread->aktion = STOP; |
---|
785 | return; |
---|
786 | } |
---|
787 | addconfiginttmp("cec_activ", 1); |
---|
788 | |
---|
789 | |
---|
790 | #ifdef DREAMBOX |
---|
791 | status.hdmiFd = open("/dev/misc/hdmi_cec0", O_RDWR | O_NONBLOCK); |
---|
792 | unsigned int val = 0; |
---|
793 | ioctl(status.hdmiFd, 4, &val); |
---|
794 | #else |
---|
795 | status.hdmiFd = open("/dev/hdmi_cec", O_RDWR | O_NONBLOCK); |
---|
796 | ioctl(status.hdmiFd, 0); /* flush old messages */ |
---|
797 | #endif |
---|
798 | |
---|
799 | if(hdmiEventthread == NULL) |
---|
800 | hdmiEventthread = addtimer(&hdmiEvent, START, 10000, 1, NULL, NULL, NULL); |
---|
801 | |
---|
802 | getAddressInfo(); |
---|
803 | |
---|
804 | if(checkbox("DM900") == 1 && getwaswakuptimer() != 1) |
---|
805 | { |
---|
806 | sleep(2); |
---|
807 | cecwakeup(); |
---|
808 | } |
---|
809 | |
---|
810 | return; |
---|
811 | } |
---|
812 | |
---|
813 | void cecstandby() |
---|
814 | { |
---|
815 | char data[1]; |
---|
816 | unsigned char address = 0x00; |
---|
817 | unsigned char cmd = 0x36; |
---|
818 | |
---|
819 | data[0] = '\0'; |
---|
820 | |
---|
821 | if(getconfigint("cec_on", NULL) == 1) |
---|
822 | { |
---|
823 | if(getconfigint("cec_all_off", NULL) == 1) |
---|
824 | { |
---|
825 | address = 0x0f; |
---|
826 | sendMessage(address, cmd, data, strlen(data)); |
---|
827 | } |
---|
828 | if(getconfigint("cec_tv_off", NULL) == 1) |
---|
829 | { |
---|
830 | address = 0x00; |
---|
831 | sendMessage(address, cmd, data, strlen(data)); |
---|
832 | //sleep(1); |
---|
833 | } |
---|
834 | if(getconfigint("cec_rec_off", NULL) == 1) |
---|
835 | { |
---|
836 | address = 0x05; |
---|
837 | sendMessage(address, cmd, data, strlen(data)); |
---|
838 | //sleep(1); |
---|
839 | } |
---|
840 | } |
---|
841 | } |
---|
842 | |
---|
843 | void cecwakeup() |
---|
844 | { |
---|
845 | char data[3]; |
---|
846 | unsigned char address = 0x00; |
---|
847 | unsigned char cmd = 0x04; |
---|
848 | |
---|
849 | data[0] = '\0'; |
---|
850 | |
---|
851 | if(getconfigint("cec_on", NULL) == 1 && cecon == 0) |
---|
852 | { |
---|
853 | if(getconfigint("cec_all_on", NULL) == 1) |
---|
854 | { |
---|
855 | address = 0x0f; |
---|
856 | sendMessage(address, cmd, data, 0); |
---|
857 | //sleep(1); |
---|
858 | } |
---|
859 | if(getconfigint("cec_rec_on", NULL) == 1) |
---|
860 | { |
---|
861 | address = 0x05; |
---|
862 | sendMessage(address, cmd, data, 0); |
---|
863 | //sleep(1); |
---|
864 | } |
---|
865 | if(getconfigint("cec_tv_on", NULL) == 1) |
---|
866 | { |
---|
867 | address = 0x00; |
---|
868 | sendMessage(address, cmd, data, 0); |
---|
869 | //sleep(1); |
---|
870 | } |
---|
871 | if(getconfigint("cec_tv_switch", NULL) == 1) |
---|
872 | { |
---|
873 | address = 0x0f; |
---|
874 | cmd = 0x82; |
---|
875 | data[0] = cec_physicalAddress[0]; |
---|
876 | data[1] = cec_physicalAddress[1]; |
---|
877 | data[2] = '\0'; |
---|
878 | sendMessage(address, cmd, data, 2); |
---|
879 | //sleep(1); |
---|
880 | } |
---|
881 | cecon = 1; |
---|
882 | printf("**********wakeup\n"); |
---|
883 | } |
---|
884 | if(cecon < 2) |
---|
885 | { |
---|
886 | //setFixedPhysicalAddress(getconfigint("cec_fixedAddress", NULL)); |
---|
887 | //setVolumeForward(); |
---|
888 | //sendMenuInfo(0x00); |
---|
889 | cecon = 2; |
---|
890 | } |
---|
891 | } |
---|
892 | |
---|
893 | void forwardKey(int key) |
---|
894 | { |
---|
895 | char data[3]; |
---|
896 | unsigned char address = 0x00; |
---|
897 | unsigned char cmd = 0x44; |
---|
898 | |
---|
899 | data[0] = '\0'; |
---|
900 | |
---|
901 | if(getconfigint("cec_volume", NULL) == 1) |
---|
902 | address = 0x05; |
---|
903 | else if(getconfigint("cec_volume", NULL) == 2) |
---|
904 | address = 0x00; |
---|
905 | |
---|
906 | if(key == getrcconfigint("rcvolup", NULL)) |
---|
907 | data[0] = 0x41; |
---|
908 | else if(key == getrcconfigint("rcvoldown", NULL)) |
---|
909 | data[0] = 0x42; |
---|
910 | else if(key == getrcconfigint("rcmute", NULL)) |
---|
911 | data[0] = 0x43; |
---|
912 | |
---|
913 | data[1] = '\0'; |
---|
914 | sendMessage(address, cmd, data, 1); |
---|
915 | data[0] = '\0'; |
---|
916 | cmd = 0x45; |
---|
917 | sendMessage(address, cmd, data, 0); /* release */ |
---|
918 | } |
---|
919 | |
---|
920 | #endif |
---|