Skip to content

added led control via ONI_DEVICE_PROPERTY_PLAYBACK_SPEED #529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions OpenNI2-FreenectDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# OpenNI2-FreenectDriver
######################################################################################

cmake_minimum_required(VERSION 3.1.0)

file(GLOB HEADERS src/*.hpp src/*.h)
file(GLOB SOURCES src/*.cpp)
add_library(FreenectDriver SHARED ${HEADERS} ${SOURCES})
Expand All @@ -17,12 +15,11 @@ set_target_properties(FreenectDriver PROPERTIES
OUTPUT_NAME FreenectDriver)

add_definitions(-DPROJECT_VER="${PROJECT_VER}")

add_definitions(--std=c++11)
include_directories(extern/OpenNI-Linux-x64-2.2.0.33/Include)
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/wrappers/cpp)

target_compile_features(FreenectDriver PUBLIC cxx_constexpr)

target_link_libraries(FreenectDriver freenectstatic ${MATH_LIB})

Expand Down
45 changes: 40 additions & 5 deletions OpenNI2-FreenectDriver/src/DeviceDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ namespace FreenectDriver
private:
ColorStream* color;
DepthStream* depth;
bool ledchanged = false;
freenect_led_options nextled ;

// for Freenect::FreenectDevice
void DepthCallback(void* data, uint32_t timestamp) {
void DepthCallback(void* data, uint32_t timestamp) {
depth->buildFrame(data, timestamp);
}
void VideoCallback(void* data, uint32_t timestamp) {
if(ledchanged)
{
printf("LED change in VideoCallback %d\n",(int)nextled);
ledchanged = false;
}
color->buildFrame(data, timestamp);
}

Expand Down Expand Up @@ -120,7 +126,6 @@ namespace FreenectDriver
case ONI_DEVICE_PROPERTY_SERIAL_NUMBER: // string
case ONI_DEVICE_PROPERTY_ERROR_STATE: // ?
// files
case ONI_DEVICE_PROPERTY_PLAYBACK_SPEED: // float
case ONI_DEVICE_PROPERTY_PLAYBACK_REPEAT_ENABLED: // OniBool
// xn
case XN_MODULE_PROPERTY_USB_INTERFACE: // XnSensorUsbInterface
Expand All @@ -139,6 +144,14 @@ namespace FreenectDriver
}
*(static_cast<OniImageRegistrationMode*>(data)) = depth->getImageRegistrationMode();
return ONI_STATUS_OK;
case ONI_DEVICE_PROPERTY_PLAYBACK_SPEED:
if (*pDataSize != sizeof(float))
{
LogError("Unexpected size of ONI_DEVICE_PROPERTY_PLAYBACK_SPEED");
return ONI_STATUS_ERROR;
}
*(static_cast<float*>(data)) = 1;
break;
}
}

Expand All @@ -153,7 +166,6 @@ namespace FreenectDriver
case ONI_DEVICE_PROPERTY_SERIAL_NUMBER: // string
case ONI_DEVICE_PROPERTY_ERROR_STATE: // ?
// files
case ONI_DEVICE_PROPERTY_PLAYBACK_SPEED: // float
case ONI_DEVICE_PROPERTY_PLAYBACK_REPEAT_ENABLED: // OniBool
// xn
case XN_MODULE_PROPERTY_USB_INTERFACE: // XnSensorUsbInterface
Expand All @@ -178,7 +190,30 @@ namespace FreenectDriver
return ONI_STATUS_ERROR;
}
return depth->setImageRegistrationMode(*(static_cast<const OniImageRegistrationMode*>(data)));
case ONI_DEVICE_PROPERTY_PLAYBACK_SPEED:
printf("ONI_DEVICE_PROPERTY_PLAYBACK_SPEED hack led \n");
if (dataSize != sizeof(float))
{

LogError("Unexpected size for setting ONI_DEVICE_PROPERTY_PLAYBACK_SPEED as led ");
return ONI_STATUS_ERROR;
}
try {
nextled = (freenect_led_options)*(static_cast<const float*>(data));
//ledchanged = true;
setLed(nextled);
updateState();

printf("ONI_DEVICE_PROPERTY_PLAYBACK_SPEED hack led value %d\n",(int)nextled);
return ONI_STATUS_OK;
}
catch(...)
{
LogError("ONI_DEVICE_PROPERTY_PLAYBACK_SPEED aka LED error");
return ONI_STATUS_ERROR;
}
}

}

OniBool isCommandSupported(int commandId)
Expand Down Expand Up @@ -232,7 +267,7 @@ namespace FreenectDriver
WriteMessage("Using libfreenect v" + to_string(PROJECT_VER));

freenect_set_log_level(m_ctx, FREENECT_LOG_DEBUG);
freenect_select_subdevices(m_ctx, FREENECT_DEVICE_CAMERA); // OpenNI2 doesn't use MOTOR or AUDIO
freenect_select_subdevices(m_ctx, (freenect_device_flags)(FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA)); // OpenNI2 doesn't use MOTOR or AUDIO
DriverServices = &getServices();
}
~Driver() { shutdown(); }
Expand Down
4 changes: 2 additions & 2 deletions examples/tiltdemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int main(int argc, char *argv[])

while (1) {
// Pick a random tilt and a random LED state
freenect_led_options led = (freenect_led_options) (rand() % 6); // explicit cast
freenect_led_options led = (freenect_led_options) (argc == 1 ? 0: 1); // explicit cast
int tilt = (rand() % 30)-15;
freenect_raw_tilt_state *state = 0;
double dx, dy, dz;
Expand All @@ -112,7 +112,7 @@ int main(int argc, char *argv[])

printf("led[%d] tilt[%d] accel[%lf,%lf,%lf]\n", led, tilt, dx,dy,dz);

sleep(3);
break;
}
}

Expand Down