Merge pull request #1 from tvdzwan/master

update my fork

Former-commit-id: 18fc1efcfc4e73b308a65b30b37c9fff037c691b
This commit is contained in:
penfold42 2016-01-05 21:18:02 +11:00
commit 847ab34183
33 changed files with 813 additions and 112 deletions

View File

@ -2,14 +2,15 @@
sudo apt-get update
sudo apt-get install git cmake build-essential libQt4-dev libusb-1.0-0-dev python-dev
# RPI ONLY: when you build on the rapberry pi and inlcude the dispmanx grabber (which is the default)
# RPI ONLY: when you build on the rapberry pi and include the dispmanx grabber (which is the default)
# you also need the firmware including headers installed. This downloads the firmware from the raspberrypi github
# and copies the required files to the correct place. The firmware directory can be deleted afterwards if desired.
export FIRMWARE_DIR="raspberrypi-firmware"
git clone https://github.com/raspberrypi/firmware.git "$FIRMWARE_DIR"
sudo cp -R "$FIRMWARE_DIR/hardfp/opt/*" /opt
git clone --depth 1 https://github.com/raspberrypi/firmware.git "$FIRMWARE_DIR"
sudo cp -R "$FIRMWARE_DIR/hardfp/opt/" /opt
# create hyperion directory and checkout the code from github
# You might want to add "--depth 1" if you only want to recompile the current source or dont want to use git any further
export HYPERION_DIR="hyperion"
git clone --recursive https://github.com/tvdzwan/hyperion.git "$HYPERION_DIR"
@ -22,7 +23,7 @@ git submodule update
mkdir "$HYPERION_DIR/build"
cd "$HYPERION_DIR/build"
# run cmake to generate make files on the rsapberry pi
# run cmake to generate make files on the raspberry pi
cmake ..
# or if you are not compiling on the raspberry pi and need to disable the Dispmanx grabber and support for spi devices
cmake -DENABLE_DISPMANX=OFF -DENABLE_SPIDEV=OFF -DENABLE_X11=ON ..
@ -39,3 +40,6 @@ make
# The binaries are build in "$HYPERION_DIR/build/bin". You could copy those to /usr/bin
sudo cp ./bin/hyperion-remote /usr/bin/
sudo cp ./bin/hyperiond /usr/bin/
# Copy the effect folder (if you did not use the normal installation methode before)
sudo mkdir -p /opt/hyperion/effects && sudo cp -R ../effects/ /opt/hyperion/

View File

@ -55,6 +55,9 @@ cmake -DENABLE_DISPMANX=OFF --build "$NATIVE_BUILD_DIR" "$HYPERION_DIR"
mkdir -p "$TARGET_BUILD_DIR"
cmake -DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN_FILE" -DIMPORT_PROTOC=$NATIVE_BUILD_DIR/protoc_export.cmake --build "$TARGET_BUILD_DIR" "$HYPERION_DIR"
# For hummingboard (imx6) the following package is required
sudo apt-get install lib32z1
------------------------------------------------------------------------------
These instructions are based on the guide given by:
http://airwiki.ws.dei.polimi.it/index.php/Cross-compiling_for_the_RaspberryPi

22
Toolchain-imx6.cmake Normal file
View File

@ -0,0 +1,22 @@
SET(CUBIXCROSS_DIR $ENV{HOME}/hummingboard)
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
# specify the cross compiler
SET(CMAKE_C_COMPILER ${CUBIXCROSS_DIR}/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER ${CUBIXCROSS_DIR}/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux/bin/arm-linux-gnueabihf-g++)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv7-a -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=vfpv3 -mfloat-abi=softfp")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv7-a -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=vfpv3 -mfloat-abi=softfp")
# where is the target environment
SET(CMAKE_FIND_ROOT_PATH ${CUBIXCROSS_DIR}/rootfs)
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
include_directories(${CMAKE_FIND_ROOT_PATH}/usr/include)

12
Toolchain-x32.cmake Normal file
View File

@ -0,0 +1,12 @@
# toolchain file for building a 32bit version on a 64bit host
# use it like this:
# cmake -DCMAKE_TOOLCHAIN_FILE=Toolchain-x32.cmake <sourcedir>
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR "i686")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32" CACHE STRING "c++ flags")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32" CACHE STRING "c flags")

View File

@ -0,0 +1,43 @@
#!/bin/sh
# Create the x64 build
mkdir build-x64
cd build-x64
cmake -DENABLE_DISPMANX=OFF -DENABLE_X11=ON ..
make -j 4
cd ..
# Create the x32 build
mkdir build-x32
cd build-x32
cmake -DIMPORT_PROTOC=../build-x64/protoc_export.cmake -DENABLE_DISPMANX=OFF -DENABLE_X11=ON ..
make -j 4
cd ..
# Create the RPI build
mkdir build-rpi
cd build-rpi
cmake -DCMAKE_TOOLCHAIN_FILE="../Toolchain-rpi.cmake" -DIMPORT_PROTOC=../build-x64/protoc_export.cmake ..
make -j 4
cd ..
# Create the WETEK build
mkdir build-wetek
cd build-wetek
cmake -DCMAKE_TOOLCHAIN_FILE="../Toolchain-rpi.cmake" -DIMPORT_PROTOC=../build-x64/protoc_export.cmake -DENABLE_DISPMANX=OFF -DENABLE_FB=ON -DENABLE_AMLOGIC=ON ..
make -j 4
cd ..
# Create the IMX6 build
mkdir build-imx6
cd build-imx6
cmake -DCMAKE_TOOLCHAIN_FILE="../Toolchain-imx6.cmake" -DIMPORT_PROTOC=../build-x64/protoc_export.cmake -DENABLE_DISPMANX=OFF -DENABLE_FB=ON ..
make -j 4
cd ..
bin/create_release.sh . x64
bin/create_release.sh . x32
bin/create_release.sh . rpi
bin/create_release.sh . wetek
bin/create_release.sh . imx6

View File

@ -0,0 +1,27 @@
#!/bin/sh
RPI_ROOTFS=/home/tvdzwan/hummingboard/rootfs
IMX6_ROOTFS=/home/tvdzwan/hummingboard/rootfs
outfile=hyperion.deps.openelec-imx6.tar.gz
tar --create --verbose --gzip --absolute-names --show-transformed-names --dereference \
--file "$outfile" \
"$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libaudio.so.2" \
"$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libffi.so.6" \
"$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libICE.so.6" \
"$IMX6_ROOTFS/lib/arm-linux-gnueabihf/libpcre.so.3" \
"$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libpng12.so.0" \
"$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libQtCore.so.4" \
"$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libQtGui.so.4" \
"$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libQtNetwork.so.4" \
"$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libSM.so.6" \
"$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libX11.so.6" \
"$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libXau.so.6" \
"$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libxcb.so.1" \
"$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libXdmcp.so.6" \
"$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libXext.so.6" \
"$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libXrender.so.1" \
"$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libXt.so.6" \
"./hyperiond.sh" \
"./hyperion-remote.sh"

35
bin/create_release.sh Normal file
View File

@ -0,0 +1,35 @@
#!/bin/sh
if [ "$#" -ne 2 ] || ! [ -d "$1" ]; then
echo "Usage: $0 <REPO-DIR> <BUILD-ID>" >&2
exit 1
fi
repodir="$1"
buildid="$2"
builddir=$repodir/build-$buildid
echo build directory = $builddir
echo repository root dirrectory = $repodir
if ! [ -d "$builddir" ]; then
echo "Could not find build director"
exit 1
fi
outfile="$repodir/deploy/hyperion_$buildid.tar.gz"
echo create $outfile
tar --create --verbose --gzip --absolute-names --show-transformed-names --ignore-failed-read\
--file "$outfile" \
--transform "s:$builddir/bin/:hyperion/bin/:" \
--transform "s:$repodir/effects/:hyperion/effects/:" \
--transform "s:$repodir/config/:hyperion/config/:" \
--transform "s:$repodir/bin/hyperion.init.sh:hyperion/init.d/hyperion.init.sh:" \
--transform "s://:/:g" \
"$builddir/bin/hyperiond" \
"$builddir/bin/hyperion-remote" \
"$builddir/bin/hyperion-v4l2" \
"$builddir/bin/dispmanx2png" \
"$repodir/effects/"* \
"$repodir/bin/hyperion.init.sh" \
"$repodir/config/hyperion.config.json"

View File

@ -0,0 +1,2 @@
#!/bin/sh
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/storage/hyperion/bin /storage/hyperion/bin/hyperion-remote "$@"

View File

@ -0,0 +1 @@
198ac3d44bac13ba993069454397ad8c201d37b9

View File

@ -1 +1 @@
8708dec3801868f8710e06bd9186fc520f7e639f
3785db40d7232275fbc00b20e627280e0e057f99

View File

@ -0,0 +1 @@
0769228a95e4a0d4b2ed6649f21ddf70b43773d6

View File

@ -0,0 +1 @@
7e53ee35b7258e7d58d96514701a50014a98da31

View File

@ -0,0 +1 @@
36d03bb18626fa0faea8aabf6426e571eab4f719

View File

@ -0,0 +1 @@
6f86ceeb6650e527d179cf7153e0beada3b73889

2
deploy/hyperiond.sh Normal file
View File

@ -0,0 +1,2 @@
#!/bin/sh
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/storage/hyperion/bin /storage/hyperion/bin/hyperiond "$@"

114
deploy/update_hyperion.sh Normal file
View File

@ -0,0 +1,114 @@
#!/bin/sh
# Script for downloading and installing the latest Hyperion release
# Make sure /sbin is on the path (for service to find sub scripts)
PATH="/sbin:$PATH"
# Find out if we are on OpenElec
OS_OPENELEC=`cat /etc/issue | grep -m 1 OpenELEC | wc -l`
# Find out if its an imx6 device
CPU_RPI=`cat /proc/cpuinfo | grep RPI | wc -l`
CPU_IMX6=`cat /proc/cpuinfo | grep i.MX6 | wc -l`
CPU_WETEK=`cat /proc/cpuinfo | grep Amlogic | wc -l`
CPU_X64=`uname -m | grep x86_64 | wc -l`
CPU_X32=`uname -m | grep x86_32 | wc -l`
# Check that we have a known configuration
if [[ $CPU_RPI -ne 1 && $CPU_IMX6 -ne 1 && $CPU_WETEK -ne 1 && $CPU_X64 -ne 1 && $CPU_X32 -ne 1 ]]; then
echo 'CPU information does not match any known releases'
exit
fi
# check which init script we should use
USE_INITCTL=`which /sbin/initctl | wc -l`
USE_SERVICE=`which /usr/sbin/service | wc -l`
# Make sure that the boblight daemon is no longer running
BOBLIGHT_PROCNR=$(pidof boblightd | 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
# Start the hyperion daemon
if [ $USE_INITCTL -eq 1 ]; then
/sbin/initctl stop hyperion
elif [ $USE_SERVICE -eq 1 ]; then
/usr/sbin/service hyperion stop
fi
# Select the appropriate release
HYPERION_ADDRESS=https://raw.githubusercontent.com/tvdzwan/hyperion/master/deploy
if [ $CPU_RPI -eq 1 ]; then
HYPERION_RELEASE=$HYPERION_ADDRESS/hyperion_rpi.tar.gz
OE_DEPENDECIES=$HYPERION_ADDRESS/hyperion.deps.openelec-rpi.tar.gz
elif [ $CPU_IMX6 -eq 1 ]; then
HYPERION_RELEASE=$HYPERION_ADDRESS/hyperion_imx6.tar.gz
OE_DEPENDECIES=$HYPERION_ADDRESS/hyperion.deps.openelec-imx6.tar.gz
elif [ $CPU_WETEK -eq 1 ]; then
HYPERION_RELEASE=$HYPERION_ADDRESS/hyperion_wetek.tar.gz
OE_DEPENDECIES=$HYPERION_ADDRESS/hyperion.deps.openelec-rpi.tar.gz
elif [ $CPU_X64 -eq 1 ]; then
HYPERION_RELEASE=$HYPERION_ADDRESS/hyperion_x64.tar.gz
OE_DEPENDECIES=$HYPERION_ADDRESS/hyperion.deps.openelec-x64.tar.gz
elif [ $CPU_X32 -eq 1 ]; then
HYPERION_RELEASE=$HYPERION_ADDRESS/hyperion_x32.tar.gz
OE_DEPENDECIES=$HYPERION_ADDRESS/hyperion.deps.openelec-x32.tar.gz
else
echo "Target platform unknown"
exit
fi
# Get and extract the Hyperion binaries and effects
echo 'Downloading hyperion'
if [ $OS_OPENELEC -eq 1 ]; then
# OpenELEC has a readonly file system. Use alternative location
curl -L --get $HYPERION_RELEASE | tar -C /storage -xz
curl -L --get $OE_DEPENDECIES | tar -C /storage/hyperion/bin -xz
# modify the default config to have a correct effect path
sed -i 's:/opt:/storage:g' /storage/hyperion/config/hyperion.config.json
# /storage/.config is available as samba share. A symbolic link would not be working
false | cp -i /storage/hyperion/config/hyperion.config.json /storage/.config/hyperion.config.json 2>/dev/null
else
wget $HYPERION_RELEASE -O - | tar -C /opt -xz
# create links to the binaries
ln -fs /opt/hyperion/bin/hyperiond /usr/bin/hyperiond
ln -fs /opt/hyperion/bin/hyperion-remote /usr/bin/hyperion-remote
ln -fs /opt/hyperion/bin/hyperion-v4l2 /usr/bin/hyperion-v4l2
# Copy a link to the hyperion configuration file to /etc
ln -s /opt/hyperion/config/hyperion.config.json /etc/hyperion.config.json
fi
# Copy the service control configuration to /etc/int
if [ $USE_INITCTL -eq 1 ]; then
echo 'Installing initctl script'
wget -N https://raw.githubusercontent.com/tvdzwan/hyperion/master/deploy/hyperion.conf -P /etc/init/
initctl reload-configuration
elif [ $USE_SERVICE -eq 1 ]; then
echo 'Installing startup script in init.d'
# place startup script in init.d and add it to upstart
ln -fs /opt/hyperion/init.d/hyperion.init.sh /etc/init.d/hyperion
chmod +x /etc/init.d/hyperion
update-rc.d hyperion defaults 98 02
elif [ $OS_OPENELEC -eq 1 ]; then
# only add to start script if hyperion is not present yet
if [ `cat /storage/.config/autostart.sh 2>/dev/null | grep hyperiond | wc -l` -eq 0 ]; then
echo 'Adding Hyperion to autostart script'
echo "/storage/hyperion/bin/hyperiond.sh /storage/.config/hyperion.config.json > /dev/null 2>&1 &" >> /storage/.config/autostart.sh
chmod +x /storage/.config/autostart.sh
fi
fi
# Start the hyperion daemon
if [ $USE_INITCTL -eq 1 ]; then
/sbin/initctl start hyperion
elif [ $USE_SERVICE -eq 1 ]; then
/usr/sbin/service hyperion start
fi

View File

@ -122,6 +122,8 @@ int AmlogicGrabber::grabFrame(Image<ColorBgr> & image)
{
// Failed to configure frame width
std::cerr << "[" << __PRETTY_FUNCTION__ << "] Failed to configure capture size (" << errno << "): " << strerror(errno) << std::endl;
close(_amlogicCaptureDev);
_amlogicCaptureDev = -1;
return -1;
}
@ -133,18 +135,27 @@ int AmlogicGrabber::grabFrame(Image<ColorBgr> & image)
if (bytesRead == -1)
{
std::cerr << "[" << __PRETTY_FUNCTION__ << "] Read of device failed (erno=" << errno << "): " << strerror(errno) << std::endl;
close(_amlogicCaptureDev);
_amlogicCaptureDev = -1;
return -1;
}
else if (bytesToRead != bytesRead)
{
// Read of snapshot failed
std::cerr << "[" << __PRETTY_FUNCTION__ << "] Capture failed to grab entire image [bytesToRead(" << bytesToRead << ") != bytesRead(" << bytesRead << ")]" << std::endl;
close(_amlogicCaptureDev);
_amlogicCaptureDev = -1;
return -1;
}
// For now we always close the device again
close(_amlogicCaptureDev);
_amlogicCaptureDev = -1;
// For now we always close the device now and again
static int readCnt = 0;
++readCnt;
if (readCnt > 20)
{
close(_amlogicCaptureDev);
_amlogicCaptureDev = -1;
readCnt = 0;
}
return 0;
}

View File

@ -15,8 +15,11 @@ include_directories(
SET(Leddevice_QT_HEADERS
${CURRENT_SOURCE_DIR}/LedRs232Device.h
${CURRENT_SOURCE_DIR}/LedDeviceAdalight.h
${CURRENT_SOURCE_DIR}/LedDeviceAdalightApa102.h
${CURRENT_SOURCE_DIR}/LedDeviceAmbiLed.h
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.h
${CURRENT_SOURCE_DIR}/LedHIDDevice.h
${CURRENT_SOURCE_DIR}/LedDeviceRawHID.h
)
SET(Leddevice_HEADERS
@ -38,9 +41,12 @@ SET(Leddevice_SOURCES
${CURRENT_SOURCE_DIR}/LedDeviceFactory.cpp
${CURRENT_SOURCE_DIR}/LedRs232Device.cpp
${CURRENT_SOURCE_DIR}/LedHIDDevice.cpp
${CURRENT_SOURCE_DIR}/LedDeviceAdalight.cpp
${CURRENT_SOURCE_DIR}/LedDeviceAdalightApa102.cpp
${CURRENT_SOURCE_DIR}/LedDeviceAmbiLed.cpp
${CURRENT_SOURCE_DIR}/LedDeviceRawHID.cpp
${CURRENT_SOURCE_DIR}/LedDeviceLightpack.cpp
${CURRENT_SOURCE_DIR}/LedDeviceMultiLightpack.cpp
${CURRENT_SOURCE_DIR}/LedDevicePaintpack.cpp

View File

@ -3,6 +3,7 @@
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
// Linux includes
#include <fcntl.h>
@ -21,14 +22,18 @@ LedDeviceAPA102::LedDeviceAPA102(const std::string& outputDevice, const unsigned
int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues)
{
const unsigned int startFrameSize = 4;
const unsigned int endFrameSize = (ledValues.size() + 63) / 64 * 4;
const unsigned int endFrameSize = std::max<unsigned int>(((ledValues.size() + 15) / 16), 4);
const unsigned int mLedCount = (ledValues.size() * 4) + startFrameSize + endFrameSize;
if(_ledBuffer.size() != mLedCount){
_ledBuffer.resize(mLedCount, 0x00);
_ledBuffer.resize(mLedCount, 0xFF);
_ledBuffer[0] = 0x00;
_ledBuffer[1] = 0x00;
_ledBuffer[2] = 0x00;
_ledBuffer[3] = 0x00;
}
for (unsigned iLed=1; iLed<=ledValues.size(); ++iLed) {
const ColorRgb& rgb = ledValues[iLed];
const ColorRgb& rgb = ledValues[iLed-1];
_ledBuffer[iLed*4] = 0xFF;
_ledBuffer[iLed*4+1] = rgb.red;
_ledBuffer[iLed*4+2] = rgb.green;

View File

@ -6,7 +6,7 @@
// Qt includes
#include <QTimer>
// hyperion incluse
// hyperion include
#include "LedRs232Device.h"
///
@ -40,7 +40,7 @@ private slots:
/// Write the last data to the leds again
void rewriteLeds();
private:
protected:
/// The buffer containing the packed RGB values
std::vector<uint8_t> _ledBuffer;

View File

@ -0,0 +1,54 @@
// STL includes
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
// Linux includes
#include <fcntl.h>
#include <sys/ioctl.h>
// hyperion local includes
#include "LedDeviceAdalightApa102.h"
LedDeviceAdalightApa102::LedDeviceAdalightApa102(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) :
LedDeviceAdalight(outputDevice, baudrate, delayAfterConnect_ms),
_ledBuffer(0),
_timer()
{
}
//comparing to ws2801 adalight, the following changes were needed:
// 1- differnt data frame (4 bytes instead of 3)
// 2 - in order to accomodate point 1 above, number of leds sent to adalight is increased by 1/3rd
int LedDeviceAdalightApa102::write(const std::vector<ColorRgb> & ledValues)
{
const unsigned int startFrameSize = 4;
const unsigned int endFrameSize = std::max<unsigned int>(((ledValues.size() + 15) / 16), 4);
const unsigned int mLedCount = (ledValues.size() * 4) + startFrameSize + endFrameSize;
if(_ledBuffer.size() != mLedCount){
_ledBuffer.resize(mLedCount, 0xFF);
_ledBuffer[0] = 'A';
_ledBuffer[1] = 'd';
_ledBuffer[2] = 'a';
_ledBuffer[3] = (((unsigned int)(ledValues.size() * 1.33) - 1) >> 8) & 0xFF; // LED count high byte
_ledBuffer[4] = ((unsigned int)(ledValues.size() * 1.33) - 1) & 0xFF; // LED count low byte
_ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum
}
for (unsigned iLed=1; iLed<=ledValues.size(); iLed++) {
const ColorRgb& rgb = ledValues[iLed-1];
_ledBuffer[iLed*4+6] = 0xFF;
_ledBuffer[iLed*4+1+6] = rgb.red;
_ledBuffer[iLed*4+2+6] = rgb.green;
_ledBuffer[iLed*4+3+6] = rgb.blue;
}
// restart the timer
_timer.start();
// write data
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
}

View File

@ -0,0 +1,46 @@
#pragma once
// STL includes
#include <string>
// Qt includes
#include <QTimer>
// hyperion incluse
#include "LedDeviceAdalight.h"
///
/// Implementation of the LedDevice interface for writing to an Adalight led device for APA102.
///
class LedDeviceAdalightApa102 : public LedDeviceAdalight
{
Q_OBJECT
public:
///
/// Constructs the LedDevice for attached Adalight device
///
/// @param outputDevice The name of the output device (eg '/dev/ttyS0')
/// @param baudrate The used baudrate for writing to the output device
///
LedDeviceAdalightApa102(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms);
///
/// Writes the led color values to the led-device
///
/// @param ledValues The color-value per led
/// @return Zero on succes else negative
///
virtual int write(const std::vector<ColorRgb> & ledValues);
private:
/// The buffer containing the packed RGB values
std::vector<uint8_t> _ledBuffer;
/// Timer object which makes sure that led data is written at a minimum rate
/// The Adalight device will switch off when it does not receive data at least
/// every 15 seconds
QTimer _timer;
};

View File

@ -23,6 +23,7 @@
#include "LedDeviceAdalight.h"
#include "LedDeviceAmbiLed.h"
#include "LedDeviceRawHID.h"
#include "LedDeviceLightpack.h"
#include "LedDeviceMultiLightpack.h"
#include "LedDevicePaintpack.h"
@ -33,6 +34,7 @@
#include "LedDevicePhilipsHue.h"
#include "LedDeviceTpm2.h"
#include "LedDeviceAtmo.h"
#include "LedDeviceAdalightApa102.h"
#ifdef ENABLE_WS2812BPWM
#include "LedDeviceWS2812b.h"
@ -58,6 +60,17 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
device = deviceAdalight;
}
else if (type == "adalightapa102")
{
const std::string output = deviceConfig["output"].asString();
const unsigned rate = deviceConfig["rate"].asInt();
const int delay_ms = deviceConfig["delayAfterConnect"].asInt();
LedDeviceAdalightApa102* deviceAdalightApa102 = new LedDeviceAdalightApa102(output, rate, delay_ms);
deviceAdalightApa102->open();
device = deviceAdalightApa102;
}
else if (type == "ambiled")
{
const std::string output = deviceConfig["output"].asString();
@ -135,6 +148,21 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
device = deviceTinkerforge;
}
#endif
else if (type == "rawhid")
{
const int delay_ms = deviceConfig["delayAfterConnect"].asInt();
auto VendorIdString = deviceConfig.get("VID", "0x2341").asString();
auto ProductIdString = deviceConfig.get("PID", "0x8036").asString();
// Convert HEX values to integer
auto VendorId = std::stoul(VendorIdString, nullptr, 16);
auto ProductId = std::stoul(ProductIdString, nullptr, 16);
LedDeviceRawHID* deviceHID = new LedDeviceRawHID(VendorId, ProductId, delay_ms);
deviceHID->open();
device = deviceHID;
}
else if (type == "lightpack")
{
const std::string output = deviceConfig.get("output", "").asString();
@ -153,7 +181,15 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
}
else if (type == "paintpack")
{
LedDevicePaintpack * devicePainLightpack = new LedDevicePaintpack();
const int delay_ms = deviceConfig["delayAfterConnect"].asInt();
auto VendorIdString = deviceConfig.get("VID", "0x0EBF").asString();
auto ProductIdString = deviceConfig.get("PID", "0x0025").asString();
// Convert HEX values to integer
auto VendorId = std::stoul(VendorIdString, nullptr, 16);
auto ProductId = std::stoul(ProductIdString, nullptr, 16);
LedDevicePaintpack * devicePainLightpack = new LedDevicePaintpack(VendorId, ProductId, delay_ms);
devicePainLightpack->open();
device = devicePainLightpack;

View File

@ -2,61 +2,25 @@
// Hyperion includes
#include "LedDevicePaintpack.h"
LedDevicePaintpack::LedDevicePaintpack() :
LedDevice(),
_deviceHandle(nullptr)
// Use out report HID device
LedDevicePaintpack::LedDevicePaintpack(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms) :
LedHIDDevice(VendorId, ProductId, delayAfterConnect_ms, false),
_ledBuffer(0)
{
// empty
}
int LedDevicePaintpack::open()
int LedDevicePaintpack::write(const std::vector<ColorRgb> & ledValues)
{
// initialize the usb context
int error = hid_init();
if (error != 0)
if (_ledBuffer.size() < 2 + ledValues.size()*3)
{
std::cerr << "Error while initializing the hidapi context" << std::endl;
return -1;
}
std::cout << "Hidapi initialized" << std::endl;
// Initialise the paintpack device
const unsigned short Paintpack_VendorId = 0x0ebf;
const unsigned short Paintpack_ProductId = 0x0025;
_deviceHandle = hid_open(Paintpack_VendorId, Paintpack_ProductId, nullptr);
if (_deviceHandle == nullptr)
{
// Failed to open the device
std::cerr << "Failed to open HID Paintpakc device " << std::endl;
return -1;
_ledBuffer.resize(2 + ledValues.size()*3, uint8_t(0));
_ledBuffer[0] = 3;
_ledBuffer[1] = 0;
}
return 0;
}
LedDevicePaintpack::~LedDevicePaintpack()
{
if (_deviceHandle != nullptr)
{
hid_close(_deviceHandle);
_deviceHandle = nullptr;
}
hid_exit();
}
int LedDevicePaintpack::write(const std::vector<ColorRgb>& ledValues)
{
if (_ledBuffer.size() < 3 + ledValues.size()*3)
{
_ledBuffer.resize(3 + ledValues.size()*3, uint8_t(0));
_ledBuffer[0] = 0;
_ledBuffer[1] = 3;
_ledBuffer[2] = 0;
}
auto bufIt = _ledBuffer.begin()+3;
auto bufIt = _ledBuffer.begin()+2;
for (const ColorRgb & ledValue : ledValues)
{
*bufIt = ledValue.red;
@ -67,11 +31,12 @@ int LedDevicePaintpack::write(const std::vector<ColorRgb>& ledValues)
++bufIt;
}
return hid_write(_deviceHandle, _ledBuffer.data(), _ledBuffer.size());
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
}
int LedDevicePaintpack::switchOff()
{
std::fill(_ledBuffer.begin()+3, _ledBuffer.end(), uint8_t(0));
return hid_write(_deviceHandle, _ledBuffer.data(), _ledBuffer.size());
std::fill(_ledBuffer.begin() + 2, _ledBuffer.end(), uint8_t(0));
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
}

View File

@ -3,34 +3,19 @@
// STL includes
#include <vector>
// libusb include
#include <hidapi/hidapi.h>
// Hyperion includes
#include <leddevice/LedDevice.h>
#include "LedHIDDevice.h"
///
/// LedDevice implementation for a paintpack device ()
///
class LedDevicePaintpack : public LedDevice
class LedDevicePaintpack : public LedHIDDevice
{
public:
/**
* Constructs the paintpack device
*/
LedDevicePaintpack();
/**
* Destructs the paintpack device, closes USB connection if open
*/
virtual ~LedDevicePaintpack();
/**
* Opens the Paintpack device
*
* @return Zero on succes else negative
*/
int open();
LedDevicePaintpack(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms);
///
/// Writes the RGB-Color values to the leds.
@ -49,11 +34,6 @@ public:
virtual int switchOff();
private:
/// libusb device handle
hid_device * _deviceHandle;
/// buffer for led data
std::vector<uint8_t> _ledBuffer;
};

View File

@ -21,27 +21,33 @@ bool operator !=(CiColor p1, CiColor p2) {
}
PhilipsHueLight::PhilipsHueLight(unsigned int id, QString originalState, QString modelId) :
id(id), originalState(originalState) {
// Hue system model ids (http://www.developers.meethue.com/documentation/supported-lights).
// Light strips, color iris, ...
const std::set<QString> GAMUT_A_MODEL_IDS = { "LLC001", "LLC005", "LLC006", "LLC007", "LLC010", "LLC011", "LLC012",
"LLC013", "LST001" };
// Hue bulbs, spots, ...
const std::set<QString> GAMUT_B_MODEL_IDS = { "LCT001", "LCT002", "LCT003", "LLM001" };
// Find id in the sets and set the appropiate color space.
if (GAMUT_A_MODEL_IDS.find(modelId) != GAMUT_A_MODEL_IDS.end()) {
colorSpace.red = {0.703f, 0.296f};
colorSpace.green = {0.2151f, 0.7106f};
colorSpace.blue = {0.138f, 0.08f};
} else if (GAMUT_B_MODEL_IDS.find(modelId) != GAMUT_B_MODEL_IDS.end()) {
colorSpace.red = {0.675f, 0.322f};
colorSpace.green = {0.4091f, 0.518f};
colorSpace.blue = {0.167f, 0.04f};
} else {
colorSpace.red = {1.0f, 0.0f};
colorSpace.green = {0.0f, 1.0f};
colorSpace.blue = {0.0f, 0.0f};
}
id(id), originalState(originalState) {
// Hue system model ids (http://www.developers.meethue.com/documentation/supported-lights).
// Light strips, color iris, ...
const std::set<QString> GAMUT_A_MODEL_IDS = { "LLC001", "LLC005", "LLC006", "LLC007", "LLC010", "LLC011", "LLC012",
"LLC013", "LLC014", "LST001" };
// Hue bulbs, spots, ...
const std::set<QString> GAMUT_B_MODEL_IDS = { "LCT001", "LCT002", "LCT003", "LCT007", "LLM001" };
// Hue Lightstrip plus, go ...
const std::set<QString> GAMUT_C_MODEL_IDS = { "LLC020", "LST002" };
// Find id in the sets and set the appropiate color space.
if (GAMUT_A_MODEL_IDS.find(modelId) != GAMUT_A_MODEL_IDS.end()) {
colorSpace.red = {0.703f, 0.296f};
colorSpace.green = {0.2151f, 0.7106f};
colorSpace.blue = {0.138f, 0.08f};
} else if (GAMUT_B_MODEL_IDS.find(modelId) != GAMUT_B_MODEL_IDS.end()) {
colorSpace.red = {0.675f, 0.322f};
colorSpace.green = {0.4091f, 0.518f};
colorSpace.blue = {0.167f, 0.04f};
} else if (GAMUT_C_MODEL_IDS.find(modelId) != GAMUT_B_MODEL_IDS.end()) {
colorSpace.red = {0.675f, 0.322f};
colorSpace.green = {0.2151f, 0.7106f};
colorSpace.blue = {0.167f, 0.04f};
} else {
colorSpace.red = {1.0f, 0.0f};
colorSpace.green = {0.0f, 1.0f};
colorSpace.blue = {0.0f, 0.0f};
}
// Initialize black color.
black = rgbToCiColor(0.0f, 0.0f, 0.0f);
// Initialize color with black

View File

@ -134,7 +134,7 @@ public:
/// @param lightIds light ids of the lights to control if not starting at one in ascending order.
///
LedDevicePhilipsHue(const std::string& output, const std::string& username = "newdeveloper", bool switchOffOnBlack =
false, int transitiontime = 1, std::vector<unsigned int> lightIds = {});
false, int transitiontime = 1, std::vector<unsigned int> lightIds = std::vector<unsigned int>());
///
/// Destructor of this device

View File

@ -0,0 +1,57 @@
// STL includes
#include <cstring>
#include <cstdio>
#include <iostream>
// Linux includes
#include <fcntl.h>
#include <sys/ioctl.h>
// hyperion local includes
#include "LedDeviceRawHID.h"
// Use feature report HID device
LedDeviceRawHID::LedDeviceRawHID(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms) :
LedHIDDevice(VendorId, ProductId, delayAfterConnect_ms, true),
_ledBuffer(0),
_timer()
{
// setup the timer
_timer.setSingleShot(false);
_timer.setInterval(5000);
connect(&_timer, SIGNAL(timeout()), this, SLOT(rewriteLeds()));
// start the timer
_timer.start();
}
int LedDeviceRawHID::write(const std::vector<ColorRgb> & ledValues)
{
// Resize buffer if required
if (_ledBuffer.size() < ledValues.size() * 3) {
_ledBuffer.resize(3 * ledValues.size());
}
// restart the timer
_timer.start();
// write data
memcpy(_ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
}
int LedDeviceRawHID::switchOff()
{
// restart the timer
_timer.start();
// write data
std::fill(_ledBuffer.begin(), _ledBuffer.end(), uint8_t(0));
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
}
void LedDeviceRawHID::rewriteLeds()
{
writeBytes(_ledBuffer.size(), _ledBuffer.data());
}

View File

@ -0,0 +1,48 @@
#pragma once
// STL includes
#include <string>
// Qt includes
#include <QTimer>
// hyperion include
#include "LedHIDDevice.h"
///
/// Implementation of the LedDevice interface for writing to an RawHID led device.
///
class LedDeviceRawHID : public LedHIDDevice
{
Q_OBJECT
public:
///
/// Constructs the LedDevice for attached RawHID device
///
LedDeviceRawHID(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms);
///
/// Writes the led color values to the led-device
///
/// @param ledValues The color-value per led
/// @return Zero on succes else negative
///
virtual int write(const std::vector<ColorRgb> & ledValues);
/// Switch the leds off
virtual int switchOff();
private slots:
/// Write the last data to the leds again
void rewriteLeds();
private:
/// The buffer containing the packed RGB values
std::vector<uint8_t> _ledBuffer;
/// Timer object which makes sure that led data is written at a minimum rate
/// The RawHID device will switch off when it does not receive data at least
/// every 15 seconds
QTimer _timer;
};

View File

@ -0,0 +1,152 @@
// STL includes
#include <cstring>
#include <iostream>
// Qt includes
#include <QTimer>
// Local Hyperion includes
#include "LedHIDDevice.h"
LedHIDDevice::LedHIDDevice(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms, const bool useFeature) :
_VendorId(VendorId),
_ProductId(ProductId),
_useFeature(useFeature),
_deviceHandle(nullptr),
_delayAfterConnect_ms(delayAfterConnect_ms),
_blockedForDelay(false)
{
// empty
}
LedHIDDevice::~LedHIDDevice()
{
if (_deviceHandle != nullptr)
{
hid_close(_deviceHandle);
_deviceHandle = nullptr;
}
hid_exit();
}
int LedHIDDevice::open()
{
// 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;
// Open the device
printf("Opening device: VID %04hx PID %04hx\n", _VendorId, _ProductId);
_deviceHandle = hid_open(_VendorId, _ProductId, nullptr);
if (_deviceHandle == nullptr)
{
// Failed to open the device
std::cerr << "Failed to open HID device. Maybe your PID/VID setting is wrong? Make sure to add a udev rule/use sudo." << std::endl;
// http://www.signal11.us/oss/hidapi/
/*
std::cout << "Showing a list of all available HID devices:" << std::endl;
auto devs = hid_enumerate(0x00, 0x00);
auto cur_dev = devs;
while (cur_dev) {
printf("Device Found\n type: %04hx %04hx\n path: %s\n serial_number: %ls",
cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number);
printf("\n");
printf(" Manufacturer: %ls\n", cur_dev->manufacturer_string);
printf(" Product: %ls\n", cur_dev->product_string);
printf("\n");
cur_dev = cur_dev->next;
}
hid_free_enumeration(devs);
*/
return -1;
}
else{
std::cout << "Opened HID device successful" << std::endl;
}
// Wait after device got opened if enabled
if (_delayAfterConnect_ms > 0)
{
_blockedForDelay = true;
QTimer::singleShot(_delayAfterConnect_ms, this, SLOT(unblockAfterDelay()));
std::cout << "Device blocked for " << _delayAfterConnect_ms << " ms" << std::endl;
}
return 0;
}
int LedHIDDevice::writeBytes(const unsigned size, const uint8_t * data)
{
if (_blockedForDelay) {
return 0;
}
if (_deviceHandle == nullptr)
{
// try to reopen
auto status = open();
if(status < 0){
// Try again in 3 seconds
int seconds = 3000;
_blockedForDelay = true;
QTimer::singleShot(seconds, this, SLOT(unblockAfterDelay()));
std::cout << "Device blocked for " << seconds << " ms" << std::endl;
}
// Return here, to not write led data if the device should be blocked after connect
return status;
}
// Prepend report ID to the buffer
uint8_t ledData[size + 1];
ledData[0] = 0; // Report ID
memcpy(ledData + 1, data, size_t(size));
// Send data via feature or out report
int ret;
if(_useFeature){
ret = hid_send_feature_report(_deviceHandle, ledData, size + 1);
}
else{
ret = hid_write(_deviceHandle, ledData, size + 1);
}
// Handle first error
if(ret < 0){
std::cerr << "Failed to write to HID device." << std::endl;
// Try again
if(_useFeature){
ret = hid_send_feature_report(_deviceHandle, ledData, size + 1);
}
else{
ret = hid_write(_deviceHandle, ledData, size + 1);
}
// Writing failed again, device might have disconnected
if(ret < 0){
std::cerr << "Failed to write to HID device." << std::endl;
hid_close(_deviceHandle);
_deviceHandle = nullptr;
}
}
return ret;
}
void LedHIDDevice::unblockAfterDelay()
{
std::cout << "Device unblocked" << std::endl;
_blockedForDelay = false;
}

View File

@ -0,0 +1,66 @@
#pragma once
#include <QObject>
// libusb include
#include <hidapi/hidapi.h>
// Leddevice includes
#include <leddevice/LedDevice.h>
///
/// The LedHIDDevice implements an abstract base-class for LedDevices using an HID-device.
///
class LedHIDDevice : public QObject, public LedDevice
{
Q_OBJECT
public:
///
/// Constructs the LedDevice attached to an HID-device
///
/// @param[in] VendorId The USB VID of the output device
/// @param[in] ProductId The USB PID of the output device
///
LedHIDDevice(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms = 0, const bool useFeature = false);
///
/// Destructor of the LedDevice; closes the output device if it is open
///
virtual ~LedHIDDevice();
///
/// Opens and configures the output device
///
/// @return Zero on succes else negative
///
int open();
protected:
/**
* Writes the given bytes to the HID-device and
*
* @param[in[ size The length of the data
* @param[in] data The data
*
* @return Zero on succes else negative
*/
int writeBytes(const unsigned size, const uint8_t *data);
private slots:
/// Unblock the device after a connection delay
void unblockAfterDelay();
private:
// HID VID and PID
const unsigned short _VendorId;
const unsigned short _ProductId;
const bool _useFeature;
/// libusb device handle
hid_device * _deviceHandle;
/// Sleep after the connect before continuing
const int _delayAfterConnect_ms;
bool _blockedForDelay;
};

View File

@ -274,7 +274,7 @@ int main(int argc, char** argv)
FramebufferWrapper * fbGrabber = nullptr;
if (config.isMember("framebuffergrabber") || config.isMember("framegrabber"))
{
const Json::Value & grabberConfig = config.isMember("framebuffergrabber")? config["framebuffergrabber"] : config.isMember("framegrabber");
const Json::Value & grabberConfig = config.isMember("framebuffergrabber")? config["framebuffergrabber"] : config["framegrabber"];
fbGrabber = new FramebufferWrapper(
grabberConfig.get("device", "/dev/fb0").asString(),
grabberConfig["width"].asUInt(),