Leddevices source tree refactoring (#461)

* rework structure of leddevice source tree

* fix data type vor v4l sig detection value in webui

* automate leddevicefactory.cpp
This commit is contained in:
redPanther 2017-08-07 10:05:46 +02:00 committed by GitHub
parent f3bbe158bf
commit 317a903b14
76 changed files with 98 additions and 222 deletions

View File

@ -27,10 +27,12 @@ IF ( ${CMAKE_SYSTEM} MATCHES "Linux" )
SET ( DEFAULT_V4L2 ON )
SET ( DEFAULT_SPIDEV ON )
SET ( DEFAULT_FB ON )
SET ( DEFAULT_USB_HID ON )
ELSE()
SET ( DEFAULT_V4L2 OFF )
SET ( DEFAULT_SPIDEV OFF )
SET ( DEFAULT_FB OFF )
SET ( DEFAULT_SPIDEV OFF )
SET ( DEFAULT_USB_HID OFF )
ENDIF()
if (APPLE)
@ -67,7 +69,8 @@ message( STATUS "PLATFORM: ${PLATFORM}")
if ( "${PLATFORM}" MATCHES "osx" )
SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "/usr/local/opt/qt5" CACHE STRING "path to your QT5 files" )
include_directories("/opt/X11/include/")
SET ( DEFAULT_OSX ON )
SET ( DEFAULT_OSX ON )
SET ( DEFAULT_USB_HID ON )
elseif ( "${PLATFORM}" STREQUAL "rpi" )
SET ( DEFAULT_DISPMANX ON )
SET ( DEFAULT_WS281XPWM ON )
@ -115,9 +118,12 @@ message(STATUS "ENABLE_TINKERFORGE = ${ENABLE_TINKERFORGE}")
option(ENABLE_V4L2 "Enable the V4L2 grabber" ${DEFAULT_V4L2})
message(STATUS "ENABLE_V4L2 = ${ENABLE_V4L2}")
option(ENABLE_WS281XPWM "Enable the WS281x-PWM device" ${DEFAULT_WS281XPWM} )
option(ENABLE_WS281XPWM "Enable the WS281x-PWM device" ${DEFAULT_WS281XPWM} )
message(STATUS "ENABLE_WS281XPWM = ${ENABLE_WS281XPWM}")
option(ENABLE_USB_HID "Enable the libusb and hid devices" ${DEFAULT_USB_HID} )
message(STATUS "ENABLE_USB_HID = ${ENABLE_USB_HID}")
option(ENABLE_X11 "Enable the X11 grabber" ${DEFAULT_X11})
message(STATUS "ENABLE_X11 = ${ENABLE_X11}")

View File

@ -6,15 +6,6 @@
// Define to enable the v4l2 grabber
#cmakedefine ENABLE_V4L2
// Define to enable the spi-device
#cmakedefine ENABLE_SPIDEV
// Define to enable the ws281x-pwm-via-dma-device using jgarff's library
#cmakedefine ENABLE_WS281XPWM
// Define to enable the spi-device
#cmakedefine ENABLE_TINKERFORGE
// Define to enable the framebuffer grabber
#cmakedefine ENABLE_FB
@ -27,6 +18,18 @@
// Define to enable the x11 grabber
#cmakedefine ENABLE_X11
// Define to enable the spi-device
#cmakedefine ENABLE_SPIDEV
// Define to enable the ws281x-pwm-via-dma-device using jgarff's library
#cmakedefine ENABLE_WS281XPWM
// Define to enable the tinkerforge device
#cmakedefine ENABLE_TINKERFORGE
// Define to enable the usb / hid devices
#cmakedefine ENABLE_USB_HID
// Define to enable profiler for development purpose
#cmakedefine ENABLE_PROFILER

View File

@ -145,7 +145,7 @@
},
"redSignalThreshold" :
{
"type" : "number",
"type" : "integer",
"title" : "edt_conf_v4l2_redSignalThreshold_title",
"minimum" : 0,
"maximum" : 100,
@ -160,7 +160,7 @@
},
"greenSignalThreshold" :
{
"type" : "number",
"type" : "integer",
"title" : "edt_conf_v4l2_greenSignalThreshold_title",
"minimum" : 0,
"maximum" : 100,
@ -175,7 +175,7 @@
},
"blueSignalThreshold" :
{
"type" : "number",
"type" : "integer",
"title" : "edt_conf_v4l2_blueSignalThreshold_title",
"minimum" : 0,
"maximum" : 100,

View File

@ -3,144 +3,84 @@
SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/leddevice)
SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/leddevice)
#add libusb and pthreads (required for the Lighpack usb device)
find_package(libusb-1.0 REQUIRED)
#find_package(Threads REQUIRED)
# qt files
find_package(Qt5 COMPONENTS Network SerialPort REQUIRED)
include_directories(
${CMAKE_SOURCE_DIR}/include/hidapi
${LIBUSB_1_INCLUDE_DIRS}
) # for Lightpack device
SET(Leddevice_HEADERS
${CURRENT_HEADER_DIR}/LedDeviceFactory.h
${CURRENT_SOURCE_DIR}/ProviderRs232.h
${CURRENT_SOURCE_DIR}/ProviderHID.h
${CURRENT_SOURCE_DIR}/ProviderUdp.h
${CURRENT_SOURCE_DIR}/LedDeviceLightpack.h
${CURRENT_SOURCE_DIR}/LedDeviceMultiLightpack.h
${CURRENT_SOURCE_DIR}/LedDevicePaintpack.h
${CURRENT_SOURCE_DIR}/LedDevicePiBlaster.h
${CURRENT_SOURCE_DIR}/LedDeviceSedu.h
${CURRENT_SOURCE_DIR}/LedDeviceDMX.h
${CURRENT_SOURCE_DIR}/LedDeviceFile.h
${CURRENT_SOURCE_DIR}/LedDeviceUdpRaw.h
${CURRENT_SOURCE_DIR}/LedDeviceUdpH801.h
${CURRENT_SOURCE_DIR}/LedDeviceUdpE131.h
${CURRENT_SOURCE_DIR}/LedDeviceUdpArtNet.h
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.h
${CURRENT_SOURCE_DIR}/LedDeviceTpm2net.h
${CURRENT_SOURCE_DIR}/LedDeviceAtmo.h
${CURRENT_HEADER_DIR}/LedDevice.h
${CURRENT_SOURCE_DIR}/LedDeviceAdalight.h
${CURRENT_SOURCE_DIR}/LedDeviceAtmoOrb.h
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.h
${CURRENT_SOURCE_DIR}/LedDeviceRawHID.h
${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.h
dev_hid
dev_net
dev_other
dev_serial
dev_spi
dev_rpi_pwm
dev_tinker
)
SET(Leddevice_SOURCES
${CURRENT_SOURCE_DIR}/LedDevice.cpp
${CURRENT_SOURCE_DIR}/LedDeviceFactory.cpp
${CURRENT_SOURCE_DIR}/ProviderRs232.cpp
${CURRENT_SOURCE_DIR}/ProviderHID.cpp
${CURRENT_SOURCE_DIR}/ProviderUdp.cpp
${CURRENT_SOURCE_DIR}/LedDeviceAdalight.cpp
${CURRENT_SOURCE_DIR}/LedDeviceAtmoOrb.cpp
${CURRENT_SOURCE_DIR}/LedDeviceRawHID.cpp
${CURRENT_SOURCE_DIR}/LedDeviceLightpack.cpp
${CURRENT_SOURCE_DIR}/LedDeviceMultiLightpack.cpp
${CURRENT_SOURCE_DIR}/LedDevicePaintpack.cpp
${CURRENT_SOURCE_DIR}/LedDevicePiBlaster.cpp
${CURRENT_SOURCE_DIR}/LedDeviceSedu.cpp
${CURRENT_SOURCE_DIR}/LedDeviceDMX.cpp
${CURRENT_SOURCE_DIR}/LedDeviceFile.cpp
${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.cpp
${CURRENT_SOURCE_DIR}/LedDeviceUdpRaw.cpp
${CURRENT_SOURCE_DIR}/LedDeviceUdpH801.cpp
${CURRENT_SOURCE_DIR}/LedDeviceUdpE131.cpp
${CURRENT_SOURCE_DIR}/LedDeviceUdpArtNet.cpp
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.cpp
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.cpp
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.cpp
${CURRENT_SOURCE_DIR}/LedDeviceTpm2net.cpp
${CURRENT_SOURCE_DIR}/LedDeviceAtmo.cpp
FILE ( GLOB Leddevice_SOURCES
"${CURRENT_HEADER_DIR}/*.h"
"${CURRENT_SOURCE_DIR}/*.h"
"${CURRENT_SOURCE_DIR}/*.cpp"
"${CURRENT_SOURCE_DIR}/dev_serial/*.h"
"${CURRENT_SOURCE_DIR}/dev_serial/*.cpp"
"${CURRENT_SOURCE_DIR}/dev_net/*.h"
"${CURRENT_SOURCE_DIR}/dev_net/*.cpp"
"${CURRENT_SOURCE_DIR}/dev_other/*.h"
"${CURRENT_SOURCE_DIR}/dev_other/*.cpp"
)
if(ENABLE_SPIDEV)
SET(Leddevice_HEADERS
${Leddevice_HEADERS}
${CURRENT_SOURCE_DIR}/ProviderSpi.h
${CURRENT_SOURCE_DIR}/LedDeviceLpd6803.h
${CURRENT_SOURCE_DIR}/LedDeviceLpd8806.h
${CURRENT_SOURCE_DIR}/LedDeviceP9813.h
${CURRENT_SOURCE_DIR}/LedDeviceWs2801.h
${CURRENT_SOURCE_DIR}/LedDeviceWs2812SPI.h
${CURRENT_SOURCE_DIR}/LedDeviceSk6822SPI.h
${CURRENT_SOURCE_DIR}/LedDeviceSk6812SPI.h
${CURRENT_SOURCE_DIR}/LedDeviceAPA102.h
)
SET(Leddevice_SOURCES
${Leddevice_SOURCES}
${CURRENT_SOURCE_DIR}/ProviderSpi.cpp
${CURRENT_SOURCE_DIR}/LedDeviceLpd6803.cpp
${CURRENT_SOURCE_DIR}/LedDeviceLpd8806.cpp
${CURRENT_SOURCE_DIR}/LedDeviceP9813.cpp
${CURRENT_SOURCE_DIR}/LedDeviceWs2801.cpp
${CURRENT_SOURCE_DIR}/LedDeviceWs2812SPI.cpp
${CURRENT_SOURCE_DIR}/LedDeviceSk6822SPI.cpp
${CURRENT_SOURCE_DIR}/LedDeviceSk6812SPI.cpp
${CURRENT_SOURCE_DIR}/LedDeviceAPA102.cpp
if ( ENABLE_USB_HID )
find_package(libusb-1.0 REQUIRED)
include_directories(
${CMAKE_SOURCE_DIR}/include/hidapi
${LIBUSB_1_INCLUDE_DIRS}
)
FILE ( GLOB Leddevice_USB_HID_SOURCES "${CURRENT_SOURCE_DIR}/dev_hid/*.h" "${CURRENT_SOURCE_DIR}/dev_hid/*.cpp")
endif()
if(ENABLE_WS281XPWM)
if ( ENABLE_SPIDEV )
FILE ( GLOB Leddevice_SPI_SOURCES "${CURRENT_SOURCE_DIR}/dev_spi/*.h" "${CURRENT_SOURCE_DIR}/dev_spi/*.cpp")
endif()
if ( ENABLE_TINKERFORGE )
FILE ( GLOB Leddevice_TINKER_SOURCES "${CURRENT_SOURCE_DIR}/dev_tinker/*.h" "${CURRENT_SOURCE_DIR}/dev_tinker/*.cpp")
endif()
if ( ENABLE_WS281XPWM )
include_directories(../../dependencies/external/rpi_ws281x)
SET(Leddevice_HEADERS
${Leddevice_HEADERS}
${CURRENT_SOURCE_DIR}/LedDeviceWS281x.h
)
SET(Leddevice_SOURCES
${Leddevice_SOURCES}
${CURRENT_SOURCE_DIR}/LedDeviceWS281x.cpp
)
FILE ( GLOB Leddevice_PWM_SOURCES "${CURRENT_SOURCE_DIR}/dev_rpi_pwm/*.h" "${CURRENT_SOURCE_DIR}/dev_rpi_pwm/*.cpp")
endif()
if(ENABLE_TINKERFORGE)
SET(Leddevice_HEADERS
${Leddevice_HEADERS}
${CURRENT_SOURCE_DIR}/LedDeviceTinkerforge.h
)
SET(Leddevice_SOURCES
${Leddevice_SOURCES}
${CURRENT_SOURCE_DIR}/LedDeviceTinkerforge.cpp
)
endif()
set(LedDevice_RESOURCES
${CURRENT_SOURCE_DIR}/LedDeviceSchemas.qrc
)
set(LedDevice_RESOURCES ${CURRENT_SOURCE_DIR}/LedDeviceSchemas.qrc )
qt5_add_resources(LedDevice_RESOURCES_RCC ${LedDevice_RESOURCES} OPTIONS "-no-compress")
add_library(leddevice
${Leddevice_HEADERS}
SET( Leddevice_SOURCES
${Leddevice_SOURCES}
${LedDevice_RESOURCES}
${LedDevice_RESOURCES_RCC}
${Leddevice_USB_HID_SOURCES}
${Leddevice_TINKER_SOURCES}
${Leddevice_SPI_SOURCES}
${Leddevice_PWM_SOURCES}
)
# auto generate header file that include all available leddevice headers
# auto generate cpp file for register() calls
FILE ( WRITE "${CMAKE_BINARY_DIR}/LedDevice_headers.h" "#pragma once\n\n//this file is autogenerated, don't touch it\n\n" )
FILE ( WRITE "${CMAKE_BINARY_DIR}/LedDevice_register.cpp" "//this file is autogenerated, don't touch it\n\n" )
FOREACH( f ${Leddevice_SOURCES} )
if ( "${f}" MATCHES "dev_.*/Led.evice.+h$" )
GET_FILENAME_COMPONENT(fname ${f} NAME)
FILE ( APPEND "${CMAKE_BINARY_DIR}/LedDevice_headers.h" "#include \"${fname}\"\n" )
STRING( SUBSTRING ${fname} 9 -1 dname)
STRING( REPLACE ".h" "" dname "${dname}" )
FILE ( APPEND "${CMAKE_BINARY_DIR}/LedDevice_register.cpp" "REGISTER(${dname});\n" )
endif()
ENDFOREACH()
add_library(leddevice ${CMAKE_BINARY_DIR}/LedDevice_headers.h ${Leddevice_SOURCES} )
target_link_libraries(leddevice
hyperion-utils
${LIBUSB_1_LIBRARIES} #apt-get install libusb-1.0-0-dev
${CMAKE_THREAD_LIBS_INIT}
Qt5::Network
Qt5::SerialPort
@ -154,8 +94,11 @@ if(ENABLE_WS281XPWM)
target_link_libraries(leddevice ws281x)
endif()
if(APPLE)
target_link_libraries(leddevice hidapi-mac)
else()
target_link_libraries(leddevice hidapi-libusb)
if (ENABLE_USB_HID)
if(APPLE)
target_link_libraries(leddevice ${LIBUSB_1_LIBRARIES} hidapi-mac)
else()
target_link_libraries(leddevice ${LIBUSB_1_LIBRARIES} hidapi-libusb)
endif()
endif()

View File

@ -10,46 +10,8 @@
#include <utils/Logger.h>
#include <leddevice/LedDevice.h>
// Local Leddevice includes
#ifdef ENABLE_SPIDEV
#include "LedDeviceLpd6803.h"
#include "LedDeviceLpd8806.h"
#include "LedDeviceP9813.h"
#include "LedDeviceWs2801.h"
#include "LedDeviceWs2812SPI.h"
#include "LedDeviceSk6812SPI.h"
#include "LedDeviceSk6822SPI.h"
#include "LedDeviceAPA102.h"
#endif
#ifdef ENABLE_TINKERFORGE
#include "LedDeviceTinkerforge.h"
#endif
#include "LedDeviceAdalight.h"
#include "LedDeviceRawHID.h"
#include "LedDeviceLightpack.h"
#include "LedDeviceMultiLightpack.h"
#include "LedDevicePaintpack.h"
#include "LedDevicePiBlaster.h"
#include "LedDeviceSedu.h"
#include "LedDeviceDMX.h"
#include "LedDeviceFile.h"
#include "LedDeviceFadeCandy.h"
#include "LedDeviceTpm2net.h"
#include "LedDeviceUdpRaw.h"
#include "LedDeviceUdpE131.h"
#include "LedDeviceUdpArtNet.h"
#include "LedDeviceHyperionUsbasp.h"
#include "LedDevicePhilipsHue.h"
#include "LedDeviceTpm2.h"
#include "LedDeviceAtmo.h"
#include "LedDeviceAtmoOrb.h"
#include "LedDeviceUdpH801.h"
#ifdef ENABLE_WS281XPWM
#include "LedDeviceWS281x.h"
#endif
// following file is auto generated by cmake! it contains all available leddevice headers
#include "LedDevice_headers.h"
LedDevice * LedDeviceFactory::construct(const QJsonObject & deviceConfig, const int ledCount)
{
@ -63,54 +25,10 @@ LedDevice * LedDeviceFactory::construct(const QJsonObject & deviceConfig, const
LedDevice::setLedCount(ledCount);
#define REGISTER(className) LedDevice::addToDeviceMap(QString(#className).toLower(), LedDevice##className::construct);
// rs232 devices
REGISTER(Adalight);
REGISTER(Sedu);
REGISTER(DMX);
REGISTER(Tpm2);
REGISTER(Atmo);
// spi devices
#ifdef ENABLE_SPIDEV
REGISTER(APA102);
REGISTER(Lpd6803);
REGISTER(Lpd8806);
REGISTER(P9813);
REGISTER(Ws2801);
REGISTER(Ws2812SPI);
REGISTER(Sk6812SPI);
REGISTER(Sk6822SPI);
#endif
// pwm devices
#ifdef ENABLE_WS281XPWM
REGISTER(WS281x);
#endif
// the REGISTER() calls are autogenerated by cmake.
#include "LedDevice_register.cpp"
// network lights
REGISTER(FadeCandy);
REGISTER(Tpm2net);
REGISTER(UdpRaw);
REGISTER(UdpE131);
REGISTER(UdpArtNet);
REGISTER(UdpH801);
REGISTER(PhilipsHue);
REGISTER(AtmoOrb);
#ifdef ENABLE_TINKERFORGE
REGISTER(Tinkerforge);
#endif
// direct usb
REGISTER(HyperionUsbasp);
REGISTER(RawHID);
REGISTER(Paintpack);
REGISTER(Lightpack);
REGISTER(MultiLightpack);
// other
REGISTER(File);
REGISTER(PiBlaster);
#undef REGISTER
const LedDeviceRegistry& devList = LedDevice::getDeviceMap();

View File

@ -11,7 +11,6 @@
///
class LedDeviceRawHID : public ProviderHID
{
Q_OBJECT
public:
///

View File

@ -1,3 +1,5 @@
// code currently disabled. must be ported to new structure
#if 0
// stl includes
#include <exception>
#include <cstring>
@ -266,3 +268,4 @@ int LedDeviceLightpackHidapi::disableSmoothing()
unsigned char buf[2] = {CMD_SET_SMOOTH_SLOWDOWN, 0};
return writeBytes(buf, sizeof(buf)) == sizeof(buf);
}
#endif

View File

@ -1,3 +1,6 @@
// code currently disabled. must be ported to new structure
#if 0
#pragma once
// stl includes
@ -101,3 +104,4 @@ private:
/// the number of bits per channel
int _bitsPerChannel;
};
#endif

View File

@ -13,7 +13,7 @@
//QT includes
#include <QJsonObject>
#include "../libsrc/leddevice/LedDeviceWs2801.h"
#include "../libsrc/leddevice/dev_spi/LedDeviceWs2801.h"
QJsonObject deviceConfig;