• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mcallegari / qlcplus / 13633248611

03 Mar 2025 02:31PM UTC coverage: 31.871% (+0.4%) from 31.5%
13633248611

push

github

web-flow
actions: add chrpath to profile

14689 of 46089 relevant lines covered (31.87%)

26426.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

99.12
/plugins/enttecwing/src/programwing.cpp
1
/*
2
  Q Light Controller
3
  programwing.cpp
4

5
  Copyright (c) Heikki Junnila
6

7
  Licensed under the Apache License, Version 2.0 (the "License");
8
  you may not use this file except in compliance with the License.
9
  You may obtain a copy of the License at
10

11
      http://www.apache.org/licenses/LICENSE-2.0.txt
12

13
  Unless required by applicable law or agreed to in writing, software
14
  distributed under the License is distributed on an "AS IS" BASIS,
15
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
  See the License for the specific language governing permissions and
17
  limitations under the License.
18
*/
19

20
#include <QHostAddress>
21
#include <QMessageBox>
22
#include <QByteArray>
23
#include <QString>
24
#include <QDebug>
25

26
#include "programwing.h"
27

28
/****************************************************************************
29
 * Program wing specifics
30
 ****************************************************************************/
31

32
#define WING_PROGRAM_BYTE_BUTTON 6
33
#define WING_PROGRAM_BUTTON_SIZE 9
34

35
#define WING_PROGRAM_BYTE_ENCODER 25
36
#define WING_PROGRAM_ENCODER_SIZE 3
37

38
/** Should constitute up to 75 channels (with some unused ones in the middle) */
39
#define WING_PROGRAM_CHANNEL_COUNT (8 * WING_PROGRAM_BUTTON_SIZE) \
40
                                        + WING_PROGRAM_ENCODER_SIZE
41

42
/****************************************************************************
43
 * Initialization
44
 ****************************************************************************/
45

46
ProgramWing::ProgramWing(QObject* parent, const QHostAddress& address,
1✔
47
                         const QByteArray& data)
1✔
48
    : Wing(parent, address, data)
1✔
49
{
50
    m_values = QByteArray(WING_PROGRAM_CHANNEL_COUNT, 0);
1✔
51

52
    m_channelMap[0] = 6;
1✔
53
    m_channelMap[1] = 5;
1✔
54
    m_channelMap[2] = WING_INVALID_CHANNEL;
1✔
55
    m_channelMap[3] = 4;
1✔
56
    m_channelMap[4] = 3;
1✔
57
    m_channelMap[5] = 2;
1✔
58
    m_channelMap[6] = 1;
1✔
59
    m_channelMap[7] = 0;
1✔
60

61
    m_channelMap[8] = 14;
1✔
62
    m_channelMap[9] = 13;
1✔
63
    m_channelMap[10] = 12;
1✔
64
    m_channelMap[11] = 11;
1✔
65
    m_channelMap[12] = 10;
1✔
66
    m_channelMap[13] = 9;
1✔
67
    m_channelMap[14] = 8;
1✔
68
    m_channelMap[15] = 7;
1✔
69

70
    m_channelMap[16] = 17;
1✔
71
    m_channelMap[17] = 16;
1✔
72
    m_channelMap[18] = WING_INVALID_CHANNEL;
1✔
73
    m_channelMap[19] = WING_INVALID_CHANNEL;
1✔
74
    m_channelMap[20] = WING_INVALID_CHANNEL;
1✔
75
    m_channelMap[21] = WING_INVALID_CHANNEL;
1✔
76
    m_channelMap[22] = WING_INVALID_CHANNEL;
1✔
77
    m_channelMap[23] = 15;
1✔
78

79
    m_channelMap[24] = 25;
1✔
80
    m_channelMap[25] = 24;
1✔
81
    m_channelMap[26] = 23;
1✔
82
    m_channelMap[27] = 22;
1✔
83
    m_channelMap[28] = 21;
1✔
84
    m_channelMap[29] = 20;
1✔
85
    m_channelMap[30] = 19;
1✔
86
    m_channelMap[31] = 18;
1✔
87

88
    m_channelMap[32] = 38;
1✔
89
    m_channelMap[33] = 37;
1✔
90
    m_channelMap[34] = 36;
1✔
91
    m_channelMap[35] = 30;
1✔
92
    m_channelMap[36] = 29;
1✔
93
    m_channelMap[37] = 28;
1✔
94
    m_channelMap[38] = 27;
1✔
95
    m_channelMap[39] = 26;
1✔
96

97
    m_channelMap[40] = 56;
1✔
98
    m_channelMap[41] = 50;
1✔
99
    m_channelMap[42] = 49;
1✔
100
    m_channelMap[43] = 48;
1✔
101
    m_channelMap[44] = 47;
1✔
102
    m_channelMap[45] = 46;
1✔
103
    m_channelMap[46] = 40;
1✔
104
    m_channelMap[47] = 39;
1✔
105

106
    m_channelMap[48] = 57;
1✔
107
    m_channelMap[49] = 35;
1✔
108
    m_channelMap[50] = 34;
1✔
109
    m_channelMap[51] = 45;
1✔
110
    m_channelMap[52] = 44;
1✔
111
    m_channelMap[53] = 55;
1✔
112
    m_channelMap[54] = 54;
1✔
113
    m_channelMap[55] = 58;
1✔
114

115
    m_channelMap[56] = 32;
1✔
116
    m_channelMap[57] = 31;
1✔
117
    m_channelMap[58] = 43;
1✔
118
    m_channelMap[59] = 42;
1✔
119
    m_channelMap[60] = 41;
1✔
120
    m_channelMap[61] = 53;
1✔
121
    m_channelMap[62] = 52;
1✔
122
    m_channelMap[63] = 51;
1✔
123

124
    m_channelMap[64] = WING_INVALID_CHANNEL;
1✔
125
    m_channelMap[65] = 64;
1✔
126
    m_channelMap[66] = 63;
1✔
127
    m_channelMap[67] = 62;
1✔
128
    m_channelMap[68] = 61;
1✔
129
    m_channelMap[69] = 60;
1✔
130
    m_channelMap[70] = 59;
1✔
131
    m_channelMap[71] = 33;
1✔
132

133
    m_channelMap[72] = 65;
1✔
134
    m_channelMap[73] = 66;
1✔
135
    m_channelMap[74] = 67;
1✔
136

137
    /* Take initial values from the first received datagram packet.
138
       The plugin hasn't yet connected to valueChanged() signal, so this
139
       won't cause any input events. */
140
    parseData(data);
1✔
141
}
1✔
142

143
ProgramWing::~ProgramWing()
2✔
144
{
145
}
2✔
146

147
/****************************************************************************
148
 * Wing data
149
 ****************************************************************************/
150

151
QString ProgramWing::name() const
3✔
152
{
153
    QString name("Program");
3✔
154
    name += QString(" ") + tr("at") + QString(" ");
9✔
155
    name += m_address.toString();
6✔
156

157
    return name;
3✔
158
}
×
159

160
/****************************************************************************
161
 * Input data
162
 ****************************************************************************/
163

164
void ProgramWing::parseData(const QByteArray& data)
1,666✔
165
{
166
    uchar value;
167
    int size;
168
    int byte;
169

170
    /* Check that we can get all buttons from the packet */
171
    size = WING_PROGRAM_BYTE_BUTTON + WING_PROGRAM_BUTTON_SIZE;
172
    if (data.size() < size)
1,666✔
173
    {
174
        qWarning() << Q_FUNC_INFO << "Expected at least" << size
2✔
175
                   << "bytes for buttons but got only" << data.size();
1✔
176
        return;
1✔
177
    }
178

179
    /* Read the state of each button */
180
    for (byte = size - 1; byte >= WING_PROGRAM_BYTE_BUTTON; byte--)
16,650✔
181
    {
182
        /* Each byte has 8 button values as binary bits */
183
        for (int bit = 7; bit >= 0; bit--)
134,865✔
184
        {
185
            int key;
186

187
            /* Calculate the key number, which is 0-64 */
188
            key = (size - byte - 1) * 8;
119,880✔
189
            key += bit;
119,880✔
190

191
            /* 0 = button down, 1 = button up */
192
            if ((data[byte] & (1 << bit)) == 0)
119,880✔
193
                value = UCHAR_MAX;
194
            else
195
                value = 0;
196

197
            /* Get the correct channel number for each key. */
198
            setCacheValue(m_channelMap[key], value);
119,880✔
199
        }
200
    }
201

202
    /* Check that we can get all sliders from the packet */
203
    size = WING_PROGRAM_BYTE_ENCODER + WING_PROGRAM_ENCODER_SIZE;
204
    if (data.size() < size)
1,665✔
205
    {
206
        qWarning() << "Expected at least" << size
2✔
207
        << "bytes for sliders but got only" << data.size();
1✔
208
        return;
1✔
209
    }
210

211
    /* Read the direction of each encoder. 255 = CW, 1 = CCW, 0 = NOP. */
212
    for (int encoder = 0; encoder < WING_PROGRAM_ENCODER_SIZE; encoder++)
6,656✔
213
    {
214
        int channel = (WING_PROGRAM_CHANNEL_COUNT -
4,992✔
215
                       WING_PROGRAM_ENCODER_SIZE) + encoder;
4,992✔
216
        unsigned char cvalue = cacheValue(m_channelMap[channel]);
4,992✔
217

218
        value = data[WING_PROGRAM_BYTE_ENCODER + encoder];
4,992✔
219
        if (value == 255)
4,992✔
220
            setCacheValue(m_channelMap[channel], ++cvalue);
765✔
221
        else if (value == 1)
4,227✔
222
            setCacheValue(m_channelMap[channel], --cvalue);
2,298✔
223
    }
224
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc