Skip to content

Commit 5b3f3a7

Browse files
committed
OpenNI2-FreenectDriver: Fix silly silly string bugs; improve logging
Fix ebuild for filename change Signed-off-by: Benn Snyder <[email protected]>
1 parent 8d8558f commit 5b3f3a7

File tree

6 files changed

+43
-16
lines changed

6 files changed

+43
-16
lines changed

OpenNI2-FreenectDriver/src/ColorStream.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ OniStatus ColorStream::setVideoMode(OniVideoMode requested_mode)
4040
try { device->setVideoFormat(format, resolution); }
4141
catch (std::runtime_error e)
4242
{
43-
LogError("Format " + format + std::string(" and resolution " + resolution) + " combination not supported by libfreenect");
43+
LogError("Format " + to_string(format) + " and resolution " + to_string(resolution) + " combination not supported by libfreenect");
4444
return ONI_STATUS_NOT_SUPPORTED;
4545
}
4646
video_mode = requested_mode;
@@ -58,7 +58,7 @@ void ColorStream::populateFrame(void* data, OniFrame* frame) const
5858
switch (video_mode.pixelFormat)
5959
{
6060
default:
61-
LogError(std::string("Pixel format " + video_mode.pixelFormat) + " not supported by populateFrame()");
61+
LogError("Pixel format " + to_string(video_mode.pixelFormat) + " not supported by populateFrame()");
6262
return;
6363

6464
case ONI_PIXEL_FORMAT_RGB888:

OpenNI2-FreenectDriver/src/DepthStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ OniStatus DepthStream::setVideoMode(OniVideoMode requested_mode)
3939
try { device->setDepthFormat(format, resolution); }
4040
catch (std::runtime_error e)
4141
{
42-
LogError("Format " + format + std::string(" and resolution " + resolution) + " combination not supported by libfreenect");
42+
LogError("Format " + to_string(format) + " and resolution " + to_string(resolution) + " combination not supported by libfreenect");
4343
if (image_registration_mode == ONI_IMAGE_REGISTRATION_DEPTH_TO_COLOR)
4444
{
4545
LogError("Could not enable image registration format; falling back to format defined in getSupportedVideoModes()");

OpenNI2-FreenectDriver/src/DeviceDriver.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace FreenectDriver
6969
switch (sensorType)
7070
{
7171
default:
72-
LogError("Cannot create a stream of type " + sensorType);
72+
LogError("Cannot create a stream of type " + to_string(sensorType));
7373
return NULL;
7474
case ONI_SENSOR_COLOR:
7575
Freenect::FreenectDevice::startVideo();
@@ -232,7 +232,10 @@ namespace FreenectDriver
232232
DriverBase::initialize(connectedCallback, disconnectedCallback, deviceStateChangedCallback, pCookie);
233233
for (int i = 0; i < Freenect::deviceCount(); i++)
234234
{
235-
std::string uri = "freenect://" + i;
235+
std::string uri = "freenect://" + to_string(i);
236+
237+
WriteMessage("Found device " + uri);
238+
236239
OniDeviceInfo info;
237240
strncpy(info.uri, uri.c_str(), ONI_MAX_STR);
238241
strncpy(info.vendor, "Microsoft", ONI_MAX_STR);
@@ -256,6 +259,8 @@ namespace FreenectDriver
256259
}
257260
else
258261
{
262+
WriteMessage("Opening device " + std::string(uri));
263+
259264
unsigned int id;
260265
std::istringstream is(iter->first.uri);
261266
is.seekg(strlen("freenect://"));
@@ -267,23 +272,30 @@ namespace FreenectDriver
267272
}
268273
}
269274

270-
LogError("Could not find device " + *uri);
275+
LogError("Could not find device " + std::string(uri));
271276
return NULL;
272277
}
273278

274279
void deviceClose(oni::driver::DeviceBase* pDevice)
275280
{
276-
for (std::map<OniDeviceInfo, oni::driver::DeviceBase*>::iterator iter = devices.begin(); iter != devices.end(); iter++)
281+
for (std::map<OniDeviceInfo, oni::driver::DeviceBase*>::iterator iter = devices.begin(); iter != devices.end();)
277282
{
278-
if (iter->second == pDevice) {
279-
iter->second = NULL;
283+
if (iter->second == pDevice)
284+
{
285+
WriteMessage("Closing device " + std::string(iter->first.uri));
286+
280287
unsigned int id;
281-
std::istringstream is(iter->first.uri);
288+
std::istringstream is(std::string(iter->first.uri));
282289
is.seekg(strlen("freenect://"));
283290
is >> id;
291+
devices.erase(iter++);
284292
deleteDevice(id);
285293
return;
286294
}
295+
else
296+
{
297+
iter++;
298+
}
287299
}
288300

289301
LogError("Could not close unrecognized device");

OpenNI2-FreenectDriver/src/VideoStream.hpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <iostream>
34
#include "libfreenect.hpp"
45
#include "Driver/OniDriverAPI.h"
56
#include "PS1080.h"
@@ -33,11 +34,26 @@ static bool operator<(const OniVideoMode& left, const OniVideoMode& right) { ret
3334

3435
namespace FreenectDriver
3536
{
36-
// DriverServices is set in DeviceDriver.cpp so all files can call LogError()
37+
template < typename T > std::string to_string(const T& n)
38+
{
39+
std::ostringstream oss;
40+
oss << n;
41+
return oss.str();
42+
}
43+
44+
static void WriteMessage(std::string info)
45+
{
46+
std::cout << "OpenNI2-FreenectDriver: " << info << std::endl;
47+
}
48+
49+
// DriverServices is set in DeviceDriver.cpp so all files can call errorLoggerAppend()
3750
static oni::driver::DriverServices* DriverServices;
3851
static void LogError(std::string error)
3952
{
40-
if (DriverServices)
53+
// errorLoggerAppend() doesn't seem to go anywhere, so call WriteMessage also
54+
WriteMessage("(ERROR) " + error);
55+
56+
if (DriverServices != NULL)
4157
DriverServices->errorLoggerAppend(std::string("OpenNI2-FreenectDriver: " + error).c_str());
4258
}
4359

@@ -52,7 +68,7 @@ namespace FreenectDriver
5268
protected:
5369
static const OniSensorType sensor_type;
5470
Freenect::FreenectDevice* device;
55-
bool running; // acquireFrame() does something iff true
71+
bool running; // buildFrame() does something iff true
5672
OniVideoMode video_mode;
5773
OniCropping cropping;
5874
bool mirroring;
@@ -189,7 +205,6 @@ namespace FreenectDriver
189205
return ONI_STATUS_ERROR;
190206
}
191207
cropping = *(static_cast<const OniCropping*>(data));
192-
193208
raisePropertyChanged(propertyId, data, dataSize);
194209
return ONI_STATUS_OK;
195210

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
EBUILD libfreenect-9999.ebuild 2246 SHA256 9c108418122975f5c9f6587e9c7e35625ce4cc47932b2c0b03b22ccb802d39da SHA512 05310b350b6598fd826c6ca6e12edc1f809157924a6fac93cb01ee8652b1d544144a22f32fe6ecf8ebd476e73c2a3c334aed02342d2e060ab6cdf88ef4ec965f WHIRLPOOL e9676dbe32df58e78c66343a0f665217b5b89b08f2caf777090536757024e57478694abe04a6cb290a6aef9e5ed46964b83d64ab55c7187f77fbf54150b83fed
1+
EBUILD libfreenect-9999.ebuild 2240 SHA256 a08047d60a53061516df2a185361ff3d6f7b126f305786cdc95977038c981255 SHA512 4bcb2bcab1e6c396d33a767d13200c5e2a15f4387d2898ec28c36edd15baf15a02b1ed3c9f356c86a0b69ccd68f238b7b9aa9aaf4b19a6b6673ac6e3823b8d89 WHIRLPOOL 11274f350181cd8d550dc4161d6de751a401665e36449bc93701183c0636f0932b3dcc84ff55a2ebf52e5b7c1713c475649713a5416e7563058f7da0c0b42d64

platform/linux/portage/dev-libs/libfreenect/libfreenect-9999.ebuild

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ src_install() {
5959
doins "${S}"/platform/linux/udev/51-kinect.rules
6060

6161
# documentation
62-
dodoc HACKING README.asciidoc
62+
dodoc HACKING README.md
6363
if use doc; then
6464
cd doc
6565
doxygen || ewarn "doxygen failed"

0 commit comments

Comments
 (0)