Skip to content

Commit c67e3b0

Browse files
saulthuxlz
authored andcommitted
Add setting of LEDs (#1052)
1 parent c203ee2 commit c67e3b0

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ SET(SOURCES
124124
include/libfreenect2/frame_listener_impl.h
125125
include/libfreenect2/libfreenect2.hpp
126126
include/libfreenect2/color_settings.h
127+
include/libfreenect2/led_settings.h
127128
include/libfreenect2/packet_pipeline.h
128129
include/internal/libfreenect2/packet_processor.h
129130
include/libfreenect2/registration.h

include/internal/libfreenect2/protocol/command.h

+14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <stdint.h>
3131
#include <cstring>
3232
#include "libfreenect2/protocol/response.h"
33+
#include "libfreenect2/led_settings.h"
3334

3435
#define KCMD_READ_FIRMWARE_VERSIONS 0x02
3536
#define KCMD_INIT_STREAMS 0x09
@@ -42,6 +43,7 @@
4243
#define KCMD_SET_MODE 0x4B
4344

4445
#define KCMD_RGB_SETTING 0x3E // Command value for color camera settings
46+
#define KCMD_LED_SETTING 0x4B
4547

4648
#define KCMD_0x46 0x46
4749
#define KCMD_0x47 0x47
@@ -253,6 +255,18 @@ struct ColorSettingCommand : public Command<KCMD_RGB_SETTING, ColorSettingRespon
253255
}
254256
};
255257

258+
259+
#define LedSettingResponseSize 0
260+
struct LedSettingCommand : public libfreenect2::protocol::Command<KCMD_LED_SETTING, LedSettingResponseSize, LedSettingResponseSize, 4>
261+
{
262+
LedSettingCommand(LedSettings led)
263+
: Command<KCMD_LED_SETTING, LedSettingResponseSize, LedSettingResponseSize, 4>(0) // seq always zero
264+
{
265+
memcpy(this->data_.parameters, &led, sizeof(led));
266+
}
267+
};
268+
269+
256270
} /* namespace protocol */
257271
} /* namespace libfreenect2 */
258272
#endif /* COMMAND_H_ */

include/libfreenect2/led_settings.h

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* This file is part of the OpenKinect Project. http://www.openkinect.org
3+
*
4+
* Copyright (c) 2011 individual OpenKinect contributors. See the CONTRIB file
5+
* for details.
6+
*
7+
* This code is licensed to you under the terms of the Apache License, version
8+
* 2.0, or, at your option, the terms of the GNU General Public License,
9+
* version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,
10+
* or the following URLs:
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
* http://www.gnu.org/licenses/gpl-2.0.txt
13+
*
14+
* If you redistribute this file in source form, modified or unmodified, you
15+
* may:
16+
* 1) Leave this header intact and distribute it under the same terms,
17+
* accompanying it with the APACHE20 and GPL20 files, or
18+
* 2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or
19+
* 3) Delete the GPL v2 clause and accompany it with the APACHE20 file
20+
* In all cases you must keep the copyright notice intact and include a copy
21+
* of the CONTRIB file.
22+
*
23+
* Binary distributions must follow the binary distribution requirements of
24+
* either License.
25+
*/
26+
27+
#ifndef LED_SETTINGS_H_
28+
#define LED_SETTINGS_H_
29+
30+
namespace libfreenect2
31+
{
32+
33+
// The following information was found by using the library released by Microsoft under MIT license,
34+
// https://github.com/Microsoft/MixedRealityCompanionKit/tree/master/KinectIPD/NuiSensor
35+
// Debugging the library assembly shows the original struct name was _PETRA_LED_STATE.
36+
struct LedSettings
37+
{
38+
uint16_t LedId; // LED index [0, 1]
39+
uint16_t Mode; // 0 = constant, 1 = blink between StartLevel, StopLevel every IntervalInMs ms
40+
uint16_t StartLevel; // LED intensity [0, 1000]
41+
uint16_t StopLevel; // LED intensity [0, 1000]
42+
uint32_t IntervalInMs; // Blink interval for Mode=1 in milliseconds
43+
uint32_t Reserved; // 0
44+
};
45+
46+
} /* namespace libfreenect2 */
47+
48+
#endif /* LED_SETTINGS_H_ */

include/libfreenect2/libfreenect2.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <libfreenect2/frame_listener.hpp>
3434
#include <libfreenect2/packet_pipeline.h>
3535
#include <libfreenect2/color_settings.h>
36+
#include <libfreenect2/led_settings.h>
3637
#include <string>
3738
#include <vector>
3839

@@ -200,6 +201,11 @@ class LIBFREENECT2_API Freenect2Device
200201
virtual uint32_t getColorSetting(ColorSettingCommandType cmd) = 0;
201202
virtual float getColorSettingFloat(ColorSettingCommandType cmd) = 0;
202203

204+
/** Set the settings of a Kinect LED.
205+
* @param led Settings for a single LED.
206+
*/
207+
virtual void setLedStatus(LedSettings led) = 0;
208+
203209
/** Start data processing with both RGB and depth streams.
204210
* All above configuration must only be called before start() or after stop().
205211
*

src/libfreenect2.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class Freenect2DeviceImpl : public Freenect2Device
263263
virtual void setColorSetting(ColorSettingCommandType cmd, float value);
264264
virtual uint32_t getColorSetting(ColorSettingCommandType cmd);
265265
virtual float getColorSettingFloat(ColorSettingCommandType cmd);
266+
virtual void setLedStatus(LedSettings led);
266267
virtual bool start();
267268
virtual bool startStreams(bool rgb, bool depth);
268269
virtual bool stop();
@@ -294,6 +295,7 @@ class Freenect2ReplayDevice : public Freenect2Device
294295
virtual void setColorSetting(ColorSettingCommandType cmd, float value) {}
295296
virtual uint32_t getColorSetting(ColorSettingCommandType cmd) { return 0u; }
296297
virtual float getColorSettingFloat(ColorSettingCommandType cmd) { return 0.0f; }
298+
virtual void setLedStatus(LedSettings led) {}
297299

298300
bool open();
299301

@@ -810,6 +812,12 @@ float Freenect2DeviceImpl::getColorSettingFloat(ColorSettingCommandType cmd)
810812
return out;
811813
}
812814

815+
void Freenect2DeviceImpl::setLedStatus(LedSettings led)
816+
{
817+
CommandTransaction::Result result;
818+
command_tx_.execute(LedSettingCommand(led), result);
819+
}
820+
813821
bool Freenect2DeviceImpl::open()
814822
{
815823
LOG_INFO << "opening...";

0 commit comments

Comments
 (0)