controlStructs.cpp
7.28 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
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
// SPDX-License-Identifier: GPL-2.0+
#include <cstring>
#include "controlStructs.h"
namespace Hantek {
//////////////////////////////////////////////////////////////////////////////
// class ControlGetSpeed
/// \brief Initializes the array.
ControlGetSpeed::ControlGetSpeed() : DataArray<uint8_t>(10) {}
/// \brief Gets the speed of the connection.
/// \return The speed level of the USB connection.
ConnectionSpeed ControlGetSpeed::getSpeed() {
return (ConnectionSpeed)this->array[0];
}
//////////////////////////////////////////////////////////////////////////////
// class ControlSetOffset
/// \brief Sets the data array to the default values.
ControlSetOffset::ControlSetOffset() : DataArray<uint8_t>(17) {}
/// \brief Sets the offsets to the given values.
/// \param channel1 The offset for channel 1.
/// \param channel2 The offset for channel 2.
/// \param trigger The offset for ext. trigger.
ControlSetOffset::ControlSetOffset(uint16_t channel1, uint16_t channel2,
uint16_t trigger)
: DataArray<uint8_t>(17) {
this->setChannel(0, channel1);
this->setChannel(1, channel2);
this->setTrigger(trigger);
}
/// \brief Get the offset for the given channel.
/// \param channel The channel whose offset should be returned.
/// \return The channel offset value.
uint16_t ControlSetOffset::getChannel(unsigned int channel) {
if (channel == 0)
return ((this->array[0] & 0x0f) << 8) | this->array[1];
else
return ((this->array[2] & 0x0f) << 8) | this->array[3];
}
/// \brief Set the offset for the given channel.
/// \param channel The channel that should be set.
/// \param offset The new channel offset value.
void ControlSetOffset::setChannel(unsigned int channel, uint16_t offset) {
if (channel == 0) {
this->array[0] = (uint8_t)(offset >> 8);
this->array[1] = (uint8_t)offset;
} else {
this->array[2] = (uint8_t)(offset >> 8);
this->array[3] = (uint8_t)offset;
}
}
/// \brief Get the trigger level.
/// \return The trigger level value.
uint16_t ControlSetOffset::getTrigger() {
return ((this->array[4] & 0x0f) << 8) | this->array[5];
}
/// \brief Set the trigger level.
/// \param level The new trigger level value.
void ControlSetOffset::setTrigger(uint16_t level) {
this->array[4] = (uint8_t)(level >> 8);
this->array[5] = (uint8_t)level;
}
//////////////////////////////////////////////////////////////////////////////
// class ControlSetRelays
/// \brief Sets all relay states.
/// \param ch1Below1V Sets the state of the Channel 1 below 1 V relay.
/// \param ch1Below100mV Sets the state of the Channel 1 below 100 mV relay.
/// \param ch1CouplingDC Sets the state of the Channel 1 coupling relay.
/// \param ch2Below1V Sets the state of the Channel 2 below 1 V relay.
/// \param ch2Below100mV Sets the state of the Channel 2 below 100 mV relay.
/// \param ch2CouplingDC Sets the state of the Channel 2 coupling relay.
/// \param triggerExt Sets the state of the external trigger relay.
ControlSetRelays::ControlSetRelays(bool ch1Below1V, bool ch1Below100mV,
bool ch1CouplingDC, bool ch2Below1V,
bool ch2Below100mV, bool ch2CouplingDC,
bool triggerExt)
: DataArray<uint8_t>(17) {
this->setBelow1V(0, ch1Below1V);
this->setBelow100mV(0, ch1Below100mV);
this->setCoupling(0, ch1CouplingDC);
this->setBelow1V(1, ch2Below1V);
this->setBelow100mV(1, ch2Below100mV);
this->setCoupling(1, ch2CouplingDC);
this->setTrigger(triggerExt);
}
/// \brief Get the below 1 V relay state for the given channel.
/// \param channel The channel whose relay state should be returned.
/// \return true, if the gain of the channel is below 1 V.
bool ControlSetRelays::getBelow1V(unsigned int channel) {
if (channel == 0)
return (this->array[1] & 0x04) == 0x00;
else
return (this->array[4] & 0x20) == 0x00;
}
/// \brief Set the below 1 V relay for the given channel.
/// \param channel The channel that should be set.
/// \param below true, if the gain of the channel should be below 1 V.
void ControlSetRelays::setBelow1V(unsigned int channel, bool below) {
if (channel == 0)
this->array[1] = below ? 0xfb : 0x04;
else
this->array[4] = below ? 0xdf : 0x20;
}
/// \brief Get the below 1 V relay state for the given channel.
/// \param channel The channel whose relay state should be returned.
/// \return true, if the gain of the channel is below 1 V.
bool ControlSetRelays::getBelow100mV(unsigned int channel) {
if (channel == 0)
return (this->array[2] & 0x08) == 0x00;
else
return (this->array[5] & 0x40) == 0x00;
}
/// \brief Set the below 100 mV relay for the given channel.
/// \param channel The channel that should be set.
/// \param below true, if the gain of the channel should be below 100 mV.
void ControlSetRelays::setBelow100mV(unsigned int channel, bool below) {
if (channel == 0)
this->array[2] = below ? 0xf7 : 0x08;
else
this->array[5] = below ? 0xbf : 0x40;
}
/// \brief Get the coupling relay state for the given channel.
/// \param channel The channel whose relay state should be returned.
/// \return true, if the coupling of the channel is DC.
bool ControlSetRelays::getCoupling(unsigned int channel) {
if (channel == 0)
return (this->array[3] & 0x02) == 0x00;
else
return (this->array[6] & 0x10) == 0x00;
}
/// \brief Set the coupling relay for the given channel.
/// \param channel The channel that should be set.
/// \param dc true, if the coupling of the channel should be DC.
void ControlSetRelays::setCoupling(unsigned int channel, bool dc) {
if (channel == 0)
this->array[3] = dc ? 0xfd : 0x02;
else
this->array[6] = dc ? 0xef : 0x10;
}
/// \brief Get the external trigger relay state.
/// \return true, if the trigger is external (EXT-Connector).
bool ControlSetRelays::getTrigger() { return (this->array[7] & 0x01) == 0x00; }
/// \brief Set the external trigger relay.
/// \param ext true, if the trigger should be external (EXT-Connector).
void ControlSetRelays::setTrigger(bool ext) {
this->array[7] = ext ? 0xfe : 0x01;
}
//////////////////////////////////////////////////////////////////////////////
// class ControlSetVoltDIV_CH1
/// \brief Sets the data array to the default values.
ControlSetVoltDIV_CH1::ControlSetVoltDIV_CH1() : DataArray<uint8_t>(1) {
this->setDiv(5);
}
void ControlSetVoltDIV_CH1::setDiv(uint8_t val) { this->array[0] = val; }
//////////////////////////////////////////////////////////////////////////////
// class ControlSetVoltDIV_CH2
/// \brief Sets the data array to the default values.
ControlSetVoltDIV_CH2::ControlSetVoltDIV_CH2() : DataArray<uint8_t>(1) {
this->setDiv(5);
}
void ControlSetVoltDIV_CH2::setDiv(uint8_t val) { this->array[0] = val; }
//////////////////////////////////////////////////////////////////////////////
// class ControlSetTimeDIV
/// \brief Sets the data array to the default values.
ControlSetTimeDIV::ControlSetTimeDIV() : DataArray<uint8_t>(1) {
this->setDiv(1);
}
void ControlSetTimeDIV::setDiv(uint8_t val) { this->array[0] = val; }
//////////////////////////////////////////////////////////////////////////////
// class ControlAcquireHardData
/// \brief Sets the data array to the default values.
ControlAcquireHardData::ControlAcquireHardData()
: DataArray<uint8_t>(1) {
this->init();
}
void ControlAcquireHardData::init() { this->array[0] = 0x01; }
}