• 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

82.93
/engine/src/keypadparser.cpp
1
/*
2
  Q Light Controller Plus
3
  keypadparser.cpp
4

5
  Copyright (c) Massimo Callegari
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 <cmath>
21

22
#include "keypadparser.h"
23
#include "qlcmacros.h"
24
#include "universe.h"
25

26
KeyPadParser::KeyPadParser()
1✔
27
{
28

29
}
1✔
30

31
QList<SceneValue> KeyPadParser::parseCommand(Doc *doc, QString command,
12✔
32
                                             QByteArray &uniData)
33
{
34
    QList<SceneValue> values;
35
    if (doc == NULL || command.isEmpty())
12✔
36
        return values;
37

38
    QStringList tokens = command.split(" ");
24✔
39

40
    int lastCommand = CommandNone;
41
    quint32 fromChannel = 0;
42
    quint32 toChannel = 0;
43
    quint32 byChannel = 1;
44
    bool channelSet = false;
45
    float fromValue = 0;
46
    float toValue = 0;
47
    int thruCount = 0;
48

49
    foreach (QString token, tokens)
62✔
50
    {
51
        if (token.isEmpty())
50✔
52
            continue;
×
53

54
        if (token == "AT")
50✔
55
        {
56
            lastCommand = CommandAT;
57
        }
58
        else if (token == "THRU")
43✔
59
        {
60
            lastCommand = CommandTHRU;
61
        }
62
        else if (token == "FULL")
36✔
63
        {
64
            toValue = 255;
65
            lastCommand = CommandFULL;
66
        }
67
        else if (token == "ZERO")
33✔
68
        {
69
            toValue = 0;
70
            lastCommand = CommandZERO;
71
        }
72
        else if (token == "BY")
31✔
73
        {
74
            lastCommand = CommandBY;
75
        }
76
        else if (token == "+")
28✔
77
        {
78
            lastCommand = CommandPlus;
79
        }
80
        else if (token == "-")
28✔
81
        {
82
            lastCommand = CommandMinus;
83
        }
84
        else if (token == "+%")
28✔
85
        {
86
            lastCommand = CommandPlusPercent;
87
        }
88
        else if (token == "-%")
27✔
89
        {
90
            lastCommand = CommandMinusPercent;
91
        }
92
        else if (token == "%")
26✔
93
        {
94
            if (lastCommand == CommandPlus)
×
95
                lastCommand = CommandPlusPercent;
96
            else if (lastCommand == CommandMinus)
×
97
                lastCommand = CommandMinusPercent;
98
        }
99
        else
100
        {
101
            // most likely a number
102
            bool ok = false;
26✔
103
            int number = token.toUInt(&ok);
26✔
104

105
            if (ok == false)
26✔
106
                continue;
×
107

108
            switch (lastCommand)
26✔
109
            {
110
                case CommandNone:
9✔
111
                    // no command: this is a channel number
112
                    if (number <= 0)
9✔
113
                        break;
114

115
                    fromChannel = number;
116
                    toChannel = fromChannel;
117
                    fromValue = uchar(uniData.at(number - 1));
9✔
118
                    toValue = fromValue;
119
                    channelSet = true;
120
                break;
9✔
121
                case CommandAT:
5✔
122
                    fromValue = float(number);
5✔
123
                    toValue = fromValue;
124
                break;
5✔
125
                case CommandTHRU:
7✔
126
                    if (thruCount == 0)
7✔
127
                        toChannel = number;
128
                    else
129
                        toValue = float(number);
1✔
130
                    thruCount++;
7✔
131
                break;
7✔
132
                case CommandFULL:
×
133
                    fromValue = 255;
134
                    toValue = 255;
135
                break;
×
136
                case CommandZERO:
×
137
                    fromValue = 0;
138
                    toValue = 0;
139
                break;
×
140
                case CommandBY:
3✔
141
                    byChannel = number;
142
                break;
3✔
143
                case CommandPlus:
×
144
                case CommandMinus:
145
                    toValue = number;
×
146
                break;
×
147
                case CommandPlusPercent:
2✔
148
                case CommandMinusPercent:
149
                    toValue = float(number) / 100.0;
2✔
150
                break;
2✔
151
            }
152
        }
153
    }
50✔
154

155
    /** handle the case where channel(s) are not specified.
156
     *  Compose a list of values based on the last channel list */
157

158
    if (channelSet == false)
12✔
159
    {
160
        if (m_channels.isEmpty())
3✔
161
            return values;
162

163
        for (int i = 0; i < m_channels.count(); i++)
27✔
164
        {
165
            SceneValue scv;
24✔
166

167
            scv.channel = m_channels.at(i);
24✔
168
            scv.value = toValue;
24✔
169
            values.append(scv);
24✔
170
        }
24✔
171

172
        return values;
173
    }
174
    else
175
    {
176
        m_channels.clear();
9✔
177
    }
178

179
    float valueDelta = 0;
180
    if (toValue != fromValue)
9✔
181
    {
182
        valueDelta = (float(toChannel) - float(fromChannel)) / float(byChannel);
5✔
183
        valueDelta = (float(toValue) - float(fromValue)) / valueDelta;
5✔
184
    }
185

186
    for (quint32 i = fromChannel - 1; i <= toChannel - 1; i += byChannel)
61✔
187
    {
188
        uchar uniValue = 0;
189
        SceneValue scv;
52✔
190

191
        if (i >= UNIVERSE_SIZE)
52✔
192
            continue;
193

194
        if (quint32(uniData.length()) > i)
52✔
195
            uniValue = uchar(uniData.at(i));
52✔
196

197
        scv.channel = i;
52✔
198
        if (lastCommand == CommandPlus)
52✔
199
            scv.value = CLAMP(uniValue + toValue, 0, 255);
×
200
        else if (lastCommand == CommandMinus)
201
            scv.value = CLAMP(uniValue - toValue, 0, 255);
×
202
        else if (lastCommand == CommandPlusPercent)
203
            scv.value = CLAMP(lrintf(uniValue * (1.0 + toValue)), 0, 255);
6✔
204
        else if (lastCommand == CommandMinusPercent)
205
            scv.value = CLAMP(lrintf(uniValue - (float(uniValue) * toValue)), 0, 255);
6✔
206
        else if (lastCommand == CommandZERO)
207
            scv.value = 0;
1✔
208
        else if (lastCommand == CommandFULL)
209
            scv.value = 255;
11✔
210
        else
211
            scv.value = uchar(fromValue);
28✔
212

213
        if (m_channels.contains(scv.channel) == false)
52✔
214
            m_channels.append(scv.channel);
52✔
215

216
        values.append(scv);
52✔
217
        fromValue += valueDelta;
52✔
218
    }
52✔
219

220
    return values;
221
}
×
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