Skip to content

Commit 21b8da3

Browse files
committed
Code cleanup
- Match conventions, remove unused enums, move method bodies out of the header file
1 parent c17fa54 commit 21b8da3

File tree

6 files changed

+92
-84
lines changed

6 files changed

+92
-84
lines changed

Source/Devices/PolledBno055.cpp

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ PolledBno055::PolledBno055(std::string name, std::string hubName, const oni_dev_
3636
"Bosch Bno055 9-axis inertial measurement unit (IMU) Euler angle",
3737
streamIdentifier,
3838
3,
39-
sampleRate,
39+
SampleRate,
4040
"Eul",
4141
ContinuousChannel::Type::AUX,
42-
eulerAngleScale,
42+
EulerAngleScale,
4343
"Degrees",
4444
{ "Y", "R", "P" },
4545
"euler",
@@ -52,10 +52,10 @@ PolledBno055::PolledBno055(std::string name, std::string hubName, const oni_dev_
5252
"Bosch Bno055 9-axis inertial measurement unit (IMU) Quaternion",
5353
streamIdentifier,
5454
4,
55-
sampleRate,
55+
SampleRate,
5656
"Quat",
5757
ContinuousChannel::Type::AUX,
58-
quaternionScale,
58+
QuaternionScale,
5959
"",
6060
{ "W", "X", "Y", "Z" },
6161
"quaternion",
@@ -68,10 +68,10 @@ PolledBno055::PolledBno055(std::string name, std::string hubName, const oni_dev_
6868
"Bosch Bno055 9-axis inertial measurement unit (IMU) Acceleration",
6969
streamIdentifier,
7070
3,
71-
sampleRate,
71+
SampleRate,
7272
"Acc",
7373
ContinuousChannel::Type::AUX,
74-
accelerationScale,
74+
AccelerationScale,
7575
"m / s ^ 2",
7676
{ "X", "Y", "Z" },
7777
"acceleration",
@@ -84,10 +84,10 @@ PolledBno055::PolledBno055(std::string name, std::string hubName, const oni_dev_
8484
"Bosch Bno055 9-axis inertial measurement unit (IMU) Gravity",
8585
streamIdentifier,
8686
3,
87-
sampleRate,
87+
SampleRate,
8888
"Grav",
8989
ContinuousChannel::Type::AUX,
90-
accelerationScale,
90+
AccelerationScale,
9191
"m/s^2",
9292
{ "X", "Y", "Z" },
9393
"gravity",
@@ -100,7 +100,7 @@ PolledBno055::PolledBno055(std::string name, std::string hubName, const oni_dev_
100100
"Bosch Bno055 9-axis inertial measurement unit (IMU) Temperature",
101101
streamIdentifier,
102102
1,
103-
sampleRate,
103+
SampleRate,
104104
"Temp",
105105
ContinuousChannel::Type::AUX,
106106
1.0f,
@@ -115,7 +115,7 @@ PolledBno055::PolledBno055(std::string name, std::string hubName, const oni_dev_
115115
"Bosch Bno055 9-axis inertial measurement unit (IMU) Calibration status",
116116
streamIdentifier,
117117
4,
118-
sampleRate,
118+
SampleRate,
119119
"Cal",
120120
ContinuousChannel::Type::AUX,
121121
1.0f,
@@ -126,10 +126,15 @@ PolledBno055::PolledBno055(std::string name, std::string hubName, const oni_dev_
126126
);
127127
streamInfos.add(calibrationStatusStream);
128128

129-
for (int i = 0; i < numFrames; i++)
129+
for (int i = 0; i < NumFrames; i++)
130130
eventCodes[i] = 0;
131131
}
132132

133+
PolledBno055::~PolledBno055()
134+
{
135+
stopTimer();
136+
}
137+
133138
OnixDeviceType PolledBno055::getDeviceType()
134139
{
135140
return OnixDeviceType::POLLEDBNO;
@@ -174,7 +179,7 @@ bool PolledBno055::updateSettings()
174179
rc = WriteByte(0x3D, 0x0C); // Operation mode is NDOF
175180
if (rc != ONI_ESUCCESS) return false;
176181

177-
rc = set933I2cRate(i2cRate);
182+
rc = set933I2cRate(I2cRate);
178183

179184
return rc == ONI_ESUCCESS;
180185
}
@@ -203,7 +208,7 @@ void PolledBno055::addFrame(oni_frame_t* frame)
203208

204209
void PolledBno055::addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers)
205210
{
206-
sourceBuffers.add(new DataBuffer(numberOfChannels, (int)sampleRate * bufferSizeInSeconds));
211+
sourceBuffers.add(new DataBuffer(NumberOfChannels, (int)SampleRate * bufferSizeInSeconds));
207212
bnoBuffer = sourceBuffers.getLast();
208213
}
209214

@@ -223,43 +228,43 @@ void PolledBno055::hiResTimerCallback()
223228
size_t offset = 0;
224229

225230
// Euler
226-
bnoSamples[offset++ * numFrames + currentFrame] = readInt16(EulerHeadingLsbAddress) * eulerAngleScale;
227-
bnoSamples[offset++ * numFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 2) * eulerAngleScale;
228-
bnoSamples[offset++ * numFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 4) * eulerAngleScale;
231+
bnoSamples[offset++ * NumFrames + currentFrame] = readInt16(EulerHeadingLsbAddress) * EulerAngleScale;
232+
bnoSamples[offset++ * NumFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 2) * EulerAngleScale;
233+
bnoSamples[offset++ * NumFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 4) * EulerAngleScale;
229234

230235
// Quaternion
231-
bnoSamples[offset++ * numFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 6) * quaternionScale;
232-
bnoSamples[offset++ * numFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 8) * quaternionScale;
233-
bnoSamples[offset++ * numFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 10) * quaternionScale;
234-
bnoSamples[offset++ * numFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 12) * quaternionScale;
236+
bnoSamples[offset++ * NumFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 6) * QuaternionScale;
237+
bnoSamples[offset++ * NumFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 8) * QuaternionScale;
238+
bnoSamples[offset++ * NumFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 10) * QuaternionScale;
239+
bnoSamples[offset++ * NumFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 12) * QuaternionScale;
235240

236241
// Acceleration
237242

238-
bnoSamples[offset++ * numFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 14) * accelerationScale;
239-
bnoSamples[offset++ * numFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 16) * accelerationScale;
240-
bnoSamples[offset++ * numFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 18) * accelerationScale;
243+
bnoSamples[offset++ * NumFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 14) * AccelerationScale;
244+
bnoSamples[offset++ * NumFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 16) * AccelerationScale;
245+
bnoSamples[offset++ * NumFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 18) * AccelerationScale;
241246

242247
// Gravity
243248

244-
bnoSamples[offset++ * numFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 20) * accelerationScale;
245-
bnoSamples[offset++ * numFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 22) * accelerationScale;
246-
bnoSamples[offset++ * numFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 24) * accelerationScale;
249+
bnoSamples[offset++ * NumFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 20) * AccelerationScale;
250+
bnoSamples[offset++ * NumFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 22) * AccelerationScale;
251+
bnoSamples[offset++ * NumFrames + currentFrame] = readInt16(EulerHeadingLsbAddress + 24) * AccelerationScale;
247252

248253
// Temperature
249254

250255
oni_reg_val_t byte;
251256
ReadByte(EulerHeadingLsbAddress + 26, &byte);
252-
bnoSamples[offset++ * numFrames + currentFrame] = static_cast<uint8_t>(byte);
257+
bnoSamples[offset++ * NumFrames + currentFrame] = static_cast<uint8_t>(byte);
253258

254259
// Calibration Status
255260

256261
ReadByte(EulerHeadingLsbAddress + 27, &byte);
257-
262+
258263
constexpr uint8_t statusMask = 0b11;
259264

260265
for (int i = 0; i < 4; i++)
261266
{
262-
bnoSamples[currentFrame + (offset + i) * numFrames] = (byte & (statusMask << (2 * i))) >> (2 * i);
267+
bnoSamples[currentFrame + (offset + i) * NumFrames] = (byte & (statusMask << (2 * i))) >> (2 * i);
263268
}
264269

265270
oni_reg_val_t timestampL = 0, timestampH = 0;
@@ -274,9 +279,9 @@ void PolledBno055::hiResTimerCallback()
274279

275280
currentFrame++;
276281

277-
if (currentFrame >= numFrames)
282+
if (currentFrame >= NumFrames)
278283
{
279-
bnoBuffer->addToBuffer(bnoSamples.data(), sampleNumbers, bnoTimestamps, eventCodes, numFrames);
284+
bnoBuffer->addToBuffer(bnoSamples.data(), sampleNumbers, bnoTimestamps, eventCodes, NumFrames);
280285
currentFrame = 0;
281286
}
282287
}

Source/Devices/PolledBno055.h

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,14 @@ namespace OnixSourcePlugin
4040
/** Constructor */
4141
PolledBno055(std::string name, std::string hubName, const oni_dev_idx_t, std::shared_ptr<Onix1> ctx);
4242

43-
~PolledBno055()
44-
{
45-
stopTimer();
46-
}
43+
~PolledBno055();
4744

4845
int configureDevice() override;
49-
50-
/** Update the settings of the device */
5146
bool updateSettings() override;
52-
53-
/** Starts probe data streaming */
5447
void startAcquisition() override;
55-
56-
/** Stops probe data streaming*/
5748
void stopAcquisition() override;
58-
5949
void addFrame(oni_frame_t*) override;
60-
61-
void processFrames() override {};
62-
50+
void processFrames() override;
6351
void addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers) override;
6452

6553
void hiResTimerCallback() override;
@@ -91,50 +79,38 @@ namespace OnixSourcePlugin
9179

9280
DataBuffer* bnoBuffer;
9381

94-
static const int Bno055Address = 0x28;
95-
static const int EulerHeadingLsbAddress = 0x1A;
82+
static constexpr int Bno055Address = 0x28;
83+
static constexpr int EulerHeadingLsbAddress = 0x1A;
9684

97-
const double i2cRate = 400e3;
85+
static constexpr double I2cRate = 400e3;
9886

99-
static const int numberOfBytes = 28;
87+
static constexpr int NumberOfBytes = 28;
10088

101-
const float eulerAngleScale = 1.0f / 16; // 1 degree = 16 LSB
102-
const float quaternionScale = 1.0f / (1 << 14); // 1 = 2^14 LSB
103-
const float accelerationScale = 1.0f / 100; // 1m / s^2 = 100 LSB
89+
static constexpr float EulerAngleScale = 1.0f / 16; // 1 degree = 16 LSB
90+
static constexpr float QuaternionScale = 1.0f / (1 << 14); // 1 = 2^14 LSB
91+
static constexpr float AccelerationScale = 1.0f / 100; // 1m / s^2 = 100 LSB
10492

10593
std::unique_ptr<I2CRegisterContext> deserializer;
10694

107-
enum class PolledBno055Registers : int32_t
108-
{
109-
EulerAngle = 0x1, // Specifies that the Euler angles will be polled.
110-
Quaternion = 0x2, // Specifies that the quaternion will be polled.
111-
Acceleration = 0x4, // Specifies that the linear acceleration will be polled.
112-
Gravity = 0x8, // Specifies that the gravity vector will be polled.
113-
Temperature = 0x10, // Specifies that the temperature measurement will be polled.
114-
Calibration = 0x20, // Specifies that the sensor calibration status will be polled.
115-
All = EulerAngle | Quaternion | Acceleration | Gravity | Temperature | Calibration, // Specifies that all sensor measurements and calibration status will be polled.
116-
};
117-
11895
Bno055AxisMap axisMap = Bno055AxisMap::XYZ;
11996
uint32_t axisSign = (uint32_t)Bno055AxisSign::Default; // NB: Holds the uint value of the flag. Allows for combinations of X/Y/Z to combined together
12097

121-
static const int numberOfChannels = 3 + 3 + 4 + 3 + 1 + 4;
122-
static constexpr double sampleRate = 30.0;
98+
static constexpr int NumberOfChannels = 3 + 3 + 4 + 3 + 1 + 4;
99+
static constexpr double SampleRate = 30.0;
123100

124-
static const int timerIntervalInMilliseconds = (int)(1e3 * (1 / sampleRate));
101+
static constexpr int TimerIntervalInMilliseconds = (int)(1e3 * (1 / SampleRate));
125102

126-
static const int numFrames = 2;
103+
static constexpr int NumFrames = 2;
127104

128-
std::array<float, numberOfChannels* numFrames> bnoSamples;
105+
std::array<float, NumberOfChannels * NumFrames> bnoSamples;
129106

130-
double bnoTimestamps[numFrames];
131-
int64 sampleNumbers[numFrames];
132-
uint64 eventCodes[numFrames];
107+
double bnoTimestamps[NumFrames];
108+
int64 sampleNumbers[NumFrames];
109+
uint64 eventCodes[NumFrames];
133110

134111
unsigned short currentFrame = 0;
135112
int sampleNumber = 0;
136113

137-
// Given the starting address (i.e., the LSB), read two bytes and convert to an int16_t
138114
int16_t readInt16(uint32_t);
139115

140116
JUCE_LEAK_DETECTOR(PolledBno055);

Source/Onix1.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ int Onix1::writeRegister(oni_dev_idx_t devIndex, oni_reg_addr_t registerAddress,
139139
return rc;
140140
}
141141

142+
int Onix1::issueReset()
143+
{
144+
int val = 1;
145+
int rc = setOption(ONI_OPT_RESET, val);
146+
return rc;
147+
}
148+
149+
std::string Onix1::getVersion() const
150+
{
151+
return std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(patch);
152+
}
153+
154+
double Onix1::convertTimestampToSeconds(uint64_t timestamp) const
155+
{
156+
return static_cast<double>(timestamp) / ACQ_CLK_HZ;
157+
}
158+
142159
oni_frame_t* Onix1::readFrame() const
143160
{
144161
oni_frame_t* frame = nullptr;

Source/Onix1.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ namespace OnixSourcePlugin
103103

104104
oni_frame_t* readFrame() const;
105105

106-
int issueReset() { int val = 1; int rc = setOption(ONI_OPT_RESET, val); return rc; }
106+
int issueReset();
107107

108-
std::string getVersion() const { return std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(patch); }
108+
std::string getVersion() const;
109109

110-
double convertTimestampToSeconds(uint32_t timestamp) const { return static_cast<double>(timestamp) / ACQ_CLK_HZ; }
110+
double convertTimestampToSeconds(uint64_t timestamp) const;
111111

112112
/** Gets a map of all hubs connected, where the index of the map is the hub address, and the value is the hub ID */
113113
std::map<int, int> getHubIds(device_map_t) const;

Source/OnixSource.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@ OnixSource::OnixSource(SourceNode* sn) :
6464
if (!context->isInitialized()) { LOGE("Failed to initialize context."); return; }
6565
}
6666

67+
OnixSource::~OnixSource()
68+
{
69+
if (context != nullptr && context->isInitialized())
70+
{
71+
portA->setVoltageOverride(0.0f, false);
72+
portB->setVoltageOverride(0.0f, false);
73+
}
74+
}
75+
76+
std::string OnixSource::getLiboniVersion()
77+
{
78+
if (context != nullptr && context->isInitialized())
79+
return context->getVersion();
80+
else
81+
return "";
82+
}
83+
6784
void OnixSource::registerParameters()
6885
{
6986
addBooleanParameter(Parameter::PROCESSOR_SCOPE, "passthroughA", "Passthrough A", "Enables passthrough mode for e-variant headstages on Port A", false, true);

Source/OnixSource.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,7 @@ namespace OnixSourcePlugin
4545
OnixSource(SourceNode* sn);
4646

4747
/** Destructor */
48-
~OnixSource()
49-
{
50-
if (context != nullptr && context->isInitialized())
51-
{
52-
portA->setVoltageOverride(0.0f, false);
53-
portB->setVoltageOverride(0.0f, false);
54-
}
55-
}
48+
~OnixSource();
5649

5750
void registerParameters() override;
5851

@@ -123,7 +116,7 @@ namespace OnixSourcePlugin
123116

124117
std::map<int, std::string> getHubNames();
125118

126-
std::string getLiboniVersion() { if (context != nullptr && context->isInitialized()) return context->getVersion(); else return ""; }
119+
std::string getLiboniVersion();
127120

128121
void updateSourceBuffers();
129122

0 commit comments

Comments
 (0)