Repository navigation
Expand file tree
/
Copy pathtcpkbd.cpp
More file actions
145 lines (131 loc) · 3.6 KB
/
Copy pathtcpkbd.cpp
File metadata and controls
145 lines (131 loc) · 3.6 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
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include "tcpkbd.h"
#include <QFile>
#include <stdlib.h>
#include "qatemmixeffect.h"
#include "qatemdownstreamkey.h"
void TCPKbd::onAtemConnected(QAtemConnection *atemconn){
qInfo() << "onAtemConnected";
this->atemconn=atemconn;
syncled();
}
/*
void TCPKbd::onAtemDownstreamKeyOnChanged(quint8 keyer, bool state) {
}
void TCPKbd::onAtemAuxSourceChanged(quint8 aux, quint16 source) {
}
*/
void TCPKbd::syncled(void) {
if(atemconn){
uint8_t prev=atemconn->mixEffect(0)->previewInput();
uint8_t prog=atemconn->mixEffect(0)->programInput();
uint8_t d0=atemconn->downstreamKey(0)->onAir();
uint8_t d1=atemconn->downstreamKey(1)->onAir();
/*
leds[(atemconn->mixEffect(0)->previewInput()-1)*2]=1;
leds[(atemconn->mixEffect(0)->programInput()-1)*2]=2;
leds[6]=atemconn->downstreamKey(1)->onAir()?2:0;
*/
for(int i=0;i<8;i++){
char color='b';
QMap<int, QString>::iterator it = leds.find(i);
if(it!=leds.end()){
QString act=*it;
if(act[0]=="D"){
int nr=act.remove(0,1).toInt();
if(nr==0){ color=d0?'y':'b';}
if(nr==1){ color=d1?'y':'b';}
}
if(act[0]=="C"){
int nr=act.remove(0,1).toInt();
if(prev==nr) color='g';
if(prog==nr) color='r';
}
}
QString toSend=QString("C%1%2\n").arg(i).arg(color);
pSocket->write(toSend.toUtf8());
}
//qout << "DSKEY: [ 0 ] "<< m_downstreamKey_0->onAir() << endl;
}
}
void TCPKbd::parse_commands() {
QFile file(TCPKBD_FILE);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
commands.clear();
leds.clear();
while (!file.atEnd()) {
QByteArray line = file.readLine();
QList<QByteArray> ba=line.split(';');
if(ba.length()<2) continue;
const char *keycode=ba.at(0).data();
int ikeycode=atoi(keycode);
ba.removeFirst();
QList<QByteArray>::iterator i;
QStringList lst;
for(i=ba.begin();i!=ba.end();i++){
QString c=QString(i->data()).trimmed();
if(c[0]=='C' || c[0]=='D'){
leds.insert(ikeycode,c);
}else{
lst << c;
}
}
commands.insert(ikeycode,lst);
}
qInfo() << "-------";
qInfo() << "cmd"<<commands;
qInfo() << "led"<<leds;
}
void TCPKbd::handle_kbdcmd(QByteArray cmd) {
if(cmd[0]!='P') return;
int button=QString(cmd.remove(0,1)).toInt();
QMap<int, QStringList>::iterator i = commands.find(button);
if(i!=commands.end()){
QStringList::iterator l;
for(l=(*i).begin();l!=(*i).end();l++){
emit cmdReady((*l).split(" "));
}
}
}
void TCPKbd::readTcpData() {
QByteArray data = pSocket->readAll();
readBuffer.append(data);
int i;
while((i=readBuffer.indexOf("\n"))>=0){
QByteArray cmd=readBuffer.left(i);
handle_kbdcmd(cmd);
readBuffer=readBuffer.remove(0,i+1);
}
}
void TCPKbd::run(){
qInfo() << "TCPKbd" << dev;
pSocket = new QTcpSocket();
connect( pSocket, SIGNAL(readyRead()), SLOT(readTcpData()) );
pSocket->connectToHost(dev, 1929);
if( pSocket->waitForConnected() ) {
pSocket->setTextModeEnabled(true);
/*
pSocket->write("C0w\nC2w\nC4w\nC6w\n",16);
qInfo() << pSocket->waitForBytesWritten();
*/
}
parse_commands();
/*
if (ev.type == EV_KEY && ev.value == 1){
QMap<int, QStringList>::iterator i = commands.find((int)ev.code);
if(i!=commands.end()){
QStringList::iterator l;
for(l=(*i).begin();l!=(*i).end();l++){
emit cmdReady((*l).split(" "));
}
}
}
}
*/
}