AB Shutter 3 でコンソール・アプリをリモート操作するためのプログラムをHDMI-CEC対応しTVリモコンでも操作できるように改良してみた。
AB Shutter 3 を使って Raspberry PI コンソール・アプリをリモート操作する。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# # remocon.conf - Application Remote Controller Configuration # # <hdmi-action-names> # # poweron # standby # activate # inactivate # volumeup # volumedown # muteaudio # [program] cmdline=command-line [control] quit=<"q"> ledpwroff=echo 0 > /sys/class/leds/PWR/brightness ledpwron=echo default-on > /sys/class/leds/PWR/trigger ledpwrblink=echo timer > /sys/class/leds/PWR/trigger ledactoff=echo mmc0 > /sys/class/leds/ACT/trigger ledacton=echo default-on > /sys/class/leds/ACT/trigger ledactblink=echo timer > /sys/class/leds/ACT/trigger [keyboard] volumeup=<"l"><activate>./left.sh volumedown=<"r"><activate>./right.sh [keyboard.long-pressed] volumeup<poweron> volumedown=<standby> [tv] name=TVの入力切替時に表示されるデバイス名 select= up=<"u">./up.sh down=<"d">./down.sh left=<"l">./left.sh right=<"r">./right.sh f1_blue=<ledpwroff> f2_red=<ledpwron> f3_green=<ledpwrblink> f4_yellow= [device] AB Shutter=Keyboard BOXPUT=Keyboard |
各イベントは下記のように、標準入力へ出力する文字列、HDMI-CEC制御アクション名、コマンドラインの3種類のパラメタが複数同時に設定可能となっている。
1 |
event=<"標準入力へ出力する文字列"><HDMI-CEC制御アクション名>コマンドライン |
AB Shutter 3 ではTVの電源を入れたり入力切替も可能であるがTVリモコンの場合は入力切替後にのみ操作可能となる。
【HDMI-CEC制御】
HDMI-CEC制御はlibCECを利用しており下記ファイルについてはlibCECのファイルの一部であるが、version.hのみMakeでコンパイルできるよう若干の修正を入れている。インストールは下記のように行う。
sudo apt-get install cec-utils -y
libcec/cec.h
libcec/cecloader.h
libcec/cectypes.h
libcec/version.h
【修正履歴】
2023-05-09
BOXPUTリモコンのOKボタン(select=)に対応。AB Shutter 3 は不安定なのでお勧めではないがBOXPUTリモコンは動作も安定していてお勧めだ。
2023-05-06
AB Shutter 3 の小さいボタンのコードの規定値をKEY_ENTERからKEY_VOLUMEDOWNに変更。あとHDMIアクション名からremote.confの[control]の設定を参照&実行できるように改良。
2023-05-05
対応デバイス名をコードで固定設定していたのをremocon.confで定義できるよう変更。これでプログラムを変更することなくlinuxで扱える様々なinputデバイスに対応することが出来るようになった。
remocon.confのデバイス定義は次のように行う。
1 2 3 |
[device] AB Shutter=Keyboard BOXPUT=Keyboard |
設定は、デバイスを接続した後、cat /proc/bus/input/devicesにより表示される N: Name=… の先頭文字と最終文字を’=’で分けて指定する。
例えば、Name=”AB Shutter3 Keyboard”の場合は、
1 |
N: Name="AB Shutter3 Keyboard" --> AB Shutter=Keyboard |
のように設定すればOKだ。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
pi@rp3ap:~ $ cat /proc/bus/input/devices I: Bus=001e Vendor=0000 Product=0000 Version=0001 N: Name="vc4-hdmi" P: Phys=vc4-hdmi/input0 S: Sysfs=/devices/platform/soc/3f902000.hdmi/rc/rc0/input0 U: Uniq= H: Handlers=kbd event0 B: PROP=20 B: EV=100017 B: KEY=ffffc000000000 3ff 0 400000320fc200 40830c900000000 0 210300 49d2c040ec00 1e378000000000 8010000010000000 B: REL=3 B: MSC=10 I: Bus=0003 Vendor=1234 Product=5678 Version=0000 N: Name="Example device" P: Phys= S: Sysfs=/devices/virtual/input/input1 U: Uniq= H: Handlers=sysrq kbd event1 rfkill B: PROP=0 B: EV=3 B: KEY=7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff fffffffffffffffe I: Bus=0005 Vendor=248a Product=8266 Version=0001 N: Name="AB Shutter3 Consumer Control" P: Phys=b8:27:eb:35:24:9c S: Sysfs=/devices/virtual/misc/uhid/0005:248A:8266.0002/input/input2 U: Uniq=ff:ff:7f:f2:30:75 H: Handlers=kbd event2 B: PROP=0 B: EV=13 B: KEY=1e000000000000 0 B: MSC=10 I: Bus=0005 Vendor=248a Product=8266 Version=0001 N: Name="AB Shutter3 Keyboard" <-- ★★★この名前を登録する★★★ P: Phys=b8:27:eb:35:24:9c S: Sysfs=/devices/virtual/misc/uhid/0005:248A:8266.0002/input/input3 U: Uniq=ff:ff:7f:f2:30:75 H: Handlers=sysrq kbd event3 B: PROP=0 B: EV=100013 B: KEY=1000000000007 ff98007ac04007ff febeffdfffefffff fffffffffffffffe B: MSC=10 |
2023-05-04
Aliexpressで購入可能なBOXPUTというbluetoothリモコンに対応。
ワイヤレスリモコン,5.0 GHz,2.4インチ,ジャイロスコープ付き,Android TV,ボックス,PC用
この対応に伴いremocon.confをより汎用的な記述方法へ変更。
2023-05-01
TVの入力切替時に表示される名前が設定できるように改良。
2023-04-30
libCECの使い方が正しくなかったため修正。
2023-04-25
Bluetoothデバイスの検索を一定間隔でポーリング処理していたがCPU使用率が若干高めであったためinotify-apiを使って効率よく処理できるように改良してみた。ちなみにダイソーのAB Shutter3は2個のデバイスが作成されるがinotify-apiではそのうちの1個の名前しか返さないためinotify-apiは同期をとるためだけに利用している。またスレッドの挙動によるタイミング・バグがあったため修正。
【プログラム】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
TARGET = remocon OBJS = $(TARGET).o DEPFILES = $(OBJS:%.o=%.d) CC = gcc CFLAGS = CPPFLAGS = CXXFLAGS = -Wall -MMD -I./libcec LDLIBS = -L. -lstdc++ -lpthread -ldl $(TARGET): $(OBJS) $(CC) -o $@ $^ $(LDLIBS) clean: rm -f $(TARGET) $(OBJS) $(DEPFILES) -include $(DEPFILES) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
#!/bin/bash CWD=$(cd $(dirname $0) && pwd) SCAN=${CWD}/ble-scan PAIRING=${CWD}/ble-pairing bluetoothctl power off bluetoothctl power on bluetoothctl agent NoInputNoOutput if [ -f ${PAIRING} ]; then MAC=$(cat ${PAIRING}) if [ "${MAC}" != "" ]; then bluetoothctl disconnect ${MAC} bluetoothctl untrust ${MAC} bluetoothctl remove ${MAC} fi rm ${PAIRING} > /dev/null 2>&1 fi stdbuf -o0 bluetoothctl scan on 1> ${SCAN} & while true do sleep 1 MAC=$(sed -n -r "s/\[.*NEW.*\] Device (.*) AB Shutter.*/\1/p" ${SCAN} | head -n 1) if [ "${MAC}" != "" ]; then break; fi MAC=$(sed -n -r "s/\[.*NEW.*\] Device (.*) BOXPUT.*/\1/p" ${SCAN} | head -n 1) if [ "${MAC}" != "" ]; then break; fi done echo ${MAC} > ${PAIRING} bluetoothctl pair ${MAC} bluetoothctl trust ${MAC} bluetoothctl connect ${MAC} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 |
/* remocon.cpp - Application Remote Controller Copyright (c) 2023 Sasapea's Lab. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <stdio.h> #include <string.h> #include <unistd.h> #include <signal.h> #include "ceclib.h" #include "remocon.h" #include "fileprops.h" #define LONGPRESS_TIME 3000000 // us typedef struct { int code; const char *name; } keyinfo_t; const keyinfo_t INPUT_KEYS[] = { { KEY_RESERVED, "reserved" }, { KEY_ESC, "esc" }, { KEY_1, "1" }, { KEY_2, "2" }, { KEY_3, "3" }, { KEY_4, "4" }, { KEY_5, "5" }, { KEY_6, "6" }, { KEY_7, "7" }, { KEY_8, "8" }, { KEY_9, "9" }, { KEY_0, "0" }, { KEY_MINUS, "minus" }, { KEY_EQUAL, "equal" }, { KEY_BACKSPACE, "backspace" }, { KEY_TAB, "tab" }, { KEY_Q, "q" }, { KEY_W, "w" }, { KEY_E, "e" }, { KEY_R, "r" }, { KEY_T, "t" }, { KEY_Y, "y" }, { KEY_U, "u" }, { KEY_I, "i" }, { KEY_O, "o" }, { KEY_P, "p" }, { KEY_LEFTBRACE, "leftbrace" }, { KEY_RIGHTBRACE, "rightbrace" }, { KEY_ENTER, "enter" }, { KEY_LEFTCTRL, "leftctrl" }, { KEY_A, "a" }, { KEY_S, "s" }, { KEY_D, "d" }, { KEY_F, "f" }, { KEY_G, "g" }, { KEY_H, "h" }, { KEY_J, "j" }, { KEY_K, "k" }, { KEY_L, "l" }, { KEY_SEMICOLON, "semicolon" }, { KEY_APOSTROPHE, "apostrophe" }, { KEY_GRAVE, "grave" }, { KEY_LEFTSHIFT, "leftshift" }, { KEY_BACKSLASH, "backslash" }, { KEY_Z, "z" }, { KEY_X, "x" }, { KEY_C, "c" }, { KEY_V, "v" }, { KEY_B, "b" }, { KEY_N, "n" }, { KEY_M, "m" }, { KEY_COMMA, "comma" }, { KEY_DOT, "dot" }, { KEY_SLASH, "slash" }, { KEY_RIGHTSHIFT, "rightshift" }, { KEY_KPASTERISK, "kpasterisk" }, { KEY_LEFTALT, "leftalt" }, { KEY_SPACE, "space" }, { KEY_CAPSLOCK, "capslock" }, { KEY_F1, "f1" }, { KEY_F2, "f2" }, { KEY_F3, "f3" }, { KEY_F4, "f4" }, { KEY_F5, "f5" }, { KEY_F6, "f6" }, { KEY_F7, "f7" }, { KEY_F8, "f8" }, { KEY_F9, "f9" }, { KEY_F10, "f10" }, { KEY_NUMLOCK, "numlock" }, { KEY_SCROLLLOCK, "scrolllock" }, { KEY_KP7, "kp7" }, { KEY_KP8, "kp8" }, { KEY_KP9, "kp9" }, { KEY_KPMINUS, "kpminus" }, { KEY_KP4, "kp4" }, { KEY_KP5, "kp5" }, { KEY_KP6, "kp6" }, { KEY_KPPLUS, "kpplus" }, { KEY_KP1, "kp1" }, { KEY_KP2, "kp2" }, { KEY_KP3, "kp3" }, { KEY_KP0, "kp0" }, { KEY_KPDOT, "kpdot" }, { KEY_ZENKAKUHANKAKU, "zenkakuhankaku" }, { KEY_102ND, "102nd" }, { KEY_F11, "f11" }, { KEY_F12, "f12" }, { KEY_RO, "ro" }, { KEY_KATAKANA, "katakana" }, { KEY_HIRAGANA, "hiragana" }, { KEY_HENKAN, "henkan" }, { KEY_KATAKANAHIRAGANA, "katakanahiragana" }, { KEY_MUHENKAN, "muhenkan" }, { KEY_KPJPCOMMA, "kpjpcomma" }, { KEY_KPENTER, "kpenter" }, { KEY_RIGHTCTRL, "rightctrl" }, { KEY_KPSLASH, "kpslash" }, { KEY_SYSRQ, "sysrq" }, { KEY_RIGHTALT, "rightalt" }, { KEY_LINEFEED, "linefeed" }, { KEY_HOME, "home" }, { KEY_UP, "up" }, { KEY_PAGEUP, "pageup" }, { KEY_LEFT, "left" }, { KEY_RIGHT, "right" }, { KEY_END, "end" }, { KEY_DOWN, "down" }, { KEY_PAGEDOWN, "pagedown" }, { KEY_INSERT, "insert" }, { KEY_DELETE, "delete" }, { KEY_MACRO, "macro" }, { KEY_MUTE, "mute" }, { KEY_VOLUMEDOWN, "volumedown" }, { KEY_VOLUMEUP, "volumeup" }, { KEY_POWER, "power" }, { KEY_KPEQUAL, "kpequal" }, { KEY_KPPLUSMINUS, "kpplusminus" }, { KEY_PAUSE, "pause" }, { KEY_SCALE, "scale" }, { KEY_KPCOMMA, "kpcomma" }, { KEY_HANGEUL, "hangeul" }, { KEY_HANGUEL, "hanguel" }, { KEY_HANJA, "hanja" }, { KEY_YEN, "yen" }, { KEY_LEFTMETA, "leftmeta" }, { KEY_RIGHTMETA, "rightmeta" }, { KEY_COMPOSE, "compose" }, { KEY_STOP, "stop" }, { KEY_AGAIN, "again" }, { KEY_PROPS, "props" }, { KEY_UNDO, "undo" }, { KEY_FRONT, "front" }, { KEY_COPY, "copy" }, { KEY_OPEN, "open" }, { KEY_PASTE, "paste" }, { KEY_FIND, "find" }, { KEY_CUT, "cut" }, { KEY_HELP, "help" }, { KEY_MENU, "menu" }, { KEY_CALC, "calc" }, { KEY_SETUP, "setup" }, { KEY_SLEEP, "sleep" }, { KEY_WAKEUP, "wakeup" }, { KEY_FILE, "file" }, { KEY_SENDFILE, "sendfile" }, { KEY_DELETEFILE, "deletefile" }, { KEY_XFER, "xfer" }, { KEY_PROG1, "prog1" }, { KEY_PROG2, "prog2" }, { KEY_WWW, "www" }, { KEY_MSDOS, "msdos" }, { KEY_COFFEE, "coffee" }, { KEY_SCREENLOCK, "screenlock" }, { KEY_ROTATE_DISPLAY, "rotate_display" }, { KEY_DIRECTION, "direction" }, { KEY_CYCLEWINDOWS, "cyclewindows" }, { KEY_MAIL, "mail" }, { KEY_BOOKMARKS, "bookmarks" }, { KEY_COMPUTER, "computer" }, { KEY_BACK, "back" }, { KEY_FORWARD, "forward" }, { KEY_CLOSECD, "closecd" }, { KEY_EJECTCD, "ejectcd" }, { KEY_EJECTCLOSECD, "ejectclosecd" }, { KEY_NEXTSONG, "nextsong" }, { KEY_PLAYPAUSE, "playpause" }, { KEY_PREVIOUSSONG, "previoussong" }, { KEY_STOPCD, "stopcd" }, { KEY_RECORD, "record" }, { KEY_REWIND, "rewind" }, { KEY_PHONE, "phone" }, { KEY_ISO, "iso" }, { KEY_CONFIG, "config" }, { KEY_HOMEPAGE, "homepage" }, { KEY_REFRESH, "refresh" }, { KEY_EXIT, "exit" }, { KEY_MOVE, "move" }, { KEY_EDIT, "edit" }, { KEY_SCROLLUP, "scrollup" }, { KEY_SCROLLDOWN, "scrolldown" }, { KEY_KPLEFTPAREN, "kpleftparen" }, { KEY_KPRIGHTPAREN, "kprightparen" }, { KEY_NEW, "new" }, { KEY_REDO, "redo" }, { KEY_F13, "f13" }, { KEY_F14, "f14" }, { KEY_F15, "f15" }, { KEY_F16, "f16" }, { KEY_F17, "f17" }, { KEY_F18, "f18" }, { KEY_F19, "f19" }, { KEY_F20, "f20" }, { KEY_F21, "f21" }, { KEY_F22, "f22" }, { KEY_F23, "f23" }, { KEY_F24, "f24" }, { KEY_PLAYCD, "playcd" }, { KEY_PAUSECD, "pausecd" }, { KEY_PROG3, "prog3" }, { KEY_PROG4, "prog4" }, { KEY_ALL_APPLICATIONS, "all_applications" }, { KEY_DASHBOARD, "dashboard" }, { KEY_SUSPEND, "suspend" }, { KEY_CLOSE, "close" }, { KEY_PLAY, "play" }, { KEY_FASTFORWARD, "fastforward" }, { KEY_BASSBOOST, "bassboost" }, { KEY_PRINT, "print" }, { KEY_HP, "hp" }, { KEY_CAMERA, "camera" }, { KEY_SOUND, "sound" }, { KEY_QUESTION, "question" }, { KEY_EMAIL, "email" }, { KEY_CHAT, "chat" }, { KEY_SEARCH, "search" }, { KEY_CONNECT, "connect" }, { KEY_FINANCE, "finance" }, { KEY_SPORT, "sport" }, { KEY_SHOP, "shop" }, { KEY_ALTERASE, "alterase" }, { KEY_CANCEL, "cancel" }, { KEY_BRIGHTNESSDOWN, "brightnessdown" }, { KEY_BRIGHTNESSUP, "brightnessup" }, { KEY_MEDIA, "media" }, { KEY_SWITCHVIDEOMODE, "switchvideomode" }, { KEY_KBDILLUMTOGGLE, "kbdillumtoggle" }, { KEY_KBDILLUMDOWN, "kbdillumdown" }, { KEY_KBDILLUMUP, "kbdillumup" }, { KEY_SEND, "send" }, { KEY_REPLY, "reply" }, { KEY_FORWARDMAIL, "forwardmail" }, { KEY_SAVE, "save" }, { KEY_DOCUMENTS, "documents" }, { KEY_BATTERY, "battery" }, { KEY_BLUETOOTH, "bluetooth" }, { KEY_WLAN, "wlan" }, { KEY_UWB, "uwb" }, { KEY_UNKNOWN, "unknown" }, { KEY_VIDEO_NEXT, "video_next" }, { KEY_VIDEO_PREV, "video_prev" }, { KEY_BRIGHTNESS_CYCLE, "brightness_cycle" }, { KEY_BRIGHTNESS_AUTO, "brightness_auto" }, { KEY_BRIGHTNESS_ZERO, "brightness_zero" }, { KEY_DISPLAY_OFF, "display_off" }, { KEY_WWAN, "wwan" }, { KEY_WIMAX, "wimax" }, { KEY_RFKILL, "rfkill" }, { KEY_MICMUTE, "micmute" }, { 353, "select" }, // BOXPUT { 0, nullptr }, }; const keyinfo_t HDMI_CEC_KEYS[] = { { CEC_USER_CONTROL_CODE_SELECT , "select" }, { CEC_USER_CONTROL_CODE_UP , "up" }, { CEC_USER_CONTROL_CODE_DOWN , "down" }, { CEC_USER_CONTROL_CODE_LEFT , "left" }, { CEC_USER_CONTROL_CODE_RIGHT , "right" }, { CEC_USER_CONTROL_CODE_RIGHT_UP , "right_up" }, { CEC_USER_CONTROL_CODE_RIGHT_DOWN , "right_down" }, { CEC_USER_CONTROL_CODE_LEFT_UP , "left_up" }, { CEC_USER_CONTROL_CODE_LEFT_DOWN , "left_down" }, { CEC_USER_CONTROL_CODE_ROOT_MENU , "root_menu" }, { CEC_USER_CONTROL_CODE_SETUP_MENU , "setup_menu" }, { CEC_USER_CONTROL_CODE_CONTENTS_MENU , "contents_menu" }, { CEC_USER_CONTROL_CODE_FAVORITE_MENU , "favorite_menu" }, { CEC_USER_CONTROL_CODE_EXIT , "exit" }, { CEC_USER_CONTROL_CODE_TOP_MENU , "top_menu" }, { CEC_USER_CONTROL_CODE_DVD_MENU , "dvd_menu" }, { CEC_USER_CONTROL_CODE_NUMBER_ENTRY_MODE , "number_entry_mode" }, { CEC_USER_CONTROL_CODE_NUMBER11 , "number11" }, { CEC_USER_CONTROL_CODE_NUMBER12 , "number12" }, { CEC_USER_CONTROL_CODE_NUMBER0 , "number0" }, { CEC_USER_CONTROL_CODE_NUMBER1 , "number1" }, { CEC_USER_CONTROL_CODE_NUMBER2 , "number2" }, { CEC_USER_CONTROL_CODE_NUMBER3 , "number3" }, { CEC_USER_CONTROL_CODE_NUMBER4 , "number4" }, { CEC_USER_CONTROL_CODE_NUMBER5 , "number5" }, { CEC_USER_CONTROL_CODE_NUMBER6 , "number6" }, { CEC_USER_CONTROL_CODE_NUMBER7 , "number7" }, { CEC_USER_CONTROL_CODE_NUMBER8 , "number8" }, { CEC_USER_CONTROL_CODE_NUMBER9 , "number9" }, { CEC_USER_CONTROL_CODE_DOT , "dot" }, { CEC_USER_CONTROL_CODE_ENTER , "enter" }, { CEC_USER_CONTROL_CODE_CLEAR , "clear" }, { CEC_USER_CONTROL_CODE_NEXT_FAVORITE , "next_favorite" }, { CEC_USER_CONTROL_CODE_CHANNEL_UP , "channel_up" }, { CEC_USER_CONTROL_CODE_CHANNEL_DOWN , "channel_down" }, { CEC_USER_CONTROL_CODE_PREVIOUS_CHANNEL , "previous_channel" }, { CEC_USER_CONTROL_CODE_SOUND_SELECT , "sound_select" }, { CEC_USER_CONTROL_CODE_INPUT_SELECT , "input_select" }, { CEC_USER_CONTROL_CODE_DISPLAY_INFORMATION , "display_information" }, { CEC_USER_CONTROL_CODE_HELP , "help" }, { CEC_USER_CONTROL_CODE_PAGE_UP , "page_up" }, { CEC_USER_CONTROL_CODE_PAGE_DOWN , "page_down" }, { CEC_USER_CONTROL_CODE_POWER , "power" }, { CEC_USER_CONTROL_CODE_VOLUME_UP , "volume_up" }, { CEC_USER_CONTROL_CODE_VOLUME_DOWN , "volume_down" }, { CEC_USER_CONTROL_CODE_MUTE , "mute" }, { CEC_USER_CONTROL_CODE_PLAY , "play" }, { CEC_USER_CONTROL_CODE_STOP , "stop" }, { CEC_USER_CONTROL_CODE_PAUSE , "pause" }, { CEC_USER_CONTROL_CODE_RECORD , "record" }, { CEC_USER_CONTROL_CODE_REWIND , "rewind" }, { CEC_USER_CONTROL_CODE_FAST_FORWARD , "fast_forward" }, { CEC_USER_CONTROL_CODE_EJECT , "eject" }, { CEC_USER_CONTROL_CODE_FORWARD , "forward" }, { CEC_USER_CONTROL_CODE_BACKWARD , "backward" }, { CEC_USER_CONTROL_CODE_STOP_RECORD , "stop_record" }, { CEC_USER_CONTROL_CODE_PAUSE_RECORD , "pause_record" }, { CEC_USER_CONTROL_CODE_ANGLE , "angle" }, { CEC_USER_CONTROL_CODE_SUB_PICTURE , "sub_picture" }, { CEC_USER_CONTROL_CODE_VIDEO_ON_DEMAND , "video_on_demand" }, { CEC_USER_CONTROL_CODE_ELECTRONIC_PROGRAM_GUIDE , "electronic_program_guide" }, { CEC_USER_CONTROL_CODE_TIMER_PROGRAMMING , "timer_programming" }, { CEC_USER_CONTROL_CODE_INITIAL_CONFIGURATION , "initial_configuration" }, { CEC_USER_CONTROL_CODE_SELECT_BROADCAST_TYPE , "select_broadcast_type" }, { CEC_USER_CONTROL_CODE_SELECT_SOUND_PRESENTATION , "select_sound_presentation" }, { CEC_USER_CONTROL_CODE_PLAY_FUNCTION , "play_function" }, { CEC_USER_CONTROL_CODE_PAUSE_PLAY_FUNCTION , "pause_play_function" }, { CEC_USER_CONTROL_CODE_RECORD_FUNCTION , "record_function" }, { CEC_USER_CONTROL_CODE_PAUSE_RECORD_FUNCTION , "pause_record_function" }, { CEC_USER_CONTROL_CODE_STOP_FUNCTION , "stop_function" }, { CEC_USER_CONTROL_CODE_MUTE_FUNCTION , "mute_function" }, { CEC_USER_CONTROL_CODE_RESTORE_VOLUME_FUNCTION , "restore_volume_function" }, { CEC_USER_CONTROL_CODE_TUNE_FUNCTION , "tune_function" }, { CEC_USER_CONTROL_CODE_SELECT_MEDIA_FUNCTION , "select_media_function" }, { CEC_USER_CONTROL_CODE_SELECT_AV_INPUT_FUNCTION , "select_av_input_function" }, { CEC_USER_CONTROL_CODE_SELECT_AUDIO_INPUT_FUNCTION, "select_audio_input_function" }, { CEC_USER_CONTROL_CODE_POWER_TOGGLE_FUNCTION , "power_toggle_function" }, { CEC_USER_CONTROL_CODE_POWER_OFF_FUNCTION , "power_off_function" }, { CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION , "power_on_function" }, { CEC_USER_CONTROL_CODE_F1_BLUE , "f1_blue" }, { CEC_USER_CONTROL_CODE_F2_RED , "f2_red" }, { CEC_USER_CONTROL_CODE_F3_GREEN , "f3_green" }, { CEC_USER_CONTROL_CODE_F4_YELLOW , "f4_yellow" }, { CEC_USER_CONTROL_CODE_F5 , "f5" }, { CEC_USER_CONTROL_CODE_DATA , "data" }, { CEC_USER_CONTROL_CODE_AN_RETURN , "an_return" }, { CEC_USER_CONTROL_CODE_AN_CHANNELS_LIST , "an_channels_list" }, { 0, nullptr }, }; FileProps props; CECLib ceclib; Remocon remocon; UInput uinput; int exitcode; FILE *redirect; bool cecready; bool debugmode; char config[PATH_MAX]; void command(const char *str); size_t escape(char *buf, const char *str, size_t len) { int cnt = 0; while (len-- > 0) { char c = *str++; if (c == '\\') { switch (c = *str++) { case 0 : case '0': c = 0; break; case 'a': c = '\a'; break; /* 07 */ case 'b': c = '\b'; break; /* 08 */ case 't': c = '\t'; break; /* 09 */ case 'n': c = '\n'; break; /* 0A */ case 'v': c = '\v'; break; /* 0B */ case 'f': c = '\f'; break; /* 0C */ case 'r': c = '\r'; break; /* 0D */ } } if ((*buf++ = c) == 0) break; cnt++; } return cnt; } void stdin_output(const char *str, size_t len) { char temp[256]; if (debugmode) printf("stdin-output(\"%.*s\")\n", (int)len, str); if ((len = escape(temp, str, len > sizeof(temp) ? sizeof(temp) : len))) { if (redirect) { fwrite(temp, 1, len, redirect); fflush(redirect); } else uinput.keystr(temp, len); } } void hdmi_control(const char *str, size_t len) { char cmd[16]; snprintf(cmd, sizeof(cmd), "%.*s", (int)len, str); if (debugmode) printf("hdmi-control(%s)\n", cmd); if (cecready) { if (strcmp(cmd, "power") == 0) { if (ceclib.GetDevicePowerStatus(CECDEVICE_TV) == CEC_POWER_STATUS_ON) ceclib.StandbyDevices(); else ceclib.PowerOnDevices(); } else if (strcmp(cmd, "poweron") == 0) ceclib.PowerOnDevices(); else if (strcmp(cmd, "standby") == 0) ceclib.StandbyDevices(); else if (strcmp(cmd, "activate") == 0) ceclib.SetActiveSource(); else if (strcmp(cmd, "inactivate") == 0) ceclib.SetInactiveView(); else if (strcmp(cmd, "volumeup") == 0) ceclib.VolumeUp(); else if (strcmp(cmd, "volumedown") == 0) ceclib.VolumeDown(); else if (strcmp(cmd, "muteaudio") == 0) ceclib.MuteAudio(); } /* extended control commands */ if (*(str = props.getProperty("control", cmd))) command(str); } void command(const char *str) { char temp[PATH_MAX]; snprintf(temp, sizeof(temp), "%s", str); str = temp; if (debugmode) printf("command(\"%s\")\n", str); while (*str == '<') { size_t i, len = strlen(str); for (i = 1; i < len; ) { char c = str[i++]; if (c == '\\') i++; else if (c == '>') { if (i > 2) { if ((i > 3) && (str[1] == '"') && (str[i - 2] == '"')) stdin_output(str + 2, i - 4); else if (cecready) hdmi_control(str + 1, i - 2); } break; } } str += i; } if (*str) { if (debugmode) printf("system(\"%s\")\n", str); system(str); } } long subtime(struct timeval &a, struct timeval &b) { return ((long long)a.tv_sec * 1000000 + a.tv_usec) - ((long long)b.tv_sec * 1000000 + b.tv_usec); } void keyboard_input(struct input_event *event, void *arg) { struct input_event pushed; const keyinfo_t *keyinfo; keyinfo_t unknown; char keyno[8]; for (keyinfo = INPUT_KEYS; keyinfo->name && (keyinfo->code != event->code); ++keyinfo) continue; if (!keyinfo->name) { snprintf(keyno, sizeof(keyno), "%u", event->code); unknown.name = keyno; unknown.code = event->code; keyinfo = &unknown; } if (debugmode) printf("keyboard_input { name=\"%s\", code=%d, value=%d }\n", keyinfo->name, event->code, event->value); if (keyinfo->name) { if (event->value) { pushed = *event; command(props.getProperty("keyboard", keyinfo->name)); } else if (subtime(event->time, pushed.time) >= LONGPRESS_TIME) { command(props.getProperty("keyboard.long-pressed", keyinfo->name)); } } } void hdmi_cec_keypress(void *cbParam, const cec_keypress* key) { const keyinfo_t *keyinfo; keyinfo_t unknown; char keyno[8]; if (key->duration) return; for (keyinfo = HDMI_CEC_KEYS; keyinfo->name && (keyinfo->code != key->keycode); ++keyinfo) continue; if (!keyinfo->name) { snprintf(keyno, sizeof(keyno), "%u", key->keycode); unknown.name = keyno; unknown.code = key->keycode; keyinfo = &unknown; } if (debugmode) printf("hdmi_cec_keypress { name=\"%s\", code=%d, duration=%d }\n", keyinfo->name, key->keycode, key->duration); if (keyinfo->name) command(props.getProperty("tv", keyinfo->name)); } void hdmi_cec_alert(void *cbParam, const libcec_alert type, const libcec_parameter param) { if (type == CEC_ALERT_CONNECTION_LOST) ceclib.Reconnect(); } void sighandler(int signum) { exitcode = 1; } void usage(void) { printf("Application Remote Controller, Version 1.00\n"); printf("Copyright (C) 2023 Sasapea's Lab. All right reserved.\n"); printf("\n"); printf("Usage: remocon [options]\n"); printf("\n"); printf(" options:\n"); printf(" -p ... redirect stdin\n"); printf(" -c ... command string\n"); printf(" -d ... debug mode\n"); printf(" -h ... this help\n"); printf("\n"); } int main(int argc, char **argv) { bool optpipe = false; // // set current directory to running process directory // snprintf(config, sizeof(config), "%s", argv[0]); char *p = strrchr(config, '/'); if (p) *p = 0; chdir(config); // // load properties // snprintf(config, sizeof(config), "%s.conf", argv[0]); props.load(config); // // command line option // int opt; while ((opt = getopt(argc, argv, "dpc:h")) != -1) { switch (opt) { case 'd': debugmode = true; break; case 'p': optpipe = true; break; case 'c': uinput.start(); command(props.getProperty("control", optarg)); uinput.stop(); exit(0); case 'h': usage(); /* fall through */ default: exit(1); } } // // setup signal handler // struct sigaction act; sigemptyset(&act.sa_mask); act.sa_handler = sighandler; act.sa_flags = SA_RESTART; sigaction(SIGINT , &act, NULL); sigaction(SIGTERM, &act, NULL); // // start Input Capture // std::vector<std::string> names; props.getPropertyNames(names, "device"); for (auto name = names.begin(); name != names.end(); ++name) remocon.add(name->c_str(), props.getProperty("device", name->c_str())); remocon.callback(keyboard_input); remocon.start(); uinput.start(); // // start HDMI-CEC Adapter // ICECCallbacks callbacks; callbacks.Clear(); callbacks.logMessage = nullptr; callbacks.keyPress = hdmi_cec_keypress; callbacks.commandReceived = nullptr; callbacks.alert = hdmi_cec_alert; cecready = ceclib.Start(callbacks, props.getProperty("tv", "name", nullptr)); // // run program // while (exitcode == 0) { // // reload properties // props.load(config); const char *cmd = props.getProperty("program", "cmdline"); if (*cmd && !debugmode) { if (!optpipe) system(cmd); else if ((redirect = popen(cmd, "w"))) pclose(redirect); } sleep(3); } // // stop HDMI-CEC Adapter // if (cecready) ceclib.Stop(); // // stop Input Capture // uinput.stop(); remocon.stop(); return exitcode; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
/* remocon.h - Remocon Library Copyright (c) 2023 Sasapea's Lab. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #pragma once #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <dirent.h> #include <pthread.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/inotify.h> #include <linux/input.h> #include <linux/uinput.h> #include <string> #include <vector> #ifndef DEBUG #define DEBUG 0 #endif typedef void (*input_cb_t)(struct input_event *, void *arg); class UInput { public: UInput(void) : _fd(-1) { } virtual ~UInput(void) { stop(); } void start(void) { if ((_fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK)) != -1) { struct uinput_setup usetup; memset(&usetup, 0, sizeof(usetup)); usetup.id.bustype = BUS_USB; usetup.id.vendor = 0x1234; /* sample vendor */ usetup.id.product = 0x5678; /* sample product */ strcpy(usetup.name, "Example device"); ioctl(_fd, UI_SET_EVBIT, EV_KEY); for (int i = 0; i < KEY_MAX; ++i) ioctl(_fd, UI_SET_KEYBIT, i); ioctl(_fd, UI_DEV_SETUP, &usetup); ioctl(_fd, UI_DEV_CREATE); } } void stop(void) { if (_fd != -1) { ioctl(_fd, UI_DEV_DESTROY); close(_fd); _fd = -1; } } void keystr(const char *str) { keystr(str, strlen(str)); } void keystr(const char *str, size_t len) { while (len-- > 0) keychar(*str++); } void keychar(char c) { static const unsigned char KEYCODES[] = { /* 00 */ KEY_RESERVED, /* 01 */ KEY_RESERVED, /* 02 */ KEY_RESERVED, /* 03 */ KEY_RESERVED, /* 04 */ KEY_RESERVED, /* 05 */ KEY_RESERVED, /* 06 */ KEY_RESERVED, /* 07 */ KEY_RESERVED, /* 08 */ KEY_RESERVED, /* 09 */ KEY_TAB, /* 0A */ KEY_LINEFEED, /* 0B */ KEY_RESERVED, /* 0C */ KEY_RESERVED, /* 0D */ KEY_ENTER, /* 0E */ KEY_RESERVED, /* 0F */ KEY_RESERVED, /* 10 */ KEY_RESERVED, /* 11 */ KEY_RESERVED, /* 12 */ KEY_RESERVED, /* 13 */ KEY_RESERVED, /* 14 */ KEY_RESERVED, /* 15 */ KEY_RESERVED, /* 16 */ KEY_RESERVED, /* 17 */ KEY_RESERVED, /* 18 */ KEY_RESERVED, /* 19 */ KEY_RESERVED, /* 1A */ KEY_RESERVED, /* 1B */ KEY_ESC, /* 1C */ KEY_RESERVED, /* 1D */ KEY_RESERVED, /* 1E */ KEY_RESERVED, /* 1F */ KEY_RESERVED, /* */ KEY_SPACE, /* ! */ KEY_1 | 0x80, /* " */ KEY_APOSTROPHE | 0x80, /* # */ KEY_3 | 0x80, /* $ */ KEY_4 | 0x80, /* % */ KEY_5 | 0x80, /* & */ KEY_7 | 0x80, /* ' */ KEY_APOSTROPHE, /* ( */ KEY_9 | 0x80, /* ) */ KEY_0 | 0x80, /* * */ KEY_8 | 0x80, /* + */ KEY_EQUAL | 0x80, /* , */ KEY_COMMA, /* - */ KEY_MINUS, /* . */ KEY_DOT, /* / */ KEY_SLASH, /* 0 */ KEY_0, /* 1 */ KEY_1, /* 2 */ KEY_2, /* 3 */ KEY_3, /* 4 */ KEY_4, /* 5 */ KEY_5, /* 6 */ KEY_6, /* 7 */ KEY_7, /* 8 */ KEY_8, /* 9 */ KEY_9, /* : */ KEY_SEMICOLON | 0x80, /* ; */ KEY_SEMICOLON, /* < */ KEY_COMMA | 0x80, /* = */ KEY_EQUAL, /* > */ KEY_DOT | 0x80, /* ? */ KEY_SLASH | 0x80, /* @ */ KEY_2 | 0x80, /* A */ KEY_A | 0x80, /* B */ KEY_B | 0x80, /* C */ KEY_C | 0x80, /* D */ KEY_D | 0x80, /* E */ KEY_E | 0x80, /* F */ KEY_F | 0x80, /* G */ KEY_G | 0x80, /* H */ KEY_H | 0x80, /* I */ KEY_I | 0x80, /* J */ KEY_J | 0x80, /* K */ KEY_K | 0x80, /* L */ KEY_L | 0x80, /* M */ KEY_M | 0x80, /* N */ KEY_N | 0x80, /* O */ KEY_O | 0x80, /* P */ KEY_P | 0x80, /* Q */ KEY_Q | 0x80, /* R */ KEY_R | 0x80, /* S */ KEY_S | 0x80, /* T */ KEY_T | 0x80, /* U */ KEY_U | 0x80, /* V */ KEY_V | 0x80, /* W */ KEY_W | 0x80, /* X */ KEY_X | 0x80, /* Y */ KEY_Y | 0x80, /* Z */ KEY_Z | 0x80, /* [ */ KEY_LEFTBRACE, /* \ */ KEY_BACKSLASH, /* ] */ KEY_RIGHTBRACE, /* ^ */ KEY_6 | 0x80, /* _ */ KEY_MINUS | 0x80, /* ` */ KEY_GRAVE, /* a */ KEY_A, /* b */ KEY_B, /* c */ KEY_C, /* d */ KEY_D, /* e */ KEY_E, /* f */ KEY_F, /* g */ KEY_G, /* h */ KEY_H, /* i */ KEY_I, /* j */ KEY_J, /* k */ KEY_K, /* l */ KEY_L, /* m */ KEY_M, /* n */ KEY_N, /* o */ KEY_O, /* p */ KEY_P, /* q */ KEY_Q, /* r */ KEY_R, /* s */ KEY_S, /* t */ KEY_T, /* u */ KEY_U, /* v */ KEY_V, /* w */ KEY_W, /* x */ KEY_X, /* y */ KEY_Y, /* z */ KEY_Z, /* { */ KEY_LEFTBRACE | 0x80, /* | */ KEY_BACKSLASH | 0x80, /* } */ KEY_RIGHTBRACE | 0x80, /* ~ */ KEY_GRAVE | 0x80, }; if ((unsigned char)c < sizeof(KEYCODES) / sizeof(KEYCODES[0])) { c = KEYCODES[(unsigned char)c]; if (c & 0x80) { keyctl(KEY_LEFTSHIFT, 1); keycode(c & ~0x80); keyctl(KEY_LEFTSHIFT, 0); } else if (c) keycode(c); } } void keycode(int code) { keyctl(code, 1); keyctl(code, 0); } void keyctl(int code, int value) { emit(EV_KEY, code, value); emit(EV_SYN, SYN_REPORT, 0); } private: void emit(int type, int code, int val) { struct input_event ie; ie.type = type; ie.code = code; ie.value = val; /* timestamp values below are ignored */ ie.time.tv_sec = 0; ie.time.tv_usec = 0; write(_fd, &ie, sizeof(ie)); } int _fd; }; class Input { public: typedef struct { uint16_t code; uint16_t value; } remap_t; Input(const char *name1, const char *name2, const remap_t *remap = nullptr) : _thid(0) , _fd(-1) , _enable(false) , _callback(nullptr) , _argument(nullptr) , _remap(nullptr) { _name1 = name1; _name2 = name2; _remap = remap; } virtual ~Input(void) { stop(); } void callback(input_cb_t cb, void *arg = nullptr) { _callback = cb; _argument = arg; } bool start(void) { return _enable = (pthread_create(&_thid, NULL, run0, this) == 0); } void stop(void) { stop0(); _enable = false; } private: void stop0(void) { if (_fd != -1) { ioctl(_fd, EVIOCGRAB, 0); close(_fd); _fd = -1; } } void run(void) { bool first = true; int nd, wd; if ((nd = inotify_init1(IN_CLOEXEC)) == -1) printf("[ERROR] inotify_init1(IN_CLOEXEC): %s\n", strerror(errno)); else { if ((wd = inotify_add_watch(nd, "/dev/input", IN_CREATE)) == -1) printf("[ERROR] inotify_add_watch(\"/dev/input\", IN_CREATE): %s\n", strerror(errno)); else { while (_enable) { ssize_t n; if (_fd != -1) { struct input_event input; while ((n = read(_fd, &input, sizeof(input))) == sizeof(input)) { if (_callback) { if (_remap) { for (const remap_t *map = _remap; map->code; ++map) { if (input.code == map->code) { input.code = map->value; break; } } } _callback(&input, _argument); } } if (n <= 0) stop0(); } else { struct inotify_event inotify[16]; if (first || read(nd, inotify, sizeof(inotify)) > 0) { DIR *dir; first = false; if ((dir = opendir("/dev/input"))) { struct dirent *entry; while ((entry = readdir(dir))) { if (strncmp(entry->d_name, "event", 5) == 0) { char path[PATH_MAX]; int fd; snprintf(path, sizeof(path), "/sys/class/input/%s/device/name", entry->d_name); if ((fd = open(path, O_RDONLY)) == -1) printf("[ERROR] open(\"%s\"): %s\n", path, strerror(errno)); else { n = read(fd, path, sizeof(path)); close(fd); if (n > 0) { path[n] = 0; if (strstr(path, _name1.c_str()) && strstr(path, _name2.c_str())) { snprintf(path, sizeof(path), "/dev/input/%s", entry->d_name); if ((_fd = open(path, O_RDONLY)) == -1) printf("[ERROR] open(\"%s\"): %s\n", path, strerror(errno)); else ioctl(_fd, EVIOCGRAB, 1); break; } } } } } closedir(dir); } } } } inotify_rm_watch(nd, wd); } close(nd); } } static void *run0(void *arg) { ((Input *)arg)->run(); return NULL; } std::string _name1; std::string _name2; pthread_t _thid; int _fd; bool _enable; input_cb_t _callback; void *_argument; const remap_t *_remap; }; class Remocon { public: static const int BUTTON_A = KEY_VOLUMEUP; static const int BUTTON_B = KEY_VOLUMEDOWN; Remocon(void) : _callback(nullptr) , _argument(nullptr) , _buttun_b(0) { } virtual ~Remocon(void) { stop(); for (auto input = _inputs.begin(); input != _inputs.end(); ++input) delete *input; _inputs.clear(); } void add(const char *name1, const char *name2, const Input::remap_t *remap = nullptr) { /* AB Shutter 3 */ if ((strcmp(name1, "AB Shutter") == 0) && (strcmp(name2, "Keyboard") == 0)) { /* support DAISO AB Shutter 3 */ add(name1, "Control"); /* remap KEY_ENTER to KEY_VOLUMEDOWN */ if (remap == nullptr) { static const Input::remap_t ABS3[] = { { KEY_ENTER, KEY_VOLUMEDOWN }, { 0, 0 }, }; remap = ABS3; } } Input *input = new Input(name1, name2, remap); input->callback(input0, this); _inputs.push_back(input); } void callback(input_cb_t cb, void *arg = nullptr) { _callback = cb; _argument = arg; } void start(void) { for (auto input = _inputs.begin(); input != _inputs.end(); ++input) (*input)->start(); } void stop(void) { for (auto input = _inputs.begin(); input != _inputs.end(); ++input) (*input)->stop(); } private: void input(struct input_event *event) { if ((event->type == EV_KEY) && (event->value <= 1)) { #if DEBUG printf("code=%d, value=%d\n", event->code, event->value); #endif /* support DAISO AB Shutter 3 */ if (event->code == BUTTON_B) _buttun_b = event->value; if ((event->code == BUTTON_B) || (_buttun_b == 0)) { if (_callback) _callback(event, _argument); } } } static void input0(struct input_event *event, void *arg) { ((Remocon *)arg)->input(event); } std::vector<Input *> _inputs; input_cb_t _callback; void *_argument; int _buttun_b; }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
/* filepros.h - File Properties Library Copyright (c) 2023 Sasapea's Lab. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #pragma once #include <stdio.h> #include "properties.h" class FileProps : public Properties { public: FileProps(void) { } virtual ~FileProps(void) { } bool load(const char* path) override { bool rv = false; FILE *fp = fopen(path, "r"); if (fp) { char buf[256]; clear(); rv = true; while (rv) { size_t len = fread(buf, 1, sizeof(buf), fp); if (len == 0) break; rv = parse(buf, len); } finish(); fclose(fp); } return rv; } bool save(const char* path, const char* header = nullptr) override { bool rv = false; FILE *fp = fopen(path, "w"); if (fp) { std::string str; toStringWithHeader(str, header); rv = fwrite(str.c_str(), 1, str.length(), fp) == str.length(); fclose(fp); } return rv; } }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
/* properties.h - Properties Library Copyright (c) 2023 Sasapea's Lab. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #pragma once #include <vector> #include <string> #include <string.h> #include <stdlib.h> #include <stdint.h> class Properties { private: typedef struct { std::string name; std::string value; } property_t; typedef struct { std::string name; std::vector<property_t> properties; } section_t; std::vector<section_t> _sections; section_t _current; std::string _linebuf; protected: std::string& trim(std::string& str) { std::string::size_type pos; pos = str.find_first_not_of(' '); if (pos != std::string::npos) str.erase(0, pos); pos = str.find_last_not_of(' '); if (pos != std::string::npos) str.erase(pos + 1); return str; } section_t* getSection(const char* name) { if (name) { for (auto sec = _sections.begin(); sec != _sections.end(); ++sec) { if (strcasecmp(sec->name.c_str(), name) == 0) return &*sec; } } return nullptr; } void setSection(section_t &newSection) { section_t* sec = getSection(newSection.name.c_str()); if (!sec) _sections.push_back(newSection); else { for (auto prop = newSection.properties.begin(); prop != newSection.properties.end(); ++prop) setProperty(*sec, *prop); } } property_t* getProperty(section_t* section, const char* name) { if (section && name) { for (auto prop = section->properties.begin(); prop != section->properties.end(); ++prop) { if (strcasecmp(prop->name.c_str(), name) == 0) return &*prop; } } return nullptr; } void setProperty(section_t §ion, property_t &prop) { trim(prop.name); trim(prop.value); property_t* exists = getProperty(§ion, prop.name.c_str()); if (exists) exists->value = prop.value; else section.properties.push_back(prop); } bool parse(const char* buf, size_t len) { while (len--) { char c = *buf++; if (c >= ' ') _linebuf += c; else if (c == 0x0A) { trim(_linebuf); if (_linebuf.length()) { c = _linebuf[0]; if (c == '[') { if (_linebuf[_linebuf.length() - 1] != ']') return false; // format error. if (_current.properties.size() || _current.name.length()) setSection(_current); _current.name = _linebuf.substr(1, _linebuf.length() - 2); _current.properties.clear(); trim(_current.name); } else if ((c != ';') && (c != '#')) { int sep = _linebuf.find('='); if (sep < 0) sep = _linebuf.length(); property_t prop = {_linebuf.substr(0, sep), _linebuf.substr(sep + 1)}; setProperty(_current, prop); } _linebuf.clear(); } } } return true; } void finish(void) { if (_current.properties.size() || _current.name.length()) setSection(_current); _current.name.clear(); _current.properties.clear(); _linebuf.clear(); } public: Properties(void) { } virtual ~Properties(void) { } void clear(void) { _sections.clear(); _current.name.clear(); _current.properties.clear(); _linebuf.clear(); } std::vector<std::string>& getSectionNames(std::vector<std::string>& names) { names.clear(); for (auto sec = _sections.begin(); sec != _sections.end(); ++sec) names.push_back(sec->name); return names; } std::vector<std::string>& getPropertyNames(std::vector<std::string>& names, const char* section) { names.clear(); section_t* sec = getSection(section); if (sec) { for (auto prop = sec->properties.begin(); prop != sec->properties.end(); ++prop) names.push_back(prop->name); } return names; } void removeSection(const char* section) { if (section) { for (auto sec = _sections.begin(); sec != _sections.end(); ++sec) { if (strcasecmp(sec->name.c_str(), section) == 0) { _sections.erase(sec); break; } } } } void removeProperty(const char* section, const char* name) { if (name) { section_t* sec = getSection(section); if (sec) { for (auto prop = sec->properties.begin(); prop != sec->properties.end(); ++prop) { if (strcasecmp(prop->name.c_str(), name) == 0) { sec->properties.erase(prop); break; } } } } } void setProperty(const char* section, const char* name, const char* value) { if (section && name && value) { section_t newsec = {section, {{name, value}}}; setSection(newsec); } } void setPropertyInt(const char* section, const char* name, int value) { if (section && name) { char buf[16]; snprintf(buf, sizeof(buf), "%d", value); section_t newsec = {section, {{name, buf}}}; setSection(newsec); } } void setPropertyI64(const char* section, const char* name, int64_t value) { if (section && name) { char buf[128]; snprintf(buf, sizeof(buf), "%lld", (long long int)value); section_t newsec = {section, {{name, buf}}}; setSection(newsec); } } const char* getProperty(const char* section, const char* name, const char* defval = "") { property_t* prop = getProperty(getSection(section), name); return prop ? prop->value.c_str() : defval; } int getPropertyInt(const char* section, const char* name, int defval = 0) { const char* value = getProperty(section, name); return *value ? atoi(value) : defval; } int getPropertyI64(const char* section, const char* name, int64_t defval = 0) { const char* value = getProperty(section, name); return *value ? strtoll(value, NULL, 10) : defval; } std::string& toString(std::string &str) { std::vector<std::string> names; std::string props; str.clear(); getSectionNames(names); for (auto name = names.begin(); name != names.end(); ++name) str.append("[").append(*name).append("]\n").append(toString(props, name->c_str())); return str; } std::string& toString(std::string &str, const char* section) { if (section == nullptr) toString(str); else { std::vector<std::string> names; str.clear(); getPropertyNames(names, section); for (auto name = names.begin(); name != names.end(); ++name) str.append(*name).append("=").append(getProperty(section, name->c_str())).append("\n"); } return str; } std::string& toStringWithHeader(std::string &str, const char* header) { str.clear(); if (header && *header) { const char* p; const char* q; p = q = header; do { if ((*q == 0) || (*q == 0x0A)) { str.append("# ").append(p, (size_t)q - (size_t)p).append("\n"); p = q + 1; } } while (*q++); } std::string props; return str.append(toString(props)); } virtual bool load(const char* path) = 0; virtual bool save(const char* path, const char* header = nullptr) = 0; }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 |
/* ceclib.h - LibCEC Wrapper Library Copyright (c) 2023 Sasapea's Lab. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #pragma once /* LibCEC version */ #if !defined(LIBCEC_VERSION_MAJOR) #define LIBCEC_VERSION_MAJOR 6 #define LIBCEC_VERSION_MINOR 0 #define LIBCEC_VERSION_PATCH 2 #endif #include <iostream> #include <stdio.h> #include <unistd.h> #include <limits.h> #include "libcec/cec.h" #include "libcec/cecloader.h" using namespace CEC; class CECLib : private ICECAdapter { public: CECLib(void) : _adapter(nullptr) { _portName[0] = 0; _callbacks.Clear(); } virtual ~CECLib(void) { Stop(); } static libcec_configuration& defaultConfig(libcec_configuration& config, ICECCallbacks *callbacks = nullptr, const char *name = nullptr) { config.Clear(); config.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE); snprintf(config.strDeviceName, sizeof(config.strDeviceName), "%s", name ? name : "CECLib"); config.clientVersion = LIBCEC_VERSION_CURRENT; config.bActivateSource = 0; config.callbacks = callbacks; return config; } bool Start(const char *name = nullptr) { libcec_configuration config; return Start(defaultConfig(config, nullptr, name)); } bool Start(ICECCallbacks& callbacks, const char *name = nullptr) { libcec_configuration config; return Start(defaultConfig(config, &callbacks, name)); } bool Start(const libcec_configuration& config) { libcec_configuration conf = config; if (conf.callbacks) { _callbacks = *conf.callbacks; conf.callbacks = &_callbacks; } if ((_adapter = LibCecInitialise(&conf)) == nullptr) printf("Can't Load LibCEC\n"); else { cec_adapter_descriptor _devices[4]; // init video on targets that need this InitVideoStandalone(); if (DetectAdapters(_devices, sizeof(_devices) / sizeof(_devices[0]), NULL, true) <= 0) printf("CEC-Adapters Not Found\n"); else if (!Open(_devices[0].strComName)) printf("unable to open the device on port %s\n", _devices[0].strComName); else { snprintf(_portName, sizeof(_portName), "%s", _devices[0].strComName);; return true; } UnloadLibCec(_adapter); _adapter = nullptr; } return false; } void Stop(void) { if (_adapter) { Close(); UnloadLibCec(_adapter); _adapter = nullptr; } } bool Reconnect(void) { Close(); return Open(_portName); } /*! * @brief Sends a ping command to the adapter, to check if it's responding. * @return True when the ping was successful, false otherwise. */ bool PingAdapter(void) override { return _adapter->PingAdapter(); } /*! * @brief Start the bootloader of the CEC adapter. Closes the connection when successful. * @return True when the command was sent successfully, false otherwise. */ bool StartBootloader(void) override { return _adapter->StartBootloader(); } /*! * @brief Transmit a raw CEC command over the CEC line. * @param data The command to send. * @return True when the data was sent and acked, false otherwise. */ bool Transmit(const cec_command &data) override { return _adapter->Transmit(data); } /*! * @brief Change the logical address on the CEC bus of the CEC adapter. libCEC automatically assigns a logical address, and this method is only available for debugging purposes. * @param iLogicalAddress The CEC adapter's new logical address. * @return True when the logical address was set successfully, false otherwise. */ bool SetLogicalAddress(cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1) override { return _adapter->SetLogicalAddress(iLogicalAddress); } /*! * @brief Change the physical address (HDMI port) of the CEC adapter. libCEC will try to autodetect the physical address when connecting. If it did, it's set in libcec_configuration. * @param iPhysicalAddress The CEC adapter's new physical address. * @brief True when the physical address was set successfully, false otherwise. */ bool SetPhysicalAddress(uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS) override { return _adapter->SetPhysicalAddress(iPhysicalAddress); } /*! * @brief Power on the given CEC capable devices. If CECDEVICE_BROADCAST is used, then wakeDevice in libcec_configuration will be used. * @param address The logical address to power on. * @return True when the command was sent successfully, false otherwise. */ bool PowerOnDevices(cec_logical_address address = CECDEVICE_TV) override { return _adapter->PowerOnDevices(address); } /*! * @brief Put the given CEC capable devices in standby mode. If CECDEVICE_BROADCAST is used, then standbyDevices in libcec_configuration will be used. * @brief address The logical address of the device to put in standby. * @return True when the command was sent successfully, false otherwise. */ bool StandbyDevices(cec_logical_address address = CECDEVICE_BROADCAST) override { return _adapter->StandbyDevices(address); } /*! * @brief Change the active source to a device type handled by libCEC. Use CEC_DEVICE_TYPE_RESERVED to make the default type used by libCEC active. * @param type The new active source. Leave empty to use the primary type * @return True when the command was sent successfully, false otherwise. */ bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED) override { return _adapter->SetActiveSource(type); } /*! * @brief Change the deck control mode, if this adapter is registered as playback or recording device. * @param mode The new control mode. * @param bSendUpdate True to send the new status over the CEC line. * @return True if set, false otherwise. */ bool SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate = true) override { return _adapter->SetDeckControlMode(mode, bSendUpdate); } /*! * @brief Change the deck info, if this adapter is a playback or recording device. * @param info The new deck info. * @param bSendUpdate True to send the new status over the CEC line. * @return True if set, false otherwise. */ bool SetDeckInfo(cec_deck_info info, bool bSendUpdate = true) override { return _adapter->SetDeckInfo(info, bSendUpdate); } /*! * @brief Broadcast a message that notifies connected CEC capable devices that this device is no longer the active source. * @return True when the command was sent successfully, false otherwise. */ bool SetInactiveView(void) override { return _adapter->SetInactiveView(); } /*! * @brief Change the menu state. This value is already changed by libCEC automatically if a device is (de)activated. * @param state The new state. * @param bSendUpdate True to send the new status over the CEC line. * @return True if set, false otherwise. */ bool SetMenuState(cec_menu_state state, bool bSendUpdate = true) override { return _adapter->SetMenuState(state, bSendUpdate); } /*! * @brief Display a message on the device with the given logical address. Not supported by most TVs. * @param iLogicalAddress The logical address of the device to display the message on. * @param duration The duration of the message * @param strMessage The message to display. * @return True when the command was sent, false otherwise. */ bool SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage) override { return _adapter->SetOSDString(iLogicalAddress, duration, strMessage); } /*! * @brief Enable or disable monitoring mode, for debugging purposes. If monitoring mode is enabled, libCEC won't respond to any command, but only log incoming data. * @param bEnable True to enable, false to disable. * @return True when switched successfully, false otherwise. */ bool SwitchMonitoring(bool bEnable) override { return _adapter->SwitchMonitoring(bEnable); } /*! * @brief Get the CEC version of the device with the given logical address * @param iLogicalAddress The logical address of the device to get the CEC version for. * @return The version or CEC_VERSION_UNKNOWN when the version couldn't be fetched. */ cec_version GetDeviceCecVersion(cec_logical_address iLogicalAddress) override { return _adapter->GetDeviceCecVersion(iLogicalAddress); } /*! * @brief Get the menu language of the device with the given logical address * @param iLogicalAddress The logical address of the device to get the menu language for. * @return The requested menu language, or '???' if unknown */ std::string GetDeviceMenuLanguage(cec_logical_address iLogicalAddress) override { return _adapter->GetDeviceMenuLanguage(iLogicalAddress); } /*! * @brief Get the vendor ID of the device with the given logical address. * @param iLogicalAddress The logical address of the device to get the vendor ID for. * @return The vendor ID or 0 if it wasn't found. */ uint32_t GetDeviceVendorId(cec_logical_address iLogicalAddress) override { return _adapter->GetDeviceVendorId(iLogicalAddress); } /*! * @brief Get the power status of the device with the given logical address. * @param iLogicalAddress The logical address of the device to get the power status for. * @return The power status or CEC_POWER_STATUS_UNKNOWN if it wasn't found. */ cec_power_status GetDevicePowerStatus(cec_logical_address iLogicalAddress) override { return _adapter->GetDevicePowerStatus(iLogicalAddress); } /*! * @brief Sends a POLL message to a device, to check if it's present and responding. * @param iLogicalAddress The device to send the message to. * @return True if the POLL was acked, false otherwise. */ bool PollDevice(cec_logical_address iLogicalAddress) override { return _adapter->PollDevice(iLogicalAddress); } /*! * @return The logical addresses of the devices that are active on the bus, including those handled by libCEC. */ cec_logical_addresses GetActiveDevices(void) override { return _adapter->GetActiveDevices(); } /*! * @brief Check whether a device is active on the bus. * @param iLogicalAddress The address to check. * @return True when active, false otherwise. */ bool IsActiveDevice(cec_logical_address iLogicalAddress) override { return _adapter->IsActiveDevice(iLogicalAddress); } /*! * @brief Check whether a device of the given type is active on the bus. * @param type The type to check. * @return True when active, false otherwise. */ bool IsActiveDeviceType(cec_device_type type) override { return _adapter->IsActiveDeviceType(type); } /*! * @brief Sends a volume up keypress to an audiosystem if it's present. * @param bSendRelease Send a key release after the keypress. * @return The new audio status. */ uint8_t VolumeUp(bool bSendRelease = true) override { return _adapter->VolumeUp(bSendRelease); } /*! * @brief Sends a volume down keypress to an audiosystem if it's present. * @param bSendRelease Send a key release after the keypress. * @return The new audio status. */ uint8_t VolumeDown(bool bSendRelease = true) override { return _adapter->VolumeDown(bSendRelease); } #if CEC_LIB_VERSION_MAJOR >= 5 /*! * @brief Toggles the mute status of an audiosystem, if it's present * @return The new audio status. */ uint8_t MuteAudio(void) override { return _adapter->MuteAudio(); } #endif /*! * @brief Send a keypress to a device on the CEC bus. * @param iDestination The logical address of the device to send the message to. * @param key The key to send. * @param bWait True to wait for a response, false otherwise. * @return True when the keypress was acked, false otherwise. */ bool SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait = false) override { return _adapter->SendKeypress(iDestination, key, bWait); } /*! * @brief Send a key release to a device on the CEC bus. * @param iDestination The logical address of the device to send the message to. * @param bWait True to wait for a response, false otherwise. * @return True when the key release was acked, false otherwise. */ bool SendKeyRelease(cec_logical_address iDestination, bool bWait = false) override { return _adapter->SendKeyRelease(iDestination, bWait); } /*! * @brief Get the OSD name of a device on the CEC bus. * @param iLogicalAddress The device to get the OSD name for. * @return The requested OSD name, or an empty string if unknown */ std::string GetDeviceOSDName(cec_logical_address iAddress) override { return _adapter->GetDeviceOSDName(iAddress); } /*! * @brief Get the logical address of the device that is currently the active source on the CEC bus. * @return The active source or CECDEVICE_UNKNOWN when unknown. */ cec_logical_address GetActiveSource(void) override { return _adapter->GetActiveSource(); } /*! * @brief Check whether a device is currently the active source on the CEC bus. * @param iLogicalAddress The logical address of the device to check. * @return True when it is the active source, false otherwise. */ bool IsActiveSource(cec_logical_address iLogicalAddress) override { return _adapter->IsActiveSource(iLogicalAddress); } /*! * @brief Sets the stream path to the device on the given logical address. * @param iLogicalAddress The address to activate. * @return True when the command was sent, false otherwise. */ bool SetStreamPath(cec_logical_address iLogicalAddress) override { return _adapter->SetStreamPath(iLogicalAddress); } /*! * @brief Sets the stream path to the device on the given physical address. * @param iPhysicalAddress The address to activate. * @return True when the command was sent, false otherwise. */ bool SetStreamPath(uint16_t iPhysicalAddress) override { return _adapter->SetStreamPath(iPhysicalAddress); } /*! * @return The list of logical addresses that libCEC is controlling */ cec_logical_addresses GetLogicalAddresses(void) override { return _adapter->GetLogicalAddresses(); } /*! * @brief Get libCEC's current configuration. * @param configuration The configuration. * @return True when the configuration was updated, false otherwise. */ bool GetCurrentConfiguration(libcec_configuration *configuration) override { return _adapter->GetCurrentConfiguration(configuration); } /*! * @brief Change libCEC's configuration. Store it updated settings in the eeprom of the device (if supported) * @param configuration The new configuration. * @return True when the configuration was changed successfully, false otherwise. */ bool SetConfiguration(const libcec_configuration *configuration) override { return _adapter->SetConfiguration(configuration); } /*! * @return True if this CEC adapter can save the user configuration, false otherwise. */ #if CEC_LIB_VERSION_MAJOR >= 5 bool CanSaveConfiguration(void) override { return _adapter->CanSaveConfiguration(); } #else bool CanPersistConfiguration(void) override { return _adapter->CanPersistConfiguration(); } /*! * @deprecated Use SetConfiguration() instead * @brief Change libCEC's configuration. Store it updated settings in the eeprom of the device (if supported) * @brief configuration The configuration to store. * @return True when the configuration was persisted, false otherwise. */ bool PersistConfiguration(libcec_configuration *configuration) override { return _adapter->PersistConfiguration(configuration); } #endif /*! * @brief Tell libCEC to poll for active devices on the bus. */ void RescanActiveDevices(void) override { _adapter->RescanActiveDevices(); } /*! * @return true when libCEC is the active source on the bus, false otherwise. */ bool IsLibCECActiveSource(void) override { return _adapter->IsLibCECActiveSource(); } /*! * @brief Get information about the given CEC adapter. * @param strPort The port to which the device is connected * @param config The device configuration * @param iTimeoutMs The timeout in milliseconds * @return True when the device was found, false otherwise */ bool GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs = 10000) override { return _adapter->GetDeviceInformation(strPort, config, iTimeoutMs); } #if CEC_LIB_VERSION_MAJOR >= 5 /*! * @brief Set and enable the callback methods * @param callbacks The callbacks to set. * @param cbParam Parameter to pass to callback methods. * @return True if enabled, false otherwise. */ bool SetCallbacks(ICECCallbacks *callbacks, void *cbParam) override { return _adapter->SetCallbacks(callbacks, cbParam); } /*! * @brief Disable all callbacks * @return True if disabled, false otherwise. */ bool DisableCallbacks(void) override { return _adapter->DisableCallbacks(); } #else /*! * @deprecated * @brief Set and enable the callback methods. * @param cbParam Parameter to pass to callback methods. * @param callbacks The callbacks to set. * @return True when enabled, false otherwise. */ bool EnableCallbacks(void *cbParam, ICECCallbacks *callbacks) override { return _adapter->EnableCallbacks(cbParam, callbacks); } #endif /*! * @brief Changes the active HDMI port. * @param iBaseDevice The device to which this libCEC is connected. * @param iPort The new port number. * @return True when changed, false otherwise. */ bool SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort) override { return _adapter->SetHDMIPort(iBaseDevice, iPort); } /*! * @brief Get the physical address of the device with the given logical address. * @param iLogicalAddress The logical address of the device to get the physical address for. * @return The physical address or 0 if it wasn't found. */ uint16_t GetDevicePhysicalAddress(cec_logical_address iLogicalAddress) override { return _adapter->GetDevicePhysicalAddress(iLogicalAddress); } /*! * @return A string with information about how libCEC was compiled. */ const char *GetLibInfo(void) override { return _adapter->GetLibInfo(); } /*! * @brief Calling this method will initialise the host on which libCEC is running. * Calling this method will initialise the host on which libCEC is running. On the RPi, it calls * bcm_host_init(), which may only be called once per process, and is called by any process using * the video api on that system. So only call this method if libCEC is used in an application that * does not already initialise the video api. * * Should be called as first call to libCEC, directly after CECInitialise() and before using Open() */ void InitVideoStandalone(void) override { _adapter->InitVideoStandalone(); } /*! * @return The (virtual) USB vendor id */ uint16_t GetAdapterVendorId(void) const override { return _adapter->GetAdapterVendorId(); } /*! * @return The (virtual) USB product id */ uint16_t GetAdapterProductId(void) const override { return _adapter->GetAdapterProductId(); } const char* ToString(const cec_menu_state state) override { return _adapter->ToString(state); } const char* ToString(const cec_version version) override { return _adapter->ToString(version); } const char* ToString(const cec_power_status status) override { return _adapter->ToString(status); } const char* ToString(const cec_logical_address address) override { return _adapter->ToString(address); } const char* ToString(const cec_deck_control_mode mode) override { return _adapter->ToString(mode); } const char* ToString(const cec_deck_info status) override { return _adapter->ToString(status); } const char* ToString(const cec_opcode opcode) override { return _adapter->ToString(opcode); } const char* ToString(const cec_system_audio_status mode) override { return _adapter->ToString(mode); } const char* ToString(const cec_audio_status status) override { return _adapter->ToString(status); } const char* ToString(const cec_vendor_id vendor) override { return _adapter->VendorIdToString((uint32_t)vendor); } const char* ToString(const cec_device_type type) override { return _adapter->ToString(type); } const char* ToString(const cec_user_control_code key) override { return _adapter->ToString(key); } const char* ToString(const cec_adapter_type type) override { return _adapter->ToString(type); } std::string VersionToString(uint32_t version) override { return _adapter->VersionToString(version); } void PrintVersion(uint32_t version, char* buf, size_t bufSize) override { _adapter->PrintVersion(version, buf, bufSize); } const char* VendorIdToString(uint32_t vendor) override { return _adapter->VendorIdToString(vendor); } /*! * @brief Toggle the mute status of the AVR (if present) * @return The new audio status. */ uint8_t AudioToggleMute(void) override { return _adapter->AudioToggleMute(); } /*! * @brief Mute the AVR (if present) * @return The new audio status. */ uint8_t AudioMute(void) override { return _adapter->AudioMute(); } /*! * @brief Mute the AVR (if connected) * @return The new audio status. */ uint8_t AudioUnmute(void) override { return _adapter->AudioUnmute(); } /*! * @brief Get the current audio status (if an AVR is connected) * @return The current audio status, or cec_audio_status if unknown. */ uint8_t AudioStatus(void) override { return _adapter->AudioStatus(); } /*! * @brief Try to find all connected CEC adapters. * @param deviceList The vector to store device descriptors in. * @param iBufSize The size of the deviceList buffer. * @param strDevicePath Optional device path. Only adds device descriptors that match the given device path. * @param bQuickScan True to do a "quick scan", which will not open a connection to the adapter. Firmware version information and the exact device type will be missing * @return The number of devices that were found, or -1 when an error occurred. */ int8_t DetectAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath = nullptr, bool bQuickScan = false) override { return _adapter->DetectAdapters(deviceList, iBufSize, strDevicePath, bQuickScan); } /*! * Create a new cec_command from a string * @param strCommand The string with the command data * @return The command */ cec_command CommandFromString(const char* strCommand) override { return _adapter->CommandFromString(strCommand); } /** * Enable or disable system audio mode * @param enable True to enable, false to disable * @return True if the command was sent, false otherwise */ bool AudioEnable(bool enable) override { return _adapter->AudioEnable(enable); } #if CEC_LIB_VERSION_MAJOR >= 5 bool GetStats(struct cec_adapter_stats* stats) override { return _adapter->GetStats(stats); } #endif protected: /*! * @brief Open a connection to the CEC adapter. * @param strPort The path to the port. * @param iTimeoutMs Connection timeout in ms. * @return True when connected, false otherwise. */ bool Open(const char *strPort, uint32_t iTimeoutMs = 10000) override { return _adapter->Open(strPort, iTimeoutMs); } /*! * @brief Close the connection to the CEC adapter. */ void Close(void) override { _adapter->Close(); } char _portName[PATH_MAX]; ICECCallbacks _callbacks; ICECAdapter *_adapter; }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
#pragma once /* * This file is part of the libCEC(R) library. * * libCEC(R) is Copyright (C) 2011-2015 Pulse-Eight Limited. All rights reserved. * libCEC(R) is an original work, containing original code. * * libCEC(R) is a trademark of Pulse-Eight Limited. * * This program is dual-licensed; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * Alternatively, you can license this library under a commercial license, * please contact Pulse-Eight Licensing for more information. * * For more information contact: * Pulse-Eight Licensing <license@pulse-eight.com> * http://www.pulse-eight.com/ * http://www.pulse-eight.net/ */ #ifndef CECEXPORTS_H_ #define CECEXPORTS_H_ #include "cectypes.h" #include <string> namespace CEC { /*! * To create a new libCEC instance, call CECInitialise() and pass the * configuration as argument. Then call Open() to open a connection to the * adapter. Close() closes the connection and CECDestroy() cleans up the * libCEC instance. * * libCEC can send commands to other devices on the CEC bus via the methods * on this interface, and all commands that libCEC received are sent back * to the application via callback methods. The callback methods can be * found in cectypes.h, ICECCallbacks. */ class ICECAdapter { public: virtual ~ICECAdapter() {}; /*! @name Adapter methods */ //@{ /*! * @brief Open a connection to the CEC adapter. * @param strPort The path to the port. * @param iTimeoutMs Connection timeout in ms. * @return True when connected, false otherwise. */ virtual bool Open(const char *strPort, uint32_t iTimeoutMs = 10000) = 0; /*! * @brief Close the connection to the CEC adapter. */ virtual void Close(void) = 0; /*! * @brief Sends a ping command to the adapter, to check if it's responding. * @return True when the ping was successful, false otherwise. */ virtual bool PingAdapter(void) = 0; /*! * @brief Start the bootloader of the CEC adapter. Closes the connection when successful. * @return True when the command was sent successfully, false otherwise. */ virtual bool StartBootloader(void) = 0; //@} /*! * @brief Transmit a raw CEC command over the CEC line. * @param data The command to send. * @return True when the data was sent and acked, false otherwise. */ virtual bool Transmit(const cec_command &data) = 0; /*! * @brief Change the logical address on the CEC bus of the CEC adapter. libCEC automatically assigns a logical address, and this method is only available for debugging purposes. * @param iLogicalAddress The CEC adapter's new logical address. * @return True when the logical address was set successfully, false otherwise. */ virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1) = 0; /*! * @brief Change the physical address (HDMI port) of the CEC adapter. libCEC will try to autodetect the physical address when connecting. If it did, it's set in libcec_configuration. * @param iPhysicalAddress The CEC adapter's new physical address. * @brief True when the physical address was set successfully, false otherwise. */ virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS) = 0; /*! * @brief Power on the given CEC capable devices. If CECDEVICE_BROADCAST is used, then wakeDevice in libcec_configuration will be used. * @param address The logical address to power on. * @return True when the command was sent successfully, false otherwise. */ virtual bool PowerOnDevices(cec_logical_address address = CECDEVICE_TV) = 0; /*! * @brief Put the given CEC capable devices in standby mode. If CECDEVICE_BROADCAST is used, then standbyDevices in libcec_configuration will be used. * @brief address The logical address of the device to put in standby. * @return True when the command was sent successfully, false otherwise. */ virtual bool StandbyDevices(cec_logical_address address = CECDEVICE_BROADCAST) = 0; /*! * @brief Change the active source to a device type handled by libCEC. Use CEC_DEVICE_TYPE_RESERVED to make the default type used by libCEC active. * @param type The new active source. Leave empty to use the primary type * @return True when the command was sent successfully, false otherwise. */ virtual bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED) = 0; /*! * @brief Change the deck control mode, if this adapter is registered as playback or recording device. * @param mode The new control mode. * @param bSendUpdate True to send the new status over the CEC line. * @return True if set, false otherwise. */ virtual bool SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate = true) = 0; /*! * @brief Change the deck info, if this adapter is a playback or recording device. * @param info The new deck info. * @param bSendUpdate True to send the new status over the CEC line. * @return True if set, false otherwise. */ virtual bool SetDeckInfo(cec_deck_info info, bool bSendUpdate = true) = 0; /*! * @brief Broadcast a message that notifies connected CEC capable devices that this device is no longer the active source. * @return True when the command was sent successfully, false otherwise. */ virtual bool SetInactiveView(void) = 0; /*! * @brief Change the menu state. This value is already changed by libCEC automatically if a device is (de)activated. * @param state The new state. * @param bSendUpdate True to send the new status over the CEC line. * @return True if set, false otherwise. */ virtual bool SetMenuState(cec_menu_state state, bool bSendUpdate = true) = 0; /*! * @brief Display a message on the device with the given logical address. Not supported by most TVs. * @param iLogicalAddress The logical address of the device to display the message on. * @param duration The duration of the message * @param strMessage The message to display. * @return True when the command was sent, false otherwise. */ virtual bool SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage) = 0; /*! * @brief Enable or disable monitoring mode, for debugging purposes. If monitoring mode is enabled, libCEC won't respond to any command, but only log incoming data. * @param bEnable True to enable, false to disable. * @return True when switched successfully, false otherwise. */ virtual bool SwitchMonitoring(bool bEnable) = 0; /*! * @brief Get the CEC version of the device with the given logical address * @param iLogicalAddress The logical address of the device to get the CEC version for. * @return The version or CEC_VERSION_UNKNOWN when the version couldn't be fetched. */ virtual cec_version GetDeviceCecVersion(cec_logical_address iLogicalAddress) = 0; /*! * @brief Get the menu language of the device with the given logical address * @param iLogicalAddress The logical address of the device to get the menu language for. * @return The requested menu language, or '???' if unknown */ virtual std::string GetDeviceMenuLanguage(cec_logical_address iLogicalAddress) = 0; /*! * @brief Get the vendor ID of the device with the given logical address. * @param iLogicalAddress The logical address of the device to get the vendor ID for. * @return The vendor ID or 0 if it wasn't found. */ virtual uint32_t GetDeviceVendorId(cec_logical_address iLogicalAddress) = 0; /*! * @brief Get the power status of the device with the given logical address. * @param iLogicalAddress The logical address of the device to get the power status for. * @return The power status or CEC_POWER_STATUS_UNKNOWN if it wasn't found. */ virtual cec_power_status GetDevicePowerStatus(cec_logical_address iLogicalAddress) = 0; /*! * @brief Sends a POLL message to a device, to check if it's present and responding. * @param iLogicalAddress The device to send the message to. * @return True if the POLL was acked, false otherwise. */ virtual bool PollDevice(cec_logical_address iLogicalAddress) = 0; /*! * @return The logical addresses of the devices that are active on the bus, including those handled by libCEC. */ virtual cec_logical_addresses GetActiveDevices(void) = 0; /*! * @brief Check whether a device is active on the bus. * @param iLogicalAddress The address to check. * @return True when active, false otherwise. */ virtual bool IsActiveDevice(cec_logical_address iLogicalAddress) = 0; /*! * @brief Check whether a device of the given type is active on the bus. * @param type The type to check. * @return True when active, false otherwise. */ virtual bool IsActiveDeviceType(cec_device_type type) = 0; /*! * @brief Sends a volume up keypress to an audiosystem if it's present. * @param bSendRelease Send a key release after the keypress. * @return The new audio status. */ virtual uint8_t VolumeUp(bool bSendRelease = true) = 0; /*! * @brief Sends a volume down keypress to an audiosystem if it's present. * @param bSendRelease Send a key release after the keypress. * @return The new audio status. */ virtual uint8_t VolumeDown(bool bSendRelease = true) = 0; #if CEC_LIB_VERSION_MAJOR >= 5 /*! * @brief Toggles the mute status of an audiosystem, if it's present * @return The new audio status. */ virtual uint8_t MuteAudio(void) = 0; #endif /*! * @brief Send a keypress to a device on the CEC bus. * @param iDestination The logical address of the device to send the message to. * @param key The key to send. * @param bWait True to wait for a response, false otherwise. * @return True when the keypress was acked, false otherwise. */ virtual bool SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait = false) = 0; /*! * @brief Send a key release to a device on the CEC bus. * @param iDestination The logical address of the device to send the message to. * @param bWait True to wait for a response, false otherwise. * @return True when the key release was acked, false otherwise. */ virtual bool SendKeyRelease(cec_logical_address iDestination, bool bWait = false) = 0; /*! * @brief Get the OSD name of a device on the CEC bus. * @param iLogicalAddress The device to get the OSD name for. * @return The requested OSD name, or an empty string if unknown */ virtual std::string GetDeviceOSDName(cec_logical_address iAddress) = 0; /*! * @brief Get the logical address of the device that is currently the active source on the CEC bus. * @return The active source or CECDEVICE_UNKNOWN when unknown. */ virtual cec_logical_address GetActiveSource(void) = 0; /*! * @brief Check whether a device is currently the active source on the CEC bus. * @param iLogicalAddress The logical address of the device to check. * @return True when it is the active source, false otherwise. */ virtual bool IsActiveSource(cec_logical_address iLogicalAddress) = 0; /*! * @brief Sets the stream path to the device on the given logical address. * @param iLogicalAddress The address to activate. * @return True when the command was sent, false otherwise. */ virtual bool SetStreamPath(cec_logical_address iLogicalAddress) = 0; /*! * @brief Sets the stream path to the device on the given physical address. * @param iPhysicalAddress The address to activate. * @return True when the command was sent, false otherwise. */ virtual bool SetStreamPath(uint16_t iPhysicalAddress) = 0; /*! * @return The list of logical addresses that libCEC is controlling */ virtual cec_logical_addresses GetLogicalAddresses(void) = 0; /*! * @brief Get libCEC's current configuration. * @param configuration The configuration. * @return True when the configuration was updated, false otherwise. */ virtual bool GetCurrentConfiguration(libcec_configuration *configuration) = 0; /*! * @brief Change libCEC's configuration. Store it updated settings in the eeprom of the device (if supported) * @param configuration The new configuration. * @return True when the configuration was changed successfully, false otherwise. */ virtual bool SetConfiguration(const libcec_configuration *configuration) = 0; /*! * @return True if this CEC adapter can save the user configuration, false otherwise. */ #if CEC_LIB_VERSION_MAJOR >= 5 virtual bool CanSaveConfiguration(void) = 0; #else virtual bool CanPersistConfiguration(void) = 0; /*! * @deprecated Use SetConfiguration() instead * @brief Change libCEC's configuration. Store it updated settings in the eeprom of the device (if supported) * @brief configuration The configuration to store. * @return True when the configuration was persisted, false otherwise. */ virtual bool PersistConfiguration(libcec_configuration *configuration) = 0; #endif /*! * @brief Tell libCEC to poll for active devices on the bus. */ virtual void RescanActiveDevices(void) = 0; /*! * @return true when libCEC is the active source on the bus, false otherwise. */ virtual bool IsLibCECActiveSource(void) = 0; /*! * @brief Get information about the given CEC adapter. * @param strPort The port to which the device is connected * @param config The device configuration * @param iTimeoutMs The timeout in milliseconds * @return True when the device was found, false otherwise */ virtual bool GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs = 10000) = 0; #if CEC_LIB_VERSION_MAJOR >= 5 /*! * @brief Set and enable the callback methods * @param callbacks The callbacks to set. * @param cbParam Parameter to pass to callback methods. * @return True if enabled, false otherwise. */ virtual bool SetCallbacks(ICECCallbacks *callbacks, void *cbParam) = 0; /*! * @brief Disable all callbacks * @return True if disabled, false otherwise. */ virtual bool DisableCallbacks(void) = 0; #else /*! * @deprecated * @brief Set and enable the callback methods. * @param cbParam Parameter to pass to callback methods. * @param callbacks The callbacks to set. * @return True when enabled, false otherwise. */ virtual bool EnableCallbacks(void *cbParam, ICECCallbacks *callbacks) = 0; #endif /*! * @brief Changes the active HDMI port. * @param iBaseDevice The device to which this libCEC is connected. * @param iPort The new port number. * @return True when changed, false otherwise. */ virtual bool SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort) = 0; /*! * @brief Get the physical address of the device with the given logical address. * @param iLogicalAddress The logical address of the device to get the physical address for. * @return The physical address or 0 if it wasn't found. */ virtual uint16_t GetDevicePhysicalAddress(cec_logical_address iLogicalAddress) = 0; /*! * @return A string with information about how libCEC was compiled. */ virtual const char *GetLibInfo(void) = 0; /*! * @brief Calling this method will initialise the host on which libCEC is running. * Calling this method will initialise the host on which libCEC is running. On the RPi, it calls * bcm_host_init(), which may only be called once per process, and is called by any process using * the video api on that system. So only call this method if libCEC is used in an application that * does not already initialise the video api. * * Should be called as first call to libCEC, directly after CECInitialise() and before using Open() */ virtual void InitVideoStandalone(void) = 0; /*! * @return The (virtual) USB vendor id */ virtual uint16_t GetAdapterVendorId(void) const = 0; /*! * @return The (virtual) USB product id */ virtual uint16_t GetAdapterProductId(void) const = 0; virtual const char* ToString(const cec_menu_state state) = 0; virtual const char* ToString(const cec_version version) = 0; virtual const char* ToString(const cec_power_status status) = 0; virtual const char* ToString(const cec_logical_address address) = 0; virtual const char* ToString(const cec_deck_control_mode mode) = 0; virtual const char* ToString(const cec_deck_info status) = 0; virtual const char* ToString(const cec_opcode opcode) = 0; virtual const char* ToString(const cec_system_audio_status mode) = 0; virtual const char* ToString(const cec_audio_status status) = 0; virtual const char* ToString(const cec_vendor_id vendor) { return VendorIdToString((uint32_t)vendor); } virtual const char* ToString(const cec_device_type type) = 0; virtual const char* ToString(const cec_user_control_code key) = 0; virtual const char* ToString(const cec_adapter_type type) = 0; virtual std::string VersionToString(uint32_t version) = 0; virtual void PrintVersion(uint32_t version, char* buf, size_t bufSize) = 0; virtual const char* VendorIdToString(uint32_t vendor) = 0; /*! * @brief Toggle the mute status of the AVR (if present) * @return The new audio status. */ virtual uint8_t AudioToggleMute(void) = 0; /*! * @brief Mute the AVR (if present) * @return The new audio status. */ virtual uint8_t AudioMute(void) = 0; /*! * @brief Mute the AVR (if connected) * @return The new audio status. */ virtual uint8_t AudioUnmute(void) = 0; /*! * @brief Get the current audio status (if an AVR is connected) * @return The current audio status, or cec_audio_status if unknown. */ virtual uint8_t AudioStatus(void) = 0; /*! * @brief Try to find all connected CEC adapters. * @param deviceList The vector to store device descriptors in. * @param iBufSize The size of the deviceList buffer. * @param strDevicePath Optional device path. Only adds device descriptors that match the given device path. * @param bQuickScan True to do a "quick scan", which will not open a connection to the adapter. Firmware version information and the exact device type will be missing * @return The number of devices that were found, or -1 when an error occurred. */ virtual int8_t DetectAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath = nullptr, bool bQuickScan = false) = 0; /*! * Create a new cec_command from a string * @param strCommand The string with the command data * @return The command */ virtual cec_command CommandFromString(const char* strCommand) = 0; /** * Enable or disable system audio mode * @param enable True to enable, false to disable * @return True if the command was sent, false otherwise */ virtual bool AudioEnable(bool enable) = 0; #if CEC_LIB_VERSION_MAJOR >= 5 virtual bool GetStats(struct cec_adapter_stats* stats) = 0; #endif }; }; /*! * @brief Unload the CEC adapter library. */ extern "C" DECLSPEC void CECDestroy(CEC::ICECAdapter *instance); /*! * @brief Load the CEC adapter library. * @param configuration The configuration to pass to libCEC * @return An instance of ICECAdapter or nullptr on error. */ extern "C" DECLSPEC CEC::ICECAdapter* CECInitialise(CEC::libcec_configuration *configuration); /*! * @brief Try to connect to the adapter and send the "start bootloader" command, without initialising libCEC and going through all checks * @return True when the command was send, false otherwise. */ extern "C" DECLSPEC bool CECStartBootloader(void); #endif /* CECEXPORTS_H_ */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
#pragma once /* * This file is part of the libCEC(R) library. * * libCEC(R) is Copyright (C) 2011-2015 Pulse-Eight Limited. All rights reserved. * libCEC(R) is an original work, containing original code. * * libCEC(R) is a trademark of Pulse-Eight Limited. * * This program is dual-licensed; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * Alternatively, you can license this library under a commercial license, * please contact Pulse-Eight Licensing for more information. * * For more information contact: * Pulse-Eight Licensing <license@pulse-eight.com> * http://www.pulse-eight.com/ * http://www.pulse-eight.net/ */ #if defined(_WIN32) || defined(_WIN64) #include <windows.h> #include <conio.h> HINSTANCE g_libCEC = NULL; /*! * @brief Create a new libCEC instance. * @param configuration The configuration to pass to libCEC * @param strLib The name of and/or path to libCEC * @return An instance of ICECAdapter or NULL on error. */ CEC::ICECAdapter *LibCecInitialise(CEC::libcec_configuration *configuration, const char *strLib = NULL) { if (!g_libCEC) g_libCEC = LoadLibrary(strLib ? strLib : "cec.dll"); if (!g_libCEC) return NULL; typedef void* (__cdecl*_LibCecInitialise)(CEC::libcec_configuration *); _LibCecInitialise LibCecInitialise; LibCecInitialise = (_LibCecInitialise) (GetProcAddress(g_libCEC, "CECInitialise")); if (!LibCecInitialise) { std::cout << "cannot find CECInitialise" << std::endl; return NULL; } return static_cast< CEC::ICECAdapter* > (LibCecInitialise(configuration)); } /*! * @brief Destroy an instance of libCEC. * @param device The instance to destroy. */ void UnloadLibCec(CEC::ICECAdapter *device) { typedef void (__cdecl*_DestroyLibCec)(void * device); _DestroyLibCec DestroyLibCec; DestroyLibCec = (_DestroyLibCec) (GetProcAddress(g_libCEC, "CECDestroy")); if (DestroyLibCec) DestroyLibCec(device); FreeLibrary(g_libCEC); g_libCEC = NULL; } /*! * @brief Start the bootloader on the first device that was detected. * @param strLib The name of and/or path to libCEC * @return True when the command was sent, false otherwise. */ bool LibCecBootloader(const char *strLib = NULL) { if (!g_libCEC) g_libCEC = LoadLibrary(strLib ? strLib : "cec.dll"); if (!g_libCEC) return NULL; typedef bool (__cdecl*_LibCecBootloader)(void); _LibCecBootloader LibCecBootloader; LibCecBootloader = (_LibCecBootloader) (GetProcAddress(g_libCEC, "CECStartBootloader")); if (!LibCecBootloader) return false; bool bReturn = LibCecBootloader(); FreeLibrary(g_libCEC); g_libCEC = NULL; return bReturn; } #else #include <dlfcn.h> void *g_libCEC = NULL; /*! * @brief Create a new libCEC instance. * @param configuration The configuration to pass to libCEC * @param strLib The name of and/or path to libCEC * @return An instance of ICECAdapter or NULL on error. */ CEC::ICECAdapter *LibCecInitialise(CEC::libcec_configuration *configuration, const char *strLib = NULL) { if (!g_libCEC) { #if defined(__APPLE__) g_libCEC = dlopen(strLib ? strLib : "libcec." CEC_LIB_VERSION_MAJOR_STR ".dylib", RTLD_LAZY); #else g_libCEC = dlopen(strLib ? strLib : "libcec.so." CEC_LIB_VERSION_MAJOR_STR, RTLD_LAZY); #endif if (!g_libCEC) { std::cout << dlerror() << std::endl; return NULL; } } typedef void* _LibCecInitialise(CEC::libcec_configuration *); _LibCecInitialise* LibCecInitialise = (_LibCecInitialise*) dlsym(g_libCEC, "CECInitialise"); if (!LibCecInitialise) { std::cout << "cannot find CECInitialise" << std::endl; return NULL; } return (CEC::ICECAdapter*) LibCecInitialise(configuration); } /*! * @brief Destroy an instance of libCEC. * @param device The instance to destroy. */ void UnloadLibCec(CEC::ICECAdapter *device) { typedef void* _DestroyLibCec(CEC::ICECAdapter *); _DestroyLibCec *DestroyLibCec = (_DestroyLibCec*) dlsym(g_libCEC, "CECDestroy"); if (DestroyLibCec) DestroyLibCec(device); dlclose(g_libCEC); } /*! * @brief Start the bootloader on the first device that was detected. * @param strLib The name of and/or path to libCEC * @return True when the command was sent, false otherwise. */ bool LibCecBootloader(const char *strLib = NULL) { if (!g_libCEC) { #if defined(__APPLE__) g_libCEC = dlopen(strLib ? strLib : "libcec.dylib", RTLD_LAZY); #else g_libCEC = dlopen(strLib ? strLib : "libcec.so." CEC_LIB_VERSION_MAJOR_STR, RTLD_LAZY); #endif if (!g_libCEC) { std::cout << dlerror() << std::endl; return NULL; } } typedef bool _LibCecBootloader(void); _LibCecBootloader* LibCecBootloader = (_LibCecBootloader*) dlsym(g_libCEC, "CECStartBootloader"); if (!LibCecBootloader) { std::cout << "cannot find CECStartBootloader" << std::endl; return NULL; } bool bReturn = LibCecBootloader(); dlclose(g_libCEC); return bReturn; } #endif |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 |
#pragma once /* * This file is part of the libCEC(R) library. * * libCEC(R) is Copyright (C) 2011-2015 Pulse-Eight Limited. All rights reserved. * libCEC(R) is an original work, containing original code. * * libCEC(R) is a trademark of Pulse-Eight Limited. * * This program is dual-licensed; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * Alternatively, you can license this library under a commercial license, * please contact Pulse-Eight Licensing for more information. * * For more information contact: * Pulse-Eight Licensing <license@pulse-eight.com> * http://www.pulse-eight.com/ * http://www.pulse-eight.net/ */ #ifndef CECTYPES_H_ #define CECTYPES_H_ #include "version.h" #include <stdint.h> #include <string.h> #if defined(_WIN32) || defined(_WIN64) #define CEC_CDECL __cdecl #else #define CEC_CDECL #endif #if !defined(DECLSPEC) #if defined(_WIN32) || defined(_WIN64) #include <windows.h> #if defined DLL_EXPORT #define DECLSPEC __declspec(dllexport) #else #define DECLSPEC __declspec(dllimport) #endif #else #define DECLSPEC #endif #endif #ifdef __cplusplus #include <string> extern "C" { namespace CEC { #endif /*! * default physical address 1.0.0.0, HDMI port 1 */ #define CEC_DEFAULT_PHYSICAL_ADDRESS 0x1000 /*! * default HDMI port to which the adapter is connected, port 1 */ #define CEC_DEFAULT_HDMI_PORT 1 /*! * default logical address of the device to which the adapter is connected, TV */ #define CEC_DEFAULT_BASE_DEVICE 0 /*! * timeout in milliseconds to send a key release event after receiving a key press */ #define CEC_BUTTON_TIMEOUT 500 /*! * don't send the same key twice within this timeout in milliseconds */ #define CEC_DOUBLE_TAP_TIMEOUT_MS 200 /*! * don't query the power state for the same device within this timeout in milliseconds */ #define CEC_POWER_STATE_REFRESH_TIME 30000 /*! * unknown firmware version value */ #define CEC_FW_VERSION_UNKNOWN 0xFFFF /*! * unknown build date value */ #define CEC_FW_BUILD_UNKNOWN 0 /*! * maximum number of retries when opening a connection */ #define CEC_CONNECT_TRIES 3 /*! * physical address of the TV */ #define CEC_PHYSICAL_ADDRESS_TV 0 /*! * minimum physical address for the adapter */ #define CEC_MIN_PHYSICAL_ADDRESS 0x1000 /*! * maximum physical address for the adapter */ #define CEC_MAX_PHYSICAL_ADDRESS 0xFFFE /*! * invalid physical address value */ #define CEC_INVALID_PHYSICAL_ADDRESS 0xFFFF /*! * minimum vendor ID value */ #define CEC_MIN_VENDORID 1 /*! * maximum vendor ID value */ #define CEC_MAX_VENDORID 0xFFFFFE /*! * invalid vendor ID value */ #define CEC_INVALID_VENDORID 0xFFFFFF /*! * minimum HDMI port number value */ #define CEC_MIN_HDMI_PORTNUMBER 1 /*! * maximum HDMI port number value */ #define CEC_MAX_HDMI_PORTNUMBER 15 /*! * invalid HDMI port number value */ #define CEC_HDMI_PORTNUMBER_NONE 0 /*! * default value for settings "activate source" */ #define CEC_DEFAULT_SETTING_ACTIVATE_SOURCE 1 /*! * default value for settings "power off on shutdown" */ #define CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN 1 /*! * default value for settings "power off on standby" */ #define CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY 1 /*! * default value for settings "device menu language" */ #define CEC_DEFAULT_DEVICE_LANGUAGE "eng" /*! * default value for settings "autodetect physical address" */ #define CEC_DEFAULT_SETTING_AUTODETECT_ADDRESS 0 /*! * default value for settings "get settings from ROM" */ #define CEC_DEFAULT_SETTING_GET_SETTINGS_FROM_ROM 0 /*! * default value for settings "libCEC CEC version" */ #define CEC_DEFAULT_SETTING_CEC_VERSION 0x05 /*! * wait this amount of milliseconds before retrying to send a failed message */ #define CEC_DEFAULT_TRANSMIT_RETRY_WAIT 500 /*! * transmission fails when not acked within this amount of milliseconds after sending the initial packet */ #define CEC_DEFAULT_TRANSMIT_TIMEOUT 1000 /*! * wait this amount of milliseconds for an ack */ #define CEC_DEFAULT_TRANSMIT_WAIT 1000 /*! * default number of retries */ #define CEC_DEFAULT_TRANSMIT_RETRIES 1 /*! * default connection timeout in milliseconds */ #define CEC_DEFAULT_CONNECT_TIMEOUT 10000 /*! * wait this amount of milliseconds before retrying when failing to connect */ #define CEC_DEFAULT_CONNECT_RETRY_WAIT 1000 /*! * default serial baudrate */ #define CEC_SERIAL_DEFAULT_BAUDRATE 38400 /*! * maximum time to wait when clearing input */ #define CEC_CLEAR_INPUT_DEFAULT_WAIT 1000 /*! * wait this amount of milliseconds before retrying when libCEC failed to make itself the active source */ #define CEC_ACTIVE_SOURCE_SWITCH_RETRY_TIME_MS 1000 /*! * don't forward any power off command to the client application for this amount of milliseconds after sending a power off command */ #define CEC_FORWARD_STANDBY_MIN_INTERVAL 10000 /*! * default timeout in milliseconds for combo keys */ #define CEC_DEFAULT_COMBO_TIMEOUT_MS 1000 /*! * the virtual device path to use for the Raspberry Pi's CEC wire */ #define CEC_RPI_VIRTUAL_PATH "Raspberry Pi" /*! * the name of the virtual COM port to use for the Raspberry Pi's CEC wire */ #define CEC_RPI_VIRTUAL_COM "RPI" /*! * the path to use for the TDA995x's CEC wire */ #define CEC_TDA995x_PATH "/dev/hdmicec" /*! * the name of the virtual COM port to use for the TDA995x's CEC wire */ #define CEC_TDA995x_VIRTUAL_COM "CuBox" /*! * the path to use for the Exynos HDMI CEC device */ #define CEC_EXYNOS_PATH "/dev/CEC" /*! * the name of the virtual COM port to use for the EXYNOS' CEC wire */ #define CEC_EXYNOS_VIRTUAL_COM "Exynos" /** * Maximum size of a data packet */ #define CEC_MAX_DATA_PACKET_SIZE (16 * 4) /*! * the path to use for the Linux CEC device */ #define CEC_LINUX_PATH "/dev/cec0" /*! * the name of the virtual COM port to use for the Linux' CEC wire */ #define CEC_LINUX_VIRTUAL_COM "Linux" /*! * the path to use for the AOCEC HDMI CEC device */ #define CEC_AOCEC_PATH "/dev/aocec" /*! * the name of the virtual COM port to use for the AOCEC' CEC wire */ #define CEC_AOCEC_VIRTUAL_COM "AOCEC" /*! * the path to use for the i.MX CEC wire */ #define CEC_IMX_PATH "/dev/mxc_hdmi_cec" /*! * the name of the virtual COM port to use for the i.MX CEC wire */ #define CEC_IMX_VIRTUAL_COM "i.MX" /*! * Mimimum client version */ #define CEC_MIN_LIB_VERSION 4 #define MSGSTART 0xFF #define MSGEND 0xFE #define MSGESC 0xFD #define ESCOFFSET 3 #define DOUBLE_TAP_TIMEOUT_UNIT_SIZE (50) // defines to make compile time checks for certain features easy #define CEC_FEATURE_CONFIGURABLE_COMBO_KEY 1 typedef enum cec_abort_reason { CEC_ABORT_REASON_UNRECOGNIZED_OPCODE = 0,//!< CEC_ABORT_REASON_UNRECOGNIZED_OPCODE CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND = 1,//!< CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND CEC_ABORT_REASON_CANNOT_PROVIDE_SOURCE = 2,//!< CEC_ABORT_REASON_CANNOT_PROVIDE_SOURCE CEC_ABORT_REASON_INVALID_OPERAND = 3,//!< CEC_ABORT_REASON_INVALID_OPERAND CEC_ABORT_REASON_REFUSED = 4 //!< CEC_ABORT_REASON_REFUSED } cec_abort_reason; typedef enum cec_analogue_broadcast_type { CEC_ANALOGUE_BROADCAST_TYPE_CABLE = 0x00, CEC_ANALOGUE_BROADCAST_TYPE_SATELLITE = 0x01, CEC_ANALOGUE_BROADCAST_TYPE_TERRESTIAL = 0x02 } cec_analogue_broadcast_type; typedef enum cec_audio_rate { CEC_AUDIO_RATE_RATE_CONTROL_OFF = 0, CEC_AUDIO_RATE_STANDARD_RATE_100 = 1, CEC_AUDIO_RATE_FAST_RATE_MAX_101 = 2, CEC_AUDIO_RATE_SLOW_RATE_MIN_99 = 3, CEC_AUDIO_RATE_STANDARD_RATE_100_0 = 4, CEC_AUDIO_RATE_FAST_RATE_MAX_100_1 = 5, CEC_AUDIO_RATE_SLOW_RATE_MIN_99_9 = 6 } cec_audio_rate; typedef enum cec_audio_status { CEC_AUDIO_MUTE_STATUS_MASK = 0x80, CEC_AUDIO_VOLUME_STATUS_MASK = 0x7F, CEC_AUDIO_VOLUME_MIN = 0x00, CEC_AUDIO_VOLUME_MAX = 0x64, CEC_AUDIO_VOLUME_STATUS_UNKNOWN = 0x7F } cec_audio_status; typedef enum cec_boolean { CEC_FALSE = 0, CEC_TRUE = 1 } cec_boolean; typedef enum cec_version { CEC_VERSION_UNKNOWN = 0x00, CEC_VERSION_1_2 = 0x01, CEC_VERSION_1_2A = 0x02, CEC_VERSION_1_3 = 0x03, CEC_VERSION_1_3A = 0x04, CEC_VERSION_1_4 = 0x05, CEC_VERSION_2_0 = 0x06, } cec_version; typedef enum cec_channel_identifier { CEC_CHANNEL_NUMBER_FORMAT_MASK = 0xFC000000, CEC_1_PART_CHANNEL_NUMBER = 0x04000000, CEC_2_PART_CHANNEL_NUMBER = 0x08000000, CEC_MAJOR_CHANNEL_NUMBER_MASK = 0x3FF0000, CEC_MINOR_CHANNEL_NUMBER_MASK = 0xFFFF } cec_channel_identifier; typedef enum cec_deck_control_mode { CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND = 1, CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND = 2, CEC_DECK_CONTROL_MODE_STOP = 3, CEC_DECK_CONTROL_MODE_EJECT = 4 } cec_deck_control_mode; typedef enum cec_deck_info { CEC_DECK_INFO_PLAY = 0x11, CEC_DECK_INFO_RECORD = 0x12, CEC_DECK_INFO_PLAY_REVERSE = 0x13, CEC_DECK_INFO_STILL = 0x14, CEC_DECK_INFO_SLOW = 0x15, CEC_DECK_INFO_SLOW_REVERSE = 0x16, CEC_DECK_INFO_FAST_FORWARD = 0x17, CEC_DECK_INFO_FAST_REVERSE = 0x18, CEC_DECK_INFO_NO_MEDIA = 0x19, CEC_DECK_INFO_STOP = 0x1A, CEC_DECK_INFO_SKIP_FORWARD_WIND = 0x1B, CEC_DECK_INFO_SKIP_REVERSE_REWIND = 0x1C, CEC_DECK_INFO_INDEX_SEARCH_FORWARD = 0x1D, CEC_DECK_INFO_INDEX_SEARCH_REVERSE = 0x1E, CEC_DECK_INFO_OTHER_STATUS = 0x1F, CEC_DECK_INFO_OTHER_STATUS_LG = 0x20 } cec_deck_info; typedef enum cec_device_type { CEC_DEVICE_TYPE_TV = 0, CEC_DEVICE_TYPE_RECORDING_DEVICE = 1, CEC_DEVICE_TYPE_RESERVED = 2, CEC_DEVICE_TYPE_TUNER = 3, CEC_DEVICE_TYPE_PLAYBACK_DEVICE = 4, CEC_DEVICE_TYPE_AUDIO_SYSTEM = 5 } cec_device_type; typedef enum cec_display_control { CEC_DISPLAY_CONTROL_DISPLAY_FOR_DEFAULT_TIME = 0x00, CEC_DISPLAY_CONTROL_DISPLAY_UNTIL_CLEARED = 0x40, CEC_DISPLAY_CONTROL_CLEAR_PREVIOUS_MESSAGE = 0x80, CEC_DISPLAY_CONTROL_RESERVED_FOR_FUTURE_USE = 0xC0 } cec_display_control; typedef enum cec_external_source_specifier { CEC_EXTERNAL_SOURCE_SPECIFIER_EXTERNAL_PLUG = 4, CEC_EXTERNAL_SOURCE_SPECIFIER_EXTERNAL_PHYSICAL_ADDRESS = 5 } cec_external_source_specifier; typedef enum cec_menu_request_type { CEC_MENU_REQUEST_TYPE_ACTIVATE = 0, CEC_MENU_REQUEST_TYPE_DEACTIVATE = 1, CEC_MENU_REQUEST_TYPE_QUERY = 2 } cec_menu_request_type; typedef enum cec_menu_state { CEC_MENU_STATE_ACTIVATED = 0, CEC_MENU_STATE_DEACTIVATED = 1 } cec_menu_state; typedef enum cec_play_mode { CEC_PLAY_MODE_PLAY_FORWARD = 0x24, CEC_PLAY_MODE_PLAY_REVERSE = 0x20, CEC_PLAY_MODE_PLAY_STILL = 0x25, CEC_PLAY_MODE_FAST_FORWARD_MIN_SPEED = 0x05, CEC_PLAY_MODE_FAST_FORWARD_MEDIUM_SPEED = 0x06, CEC_PLAY_MODE_FAST_FORWARD_MAX_SPEED = 0x07, CEC_PLAY_MODE_FAST_REVERSE_MIN_SPEED = 0x09, CEC_PLAY_MODE_FAST_REVERSE_MEDIUM_SPEED = 0x0A, CEC_PLAY_MODE_FAST_REVERSE_MAX_SPEED = 0x0B, CEC_PLAY_MODE_SLOW_FORWARD_MIN_SPEED = 0x15, CEC_PLAY_MODE_SLOW_FORWARD_MEDIUM_SPEED = 0x16, CEC_PLAY_MODE_SLOW_FORWARD_MAX_SPEED = 0x17, CEC_PLAY_MODE_SLOW_REVERSE_MIN_SPEED = 0x19, CEC_PLAY_MODE_SLOW_REVERSE_MEDIUM_SPEED = 0x1A, CEC_PLAY_MODE_SLOW_REVERSE_MAX_SPEED = 0x1B } cec_play_mode; typedef enum cec_power_status { CEC_POWER_STATUS_ON = 0x00, CEC_POWER_STATUS_STANDBY = 0x01, CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON = 0x02, CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY = 0x03, CEC_POWER_STATUS_UNKNOWN = 0x99 } cec_power_status; typedef enum cec_record_source_type { CEC_RECORD_SOURCE_TYPE_OWN_SOURCE = 1, CEC_RECORD_SOURCE_TYPE_DIGITAL_SERVICE = 2, CEC_RECORD_SOURCE_TYPE_ANALOGUE_SERVICE = 3, CEC_RECORD_SOURCE_TYPE_EXTERNAL_PLUS = 4, CEC_RECORD_SOURCE_TYPE_EXTERNAL_PHYSICAL_ADDRESS = 5 } cec_record_source_type; typedef enum cec_record_status_info { CEC_RECORD_STATUS_INFO_RECORDING_CURRENTLY_SELECTED_SOURCE = 0x01, CEC_RECORD_STATUS_INFO_RECORDING_DIGITAL_SERVICE = 0x02, CEC_RECORD_STATUS_INFO_RECORDING_ANALOGUE_SERVICE = 0x03, CEC_RECORD_STATUS_INFO_RECORDING_EXTERNAL_INPUT = 0x04, CEC_RECORD_STATUS_INFO_NO_RECORDING_UNABLE_TO_RECORD_DIGITAL_SERVICE = 0x05, CEC_RECORD_STATUS_INFO_NO_RECORDING_UNABLE_TO_RECORD_ANALOGUE_SERVICE = 0x06, CEC_RECORD_STATUS_INFO_NO_RECORDING_UNABLE_TO_SELECT_REQUIRED_SERVICE = 0x07, CEC_RECORD_STATUS_INFO_NO_RECORDING_INVALID_EXTERNAL_PLUG_NUMBER = 0x09, CEC_RECORD_STATUS_INFO_NO_RECORDING_INVALID_EXTERNAL_ADDRESS = 0x0A, CEC_RECORD_STATUS_INFO_NO_RECORDING_CA_SYSTEM_NOT_SUPPORTED = 0x0B, CEC_RECORD_STATUS_INFO_NO_RECORDING_NO_OR_INSUFFICIENT_ENTITLEMENTS = 0x0C, CEC_RECORD_STATUS_INFO_NO_RECORDING_NOT_ALLOWED_TO_COPY_SOURCE = 0x0D, CEC_RECORD_STATUS_INFO_NO_RECORDING_NO_FURTHER_COPIES_ALLOWED = 0x0E, CEC_RECORD_STATUS_INFO_NO_RECORDING_NO_MEDIA = 0x10, CEC_RECORD_STATUS_INFO_NO_RECORDING_PLAYING = 0x11, CEC_RECORD_STATUS_INFO_NO_RECORDING_ALREADY_RECORDING = 0x12, CEC_RECORD_STATUS_INFO_NO_RECORDING_MEDIA_PROTECTED = 0x13, CEC_RECORD_STATUS_INFO_NO_RECORDING_NO_SOURCE_SIGNAL = 0x14, CEC_RECORD_STATUS_INFO_NO_RECORDING_MEDIA_PROBLEM = 0x15, CEC_RECORD_STATUS_INFO_NO_RECORDING_NOT_ENOUGH_SPACE_AVAILABLE = 0x16, CEC_RECORD_STATUS_INFO_NO_RECORDING_PARENTAL_LOCK_ON = 0x17, CEC_RECORD_STATUS_INFO_RECORDING_TERMINATED_NORMALLY = 0x1A, CEC_RECORD_STATUS_INFO_RECORDING_HAS_ALREADY_TERMINATED = 0x1B, CEC_RECORD_STATUS_INFO_NO_RECORDING_OTHER_REASON = 0x1F } cec_record_status_info; typedef enum cec_recording_sequence { CEC_RECORDING_SEQUENCE_SUNDAY = 0x01, CEC_RECORDING_SEQUENCE_MONDAY = 0x02, CEC_RECORDING_SEQUENCE_TUESDAY = 0x04, CEC_RECORDING_SEQUENCE_WEDNESDAY = 0x08, CEC_RECORDING_SEQUENCE_THURSDAY = 0x10, CEC_RECORDING_SEQUENCE_FRIDAY = 0x20, CEC_RECORDING_SEQUENCE_SATURDAY = 0x40, CEC_RECORDING_SEQUENCE_ONCE_ONLY = 0x00 } cec_recording_sequence; typedef enum cec_status_request { CEC_STATUS_REQUEST_ON = 1, CEC_STATUS_REQUEST_OFF = 2, CEC_STATUS_REQUEST_ONCE = 3 } cec_status_request; typedef enum cec_system_audio_status { CEC_SYSTEM_AUDIO_STATUS_OFF = 0, CEC_SYSTEM_AUDIO_STATUS_ON = 1 } cec_system_audio_status; typedef enum cec_timer_cleared_status_data { CEC_TIMER_CLEARED_STATUS_DATA_TIMER_NOT_CLEARED_RECORDING = 0x00, CEC_TIMER_CLEARED_STATUS_DATA_TIMER_NOT_CLEARED_NO_MATCHING = 0x01, CEC_TIMER_CLEARED_STATUS_DATA_TIMER_NOT_CLEARED_NO_INF0_AVAILABLE = 0x02, CEC_TIMER_CLEARED_STATUS_DATA_TIMER_CLEARED = 0x80 } cec_timer_cleared_status_data; typedef enum cec_timer_overlap_warning { CEC_TIMER_OVERLAP_WARNING_NO_OVERLAP = 0, CEC_TIMER_OVERLAP_WARNING_TIMER_BLOCKS_OVERLAP = 1 } cec_timer_overlap_warning; typedef enum cec_media_info { CEC_MEDIA_INFO_MEDIA_PRESENT_AND_NOT_PROTECTED = 0x00, CEC_MEDIA_INFO_MEDIA_PRESENT_BUT_PROTECTED = 0x01, CEC_MEDIA_INFO_MEDIA_NOT_PRESENT = 0x02, CEC_MEDIA_INFO_FUTURE_USE = 0x03 } cec_media_info; typedef enum cec_programmed_indicator { CEC_PROGRAMMED_INDICATOR_NOT_PROGRAMMED = 0, CEC_PROGRAMMED_INDICATOR_PROGRAMMED = 1 } cec_programmed_indicator; typedef enum cec_programmed_info { CEC_PROGRAMMED_INFO_FUTURE_USE = 0x0, CEC_PROGRAMMED_INFO_ENOUGH_SPACE_AVAILABLE_FOR_RECORDING = 0x08, CEC_PROGRAMMED_INFO_NOT_ENOUGH_SPACE_AVAILABLE_FOR_RECORDING = 0x09, CEC_PROGRAMMED_INFO_MAY_NOT_BE_ENOUGH_SPACE_AVAILABLE = 0x0B, CEC_PROGRAMMED_INFO_NO_MEDIA_INFO_AVAILABLE = 0x0A } cec_programmed_info; typedef enum cec_not_programmed_error_info { CEC_NOT_PROGRAMMED_ERROR_INFO_FUTURE_USE = 0x0, CEC_NOT_PROGRAMMED_ERROR_INFO_NO_FREE_TIMER_AVAILABLE = 0x01, CEC_NOT_PROGRAMMED_ERROR_INFO_DATE_OUT_OF_RANGE = 0x02, CEC_NOT_PROGRAMMED_ERROR_INFO_RECORDING_SEQUENCE_ERROR = 0x03, CEC_NOT_PROGRAMMED_ERROR_INFO_INVALID_EXTERNAL_PLUG_NUMBER = 0x04, CEC_NOT_PROGRAMMED_ERROR_INFO_INVALID_EXTERNAL_PHYSICAL_ADDRESS = 0x05, CEC_NOT_PROGRAMMED_ERROR_INFO_CA_SYSTEM_NOT_SUPPORTED = 0x06, CEC_NOT_PROGRAMMED_ERROR_INFO_NO_OR_INSUFFICIENT_CA_ENTITLEMENTS = 0x07, CEC_NOT_PROGRAMMED_ERROR_INFO_DOES_NOT_SUPPORT_RESOLUTION = 0x08, CEC_NOT_PROGRAMMED_ERROR_INFO_PARENTAL_LOCK_ON = 0x09, CEC_NOT_PROGRAMMED_ERROR_INFO_CLOCK_FAILURE = 0x0A, CEC_NOT_PROGRAMMED_ERROR_INFO_RESERVED_FOR_FUTURE_USE_START = 0x0B, CEC_NOT_PROGRAMMED_ERROR_INFO_RESERVED_FOR_FUTURE_USE_END = 0x0D, CEC_NOT_PROGRAMMED_ERROR_INFO_DUPLICATE_ALREADY_PROGRAMMED = 0x0E } cec_not_programmed_error_info; typedef enum cec_recording_flag { CEC_RECORDING_FLAG_NOT_BEING_USED_FOR_RECORDING = 0, CEC_RECORDING_FLAG_BEING_USED_FOR_RECORDING = 1 } cec_recording_flag; typedef enum cec_tuner_display_info { CEC_TUNER_DISPLAY_INFO_DISPLAYING_DIGITAL_TUNER = 0, CEC_TUNER_DISPLAY_INFO_NOT_DISPLAYING_TUNER = 1, CEC_TUNER_DISPLAY_INFO_DISPLAYING_ANALOGUE_TUNER = 2 } cec_tuner_display_info; typedef enum cec_broadcast_system { CEC_BROADCAST_SYSTEM_PAL_B_G = 0, CEC_BROADCAST_SYSTEM_SECAM_L1 = 1, CEC_BROADCAST_SYSTEM_PAL_M = 2, CEC_BROADCAST_SYSTEM_NTSC_M = 3, CEC_BROADCAST_SYSTEM_PAL_I = 4, CEC_BROADCAST_SYSTEM_SECAM_DK = 5, CEC_BROADCAST_SYSTEM_SECAM_B_G = 6, CEC_BROADCAST_SYSTEM_SECAM_L2 = 7, CEC_BROADCAST_SYSTEM_PAL_DK = 8, CEC_BROADCAST_SYSTEM_OTHER_SYSTEM = 30 } cec_broadcast_system; typedef enum cec_user_control_code { CEC_USER_CONTROL_CODE_SELECT = 0x00, CEC_USER_CONTROL_CODE_UP = 0x01, CEC_USER_CONTROL_CODE_DOWN = 0x02, CEC_USER_CONTROL_CODE_LEFT = 0x03, CEC_USER_CONTROL_CODE_RIGHT = 0x04, CEC_USER_CONTROL_CODE_RIGHT_UP = 0x05, CEC_USER_CONTROL_CODE_RIGHT_DOWN = 0x06, CEC_USER_CONTROL_CODE_LEFT_UP = 0x07, CEC_USER_CONTROL_CODE_LEFT_DOWN = 0x08, CEC_USER_CONTROL_CODE_ROOT_MENU = 0x09, CEC_USER_CONTROL_CODE_SETUP_MENU = 0x0A, CEC_USER_CONTROL_CODE_CONTENTS_MENU = 0x0B, CEC_USER_CONTROL_CODE_FAVORITE_MENU = 0x0C, CEC_USER_CONTROL_CODE_EXIT = 0x0D, // reserved: 0x0E, 0x0F CEC_USER_CONTROL_CODE_TOP_MENU = 0x10, CEC_USER_CONTROL_CODE_DVD_MENU = 0x11, // reserved: 0x12 ... 0x1C CEC_USER_CONTROL_CODE_NUMBER_ENTRY_MODE = 0x1D, CEC_USER_CONTROL_CODE_NUMBER11 = 0x1E, CEC_USER_CONTROL_CODE_NUMBER12 = 0x1F, CEC_USER_CONTROL_CODE_NUMBER0 = 0x20, CEC_USER_CONTROL_CODE_NUMBER1 = 0x21, CEC_USER_CONTROL_CODE_NUMBER2 = 0x22, CEC_USER_CONTROL_CODE_NUMBER3 = 0x23, CEC_USER_CONTROL_CODE_NUMBER4 = 0x24, CEC_USER_CONTROL_CODE_NUMBER5 = 0x25, CEC_USER_CONTROL_CODE_NUMBER6 = 0x26, CEC_USER_CONTROL_CODE_NUMBER7 = 0x27, CEC_USER_CONTROL_CODE_NUMBER8 = 0x28, CEC_USER_CONTROL_CODE_NUMBER9 = 0x29, CEC_USER_CONTROL_CODE_DOT = 0x2A, CEC_USER_CONTROL_CODE_ENTER = 0x2B, CEC_USER_CONTROL_CODE_CLEAR = 0x2C, CEC_USER_CONTROL_CODE_NEXT_FAVORITE = 0x2F, CEC_USER_CONTROL_CODE_CHANNEL_UP = 0x30, CEC_USER_CONTROL_CODE_CHANNEL_DOWN = 0x31, CEC_USER_CONTROL_CODE_PREVIOUS_CHANNEL = 0x32, CEC_USER_CONTROL_CODE_SOUND_SELECT = 0x33, CEC_USER_CONTROL_CODE_INPUT_SELECT = 0x34, CEC_USER_CONTROL_CODE_DISPLAY_INFORMATION = 0x35, CEC_USER_CONTROL_CODE_HELP = 0x36, CEC_USER_CONTROL_CODE_PAGE_UP = 0x37, CEC_USER_CONTROL_CODE_PAGE_DOWN = 0x38, // reserved: 0x39 ... 0x3F CEC_USER_CONTROL_CODE_POWER = 0x40, CEC_USER_CONTROL_CODE_VOLUME_UP = 0x41, CEC_USER_CONTROL_CODE_VOLUME_DOWN = 0x42, CEC_USER_CONTROL_CODE_MUTE = 0x43, CEC_USER_CONTROL_CODE_PLAY = 0x44, CEC_USER_CONTROL_CODE_STOP = 0x45, CEC_USER_CONTROL_CODE_PAUSE = 0x46, CEC_USER_CONTROL_CODE_RECORD = 0x47, CEC_USER_CONTROL_CODE_REWIND = 0x48, CEC_USER_CONTROL_CODE_FAST_FORWARD = 0x49, CEC_USER_CONTROL_CODE_EJECT = 0x4A, CEC_USER_CONTROL_CODE_FORWARD = 0x4B, CEC_USER_CONTROL_CODE_BACKWARD = 0x4C, CEC_USER_CONTROL_CODE_STOP_RECORD = 0x4D, CEC_USER_CONTROL_CODE_PAUSE_RECORD = 0x4E, // reserved: 0x4F CEC_USER_CONTROL_CODE_ANGLE = 0x50, CEC_USER_CONTROL_CODE_SUB_PICTURE = 0x51, CEC_USER_CONTROL_CODE_VIDEO_ON_DEMAND = 0x52, CEC_USER_CONTROL_CODE_ELECTRONIC_PROGRAM_GUIDE = 0x53, CEC_USER_CONTROL_CODE_TIMER_PROGRAMMING = 0x54, CEC_USER_CONTROL_CODE_INITIAL_CONFIGURATION = 0x55, CEC_USER_CONTROL_CODE_SELECT_BROADCAST_TYPE = 0x56, CEC_USER_CONTROL_CODE_SELECT_SOUND_PRESENTATION = 0x57, // reserved: 0x58 ... 0x5F CEC_USER_CONTROL_CODE_PLAY_FUNCTION = 0x60, CEC_USER_CONTROL_CODE_PAUSE_PLAY_FUNCTION = 0x61, CEC_USER_CONTROL_CODE_RECORD_FUNCTION = 0x62, CEC_USER_CONTROL_CODE_PAUSE_RECORD_FUNCTION = 0x63, CEC_USER_CONTROL_CODE_STOP_FUNCTION = 0x64, CEC_USER_CONTROL_CODE_MUTE_FUNCTION = 0x65, CEC_USER_CONTROL_CODE_RESTORE_VOLUME_FUNCTION = 0x66, CEC_USER_CONTROL_CODE_TUNE_FUNCTION = 0x67, CEC_USER_CONTROL_CODE_SELECT_MEDIA_FUNCTION = 0x68, CEC_USER_CONTROL_CODE_SELECT_AV_INPUT_FUNCTION = 0x69, CEC_USER_CONTROL_CODE_SELECT_AUDIO_INPUT_FUNCTION = 0x6A, CEC_USER_CONTROL_CODE_POWER_TOGGLE_FUNCTION = 0x6B, CEC_USER_CONTROL_CODE_POWER_OFF_FUNCTION = 0x6C, CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION = 0x6D, // reserved: 0x6E ... 0x70 CEC_USER_CONTROL_CODE_F1_BLUE = 0x71, CEC_USER_CONTROL_CODE_F2_RED = 0X72, CEC_USER_CONTROL_CODE_F3_GREEN = 0x73, CEC_USER_CONTROL_CODE_F4_YELLOW = 0x74, CEC_USER_CONTROL_CODE_F5 = 0x75, CEC_USER_CONTROL_CODE_DATA = 0x76, // reserved: 0x77 ... 0xFF CEC_USER_CONTROL_CODE_AN_RETURN = 0x91, // return (Samsung) CEC_USER_CONTROL_CODE_AN_CHANNELS_LIST = 0x96, // channels list (Samsung) CEC_USER_CONTROL_CODE_MAX = 0x96, CEC_USER_CONTROL_CODE_UNKNOWN = 0xFF } cec_user_control_code; typedef enum cec_logical_address { CECDEVICE_UNKNOWN = -1, //not a valid logical address CECDEVICE_TV = 0, CECDEVICE_RECORDINGDEVICE1 = 1, CECDEVICE_RECORDINGDEVICE2 = 2, CECDEVICE_TUNER1 = 3, CECDEVICE_PLAYBACKDEVICE1 = 4, CECDEVICE_AUDIOSYSTEM = 5, CECDEVICE_TUNER2 = 6, CECDEVICE_TUNER3 = 7, CECDEVICE_PLAYBACKDEVICE2 = 8, CECDEVICE_RECORDINGDEVICE3 = 9, CECDEVICE_TUNER4 = 10, CECDEVICE_PLAYBACKDEVICE3 = 11, CECDEVICE_RESERVED1 = 12, CECDEVICE_RESERVED2 = 13, CECDEVICE_FREEUSE = 14, CECDEVICE_UNREGISTERED = 15, CECDEVICE_BROADCAST = 15 } cec_logical_address; typedef enum cec_opcode { CEC_OPCODE_ACTIVE_SOURCE = 0x82, CEC_OPCODE_IMAGE_VIEW_ON = 0x04, CEC_OPCODE_TEXT_VIEW_ON = 0x0D, CEC_OPCODE_INACTIVE_SOURCE = 0x9D, CEC_OPCODE_REQUEST_ACTIVE_SOURCE = 0x85, CEC_OPCODE_ROUTING_CHANGE = 0x80, CEC_OPCODE_ROUTING_INFORMATION = 0x81, CEC_OPCODE_SET_STREAM_PATH = 0x86, CEC_OPCODE_STANDBY = 0x36, CEC_OPCODE_RECORD_OFF = 0x0B, CEC_OPCODE_RECORD_ON = 0x09, CEC_OPCODE_RECORD_STATUS = 0x0A, CEC_OPCODE_RECORD_TV_SCREEN = 0x0F, CEC_OPCODE_CLEAR_ANALOGUE_TIMER = 0x33, CEC_OPCODE_CLEAR_DIGITAL_TIMER = 0x99, CEC_OPCODE_CLEAR_EXTERNAL_TIMER = 0xA1, CEC_OPCODE_SET_ANALOGUE_TIMER = 0x34, CEC_OPCODE_SET_DIGITAL_TIMER = 0x97, CEC_OPCODE_SET_EXTERNAL_TIMER = 0xA2, CEC_OPCODE_SET_TIMER_PROGRAM_TITLE = 0x67, CEC_OPCODE_TIMER_CLEARED_STATUS = 0x43, CEC_OPCODE_TIMER_STATUS = 0x35, CEC_OPCODE_CEC_VERSION = 0x9E, CEC_OPCODE_GET_CEC_VERSION = 0x9F, CEC_OPCODE_GIVE_PHYSICAL_ADDRESS = 0x83, CEC_OPCODE_GET_MENU_LANGUAGE = 0x91, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS = 0x84, CEC_OPCODE_SET_MENU_LANGUAGE = 0x32, CEC_OPCODE_DECK_CONTROL = 0x42, CEC_OPCODE_DECK_STATUS = 0x1B, CEC_OPCODE_GIVE_DECK_STATUS = 0x1A, CEC_OPCODE_PLAY = 0x41, CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS = 0x08, CEC_OPCODE_SELECT_ANALOGUE_SERVICE = 0x92, CEC_OPCODE_SELECT_DIGITAL_SERVICE = 0x93, CEC_OPCODE_TUNER_DEVICE_STATUS = 0x07, CEC_OPCODE_TUNER_STEP_DECREMENT = 0x06, CEC_OPCODE_TUNER_STEP_INCREMENT = 0x05, CEC_OPCODE_DEVICE_VENDOR_ID = 0x87, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID = 0x8C, CEC_OPCODE_VENDOR_COMMAND = 0x89, CEC_OPCODE_VENDOR_COMMAND_WITH_ID = 0xA0, CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN = 0x8A, CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP = 0x8B, CEC_OPCODE_SET_OSD_STRING = 0x64, CEC_OPCODE_GIVE_OSD_NAME = 0x46, CEC_OPCODE_SET_OSD_NAME = 0x47, CEC_OPCODE_MENU_REQUEST = 0x8D, CEC_OPCODE_MENU_STATUS = 0x8E, CEC_OPCODE_USER_CONTROL_PRESSED = 0x44, CEC_OPCODE_USER_CONTROL_RELEASE = 0x45, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS = 0x8F, CEC_OPCODE_REPORT_POWER_STATUS = 0x90, CEC_OPCODE_FEATURE_ABORT = 0x00, CEC_OPCODE_ABORT = 0xFF, CEC_OPCODE_GIVE_AUDIO_STATUS = 0x71, CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS = 0x7D, CEC_OPCODE_REPORT_AUDIO_STATUS = 0x7A, CEC_OPCODE_SET_SYSTEM_AUDIO_MODE = 0x72, CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST = 0x70, CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS = 0x7E, CEC_OPCODE_SET_AUDIO_RATE = 0x9A, /* CEC 1.4 */ CEC_OPCODE_REPORT_SHORT_AUDIO_DESCRIPTORS = 0xA3, CEC_OPCODE_REQUEST_SHORT_AUDIO_DESCRIPTORS = 0xA4, CEC_OPCODE_START_ARC = 0xC0, CEC_OPCODE_REPORT_ARC_STARTED = 0xC1, CEC_OPCODE_REPORT_ARC_ENDED = 0xC2, CEC_OPCODE_REQUEST_ARC_START = 0xC3, CEC_OPCODE_REQUEST_ARC_END = 0xC4, CEC_OPCODE_END_ARC = 0xC5, CEC_OPCODE_CDC = 0xF8, /* when this opcode is set, no opcode will be sent to the device. this is one of the reserved numbers */ CEC_OPCODE_NONE = 0xFD } cec_opcode; typedef enum cec_log_level { CEC_LOG_ERROR = 1, CEC_LOG_WARNING = 2, CEC_LOG_NOTICE = 4, CEC_LOG_TRAFFIC = 8, CEC_LOG_DEBUG = 16, CEC_LOG_ALL = 31 } cec_log_level; typedef enum cec_bus_device_status { CEC_DEVICE_STATUS_UNKNOWN, CEC_DEVICE_STATUS_PRESENT, CEC_DEVICE_STATUS_NOT_PRESENT, CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC } cec_bus_device_status; typedef enum cec_vendor_id { CEC_VENDOR_TOSHIBA = 0x000039, CEC_VENDOR_SAMSUNG = 0x0000F0, CEC_VENDOR_DENON = 0x0005CD, CEC_VENDOR_MARANTZ = 0x000678, CEC_VENDOR_LOEWE = 0x000982, CEC_VENDOR_ONKYO = 0x0009B0, CEC_VENDOR_MEDION = 0x000CB8, CEC_VENDOR_TOSHIBA2 = 0x000CE7, CEC_VENDOR_APPLE = 0x0010FA, CEC_VENDOR_PULSE_EIGHT = 0x001582, CEC_VENDOR_HARMAN_KARDON2 = 0x001950, CEC_VENDOR_GOOGLE = 0x001A11, CEC_VENDOR_AKAI = 0x0020C7, CEC_VENDOR_AOC = 0x002467, CEC_VENDOR_PANASONIC = 0x008045, CEC_VENDOR_PHILIPS = 0x00903E, CEC_VENDOR_DAEWOO = 0x009053, CEC_VENDOR_YAMAHA = 0x00A0DE, CEC_VENDOR_GRUNDIG = 0x00D0D5, CEC_VENDOR_PIONEER = 0x00E036, CEC_VENDOR_LG = 0x00E091, CEC_VENDOR_SHARP = 0x08001F, CEC_VENDOR_SONY = 0x080046, CEC_VENDOR_BROADCOM = 0x18C086, CEC_VENDOR_SHARP2 = 0x534850, CEC_VENDOR_VIZIO = 0x6B746D, CEC_VENDOR_BENQ = 0x8065E9, CEC_VENDOR_HARMAN_KARDON = 0x9C645E, CEC_VENDOR_UNKNOWN = 0 } cec_vendor_id; typedef enum cec_adapter_type { ADAPTERTYPE_UNKNOWN = 0, ADAPTERTYPE_P8_EXTERNAL = 0x1, ADAPTERTYPE_P8_DAUGHTERBOARD = 0x2, ADAPTERTYPE_RPI = 0x100, ADAPTERTYPE_TDA995x = 0x200, ADAPTERTYPE_EXYNOS = 0x300, ADAPTERTYPE_LINUX = 0x400, ADAPTERTYPE_AOCEC = 0x500, ADAPTERTYPE_IMX = 0x600 } cec_adapter_type; /** force exporting through swig */ enum libcec_version { LIBCEC_VERSION_CURRENT = _LIBCEC_VERSION_CURRENT }; typedef char cec_menu_language[4]; /**< the iso language code + (char)0 */ typedef char cec_osd_name[14]; /**< the name of the device */ typedef struct cec_log_message { const char* message; /**< the actual message, valid until returning from the log callback */ cec_log_level level; /**< log level of the message */ int64_t time; /**< the timestamp of this message */ } cec_log_message; typedef struct cec_keypress { cec_user_control_code keycode; /**< the keycode */ unsigned int duration; /**< the duration of the keypress */ } cec_keypress; typedef struct cec_adapter { char path[1024]; /**< the path to the com port */ char comm[1024]; /**< the name of the com port */ } cec_adapter; typedef struct cec_adapter_descriptor { char strComPath[1024]; /**< the path to the com port */ char strComName[1024]; /**< the name of the com port */ uint16_t iVendorId; uint16_t iProductId; uint16_t iFirmwareVersion; uint16_t iPhysicalAddress; uint32_t iFirmwareBuildDate; cec_adapter_type adapterType; } cec_adapter_descriptor; #if defined(__cplusplus) typedef struct AdapterDescriptor { AdapterDescriptor(void) : iVendorId(0), iProductId(0), iFirmwareVersion(0), iPhysicalAddress(0), iFirmwareBuildDate(0), adapterType(ADAPTERTYPE_UNKNOWN) { } AdapterDescriptor(const cec_adapter_descriptor& other) { strComPath = other.strComPath; strComName = other.strComName; iVendorId = other.iVendorId; iProductId = other.iProductId; iFirmwareVersion = other.iFirmwareVersion; iPhysicalAddress = other.iPhysicalAddress; iFirmwareBuildDate = other.iFirmwareBuildDate; adapterType = other.adapterType; } std::string strComPath; /**< the path to the com port */ std::string strComName; /**< the name of the com port */ uint16_t iVendorId; uint16_t iProductId; uint16_t iFirmwareVersion; uint16_t iPhysicalAddress; uint32_t iFirmwareBuildDate; cec_adapter_type adapterType; } AdapterDescriptor; #endif typedef struct cec_datapacket { uint8_t data[CEC_MAX_DATA_PACKET_SIZE]; /**< the actual data */ uint8_t size; /**< the size of the data */ #ifdef __cplusplus cec_datapacket &operator =(const struct cec_datapacket &packet) { Clear(); for (uint8_t iPtr = 0; iPtr < packet.size; iPtr++) PushBack(packet[iPtr]); return *this; } bool operator ==(const struct cec_datapacket& packet) const { if (size != packet.size) return false; for (uint8_t iPtr = 0; iPtr < size; iPtr++) if (packet.data[iPtr] != data[iPtr]) return false; return true; } /** @return True when this packet is empty, false otherwise. */ bool IsEmpty(void) const { return size == 0; } /** @return True when this packet is false, false otherwise. */ bool IsFull(void) const { return size == CEC_MAX_DATA_PACKET_SIZE; } /*! * @brief Get the byte at the requested position. * @param pos The position. * @return The byte, or 0 when out of bounds. */ uint8_t operator[](uint8_t pos) const { return pos < size ? data[pos] : 0; } /*! * @brief Get the byte at the requested position. * @param pos The position. * @return The byte, or 0 when out of bounds. */ uint8_t At(uint8_t pos) const { return pos < size ? data[pos] : 0; } /*! * @brief Shift the contents of this packet. * @param iShiftBy The number of positions to shift. */ void Shift(uint8_t iShiftBy) { if (iShiftBy >= size) { Clear(); } else { for (uint8_t iPtr = 0; iPtr < size; iPtr++) data[iPtr] = (iPtr + iShiftBy < size) ? data[iPtr + iShiftBy] : 0; size = (uint8_t) (size - iShiftBy); } } /*! * @brief Push a byte to the end of this packet. * @param add The byte to add. */ void PushBack(uint8_t add) { if (size < CEC_MAX_DATA_PACKET_SIZE) data[size++] = add; } /*! * @brief Clear this packet. */ void Clear(void) { memset(data, 0, sizeof(data)); size = 0; } #endif } cec_datapacket; typedef struct cec_command { cec_logical_address initiator; /**< the logical address of the initiator of this message */ cec_logical_address destination; /**< the logical address of the destination of this message */ int8_t ack; /**< 1 when the ACK bit is set, 0 otherwise */ int8_t eom; /**< 1 when the EOM bit is set, 0 otherwise */ cec_opcode opcode; /**< the opcode of this message */ cec_datapacket parameters; /**< the parameters attached to this message */ int8_t opcode_set; /**< 1 when an opcode is set, 0 otherwise (POLL message) */ int32_t transmit_timeout; /**< the timeout to use in ms */ #ifdef __cplusplus cec_command(void) { Clear(); } cec_command &operator =(const struct cec_command &command) { initiator = command.initiator; destination = command.destination; ack = command.ack; eom = command.eom; opcode = command.opcode; opcode_set = command.opcode_set; transmit_timeout = command.transmit_timeout; parameters = command.parameters; return *this; } uint8_t Size(void) const { return parameters.size + opcode_set + 1; } /*! * @brief Formats a cec_command. * @param command The command to format. * @param initiator The logical address of the initiator. * @param destination The logical address of the destination. * @param opcode The opcode of the command. * @param timeout The transmission timeout. */ static void Format(cec_command &command, cec_logical_address initiator, cec_logical_address destination, cec_opcode opcode, int32_t timeout = CEC_DEFAULT_TRANSMIT_TIMEOUT) { command.Clear(); command.initiator = initiator; command.destination = destination; command.transmit_timeout = timeout; if (opcode != CEC_OPCODE_NONE) { command.opcode = opcode; command.opcode_set = 1; } } /*! * @brief Push a byte to the back of this command. * @param data The byte to push. */ void PushBack(uint8_t data) { if (initiator == CECDEVICE_UNKNOWN && destination == CECDEVICE_UNKNOWN) { initiator = (cec_logical_address) (data >> 4); destination = (cec_logical_address) (data & 0xF); } else if (!opcode_set) { opcode_set = 1; opcode = (cec_opcode) data; } else parameters.PushBack(data); } /*! * @brief Clear this command, resetting everything to the default values. */ void Clear(void) { initiator = CECDEVICE_UNKNOWN; destination = CECDEVICE_UNKNOWN; ack = 0; eom = 0; opcode_set = 0; opcode = CEC_OPCODE_FEATURE_ABORT; transmit_timeout = CEC_DEFAULT_TRANSMIT_TIMEOUT; parameters.Clear(); }; static cec_opcode GetResponseOpcode(cec_opcode opcode) { switch (opcode) { case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: return CEC_OPCODE_ACTIVE_SOURCE; case CEC_OPCODE_GET_CEC_VERSION: return CEC_OPCODE_CEC_VERSION; case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: return CEC_OPCODE_REPORT_PHYSICAL_ADDRESS; case CEC_OPCODE_GET_MENU_LANGUAGE: return CEC_OPCODE_SET_MENU_LANGUAGE; case CEC_OPCODE_GIVE_DECK_STATUS: return CEC_OPCODE_DECK_STATUS; case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS: return CEC_OPCODE_TUNER_DEVICE_STATUS; case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID: return CEC_OPCODE_DEVICE_VENDOR_ID; case CEC_OPCODE_GIVE_OSD_NAME: return CEC_OPCODE_SET_OSD_NAME; case CEC_OPCODE_MENU_REQUEST: return CEC_OPCODE_MENU_STATUS; case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: return CEC_OPCODE_REPORT_POWER_STATUS; case CEC_OPCODE_GIVE_AUDIO_STATUS: return CEC_OPCODE_REPORT_AUDIO_STATUS; case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS: return CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS; case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: return CEC_OPCODE_SET_SYSTEM_AUDIO_MODE; default: break; } return CEC_OPCODE_NONE; } void PushArray(size_t len, const uint8_t *data) { for (size_t iPtr = 0; iPtr < len; iPtr++) PushBack(data[iPtr]); } #endif } cec_command; typedef struct cec_device_type_list { cec_device_type types[5]; /**< the list of device types */ #ifdef __cplusplus /*! * @brief Clear this list. */ void Clear(void) { for (unsigned int iPtr = 0; iPtr < 5; iPtr++) types[iPtr] = CEC_DEVICE_TYPE_RESERVED; } /*! * @brief Add a type to this list. * @param type The type to add. */ void Add(const cec_device_type type) { for (unsigned int iPtr = 0; iPtr < 5; iPtr++) { if (types[iPtr] == CEC_DEVICE_TYPE_RESERVED) { types[iPtr] = type; break; } } } /*! * @brief Check whether a type is set in this list. * @param type The type to check. * @return True when set, false otherwise. */ bool IsSet(cec_device_type type) { bool bReturn(false); for (unsigned int iPtr = 0; !bReturn && iPtr < 5; iPtr++) { if (types[iPtr] == type) bReturn = true; } return bReturn; } /*! * @return True when this list is empty, false otherwise. */ bool IsEmpty() const { bool bReturn(true); for (unsigned int iPtr = 0; bReturn && iPtr < 5; iPtr++) { if (types[iPtr] != CEC_DEVICE_TYPE_RESERVED) bReturn = false; } return bReturn; } /*! * @brief Get the type at the requested position. * @param pos The position. * @return The type, or CEC_DEVICE_TYPE_RESERVED when out of bounds. */ cec_device_type operator[](uint8_t pos) const { return pos < 5 ? types[pos] : CEC_DEVICE_TYPE_RESERVED; } bool operator==(const cec_device_type_list &other) const { bool bEqual(true); for (uint8_t iPtr = 0; iPtr < 5; iPtr++) bEqual &= (types[iPtr] == other[iPtr]); return bEqual; } bool operator!=(const cec_device_type_list &other) const { return !(*this == other); } #endif } cec_device_type_list; typedef struct cec_logical_addresses { cec_logical_address primary; /**< the primary logical address to use */ int addresses[16]; /**< the list of addresses */ #ifdef __cplusplus /*! * @brief Clear this list. */ void Clear(void) { primary = CECDEVICE_UNREGISTERED; for (unsigned int iPtr = 0; iPtr < 16; iPtr++) addresses[iPtr] = 0; } /*! * @return True when empty, false otherwise. */ bool IsEmpty(void) const { return primary == CECDEVICE_UNREGISTERED; } /*! * @brief Calculate the ack-mask for this list, the mask to use when determining whether to send an ack message or not. * @return The ack-mask. */ uint16_t AckMask(void) const { uint16_t mask = 0; for (unsigned int iPtr = 0; iPtr < 16; iPtr++) if (addresses[iPtr] == 1) mask |= 0x1 << iPtr; return mask; } /*! * @brief Mark a logical address as 'set' * @param address The logical address to add to this list. */ void Set(cec_logical_address address) { if (primary == CECDEVICE_UNREGISTERED) primary = address; addresses[(int) address] = 1; } /*! * @brief Mark a logical address as 'unset' * @param address The logical address to remove from this list. */ void Unset(const cec_logical_address address) { if (primary == address) primary = CECDEVICE_UNREGISTERED; addresses[(int) address] = 0; } /*! * @brief Check whether an address is set in this list. * @param address The address to check. * @return True when set, false otherwise. */ bool IsSet(cec_logical_address address) const { return addresses[(int) address] == 1; } /*! * @brief Check whether an address is set in this list. * @param pos The address to check. * @return True when set, false otherwise. */ bool operator[](uint8_t pos) const { return pos < 16 ? IsSet((cec_logical_address) pos) : false; } bool operator==(const cec_logical_addresses &other) const { bool bEqual(true); for (uint8_t iPtr = 0; iPtr < 16; iPtr++) bEqual &= ((addresses[(int)iPtr] == 1) == other[iPtr]); return bEqual; } bool operator!=(const cec_logical_addresses &other) const { return !(*this == other); } #endif } cec_logical_addresses; typedef enum libcec_alert { CEC_ALERT_SERVICE_DEVICE, CEC_ALERT_CONNECTION_LOST, CEC_ALERT_PERMISSION_ERROR, CEC_ALERT_PORT_BUSY, CEC_ALERT_PHYSICAL_ADDRESS_ERROR, CEC_ALERT_TV_POLL_FAILED } libcec_alert; typedef enum libcec_parameter_type { CEC_PARAMETER_TYPE_STRING, CEC_PARAMETER_TYPE_UNKOWN } libcec_parameter_type; typedef struct libcec_parameter { libcec_parameter_type paramType; /**< the type of this parameter */ void* paramData; /**< the value of this parameter */ } libcec_parameter; struct cec_adapter_stats { unsigned int tx_ack; unsigned int tx_nack; unsigned int tx_error; unsigned int rx_total; unsigned int rx_error; }; typedef struct libcec_configuration libcec_configuration; typedef struct ICECCallbacks { /*! * @brief Transfer a log message from libCEC to the client. * @param cbparam Callback parameter provided when the callbacks were set up * @param message The message to transfer. */ void (CEC_CDECL* logMessage)(void* cbparam, const cec_log_message* message); /*! * @brief Transfer a keypress from libCEC to the client. * @param cbparam Callback parameter provided when the callbacks were set up * @param key The keypress to transfer. */ void (CEC_CDECL* keyPress)(void* cbparam, const cec_keypress* key); /*! * @brief Transfer a CEC command from libCEC to the client. * @param cbparam Callback parameter provided when the callbacks were set up * @param command The command to transfer. */ void (CEC_CDECL* commandReceived)(void* cbparam, const cec_command* command); /*! * @brief Transfer a changed configuration from libCEC to the client * @param cbparam Callback parameter provided when the callbacks were set up * @param configuration The configuration to transfer */ void (CEC_CDECL* configurationChanged)(void* cbparam, const libcec_configuration* configuration); /*! * @brief Transfer a libcec alert message from libCEC to the client * @param cbparam Callback parameter provided when the callbacks were set up * @param alert The alert type transfer. * @param data Misc. additional information. */ void (CEC_CDECL* alert)(void* cbparam, const libcec_alert alert, const libcec_parameter param); /*! * @brief Transfer a menu state change to the client. * Transfer a menu state change to the client. If the command returns 1, then the change will be processed by * the busdevice. If 0, then the state of the busdevice won't be changed, and will always be kept 'activated', * @warning CEC does not allow the player to suppress the menu state change on the TV, so the menu on the TV will always be displayed, whatever the return value of this method is. * so keypresses are always routed. * @param cbparam Callback parameter provided when the callbacks were set up * @param state The new value. * * @return 1 if libCEC should use this new value, 0 otherwise. */ int (CEC_CDECL* menuStateChanged)(void* cbparam, const cec_menu_state state); /*! * @brief Called when a source that's handled by this client is activated. * @param cbparam Callback parameter provided when the callbacks were set up * @param logicalAddress The address that was just activated. * @param bActivated 1 if activated, 0 when deactivated. */ void (CEC_CDECL* sourceActivated)(void* cbParam, const cec_logical_address logicalAddress, const uint8_t bActivated); #ifdef __cplusplus ICECCallbacks(void) { Clear(); } ~ICECCallbacks(void) { Clear(); }; void Clear(void) { logMessage = nullptr; keyPress = nullptr; commandReceived = nullptr; configurationChanged = nullptr; alert = nullptr; menuStateChanged = nullptr; sourceActivated = nullptr; } #endif } ICECCallbacks; #if CEC_LIB_VERSION_MAJOR >= 5 #define LIBCEC_OSD_NAME_SIZE (15) #else #define LIBCEC_OSD_NAME_SIZE (13) #endif struct libcec_configuration { uint32_t clientVersion; /*!< the version of the client that is connecting */ char strDeviceName[LIBCEC_OSD_NAME_SIZE]; /*!< the device name to use on the CEC bus, name + 0 terminator */ cec_device_type_list deviceTypes; /*!< the device type(s) to use on the CEC bus for libCEC */ uint8_t bAutodetectAddress; /*!< (read only) set to 1 by libCEC when the physical address was autodetected */ uint16_t iPhysicalAddress; /*!< the physical address of the CEC adapter */ cec_logical_address baseDevice; /*!< the logical address of the device to which the adapter is connected. only used when iPhysicalAddress = 0 or when the adapter doesn't support autodetection */ uint8_t iHDMIPort; /*!< the HDMI port to which the adapter is connected. only used when iPhysicalAddress = 0 or when the adapter doesn't support autodetection */ uint32_t tvVendor; /*!< override the vendor ID of the TV. leave this untouched to autodetect */ cec_logical_addresses wakeDevices; /*!< list of devices to wake when initialising libCEC or when calling PowerOnDevices() without any parameter. */ cec_logical_addresses powerOffDevices; /*!< list of devices to power off when calling StandbyDevices() without any parameter. */ uint32_t serverVersion; /*!< the version number of the server. read-only */ // player specific settings uint8_t bGetSettingsFromROM; /*!< true to get the settings from the ROM (if set, and a v2 ROM is present), false to use these settings. */ uint8_t bActivateSource; /*!< make libCEC the active source on the bus when starting the player application */ uint8_t bPowerOffOnStandby; /*!< put this PC in standby mode when the TV is switched off. only used when bShutdownOnStandby = 0 */ void * callbackParam; /*!< the object to pass along with a call of the callback methods. NULL to ignore */ ICECCallbacks * callbacks; /*!< the callback methods to use. set this to NULL when not using callbacks */ cec_logical_addresses logicalAddresses; /*!< (read-only) the current logical addresses. added in 1.5.3 */ uint16_t iFirmwareVersion; /*!< (read-only) the firmware version of the adapter. added in 1.6.0 */ char strDeviceLanguage[3]; /*!< the menu language used by the client. 3 character ISO 639-2 country code. see http://http://www.loc.gov/standards/iso639-2/ added in 1.6.2 */ uint32_t iFirmwareBuildDate; /*!< (read-only) the build date of the firmware, in seconds since epoch. if not available, this value will be set to 0. added in 1.6.2 */ uint8_t bMonitorOnly; /*!< won't allocate a CCECClient when starting the connection when set (same as monitor mode). added in 1.6.3 */ cec_version cecVersion; /*!< CEC spec version to use by libCEC. defaults to v1.4. added in 1.8.0 */ cec_adapter_type adapterType; /*!< type of the CEC adapter that we're connected to. added in 1.8.2 */ cec_user_control_code comboKey; /*!< key code that initiates combo keys. defaults to CEC_USER_CONTROL_CODE_STOP. CEC_USER_CONTROL_CODE_UNKNOWN to disable. added in 2.0.5 */ uint32_t iComboKeyTimeoutMs; /*!< timeout until the combo key is sent as normal keypress */ uint32_t iButtonRepeatRateMs; /*!< rate at which buttons autorepeat. 0 means rely on CEC device */ uint32_t iButtonReleaseDelayMs;/*!< duration after last update until a button is considered released */ uint32_t iDoubleTapTimeoutMs; /*!< prevent double taps within this timeout. defaults to 200ms. added in 4.0.0 */ uint8_t bAutoWakeAVR; /*!< set to 1 to automatically waking an AVR when the source is activated. added in 4.0.0 */ #if CEC_LIB_VERSION_MAJOR >= 5 uint8_t bAutoPowerOn; /*!< set to 1 and save eeprom config to wake the tv when usb is powered. added in 5.0.0 / fw v9 */ #endif #ifdef __cplusplus libcec_configuration(void) { Clear(); } ~libcec_configuration(void) { Clear(); } bool operator==(const libcec_configuration &other) const { return ( clientVersion == other.clientVersion && !strcmp(strDeviceName, other.strDeviceName) && deviceTypes == other.deviceTypes && bAutodetectAddress == other.bAutodetectAddress && iPhysicalAddress == other.iPhysicalAddress && baseDevice == other.baseDevice && iHDMIPort == other.iHDMIPort && tvVendor == other.tvVendor && wakeDevices == other.wakeDevices && powerOffDevices == other.powerOffDevices && serverVersion == other.serverVersion && bGetSettingsFromROM == other.bGetSettingsFromROM && bActivateSource == other.bActivateSource && bPowerOffOnStandby == other.bPowerOffOnStandby && logicalAddresses == other.logicalAddresses && iFirmwareVersion == other.iFirmwareVersion && !strncmp(strDeviceLanguage, other.strDeviceLanguage, 3) && iFirmwareBuildDate == other.iFirmwareBuildDate && bMonitorOnly == other.bMonitorOnly && cecVersion == other.cecVersion && adapterType == other.adapterType && iDoubleTapTimeoutMs == other.iDoubleTapTimeoutMs && iButtonRepeatRateMs == other.iButtonRepeatRateMs && iButtonReleaseDelayMs == other.iButtonReleaseDelayMs && comboKey == other.comboKey && iComboKeyTimeoutMs == other.iComboKeyTimeoutMs && bAutoWakeAVR == other.bAutoWakeAVR #if CEC_LIB_VERSION_MAJOR >= 5 && bAutoPowerOn == other.bAutoPowerOn #endif ); } bool operator!=(const libcec_configuration &other) const { return !(*this == other); } /*! * @brief Reset this configution struct to the default values. */ void Clear(void) { iPhysicalAddress = CEC_PHYSICAL_ADDRESS_TV; baseDevice = (cec_logical_address)CEC_DEFAULT_BASE_DEVICE; iHDMIPort = CEC_DEFAULT_HDMI_PORT; tvVendor = (uint32_t)CEC_VENDOR_UNKNOWN; clientVersion = LIBCEC_VERSION_CURRENT; serverVersion = LIBCEC_VERSION_CURRENT; bAutodetectAddress = 0; bGetSettingsFromROM = CEC_DEFAULT_SETTING_GET_SETTINGS_FROM_ROM; bActivateSource = CEC_DEFAULT_SETTING_ACTIVATE_SOURCE; bPowerOffOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY; iFirmwareVersion = CEC_FW_VERSION_UNKNOWN; memcpy(strDeviceLanguage, CEC_DEFAULT_DEVICE_LANGUAGE, 3); iFirmwareBuildDate = CEC_FW_BUILD_UNKNOWN; bMonitorOnly = 0; cecVersion = (cec_version)CEC_DEFAULT_SETTING_CEC_VERSION; adapterType = ADAPTERTYPE_UNKNOWN; iDoubleTapTimeoutMs = CEC_DOUBLE_TAP_TIMEOUT_MS; comboKey = CEC_USER_CONTROL_CODE_STOP; iComboKeyTimeoutMs = CEC_DEFAULT_COMBO_TIMEOUT_MS; iButtonRepeatRateMs = 0; iButtonReleaseDelayMs = CEC_BUTTON_TIMEOUT; bAutoWakeAVR = 0; #if CEC_LIB_VERSION_MAJOR >= 5 bAutoPowerOn = 2; #endif strDeviceName[0] = (char)0; deviceTypes.Clear(); logicalAddresses.Clear(); wakeDevices.Clear(); powerOffDevices.Clear(); #if CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN == 1 powerOffDevices.Set(CECDEVICE_BROADCAST); #endif #if CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1 wakeDevices.Set(CECDEVICE_TV); #endif callbackParam = nullptr; callbacks = nullptr; } #endif }; #ifdef __cplusplus }; }; #endif #endif /* CECTYPES_H_ */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
#pragma once /* * This file is part of the libCEC(R) library. * * libCEC(R) is Copyright (C) 2011-2015 Pulse-Eight Limited. All rights reserved. * libCEC(R) is an original work, containing original code. * * libCEC(R) is a trademark of Pulse-Eight Limited. * * This program is dual-licensed; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * Alternatively, you can license this library under a commercial license, * please contact Pulse-Eight Licensing for more information. * * For more information contact: * Pulse-Eight Licensing <license@pulse-eight.com> * http://www.pulse-eight.com/ * http://www.pulse-eight.net/ */ /** * Convert a version number to an uint32_t * @param[in] major Major version number * @param[in] minor Minor version number * @param[in] patch Patch number * * @return The version number as uint32_t */ #define LIBCEC_VERSION_TO_UINT(major, minor, patch) \ ((major < 2 || (major == 2 && minor <= 2)) ? \ (uint32_t) (major << 8) | (minor << 4) | (patch) : \ (uint32_t) (major << 16) | (minor << 8) | (patch)) /* new style version numbers, 2.3.0 and later */ #define LIBCEC_UINT_TO_VERSION_MAJOR(x) ((x >> 16) & 0xFF) #define LIBCEC_UINT_TO_VERSION_MINOR(x) ((x >> 8 ) & 0xFF) #define LIBCEC_UINT_TO_VERSION_PATCH(x) ((x >> 0 ) & 0xFF) /* old style version numbers, before 2.3.0 */ #define LIBCEC_UINT_TO_VERSION_MAJOR_OLD(x) ((x >> 8) & 0xFF) #define LIBCEC_UINT_TO_VERSION_MINOR_OLD(x) ((x >> 4) & 0x0F) #define LIBCEC_UINT_TO_VERSION_PATCH_OLD(x) ((x >> 0) & 0x0F) /*! * libCEC's major version number */ #define CEC_LIB_VERSION_MAJOR LIBCEC_VERSION_MAJOR /*! * libCEC's major version number as string */ #define CEC_LIB_VERSION_STR(s) #s #define CEC_LIB_VERSION_XSTR(s) CEC_LIB_VERSION_STR(s) #define CEC_LIB_VERSION_MAJOR_STR CEC_LIB_VERSION_XSTR(LIBCEC_VERSION_MAJOR) /*! * libCEC's minor version number */ #define CEC_LIB_VERSION_MINOR LIBCEC_VERSION_MINOR /* current libCEC version number */ #define _LIBCEC_VERSION_CURRENT \ LIBCEC_VERSION_TO_UINT(LIBCEC_VERSION_MAJOR, LIBCEC_VERSION_MINOR, LIBCEC_VERSION_PATCH) |