Merge branch 'master' into add_effect_engine

Conflicts:
	CrossCompileHowto.txt

Former-commit-id: 644f194464bfdcb8adbaced43ec5300f8ec6d62c
This commit is contained in:
johan 2013-11-29 17:39:15 +01:00
commit fafed8fb09
19 changed files with 2368 additions and 35 deletions

View File

@ -1,4 +1,5 @@
project(hyperion) # Define the main-project name
project(Hyperion)
# define the minimum cmake version (as required by cmake) # define the minimum cmake version (as required by cmake)
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
@ -15,9 +16,6 @@ message(STATUS "ENABLE_DISPMANX = " ${ENABLE_DISPMANX})
configure_file ("${PROJECT_SOURCE_DIR}/HyperionConfig.h.in" "${PROJECT_BINARY_DIR}/HyperionConfig.h") configure_file ("${PROJECT_SOURCE_DIR}/HyperionConfig.h.in" "${PROJECT_BINARY_DIR}/HyperionConfig.h")
include_directories("${PROJECT_BINARY_DIR}") include_directories("${PROJECT_BINARY_DIR}")
# Define the main-project name
project(Hyperion)
# Add project specific cmake modules (find, etc) # Add project specific cmake modules (find, etc)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Add specific cmake modules to find qt4 (default version finds first available QT which might not be qt4) # Add specific cmake modules to find qt4 (default version finds first available QT which might not be qt4)
@ -45,13 +43,6 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall")
# Configure the use of QT4 # Configure the use of QT4
find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork REQUIRED QUIET) find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork REQUIRED QUIET)
# add protocol buffers
find_package(Protobuf REQUIRED)
#add libusb and pthreads
find_package(libusb-1.0 REQUIRED)
find_package(Threads REQUIRED)
#SET(QT_DONT_USE_QTGUI TRUE) #SET(QT_DONT_USE_QTGUI TRUE)
#SET(QT_USE_QTCONSOLE TRUE) #SET(QT_USE_QTCONSOLE TRUE)
include(${QT_USE_FILE}) include(${QT_USE_FILE})

View File

@ -2,6 +2,9 @@
# Script for downloading and installing the latest Hyperion release # Script for downloading and installing the latest Hyperion release
# Find out if we are on XBian
IS_XBIAN=`cat /etc/issue | grep XBian | wc -l`
# Make sure that the boblight daemon is no longer running # Make sure that the boblight daemon is no longer running
BOBLIGHT_PROCNR=$(ps -e | grep "boblight" | wc -l) BOBLIGHT_PROCNR=$(ps -e | grep "boblight" | wc -l)
if [ $BOBLIGHT_PROCNR -eq 1 ]; if [ $BOBLIGHT_PROCNR -eq 1 ];
@ -11,24 +14,31 @@ then
fi fi
# Stop hyperion daemon if it is running # Stop hyperion daemon if it is running
initctl stop hyperion /sbin/initctl stop hyperion
# Get the Hyperion executable
wget -N github.com/tvdzwan/hyperion/raw/master/deploy/hyperiond -P /usr/bin/ wget -N github.com/tvdzwan/hyperion/raw/master/deploy/hyperiond -P /usr/bin/
chmod +x /usr/bin/hyperiond
# Get the Hyperion command line utility
wget -N github.com/tvdzwan/hyperion/raw/master/deploy/hyperion-remote -P /usr/bin/ wget -N github.com/tvdzwan/hyperion/raw/master/deploy/hyperion-remote -P /usr/bin/
chmod +x /usr/bin/hyperion-remote
# Copy the gpio changer (gpio->spi) to the /usr/bin # Copy the gpio changer (gpio->spi) to the /usr/bin
wget -N github.com/tvdzwan/hyperion/raw/master/deploy/gpio2spi -P /usr/bin/ if [ $IS_XBIAN -eq 0 ]; then
wget -N github.com/tvdzwan/hyperion/raw/master/deploy/gpio2spi -P /usr/bin/
chmod +x /usr/bin/gpio2spi
fi
# Copy the hyperion configuration file to /etc # Copy the hyperion configuration file to /etc
wget -N github.com/tvdzwan/hyperion/raw/master/config/hyperion.config.json -P /etc/ wget -N github.com/tvdzwan/hyperion/raw/master/config/hyperion.config.json -P /etc/
# Copy the service control configuration to /etc/int # Copy the service control configuration to /etc/int
wget -N github.com/tvdzwan/hyperion/raw/master/deploy/hyperion.conf -P /etc/init/ if [ $IS_XBIAN -eq 0 ]; then
wget -N github.com/tvdzwan/hyperion/raw/master/deploy/hyperion.conf -P /etc/init/
# Set permissions else
chmod +x /usr/bin/hyperiond wget -N github.com/tvdzwan/hyperion/raw/master/deploy/hyperion.xbian.conf -O /etc/init/hyperion.conf
chmod +x /usr/bin/hyperion-remote fi
chmod +x /usr/bin/gpio2spi
# Start the hyperion daemon # Start the hyperion daemon
initctl start hyperion /sbin/initctl start hyperion

View File

@ -2,22 +2,40 @@
# Script for downloading and installing the latest Hyperion release # Script for downloading and installing the latest Hyperion release
# Stop hyperion daemon if it is running # Find out if we are on XBian
initctl stop hyperion IS_XBIAN=`cat /etc/issue | grep XBian | wc -l`
# Make sure that the boblight daemon is no longer running
BOBLIGHT_PROCNR=$(ps -e | grep "boblight" | wc -l)
if [ $BOBLIGHT_PROCNR -eq 1 ];
then
echo 'Found running instance of boblight. Please stop boblight via XBMC menu before installing hyperion'
exit
fi
# Stop hyperion daemon if it is running
/sbin/initctl stop hyperion
# Get the Hyperion executable
wget -N github.com/tvdzwan/hyperion/raw/master/deploy/hyperiond -P /usr/bin/ wget -N github.com/tvdzwan/hyperion/raw/master/deploy/hyperiond -P /usr/bin/
chmod +x /usr/bin/hyperiond
# Get the Hyperion command line utility
wget -N github.com/tvdzwan/hyperion/raw/master/deploy/hyperion-remote -P /usr/bin/ wget -N github.com/tvdzwan/hyperion/raw/master/deploy/hyperion-remote -P /usr/bin/
chmod +x /usr/bin/hyperion-remote
# Copy the gpio changer (gpio->spi) to the /usr/bin # Copy the gpio changer (gpio->spi) to the /usr/bin
wget -N github.com/tvdzwan/hyperion/raw/master/deploy/gpio2spi -P /usr/bin/ if [ $IS_XBIAN -eq 0 ]; then
wget -N github.com/tvdzwan/hyperion/raw/master/deploy/gpio2spi -P /usr/bin/
chmod +x /usr/bin/gpio2spi
fi
# Copy the service control configuration to /etc/int # Copy the service control configuration to /etc/int
wget -N github.com/tvdzwan/hyperion/raw/master/deploy/hyperion.conf -P /etc/init/ if [ $IS_XBIAN -eq 0 ]; then
wget -N github.com/tvdzwan/hyperion/raw/master/deploy/hyperion.conf -P /etc/init/
# Set permissions else
chmod +x /usr/bin/hyperiond wget -N github.com/tvdzwan/hyperion/raw/master/deploy/hyperion.xbian.conf -P /etc/init/ -O hyperion.conf
chmod +x /usr/bin/hyperion-remote fi
chmod +x /usr/bin/gpio2spi
# Start the hyperion daemon # Start the hyperion daemon
initctl start hyperion /sbin/initctl start hyperion

53
cmake/FindUDev.cmake Normal file
View File

@ -0,0 +1,53 @@
# razor-de: Configure libudev environment
#
# UDEV_FOUND - system has a libudev
# UDEV_INCLUDE_DIR - where to find header files
# UDEV_LIBRARIES - the libraries to link against udev
# UDEV_STABLE - it's true when is the version greater or equals to 143 - version when the libudev was stabilized in its API
#
# copyright (c) 2011 Petr Vanek <petr@scribus.info>
# Redistribution and use is allowed according to the terms of the BSD license.
#
FIND_PATH(
UDEV_INCLUDE_DIR
libudev.h
/usr/include
/usr/local/include
${UDEV_PATH_INCLUDES}
)
FIND_LIBRARY(
UDEV_LIBRARIES
NAMES udev libudev
PATHS
/usr/lib${LIB_SUFFIX}
/usr/local/lib${LIB_SUFFIX}
${UDEV_PATH_LIB}
)
IF (UDEV_LIBRARIES AND UDEV_INCLUDE_DIR)
SET(UDEV_FOUND "YES")
execute_process(COMMAND pkg-config --atleast-version=143 libudev RESULT_VARIABLE UDEV_STABLE)
# retvale is 0 of the condition is "true" so we need to negate the value...
if (UDEV_STABLE)
set(UDEV_STABLE 0)
else (UDEV_STABLE)
set(UDEV_STABLE 1)
endif (UDEV_STABLE)
message(STATUS "libudev stable: ${UDEV_STABLE}")
ENDIF (UDEV_LIBRARIES AND UDEV_INCLUDE_DIR)
IF (UDEV_FOUND)
MESSAGE(STATUS "Found UDev: ${UDEV_LIBRARIES}")
MESSAGE(STATUS " include: ${UDEV_INCLUDE_DIR}")
ELSE (UDEV_FOUND)
MESSAGE(STATUS "UDev not found.")
MESSAGE(STATUS "UDev: You can specify includes: -DUDEV_PATH_INCLUDES=/opt/udev/include")
MESSAGE(STATUS " currently found includes: ${UDEV_INCLUDE_DIR}")
MESSAGE(STATUS "UDev: You can specify libs: -DUDEV_PATH_LIB=/opt/udev/lib")
MESSAGE(STATUS " currently found libs: ${UDEV_LIBRARIES}")
IF (UDev_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find UDev library")
ENDIF (UDev_FIND_REQUIRED)
ENDIF (UDEV_FOUND)

View File

@ -2,3 +2,4 @@
add_subdirectory(jsoncpp) add_subdirectory(jsoncpp)
add_subdirectory(getoptPlusPlus) add_subdirectory(getoptPlusPlus)
add_subdirectory(serial) add_subdirectory(serial)
add_subdirectory(hidapi)

8
dependencies/build/hidapi/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
*.o
*.so
*.la
*.lo
*.a
.libs
.deps
hidtest-libusb

View File

@ -0,0 +1,16 @@
project(hidapi)
#add libusb and pthreads
find_package(libusb-1.0 REQUIRED)
find_package(Threads REQUIRED)
include_directories(
../../include/hidapi
${LIBUSB_1_INCLUDE_DIRS})
add_library(hidapi-libusb hid-libusb.c)
target_link_libraries(hidapi-libusb
${LIBUSB_1_LIBRARIES} #apt-get install libusb-1.0-0-dev
${CMAKE_THREAD_LIBS_INIT}
)

1427
dependencies/build/hidapi/hid-libusb.c vendored Normal file

File diff suppressed because it is too large Load Diff

BIN
dependencies/hidapi-master-20131122.zip vendored Normal file

Binary file not shown.

387
dependencies/include/hidapi/hidapi.h vendored Normal file
View File

@ -0,0 +1,387 @@
/*******************************************************
HIDAPI - Multi-Platform library for
communication with HID devices.
Alan Ott
Signal 11 Software
8/22/2009
Copyright 2009, All Rights Reserved.
At the discretion of the user of this library,
this software may be licensed under the terms of the
GNU General Public License v3, a BSD-Style license, or the
original HIDAPI license as outlined in the LICENSE.txt,
LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt
files located at the root of the source distribution.
These files may also be found in the public source
code repository located at:
http://github.com/signal11/hidapi .
********************************************************/
/** @file
* @defgroup API hidapi API
*/
#ifndef HIDAPI_H__
#define HIDAPI_H__
#include <wchar.h>
#ifdef _WIN32
#define HID_API_EXPORT __declspec(dllexport)
#define HID_API_CALL
#else
#define HID_API_EXPORT /**< API export macro */
#define HID_API_CALL /**< API call macro */
#endif
#define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/
#ifdef __cplusplus
extern "C" {
#endif
struct hid_device_;
typedef struct hid_device_ hid_device; /**< opaque hidapi structure */
/** hidapi info structure */
struct hid_device_info {
/** Platform-specific device path */
char *path;
/** Device Vendor ID */
unsigned short vendor_id;
/** Device Product ID */
unsigned short product_id;
/** Serial Number */
wchar_t *serial_number;
/** Device Release Number in binary-coded decimal,
also known as Device Version Number */
unsigned short release_number;
/** Manufacturer String */
wchar_t *manufacturer_string;
/** Product string */
wchar_t *product_string;
/** Usage Page for this Device/Interface
(Windows/Mac only). */
unsigned short usage_page;
/** Usage for this Device/Interface
(Windows/Mac only).*/
unsigned short usage;
/** The USB interface which this logical device
represents. Valid on both Linux implementations
in all cases, and valid on the Windows implementation
only if the device contains more than one interface. */
int interface_number;
/** Pointer to the next device */
struct hid_device_info *next;
};
/** @brief Initialize the HIDAPI library.
This function initializes the HIDAPI library. Calling it is not
strictly necessary, as it will be called automatically by
hid_enumerate() and any of the hid_open_*() functions if it is
needed. This function should be called at the beginning of
execution however, if there is a chance of HIDAPI handles
being opened by different threads simultaneously.
@ingroup API
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_init(void);
/** @brief Finalize the HIDAPI library.
This function frees all of the static data associated with
HIDAPI. It should be called at the end of execution to avoid
memory leaks.
@ingroup API
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_exit(void);
/** @brief Enumerate the HID Devices.
This function returns a linked list of all the HID devices
attached to the system which match vendor_id and product_id.
If @p vendor_id is set to 0 then any vendor matches.
If @p product_id is set to 0 then any product matches.
If @p vendor_id and @p product_id are both set to 0, then
all HID devices will be returned.
@ingroup API
@param vendor_id The Vendor ID (VID) of the types of device
to open.
@param product_id The Product ID (PID) of the types of
device to open.
@returns
This function returns a pointer to a linked list of type
struct #hid_device, containing information about the HID devices
attached to the system, or NULL in the case of failure. Free
this linked list by calling hid_free_enumeration().
*/
struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id);
/** @brief Free an enumeration Linked List
This function frees a linked list created by hid_enumerate().
@ingroup API
@param devs Pointer to a list of struct_device returned from
hid_enumerate().
*/
void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs);
/** @brief Open a HID device using a Vendor ID (VID), Product ID
(PID) and optionally a serial number.
If @p serial_number is NULL, the first device with the
specified VID and PID is opened.
@ingroup API
@param vendor_id The Vendor ID (VID) of the device to open.
@param product_id The Product ID (PID) of the device to open.
@param serial_number The Serial Number of the device to open
(Optionally NULL).
@returns
This function returns a pointer to a #hid_device object on
success or NULL on failure.
*/
HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number);
/** @brief Open a HID device by its path name.
The path name be determined by calling hid_enumerate(), or a
platform-specific path name can be used (eg: /dev/hidraw0 on
Linux).
@ingroup API
@param path The path name of the device to open
@returns
This function returns a pointer to a #hid_device object on
success or NULL on failure.
*/
HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path);
/** @brief Write an Output report to a HID device.
The first byte of @p data[] must contain the Report ID. For
devices which only support a single report, this must be set
to 0x0. The remaining bytes contain the report data. Since
the Report ID is mandatory, calls to hid_write() will always
contain one more byte than the report contains. For example,
if a hid report is 16 bytes long, 17 bytes must be passed to
hid_write(), the Report ID (or 0x0, for devices with a
single report), followed by the report data (16 bytes). In
this example, the length passed in would be 17.
hid_write() will send the data on the first OUT endpoint, if
one exists. If it does not, it will send the data through
the Control Endpoint (Endpoint 0).
@ingroup API
@param device A device handle returned from hid_open().
@param data The data to send, including the report number as
the first byte.
@param length The length in bytes of the data to send.
@returns
This function returns the actual number of bytes written and
-1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length);
/** @brief Read an Input report from a HID device with timeout.
Input reports are returned
to the host through the INTERRUPT IN endpoint. The first byte will
contain the Report number if the device uses numbered reports.
@ingroup API
@param device A device handle returned from hid_open().
@param data A buffer to put the read data into.
@param length The number of bytes to read. For devices with
multiple reports, make sure to read an extra byte for
the report number.
@param milliseconds timeout in milliseconds or -1 for blocking wait.
@returns
This function returns the actual number of bytes read and
-1 on error. If no packet was available to be read within
the timeout period, this function returns 0.
*/
int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds);
/** @brief Read an Input report from a HID device.
Input reports are returned
to the host through the INTERRUPT IN endpoint. The first byte will
contain the Report number if the device uses numbered reports.
@ingroup API
@param device A device handle returned from hid_open().
@param data A buffer to put the read data into.
@param length The number of bytes to read. For devices with
multiple reports, make sure to read an extra byte for
the report number.
@returns
This function returns the actual number of bytes read and
-1 on error. If no packet was available to be read and
the handle is in non-blocking mode, this function returns 0.
*/
int HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length);
/** @brief Set the device handle to be non-blocking.
In non-blocking mode calls to hid_read() will return
immediately with a value of 0 if there is no data to be
read. In blocking mode, hid_read() will wait (block) until
there is data to read before returning.
Nonblocking can be turned on and off at any time.
@ingroup API
@param device A device handle returned from hid_open().
@param nonblock enable or not the nonblocking reads
- 1 to enable nonblocking
- 0 to disable nonblocking.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock);
/** @brief Send a Feature report to the device.
Feature reports are sent over the Control endpoint as a
Set_Report transfer. The first byte of @p data[] must
contain the Report ID. For devices which only support a
single report, this must be set to 0x0. The remaining bytes
contain the report data. Since the Report ID is mandatory,
calls to hid_send_feature_report() will always contain one
more byte than the report contains. For example, if a hid
report is 16 bytes long, 17 bytes must be passed to
hid_send_feature_report(): the Report ID (or 0x0, for
devices which do not use numbered reports), followed by the
report data (16 bytes). In this example, the length passed
in would be 17.
@ingroup API
@param device A device handle returned from hid_open().
@param data The data to send, including the report number as
the first byte.
@param length The length in bytes of the data to send, including
the report number.
@returns
This function returns the actual number of bytes written and
-1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length);
/** @brief Get a feature report from a HID device.
Make sure to set the first byte of @p data[] to the Report
ID of the report to be read. Make sure to allow space for
this extra byte in @p data[].
@ingroup API
@param device A device handle returned from hid_open().
@param data A buffer to put the read data into, including
the Report ID. Set the first byte of @p data[] to the
Report ID of the report to be read.
@param length The number of bytes to read, including an
extra byte for the report ID. The buffer can be longer
than the actual report.
@returns
This function returns the number of bytes read and
-1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length);
/** @brief Close a HID device.
@ingroup API
@param device A device handle returned from hid_open().
*/
void HID_API_EXPORT HID_API_CALL hid_close(hid_device *device);
/** @brief Get The Manufacturer String from a HID device.
@ingroup API
@param device A device handle returned from hid_open().
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen);
/** @brief Get The Product String from a HID device.
@ingroup API
@param device A device handle returned from hid_open().
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen);
/** @brief Get The Serial Number String from a HID device.
@ingroup API
@param device A device handle returned from hid_open().
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen);
/** @brief Get a string from a HID device, based on its string index.
@ingroup API
@param device A device handle returned from hid_open().
@param string_index The index of the string to get.
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *device, int string_index, wchar_t *string, size_t maxlen);
/** @brief Get a string describing the last error which occurred.
@ingroup API
@param device A device handle returned from hid_open().
@returns
This function returns a string containing the last error
which occurred or NULL if none has occurred.
*/
HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *device);
#ifdef __cplusplus
}
#endif
#endif

Binary file not shown.

View File

@ -0,0 +1,16 @@
## Hyperion daemon
description "hyperion"
author "poljvd & tvdzwan"
start on (runlevel [2345])
stop on (runlevel [!2345])
respawn
pre-start script
modprobe spi-bcm2708
end script
exec /usr/bin/hyperiond /etc/hyperion.config.json

View File

@ -1 +1 @@
5078baeb33a6dca64d20161907b9638aeb047ffb cb10b0acda414c8d57cd1cc1bf49c48c142ec6b8

View File

@ -3,7 +3,22 @@
SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/hyperion) SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/hyperion)
SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/hyperion) SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/hyperion)
include_directories(${LIBUSB_1_INCLUDE_DIRS}) #add libusb and pthreads (required for the Lighpack usb device)
find_package(libusb-1.0 REQUIRED)
find_package(Threads REQUIRED)
include_directories(
../../include/hidapi
${LIBUSB_1_INCLUDE_DIRS}) # for Lightpack device
# set the build options
option (LIBUDEV_REQUIRED "Add libudev to the build (needed on Ubuntu 13.10, but gives errors when added on the RPi) :-S" OFF)
message(STATUS "LIBUDEV_REQUIRED = " ${LIBUDEV_REQUIRED})
if (LIBUDEV_REQUIRED)
find_package(UDev REQUIRED)
include_directories(${UDEV_INCLUDE_DIR})
endif (LIBUDEV_REQUIRED)
# Group the headers that go through the MOC compiler # Group the headers that go through the MOC compiler
SET(Hyperion_QT_HEADERS SET(Hyperion_QT_HEADERS
@ -79,6 +94,13 @@ target_link_libraries(hyperion
hyperion-utils hyperion-utils
effectengine effectengine
serialport serialport
${LIBUSB_1_LIBRARIES} #apt-get install libusb-1.0-0-dev
${CMAKE_THREAD_LIBS_INIT}
${QT_LIBRARIES} ${QT_LIBRARIES}
${LIBUSB_1_LIBRARIES} )
${CMAKE_THREAD_LIBS_INIT})
if (LIBUDEV_REQUIRED)
target_link_libraries(hyperion
${UDEV_LIBRARIES} # apt-get install libudev-dev
)
endif (LIBUDEV_REQUIRED)

View File

@ -0,0 +1,270 @@
// stl includes
#include <exception>
#include <cstring>
#include <wchar.h>
// Local Hyperion includes
#include "LedDeviceLightpack-hidapi.h"
// from USB_ID.h (http://code.google.com/p/light-pack/source/browse/CommonHeaders/USB_ID.h)
#define USB_OLD_VENDOR_ID 0x03EB
#define USB_OLD_PRODUCT_ID 0x204F
#define USB_VENDOR_ID 0x1D50
#define USB_PRODUCT_ID 0x6022
#define LIGHTPACK_INTERFACE 0
// from commands.h (http://code.google.com/p/light-pack/source/browse/CommonHeaders/commands.h)
// Commands to device, sends it in first byte of data[]
enum COMMANDS{
CMD_UPDATE_LEDS = 1,
CMD_OFF_ALL,
CMD_SET_TIMER_OPTIONS,
CMD_SET_PWM_LEVEL_MAX_VALUE, /* deprecated */
CMD_SET_SMOOTH_SLOWDOWN,
CMD_SET_BRIGHTNESS,
CMD_NOP = 0x0F
};
// from commands.h (http://code.google.com/p/light-pack/source/browse/CommonHeaders/commands.h)
enum DATA_VERSION_INDEXES{
INDEX_FW_VER_MAJOR = 1,
INDEX_FW_VER_MINOR
};
LedDeviceLightpackHidapi::LedDeviceLightpackHidapi() :
LedDevice(),
_deviceHandle(nullptr),
_serialNumber(""),
_firmwareVersion({-1,-1}),
_ledCount(-1),
_bitsPerChannel(-1),
_ledBuffer()
{
}
LedDeviceLightpackHidapi::~LedDeviceLightpackHidapi()
{
if (_deviceHandle != nullptr)
{
hid_close(_deviceHandle);
_deviceHandle = nullptr;
}
// TODO: Should be called to avoid memory loss, but only at the end of the application
//hid_exit();
}
int LedDeviceLightpackHidapi::open(const std::string & serialNumber)
{
// initialize the usb context
int error = hid_init();
if (error != 0)
{
std::cerr << "Error while initializing the hidapi context" << std::endl;
return -1;
}
std::cout << "Hidapi initialized" << std::endl;
// retrieve the list of usb devices
hid_device_info * deviceList = hid_enumerate(0x0, 0x0);
// iterate the list of devices
for (hid_device_info * deviceInfo = deviceList; deviceInfo != nullptr; deviceInfo = deviceInfo->next)
{
// try to open and initialize the device
error = testAndOpen(deviceInfo, serialNumber);
if (error == 0)
{
// a device was sucessfully opened. break from list
break;
}
}
// free the device list
hid_free_enumeration(deviceList);
if (_deviceHandle == nullptr)
{
if (_serialNumber.empty())
{
std::cerr << "No Lightpack device has been found" << std::endl;
}
else
{
std::cerr << "No Lightpack device has been found with serial " << _serialNumber << std::endl;
}
}
return _deviceHandle == nullptr ? -1 : 0;
}
int LedDeviceLightpackHidapi::testAndOpen(hid_device_info *device, const std::string & requestedSerialNumber)
{
if ((device->vendor_id == USB_VENDOR_ID && device->product_id == USB_PRODUCT_ID) ||
(device->vendor_id == USB_OLD_VENDOR_ID && device->product_id == USB_OLD_PRODUCT_ID))
{
std::cout << "Found a lightpack device. Retrieving more information..." << std::endl;
// get the serial number
std::string serialNumber = "";
if (device->serial_number != nullptr)
{
// the serial number needs to be converted to a char array instead of wchar
size_t size = wcslen(device->serial_number);
serialNumber.resize(size, '.');
for (size_t i = 0; i < size; ++i)
{
int c = wctob(device->serial_number[i]);
if (c != EOF)
{
serialNumber[i] = c;
}
}
}
else
{
std::cerr << "No serial number for Lightpack device" << std::endl;
}
std::cout << "Lightpack device found: path=" << device->path << " serial=" << serialNumber << std::endl;
// check if this is the device we are looking for
if (requestedSerialNumber.empty() || requestedSerialNumber == serialNumber)
{
// This is it!
_deviceHandle = hid_open_path(device->path);
if (_deviceHandle != nullptr)
{
_serialNumber = serialNumber;
std::cout << "Lightpack device successfully opened" << std::endl;
// get the firmware version
uint8_t buffer[256];
buffer[0] = 0; // report id
int error = hid_get_feature_report(_deviceHandle, buffer, sizeof(buffer));
if (error < 4)
{
std::cerr << "Unable to retrieve firmware version number from Lightpack device" << std::endl;
}
else
{
_firmwareVersion.majorVersion = buffer[INDEX_FW_VER_MAJOR+1];
_firmwareVersion.minorVersion = buffer[INDEX_FW_VER_MINOR+1];
}
// FOR TESTING PURPOSE: FORCE MAJOR VERSION TO 6
_firmwareVersion.majorVersion = 6;
// disable smoothing of the chosen device
disableSmoothing();
// determine the number of leds
if (_firmwareVersion.majorVersion == 4)
{
_ledCount = 8;
}
else
{
_ledCount = 10;
}
// determine the bits per channel
if (_firmwareVersion.majorVersion == 6)
{
// maybe also or version 7? The firmware suggest this is only for 6... (2013-11-13)
_bitsPerChannel = 12;
}
else
{
_bitsPerChannel = 8;
}
// set the led buffer size (repport id + command + 6 bytes per led)
_ledBuffer = std::vector<uint8_t>(2 + _ledCount * 6, 0);
_ledBuffer[0] = 0x0; // report id
_ledBuffer[1] = CMD_UPDATE_LEDS;
// return success
std::cout << "Lightpack device opened: path=" << device->path << " serial=" << _serialNumber << " version=" << _firmwareVersion.majorVersion << "." << _firmwareVersion.minorVersion << std::endl;
return 0;
}
else
{
std::cerr << "Unable to open Lightpack device. Searching for other device" << std::endl;
}
}
}
return -1;
}
int LedDeviceLightpackHidapi::write(const std::vector<ColorRgb> &ledValues)
{
return write(ledValues.data(), ledValues.size());
}
int LedDeviceLightpackHidapi::write(const ColorRgb * ledValues, int size)
{
int count = std::min(_ledCount, size);
for (int i = 0; i < count ; ++i)
{
const ColorRgb & color = ledValues[i];
// copy the most significant bits of the rgb values to the first three bytes
// offset 1 to accomodate for the report id and command byte
_ledBuffer[6*i+2] = color.red;
_ledBuffer[6*i+3] = color.green;
_ledBuffer[6*i+4] = color.blue;
// leave the next three bytes on zero...
// 12-bit values having zeros in the lowest 4 bits which is almost correct, but it saves extra
// switches to determine what to do and some bit shuffling
}
int error = writeBytes(_ledBuffer.data(), _ledBuffer.size());
return error >= 0 ? 0 : error;
}
int LedDeviceLightpackHidapi::switchOff()
{
unsigned char buf[2] = {0x0, CMD_OFF_ALL};
return writeBytes(buf, sizeof(buf)) == sizeof(buf);
}
const std::string &LedDeviceLightpackHidapi::getSerialNumber() const
{
return _serialNumber;
}
int LedDeviceLightpackHidapi::getLedCount() const
{
return _ledCount;
}
int LedDeviceLightpackHidapi::writeBytes(uint8_t *data, int size)
{
// std::cout << "Writing " << size << " bytes: ";
// for (int i = 0; i < size ; ++i) printf("%02x ", data[i]);
// std::cout << std::endl;
int error = hid_send_feature_report(_deviceHandle, data, size);
if (error == size)
{
return 0;
}
std::cerr << "Unable to write " << size << " bytes to Lightpack device(" << error << ")" << std::endl;
return error;
}
int LedDeviceLightpackHidapi::disableSmoothing()
{
unsigned char buf[2] = {CMD_SET_SMOOTH_SLOWDOWN, 0};
return writeBytes(buf, sizeof(buf)) == sizeof(buf);
}

View File

@ -0,0 +1,107 @@
#pragma once
// stl includes
#include <vector>
#include <cstdint>
#include <string>
// libusb include
#include <hidapi/hidapi.h>
// Hyperion includes
#include <hyperion/LedDevice.h>
///
/// LedDevice implementation for a lightpack device (http://code.google.com/p/light-pack/)
///
class LedDeviceLightpackHidapi : public LedDevice
{
public:
///
/// Constructs the LedDeviceLightpack
///
LedDeviceLightpackHidapi();
///
/// Destructor of the LedDevice; closes the output device if it is open
///
virtual ~LedDeviceLightpackHidapi();
///
/// Opens and configures the output device
///
/// @return Zero on succes else negative
///
int open(const std::string & serialNumber = "");
///
/// Writes the RGB-Color values to the leds.
///
/// @param[in] ledValues The RGB-color per led
///
/// @return Zero on success else negative
///
virtual int write(const std::vector<ColorRgb>& ledValues);
///
/// Writes the RGB-Color values to the leds.
///
/// @param[in] ledValues Array of RGB values
/// @param[in] size The number of RGB values
///
/// @return Zero on success else negative
///
int write(const ColorRgb * ledValues, int size);
///
/// Switch the leds off
///
/// @return Zero on success else negative
///
virtual int switchOff();
/// Get the serial of the Lightpack
const std::string & getSerialNumber() const;
/// Get the number of leds
int getLedCount() const;
private:
///
/// Test if the device is a (or the) lightpack we are looking for
///
/// @return Zero on succes else negative
///
int testAndOpen(hid_device_info * device, const std::string & requestedSerialNumber);
/// write bytes to the device
int writeBytes(uint8_t *data, int size);
/// Disable the internal smoothing on the Lightpack device
int disableSmoothing();
struct Version
{
int majorVersion;
int minorVersion;
};
private:
/// libusb device handle
hid_device * _deviceHandle;
/// device serial number
std::string _serialNumber;
/// firmware version of the device
Version _firmwareVersion;
/// the number of leds of the device
int _ledCount;
/// the number of bits per channel
int _bitsPerChannel;
/// buffer for led data
std::vector<uint8_t> _ledBuffer;
};

View File

@ -279,7 +279,7 @@ int LedDeviceLightpack::writeBytes(uint8_t *data, int size)
int error = libusb_control_transfer(_deviceHandle, int error = libusb_control_transfer(_deviceHandle,
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
LIBUSB_REQUEST_SET_CONFIGURATION, 0x09,
(2 << 8), (2 << 8),
0x00, 0x00,
data, size, 1000); data, size, 1000);

View File

@ -3,6 +3,9 @@
set(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/protoserver) set(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/protoserver)
set(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/protoserver) set(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/protoserver)
# add protocol buffers
find_package(Protobuf REQUIRED)
include_directories( include_directories(
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${PROTOBUF_INCLUDE_DIRS}) ${PROTOBUF_INCLUDE_DIRS})

View File

@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 2.8)
project(hyperion-remote) project(hyperion-remote)
# add protocol buffers
find_package(Protobuf REQUIRED)
# find Qt4
find_package(Qt4 REQUIRED QtCore QtGui QtNetwork) find_package(Qt4 REQUIRED QtCore QtGui QtNetwork)
# The following I do not undrstand completely... # The following I do not undrstand completely...