-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcec.cpp
More file actions
155 lines (124 loc) · 3.73 KB
/
cec.cpp
File metadata and controls
155 lines (124 loc) · 3.73 KB
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
/*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 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/
*/
#include "cec.h"
#include <cstdio>
#include <fcntl.h>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <signal.h>
#include <stdlib.h>
extern "C" {
int cec_init();
int cec_exit();
int ProcessCommandTX(char *);
int cec_send_command(int, char*);
}
using namespace CEC;
#if CEC_LIB_VERSION_MAJOR >= 5
#define LIBCEC_OSD_NAME_SIZE (15)
#else
#define LIBCEC_OSD_NAME_SIZE (13)
#endif
ICECCallbacks g_callbacks;
libcec_configuration g_config;
int g_cecLogLevel(-1);
int g_cecDefaultLogLevel(0);
std::string g_strPort;
ICECAdapter* g_parser;
int ProcessCommandTX(char *arguments)
{
std::string strvalue;
cec_command bytes = g_parser->CommandFromString(arguments);
bytes.ack = 0;
bytes.eom = 0;
bytes.transmit_timeout = 1000;
g_parser->Transmit(bytes);
return 0;
}
int cec_send_command(int dev,char *buffer) {
cec_command tx;
tx.initiator = (cec_logical_address)1;
tx.destination = (cec_logical_address)dev;
tx.ack = 0;
tx.eom = 0;
tx.opcode = CEC_OPCODE_USER_CONTROL_PRESSED;
tx.parameters.size = 1;
tx.opcode_set = 1;
tx.transmit_timeout = 1000;
if (strcmp("up",buffer) == 0) {
tx.parameters.data[0]= CEC_USER_CONTROL_CODE_VOLUME_UP;
} else {
tx.parameters.data[0]= CEC_USER_CONTROL_CODE_VOLUME_DOWN;
}
g_parser->Transmit(tx);
return 0;
}
int cec_init() {
g_config.Clear();
g_callbacks.Clear();
snprintf(g_config.strDeviceName, LIBCEC_OSD_NAME_SIZE, "VDR CEC");
g_config.clientVersion = LIBCEC_VERSION_CURRENT;
g_config.bActivateSource = 0;
g_callbacks.logMessage = NULL;
g_callbacks.keyPress = NULL;
g_callbacks.commandReceived = NULL;
g_callbacks.alert = NULL;
g_config.callbacks = &g_callbacks;
g_config.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
if (g_cecLogLevel == -1)
g_cecLogLevel = g_cecDefaultLogLevel;
g_parser = CECInitialise(&g_config);
if (!g_parser)
{
std::cout << "Cannot load libcec.so" << std::endl;
if (g_parser)
CECDestroy(g_parser);
return 0;
}
g_strPort = "AOCEC";
if (!g_parser->Open(g_strPort.c_str()))
{
CECDestroy(g_parser);
return 0;
}
return 1;
}
int cec_exit() {
if (g_parser) {
CECDestroy(g_parser);
g_parser = NULL;
}
return 0;
}