mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
commit
4f5892bb72
12
.gitignore
vendored
12
.gitignore
vendored
@ -4,3 +4,15 @@
|
||||
.DS_Store
|
||||
CMakeFiles/
|
||||
__/
|
||||
|
||||
# Ignoring autogenerated files
|
||||
*.cmake
|
||||
Makefile
|
||||
qrc_*.cpp
|
||||
*.qrc.depends
|
||||
moc_*.cpp
|
||||
moc_*.cpp_parameters
|
||||
CMakeCache.txt
|
||||
*.log
|
||||
/HyperionConfig.h
|
||||
/lib
|
||||
|
@ -1,32 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
# for executing in non travis environment
|
||||
[ -z "$TRAVIS_OS_NAME" ] && TRAVIS_OS_NAME="$( uname -s | tr '[:upper:]' '[:lower:]' )"
|
||||
|
||||
[ -z "$TRAVIS_OS_NAME" ] && TRAVIS_OS_NAME="$(uname -s | tr 'A-Z' 'a-z')"
|
||||
|
||||
######################################
|
||||
## COMPILE HYPERION
|
||||
# Detect number of processor cores
|
||||
|
||||
# compile hyperion on osx
|
||||
if [[ $TRAVIS_OS_NAME == 'osx' ]]
|
||||
then
|
||||
if [[ $TRAVIS_OS_NAME == 'osx' || $TRAVIS_OS_NAME == 'darwin' ]]; then
|
||||
procs=$(sysctl -n hw.ncpu | xargs)
|
||||
echo "Processes: $procs"
|
||||
|
||||
mkdir build || exit 1
|
||||
cd build
|
||||
cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON -Wno-dev .. || exit 2
|
||||
make -j$procs || exit 3
|
||||
# make -j$(nproc) package || exit 4 # currently osx(dmg) package creation not implemented
|
||||
elif [[ $TRAVIS_OS_NAME == 'linux' ]]; then
|
||||
procs=$(nproc)
|
||||
else
|
||||
# For most modern systems, including the pi, this is a sane default
|
||||
procs=4
|
||||
fi
|
||||
|
||||
# compile hyperion on linux
|
||||
if [[ $TRAVIS_OS_NAME == 'linux' ]]
|
||||
then
|
||||
mkdir build || exit 1
|
||||
cd build
|
||||
cmake -DPLATFORM=x86-dev -DCMAKE_BUILD_TYPE=Debug .. || exit 2
|
||||
make -j$(nproc) || exit 3
|
||||
make -j$(nproc) package || exit 4
|
||||
|
||||
# Compile hyperion
|
||||
|
||||
mkdir build || exit 1
|
||||
cd build
|
||||
cmake -DPLATFORM=x86-dev -DCMAKE_BUILD_TYPE=Debug .. || exit 2
|
||||
make -j$(nproc) || exit 3
|
||||
|
||||
|
||||
# Build the package on Linux
|
||||
|
||||
if [[ $TRAVIS_OS_NAME == 'linux' ]]; then
|
||||
make -j$(nproc) package || exit 4
|
||||
fi
|
||||
|
||||
|
@ -1,7 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
# for executing in non travis environment
|
||||
[ -z "$TRAVIS_OS_NAME" ] && TRAVIS_OS_NAME="$( uname -s | tr '[:upper:]' '[:lower:]' )"
|
||||
|
||||
# install osx deps for hyperion compile
|
||||
if [[ $TRAVIS_OS_NAME == 'osx' ]]
|
||||
if [[ $TRAVIS_OS_NAME == 'osx' || $TRAVIS_OS_NAME == 'darwin' ]]
|
||||
then
|
||||
echo "Install OSX deps"
|
||||
time brew update
|
||||
@ -9,13 +12,15 @@ then
|
||||
time brew install libusb || true
|
||||
time brew install cmake || true
|
||||
time brew install doxygen || true
|
||||
fi
|
||||
|
||||
# install linux deps for hyperion compile
|
||||
if [[ $TRAVIS_OS_NAME == 'linux' ]]
|
||||
elif [[ $TRAVIS_OS_NAME == 'linux' ]]
|
||||
then
|
||||
echo "Install linux deps"
|
||||
sudo apt-get -qq update
|
||||
sudo apt-get install -qq -y qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev doxygen
|
||||
else
|
||||
echo "Unsupported platform: $TRAVIS_OS_NAME"
|
||||
exit 5
|
||||
fi
|
||||
|
||||
|
111
CMakeLists.txt
111
CMakeLists.txt
@ -30,55 +30,58 @@ SET ( DEFAULT_USE_SHARED_AVAHI_LIBS OFF )
|
||||
SET ( DEFAULT_USE_AVAHI_LIBS ON )
|
||||
SET ( DEFAULT_TESTS OFF )
|
||||
|
||||
if ( NOT DEFINED PLATFORM )
|
||||
if ( "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86" )
|
||||
SET( PLATFORM "x86")
|
||||
elseif ( "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm" )
|
||||
SET( PLATFORM "rpi")
|
||||
EXEC_PROGRAM( "nproc" OUTPUT_VARIABLE SYSTEM_CPU_CORES )
|
||||
FILE( READ /proc/cpuinfo SYSTEM_CPUINFO )
|
||||
STRING ( TOLOWER "${SYSTEM_CPUINFO}" SYSTEM_CPUINFO )
|
||||
if ( "${SYSTEM_CPUINFO}" MATCHES "amlogic" )
|
||||
SET( PLATFORM "wetek" )
|
||||
elseif( SYSTEM_CPU_CORES GREATER 1 AND "${SYSTEM_CPUINFO}" MATCHES "bcm" )
|
||||
SET( PLATFORM "rpi-pwm" )
|
||||
endif()
|
||||
endif()
|
||||
if ( PLATFORM )
|
||||
message( STATUS "PLATFORM is not defined, evaluated platform: ${PLATFORM}")
|
||||
else()
|
||||
message( FATAL_ERROR "PLATFORM is not defined and could not be evaluated. Set -DPLATFORM=<rpi|pri-pwm|wetek|x86>")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if ( "${PLATFORM}" STREQUAL "rpi" )
|
||||
SET ( DEFAULT_DISPMANX ON )
|
||||
elseif ( "${PLATFORM}" STREQUAL "rpi-pwm" )
|
||||
SET ( DEFAULT_DISPMANX ON )
|
||||
SET ( DEFAULT_WS2812BPWM ON )
|
||||
SET ( DEFAULT_WS281XPWM ON )
|
||||
elseif ( "${PLATFORM}" STREQUAL "wetek" )
|
||||
SET ( DEFAULT_AMLOGIC ON )
|
||||
elseif ( "${PLATFORM}" STREQUAL "x86" )
|
||||
SET ( DEFAULT_X11 ON )
|
||||
SET ( DEFAULT_USE_SHARED_AVAHI_LIBS ON )
|
||||
elseif ( "${PLATFORM}" STREQUAL "x86-dev" )
|
||||
SET ( DEFAULT_X11 ON )
|
||||
SET ( DEFAULT_AMLOGIC ON)
|
||||
SET ( DEFAULT_WS281XPWM ON )
|
||||
SET ( DEFAULT_USE_SHARED_AVAHI_LIBS ON )
|
||||
SET ( DEFAULT_TESTS ON )
|
||||
elseif ( "${PLATFORM}" STREQUAL "imx6" )
|
||||
SET ( DEFAULT_FB ON )
|
||||
endif()
|
||||
|
||||
if (APPLE)
|
||||
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "/usr/local/opt/qt5")
|
||||
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "/usr/local/opt/qt5")
|
||||
include_directories("/opt/X11/include/")
|
||||
SET ( DEFAULT_OSX ON )
|
||||
SET ( DEFAULT_V4L2 OFF )
|
||||
SET ( DEFAULT_V4L2 OFF )
|
||||
SET ( DEFAULT_SPIDEV OFF )
|
||||
SET ( DEFAULT_FB OFF )
|
||||
SET ( DEFAULT_USE_AVAHI_LIBS OFF )
|
||||
else ()
|
||||
if ( NOT DEFINED PLATFORM )
|
||||
if ( "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86" )
|
||||
SET( PLATFORM "x86")
|
||||
elseif ( "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm" )
|
||||
SET( PLATFORM "rpi")
|
||||
EXEC_PROGRAM( "nproc" OUTPUT_VARIABLE SYSTEM_CPU_CORES )
|
||||
FILE( READ /proc/cpuinfo SYSTEM_CPUINFO )
|
||||
STRING ( TOLOWER "${SYSTEM_CPUINFO}" SYSTEM_CPUINFO )
|
||||
if ( "${SYSTEM_CPUINFO}" MATCHES "amlogic" )
|
||||
SET( PLATFORM "wetek" )
|
||||
elseif( SYSTEM_CPU_CORES GREATER 1 AND "${SYSTEM_CPUINFO}" MATCHES "bcm" )
|
||||
SET( PLATFORM "rpi-pwm" )
|
||||
endif()
|
||||
endif()
|
||||
if ( PLATFORM )
|
||||
message( STATUS "PLATFORM is not defined, evaluated platform: ${PLATFORM}")
|
||||
else()
|
||||
message( FATAL_ERROR "PLATFORM is not defined and could not be evaluated. Set -DPLATFORM=<rpi|pri-pwm|wetek|x86>")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if ( "${PLATFORM}" STREQUAL "rpi" )
|
||||
SET ( DEFAULT_DISPMANX ON )
|
||||
elseif ( "${PLATFORM}" STREQUAL "rpi-pwm" )
|
||||
SET ( DEFAULT_DISPMANX ON )
|
||||
SET ( DEFAULT_WS2812BPWM ON )
|
||||
SET ( DEFAULT_WS281XPWM ON )
|
||||
elseif ( "${PLATFORM}" STREQUAL "wetek" )
|
||||
SET ( DEFAULT_AMLOGIC ON )
|
||||
elseif ( "${PLATFORM}" STREQUAL "x86" )
|
||||
SET ( DEFAULT_X11 ON )
|
||||
SET ( DEFAULT_USE_SHARED_AVAHI_LIBS ON )
|
||||
elseif ( "${PLATFORM}" STREQUAL "x86-dev" )
|
||||
SET ( DEFAULT_X11 ON )
|
||||
SET ( DEFAULT_AMLOGIC ON)
|
||||
SET ( DEFAULT_WS281XPWM ON )
|
||||
SET ( DEFAULT_USE_SHARED_AVAHI_LIBS ON )
|
||||
SET ( DEFAULT_TESTS ON )
|
||||
elseif ( "${PLATFORM}" STREQUAL "imx6" )
|
||||
SET ( DEFAULT_FB ON )
|
||||
endif()
|
||||
SET ( DEFAULT_WS281XPWM OFF )
|
||||
SET ( DEFAULT_USE_AVAHI_LIBS OFF )
|
||||
SET ( DEFAULT_USE_SHARED_AVAHI_LIBS OFF )
|
||||
endif ()
|
||||
|
||||
# set the build options
|
||||
@ -124,10 +127,6 @@ message(STATUS "ENABLE_PROFILER = " ${ENABLE_PROFILER})
|
||||
SET ( PROTOBUF_INSTALL_BIN_DIR ${CMAKE_BINARY_DIR}/proto )
|
||||
SET ( PROTOBUF_INSTALL_LIB_DIR ${CMAKE_BINARY_DIR}/proto )
|
||||
|
||||
#if(ENABLE_QT5)
|
||||
# TODO vs ENABLE_QT4?
|
||||
#endif(ENABLE_QT5)
|
||||
|
||||
# Createt the configuration file
|
||||
|
||||
# Add project specific cmake modules (find, etc)
|
||||
@ -156,8 +155,18 @@ include_directories(${CMAKE_SOURCE_DIR}/include)
|
||||
#set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so")
|
||||
|
||||
# enable C++11
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall")
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -std=c++11 -Wall")
|
||||
include(CheckCXXCompilerFlag)
|
||||
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
||||
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
||||
if(COMPILER_SUPPORTS_CXX11)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
elseif(COMPILER_SUPPORTS_CXX0X)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||
else()
|
||||
message(STATUS "No support for C++11 detected. Compilation will most likely fail on your compiler")
|
||||
endif()
|
||||
|
||||
SET(QT_MIN_VERSION "5.2.0")
|
||||
find_package(Qt5 COMPONENTS Core Gui Network REQUIRED)
|
||||
|
@ -290,43 +290,45 @@
|
||||
<li>
|
||||
<a class="active" href="index.html"><i class="fa fa-dashboard fa-fw"></i><span lang="en" data-lang-token="main_menu_dashboard_token">Dashboard</span></a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="inactive" href="#"><i class="fa fa-cog fa-fw"></i><span lang="en" data-lang-token="main_menu_configuration_token">Configuration</span><span class="fa arrow"></span></a>
|
||||
<ul class="nav nav-second-level">
|
||||
<li>
|
||||
<a class="inactive" href="#" id="load_confGeneral"><i class="fa fa-play-circle-o fa-fw"></i><span lang="en" data-lang-token="main_menu_general_conf_token">General</span></a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="inactive" href="#" id="load_confKodi"><i class="fa fa-play-circle-o fa-fw"></i><span lang="en" data-lang-token="main_menu_kodiwatch_token">Kodi Watch</span></a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="inactive" href="#" id="load_huebridge"><i class="fa fa-cog fa-fw"></i><span lang="en" data-lang-token="main_menu_huebridge_token">Hue Bridge</span></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a class="inactive" href="#"><i class="fa fa-lightbulb-o fa-fw"></i><span lang="en" data-lang-token="main_menu_remotecontrol_token">Remote Control</span><span class="fa arrow"></span></a>
|
||||
<ul class="nav nav-second-level">
|
||||
<li>
|
||||
<a class="inactive" href="#" id="load_lighttest"><i class="fa fa-lightbulb-o fa-fw"></i><span lang="en" data-lang-token="main_menu_colors_token">Colors</span></a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="inactive" href="#" id="load_effects"><i class="fa fa-certificate fa-fw"></i><span lang="en" data-lang-token="main_menu_effects_token">Effects</span></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a class="inactive" href="#" id="load_support"><i class="fa fa-info fa-fw"></i><span lang="en" data-lang-token="main_menu_support_token">Support</span></a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="inactive" href="#"><i class="fa fa-cog fa-fw"></i><span lang="en" data-lang-token="main_menu_system_token">System</span><span class="fa arrow"></span></a>
|
||||
<ul class="nav nav-second-level">
|
||||
<li>
|
||||
<a class="inactive" href="#" id="load_update"><i class="fa fa-download fa-fw"></i><span lang="en" data-lang-token="main_menu_update_token">Update</span></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</li>
|
||||
<li>
|
||||
<a class="inactive" href="#"><i class="fa fa-cog fa-fw"></i><span lang="en" data-lang-token="main_menu_configuration_token">Configuration</span><span class="fa arrow"></span></a>
|
||||
<ul class="nav nav-second-level">
|
||||
<li>
|
||||
<a class="inactive" href="#" id="load_confGeneral"><i class="fa fa-play-circle-o fa-fw"></i><span lang="en" data-lang-token="main_menu_general_conf_token">General</span></a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="inactive" href="#" id="load_confKodi"><i class="fa fa-play-circle-o fa-fw"></i><span lang="en" data-lang-token="main_menu_kodiwatch_token">Kodi Watch</span></a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="inactive" href="#" id="load_huebridge"><i class="fa fa-cog fa-fw"></i><span lang="en" data-lang-token="main_menu_huebridge_token">Hue Bridge</span></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a class="inactive" href="#"><i class="fa fa-lightbulb-o fa-fw"></i><span lang="en" data-lang-token="main_menu_remotecontrol_token">Remote Control</span><span class="fa arrow"></span></a>
|
||||
<ul class="nav nav-second-level">
|
||||
<li>
|
||||
<a class="inactive" href="#" id="load_lighttest"><i class="fa fa-lightbulb-o fa-fw"></i><span lang="en" data-lang-token="main_menu_colors_token">Colors</span></a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="inactive" href="#" id="load_effects"><i class="fa fa-certificate fa-fw"></i><span lang="en" data-lang-token="main_menu_effects_token">Effects</span></a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="inactive" href="#" id="load_components"><i class="fa fa-list fa-fw"></i><span lang="en" data-lang-token="main_menu_component_token">Components</span></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a class="inactive" href="#" id="load_support"><i class="fa fa-info fa-fw"></i><span lang="en" data-lang-token="main_menu_support_token">Support</span></a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="inactive" href="#"><i class="fa fa-cog fa-fw"></i><span lang="en" data-lang-token="main_menu_system_token">System</span><span class="fa arrow"></span></a>
|
||||
<ul class="nav nav-second-level">
|
||||
<li>
|
||||
<a class="inactive" href="#" id="load_update"><i class="fa fa-download fa-fw"></i><span lang="en" data-lang-token="main_menu_update_token">Update</span></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
@ -449,6 +451,10 @@
|
||||
$("#load_effects").on("click", function() {
|
||||
$("#page-wrapper").load("effects.html");
|
||||
});
|
||||
|
||||
$("#load_components").on("click", function() {
|
||||
$("#page-wrapper").load("remote_components.html");
|
||||
});
|
||||
|
||||
$("#load_huebridge").on("click", function() {
|
||||
$("#page-wrapper").load("huebridge.html");
|
||||
|
@ -25,6 +25,7 @@
|
||||
"main_menu_remotecontrol_token" : "Fernbedienung",
|
||||
"main_menu_colors_token" : "Farben",
|
||||
"main_menu_effects_token" : "Effekte",
|
||||
"main_menu_component_token" : "Komponenten",
|
||||
"main_menu_support_token" : "Hilfe",
|
||||
"main_menu_update_token" : "Update",
|
||||
"main_menu_system_token" : "System",
|
||||
@ -34,6 +35,7 @@
|
||||
"remote_effects_intro" : "Die Effekt-Fernbedienung ermöglicht es dir Effekte zu starten für Demonstrations- oder Testzwecke. Vergessse nicht den Effekt wieder zu stoppen, wenn du fertig bist.",
|
||||
"remote_effects_label_effects":"Effekte",
|
||||
"remote_effects_label_stopeffect":"Stoppe Effekte",
|
||||
"remote_components_intro" : "Die Komponenten-Fenbedienung ermöglicht es dir Komponenten von Hyperion zu starten und stoppen. Beachte: Dies ist nur temporär und geht nach einem Neustart verloren. Möchtest du dauerhaft Komponenten aktivieren/deaktivieren benutze die Konfigurationsseiten.",
|
||||
"hue_button_create_user_token":"Benutzer anlegen",
|
||||
"hue_press_link_modal":"Link Taste auf der Hue Bridge drücken und mit Button bestätigen.",
|
||||
"hue_press_link_modal_failure":"Bitte drücke die Link Taste auf deiner Hue Bridge.",
|
||||
|
42
assets/webconfig/remote_components.html
Normal file
42
assets/webconfig/remote_components.html
Normal file
@ -0,0 +1,42 @@
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<h1 class="page-header" lang="en" data-lang-token="main_menu_component_token">Effects</h1>
|
||||
<div class="introd">
|
||||
<h4 lang="en" data-lang-token="remote_components_intro">The components remote enables you to disable and enable certain components of Hyperion during runtime. Keep in mind this persist just until the next reboot! To enable/disable components permament, use the configuration section.</h4>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="col-lg-12" id="componentsbutton">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
webSocket = new WebSocket('ws://'+document.location.hostname+':19444');
|
||||
|
||||
new Enum('SMOOTHING', 'BLACKBORDER', 'KODICHECKER', 'FORWARDER', 'UDPLISTENER', 'BOBLIGHT_SERVER','GRABBER');
|
||||
|
||||
function Enum() {
|
||||
for (var i in arguments) {
|
||||
this[arguments[i]] = i;
|
||||
$('#componentsbutton').append('<button type="button" class="btn btn-success" onclick="compenable(\''+arguments[i]+'\')"><i class="fa fa-play"></i></button> '+arguments[i]+'<br />');
|
||||
$('#componentsbutton').append('<button type="button" class="btn btn-danger" onclick="compdisable(\''+arguments[i]+'\')"><i class="fa fa-play"></i></button> '+arguments[i]+'<br />');
|
||||
}
|
||||
}
|
||||
|
||||
function compenable(comp){
|
||||
|
||||
webSocket.send('{"command":"componentstate","componentstate":{"component":"'+comp+'","state":true}}');
|
||||
console.log('enable: '+comp);
|
||||
|
||||
}
|
||||
function compdisable(comp){
|
||||
|
||||
webSocket.send('{"command":"componentstate","componentstate":{"component":"'+comp+'","state":false}}');
|
||||
console.log('disable: '+comp);
|
||||
|
||||
}
|
||||
|
||||
</script>
|
1
bin/.gitignore
vendored
Normal file
1
bin/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
protoc
|
1
config/.gitignore
vendored
Normal file
1
config/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/*.json
|
1
dependencies/CMakeLists.txt
vendored
1
dependencies/CMakeLists.txt
vendored
@ -1,4 +1,3 @@
|
||||
add_subdirectory(build/getoptPlusPlus)
|
||||
add_subdirectory(build/hidapi)
|
||||
add_subdirectory(build/jsoncpp)
|
||||
add_subdirectory(build/tinkerforge)
|
||||
|
BIN
dependencies/LightberryHDUSBAPA1021.1.zip
vendored
BIN
dependencies/LightberryHDUSBAPA1021.1.zip
vendored
Binary file not shown.
@ -1,9 +0,0 @@
|
||||
project(getoptPlusPlus)
|
||||
|
||||
include_directories(
|
||||
../../include/getoptPlusPlus)
|
||||
|
||||
add_library(getoptPlusPlus
|
||||
../../include/getoptPlusPlus/getoptpp.h
|
||||
../../include/getoptPlusPlus/parameter.include.cc
|
||||
getoptpp.cc)
|
66
dependencies/build/getoptPlusPlus/COPYING
vendored
66
dependencies/build/getoptPlusPlus/COPYING
vendored
@ -1,66 +0,0 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.
|
||||
|
||||
“The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.
|
||||
|
||||
An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.
|
||||
|
||||
A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.
|
||||
|
||||
The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.
|
||||
|
||||
The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:
|
||||
|
||||
* a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or
|
||||
* b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:
|
||||
|
||||
* a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.
|
||||
* b) Accompany the object code with a copy of the GNU GPL and this license document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:
|
||||
|
||||
* a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.
|
||||
* b) Accompany the Combined Work with a copy of the GNU GPL and this license document.
|
||||
* c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.
|
||||
* d) Do one of the following:
|
||||
o 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
|
||||
o 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.
|
||||
* e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:
|
||||
|
||||
* a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.
|
||||
* b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
|
||||
|
16
dependencies/build/getoptPlusPlus/Makefile
vendored
16
dependencies/build/getoptPlusPlus/Makefile
vendored
@ -1,16 +0,0 @@
|
||||
SOURCES=getoptpp.cc test.cc
|
||||
HEADERS=getoptpp.h
|
||||
OBJECTS=$(SOURCES:.cc=.o)
|
||||
LDFLAGS=
|
||||
CXXFLAGS=-O0 -ggdb -Wall
|
||||
CFLAGS=$(CXXFLAGS)
|
||||
CC=g++
|
||||
TARGET=getopt-test
|
||||
|
||||
all: $(TARGET)
|
||||
$(TARGET): $(OBJECTS)
|
||||
$(CXX) $(LDFLAGS) -o $(TARGET) $(OBJECTS)
|
||||
$(SOURCES): $(HEADERS)
|
||||
|
||||
clean:
|
||||
rm -rf $(TARGET) $(OBJECTS) *~
|
8
dependencies/build/getoptPlusPlus/README
vendored
8
dependencies/build/getoptPlusPlus/README
vendored
@ -1,8 +0,0 @@
|
||||
A very small class library that replaces getopt() and
|
||||
getopt_long()-functionality with a more C++-friendly approach.
|
||||
|
||||
Additionally, it does not rely on UNIX-specific code.
|
||||
|
||||
See test.cc for a sample application and COPYING for license information.
|
||||
|
||||
|
1630
dependencies/build/getoptPlusPlus/config.doxygen
vendored
1630
dependencies/build/getoptPlusPlus/config.doxygen
vendored
File diff suppressed because it is too large
Load Diff
357
dependencies/build/getoptPlusPlus/getoptpp.cc
vendored
357
dependencies/build/getoptPlusPlus/getoptpp.cc
vendored
@ -1,357 +0,0 @@
|
||||
/* (C) 2011 Viktor Lofgren
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "getoptpp.h"
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace vlofgren {
|
||||
|
||||
/*
|
||||
*
|
||||
* Class OptionsParser
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
OptionsParser::OptionsParser(const char* programDesc) : fprogramDesc(programDesc) {}
|
||||
OptionsParser::~OptionsParser() {}
|
||||
|
||||
ParameterSet& OptionsParser::getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
void OptionsParser::parse(int argc, const char* argv[]) throw(runtime_error)
|
||||
{
|
||||
argv0 = argv[0];
|
||||
|
||||
if(argc == 1) return;
|
||||
|
||||
vector<string> v(&argv[1], &argv[argc]);
|
||||
|
||||
ParserState state(/* *this,*/ v);
|
||||
|
||||
for(; !state.end(); state.advance()) {
|
||||
|
||||
std::list<Parameter*>::iterator i;
|
||||
|
||||
for(i = parameters.parameters.begin();
|
||||
i != parameters.parameters.end(); i++)
|
||||
{
|
||||
int n = 0;
|
||||
try
|
||||
{
|
||||
n = (*i)->receive(state);
|
||||
}
|
||||
catch(Parameter::ExpectedArgument &)
|
||||
{
|
||||
throw Parameter::ExpectedArgument(state.get() + ": expected an argument");
|
||||
}
|
||||
catch(Parameter::UnexpectedArgument &)
|
||||
{
|
||||
throw Parameter::UnexpectedArgument(state.get() + ": did not expect an argument");
|
||||
}
|
||||
catch(Switchable::SwitchingError &)
|
||||
{
|
||||
throw Parameter::ParameterRejected(state.get() + ": parameter already set");
|
||||
}
|
||||
catch(Parameter::ParameterRejected & pr) {
|
||||
std::string what = pr.what();
|
||||
if(what.length())
|
||||
{
|
||||
throw Parameter::ParameterRejected(state.get() + ": " + what);
|
||||
}
|
||||
throw Parameter::ParameterRejected(state.get() + " (unspecified error)");
|
||||
}
|
||||
|
||||
for (int j = 1; j < n; ++j)
|
||||
{
|
||||
state.advance();
|
||||
}
|
||||
|
||||
if(n != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(i == parameters.parameters.end()) {
|
||||
std::string file = state.get();
|
||||
if(file == "--") {
|
||||
state.advance();
|
||||
break;
|
||||
}
|
||||
else if(file.at(0) == '-')
|
||||
throw Parameter::ParameterRejected(string("Bad parameter: ") + file);
|
||||
else files.push_back(state.get());
|
||||
}
|
||||
}
|
||||
|
||||
if(!state.end()) for(; !state.end(); state.advance()) {
|
||||
files.push_back(state.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OptionsParser::usage() const {
|
||||
cerr << fprogramDesc << endl;
|
||||
cerr << "Build time: " << __DATE__ << " " << __TIME__ << endl << endl;
|
||||
cerr << "Usage: " << programName() << " [OPTIONS]" << endl << endl;
|
||||
|
||||
cerr << "Parameters: " << endl;
|
||||
|
||||
int totalWidth = 80;
|
||||
int usageWidth = 33;
|
||||
|
||||
// read total width from the terminal
|
||||
struct winsize w;
|
||||
if (ioctl(0, TIOCGWINSZ, &w) == 0)
|
||||
{
|
||||
if (w.ws_col > totalWidth)
|
||||
totalWidth = w.ws_col;
|
||||
}
|
||||
|
||||
std::list<Parameter*>::const_iterator i;
|
||||
for(i = parameters.parameters.begin();
|
||||
i != parameters.parameters.end(); i++)
|
||||
{
|
||||
cerr.width(usageWidth);
|
||||
cerr << std::left << " " + (*i)->usageLine();
|
||||
|
||||
std::string description = (*i)->description();
|
||||
while (int(description.length()) > (totalWidth - usageWidth))
|
||||
{
|
||||
size_t pos = description.find_last_of(' ', totalWidth - usageWidth);
|
||||
cerr << description.substr(0, pos) << std::endl << std::string(usageWidth - 1, ' ');
|
||||
description = description.substr(pos);
|
||||
}
|
||||
cerr << description << endl;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
const vector<string>& OptionsParser::getFiles() const {
|
||||
return files;
|
||||
}
|
||||
|
||||
const string& OptionsParser::programName() const {
|
||||
return argv0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parameter set
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
ParameterSet::ParameterSet(const ParameterSet& ps) {
|
||||
throw new runtime_error("ParameterSet not copyable");
|
||||
}
|
||||
|
||||
ParameterSet::~ParameterSet() {
|
||||
for(std::list<Parameter*>::iterator i = parameters.begin();
|
||||
i != parameters.end(); i++)
|
||||
{
|
||||
delete *i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* The typical use case for command line arguments makes linear searching completely
|
||||
* acceptable here.
|
||||
*/
|
||||
|
||||
Parameter& ParameterSet::operator[](char c) const {
|
||||
for(std::list<Parameter*>::const_iterator i = parameters.begin(); i!= parameters.end(); i++) {
|
||||
if((*i)->shortOption() == c) return *(*i);
|
||||
}
|
||||
throw out_of_range("ParameterSet["+string(&c)+string("]"));
|
||||
}
|
||||
|
||||
|
||||
Parameter& ParameterSet::operator[](const string& param) const {
|
||||
for(std::list<Parameter*>::const_iterator i = parameters.begin(); i!= parameters.end(); i++) {
|
||||
if((*i)->longOption() == param) return *(*i);
|
||||
}
|
||||
throw out_of_range("ParameterSet["+param+"]");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Class ParserState
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
ParserState::ParserState(/*OptionsParser &opts, */vector<string>& args) :
|
||||
/*opts(opts),*/ arguments(args), iterator(args.begin())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const string ParserState::peek() const {
|
||||
vector<string>::const_iterator next = iterator+1;
|
||||
if(next != arguments.end()) return *next;
|
||||
else return "";
|
||||
|
||||
}
|
||||
|
||||
const string ParserState::get() const {
|
||||
if(!end()) return *iterator;
|
||||
else return "";
|
||||
}
|
||||
|
||||
void ParserState::advance() {
|
||||
iterator++;
|
||||
}
|
||||
|
||||
bool ParserState::end() const {
|
||||
return iterator == arguments.end();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Class Parameter
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
Parameter::Parameter(char shortOption, const std::string & longOption, const std::string & description) :
|
||||
fshortOption(shortOption), flongOption(longOption), fdescription(description)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Parameter::~Parameter() {}
|
||||
|
||||
const string& Parameter::description() const { return fdescription; }
|
||||
const string& Parameter::longOption() const { return flongOption; }
|
||||
bool Parameter::hasShortOption() const { return fshortOption != 0x0; }
|
||||
char Parameter::shortOption() const { assert(hasShortOption()); return fshortOption; }
|
||||
|
||||
/*
|
||||
*
|
||||
* Class Switchable
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
bool Switchable::isSet() const { return fset; }
|
||||
Switchable::~Switchable() {};
|
||||
Switchable::Switchable() : fset(false) {}
|
||||
|
||||
void MultiSwitchable::set() throw (Switchable::SwitchingError) { fset = true; }
|
||||
MultiSwitchable::~MultiSwitchable() {}
|
||||
|
||||
|
||||
void UniquelySwitchable::set() throw (Switchable::SwitchingError) {
|
||||
if(UniquelySwitchable::isSet()) throw Switchable::SwitchingError();
|
||||
fset = true;
|
||||
}
|
||||
UniquelySwitchable::~UniquelySwitchable() {}
|
||||
|
||||
|
||||
PresettableUniquelySwitchable::~PresettableUniquelySwitchable() {}
|
||||
bool PresettableUniquelySwitchable::isSet() const {
|
||||
return UniquelySwitchable::isSet() || fpreset.isSet();
|
||||
}
|
||||
void PresettableUniquelySwitchable::set() throw (Switchable::SwitchingError)
|
||||
{
|
||||
UniquelySwitchable::set();
|
||||
}
|
||||
void PresettableUniquelySwitchable::preset() {
|
||||
fpreset.set();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* PODParameter specializations
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
template<>
|
||||
PODParameter<string>::PODParameter(char shortOption, const char *longOption,
|
||||
const char* description) : CommonParameter<PresettableUniquelySwitchable>(shortOption, longOption, description) {
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
int PODParameter<int>::validate(const string &s) throw(Parameter::ParameterRejected)
|
||||
{
|
||||
// This is sadly necessary for strto*-functions to operate on
|
||||
// const char*. The function doesn't write to the memory, though,
|
||||
// so it's quite safe.
|
||||
|
||||
char* cstr = const_cast<char*>(s.c_str());
|
||||
if(*cstr == '\0') throw ParameterRejected("No argument given");
|
||||
|
||||
long l = strtol(cstr, &cstr, 10);
|
||||
if(*cstr != '\0') throw ParameterRejected("Expected int");
|
||||
|
||||
if(l > INT_MAX || l < INT_MIN) {
|
||||
throw ParameterRejected("Expected int");
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
template<>
|
||||
long PODParameter<long>::validate(const string &s) throw(Parameter::ParameterRejected)
|
||||
{
|
||||
char* cstr = const_cast<char*>(s.c_str());
|
||||
if(*cstr == '\0') throw ParameterRejected("No argument given");
|
||||
|
||||
long l = strtol(cstr, &cstr, 10);
|
||||
if(*cstr != '\0') throw ParameterRejected("Expected long");
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
template<>
|
||||
double PODParameter<double>::validate(const string &s) throw(Parameter::ParameterRejected)
|
||||
{
|
||||
char* cstr = const_cast<char*>(s.c_str());
|
||||
if(*cstr == '\0') throw ParameterRejected("No argument given");
|
||||
|
||||
double d = strtod(cstr, &cstr);
|
||||
if(*cstr != '\0') throw ParameterRejected("Expected double");
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
template<>
|
||||
string PODParameter<string>::validate(const string &s) throw(Parameter::ParameterRejected)
|
||||
{
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
} //namespace
|
196
dependencies/build/getoptPlusPlus/test.cc
vendored
196
dependencies/build/getoptPlusPlus/test.cc
vendored
@ -1,196 +0,0 @@
|
||||
/* (C) 2011 Viktor Lofgren
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "getoptpp.h"
|
||||
#include <cstdlib>
|
||||
#include <cctype>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
using namespace vlofgren;
|
||||
|
||||
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
||||
|
||||
/*
|
||||
*
|
||||
* This is one way of adding new parameter types,
|
||||
* inheriting existing types and adding new validation.
|
||||
*
|
||||
* In this case, StringParameter (which is a typedef of PODParameter<string> gets
|
||||
* a new validator that only accepts strings with only letters.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class AlphabeticParameter : public StringParameter {
|
||||
public:
|
||||
AlphabeticParameter(char shortName, const char* longName, const char* description) :
|
||||
StringParameter(shortName, longName, description) {}
|
||||
virtual ~AlphabeticParameter() {}
|
||||
|
||||
void receiveSwitch() throw(Parameter::ParameterRejected) {
|
||||
throw Parameter::ParameterRejected();
|
||||
}
|
||||
|
||||
|
||||
/* isalpha may be a macro */
|
||||
static bool isNotAlpha(char c) { return !isalpha(c); }
|
||||
|
||||
virtual string validate(const string& arg) throw(Parameter::ParameterRejected) {
|
||||
int nonalpha = count_if(arg.begin(), arg.end(), isNotAlpha);
|
||||
|
||||
|
||||
if(nonalpha) throw Parameter::ParameterRejected("I only want numbers");
|
||||
else return arg;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
*
|
||||
* The other way is to specialize the PODParameter class
|
||||
*
|
||||
*/
|
||||
|
||||
enum RockPaperScissor { ROCK, PAPER, SCISSOR } ;
|
||||
|
||||
namespace vlofgren {
|
||||
// needs to live in the vlofgren namespace for whatever reason
|
||||
template<> enum RockPaperScissor
|
||||
PODParameter<enum RockPaperScissor>::validate(const string &s) throw(Parameter::ParameterRejected)
|
||||
{
|
||||
if(s == "rock")
|
||||
return ROCK;
|
||||
else if(s == "paper")
|
||||
return PAPER;
|
||||
else if(s == "scissor")
|
||||
return SCISSOR;
|
||||
else {
|
||||
throw ParameterRejected("Invalid argument");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
typedef PODParameter<enum RockPaperScissor> RockPaperScissorParameter;
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Dummy program
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
|
||||
// Create a parser
|
||||
|
||||
OptionsParser optp("An example program (that also runs some tests)");
|
||||
ParameterSet& ps = optp.getParameters();
|
||||
|
||||
/* An alternative option is to simply extend the options parser and set all this up
|
||||
* in the constructor.
|
||||
*/
|
||||
|
||||
ps.add<SwitchParameter>('f', "foo", "Enable the foo system (no argument)");
|
||||
ps.add<StringParameter>('b', "bar", "Enable the bar system (string argument)");
|
||||
ps.add<PODParameter<double> >('z', "baz", "Enable the baz system (floating point argument");
|
||||
|
||||
PODParameter<int>& i = ps.add<PODParameter<int> >('i', "foobar", "Enable the foobar system (integer argument");
|
||||
i.setDefault(15);
|
||||
|
||||
ps.add<AlphabeticParameter>('a', "alpha", "Custom parameter that requires a string of letters");
|
||||
ps.add<RockPaperScissorParameter>('r', "rps", "Takes the values rock, paper or scissor");
|
||||
ps.add<SwitchParameter>('h', "help", "Display help screen");
|
||||
|
||||
|
||||
// Register the parameters with the parser
|
||||
|
||||
try {
|
||||
// Parse argv
|
||||
optp.parse(argc, argv);
|
||||
|
||||
// Test for the help flag
|
||||
if(ps['h'].isSet()) {
|
||||
optp.usage();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
// Print out what values the parameters were given
|
||||
|
||||
cout << "The following parameters were set:" << endl;
|
||||
|
||||
cout << "foo: " << (ps['f'].isSet() ? "true" : "false") << endl;
|
||||
cout << "bar: \"" << ps['b'].get<string>() << "\""<< endl;
|
||||
cout << "baz: ";
|
||||
|
||||
if(ps['z'].isSet()) {
|
||||
cout << ps['z'].get<double>() << endl;
|
||||
} else {
|
||||
cout << "not set" << endl;
|
||||
}
|
||||
|
||||
/* You can also save the return value from ParserSet::add() if
|
||||
* you feel the operator[].get<T>() stuff is a bit much */
|
||||
cout << "foobar: ";
|
||||
if(i.isSet()) {
|
||||
cout << i.get<int>() << endl;
|
||||
} else {
|
||||
cout << "not set" << endl;
|
||||
}
|
||||
cout << "alpha: ";
|
||||
if(ps["alpha"].isSet()) {
|
||||
cout << ps["alpha"].get<string>() << endl;
|
||||
} else {
|
||||
cout << "not set" << endl;
|
||||
}
|
||||
|
||||
cout << "rps: ";
|
||||
if(ps["rps"].isSet()) {
|
||||
cout << ps["rps"].get<enum RockPaperScissor>() << endl;
|
||||
} else {
|
||||
cout << "not set" << endl;
|
||||
}
|
||||
|
||||
} catch(Parameter::ParameterRejected &p){
|
||||
// This will happen if the user has fed some malformed parameter to the program
|
||||
cerr << p.what() << endl;
|
||||
optp.usage();
|
||||
return EXIT_FAILURE;
|
||||
} catch(runtime_error &e) {
|
||||
// This will happen if you try to access a parameter that hasn't been set
|
||||
cerr << e.what() << endl;
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
// List what non-parameter options were given (typically files)
|
||||
cout << "The following file arguments were given:" << endl;
|
||||
|
||||
vector<string> files = optp.getFiles();
|
||||
for(vector<string>::iterator i = files.begin(); i != files.end(); i++) {
|
||||
cout << "\t" << *i << endl;
|
||||
}
|
||||
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#endif
|
BIN
dependencies/getoptPlusPlus-master-20130810.zip
vendored
BIN
dependencies/getoptPlusPlus-master-20130810.zip
vendored
Binary file not shown.
398
dependencies/include/getoptPlusPlus/getoptpp.h
vendored
398
dependencies/include/getoptPlusPlus/getoptpp.h
vendored
@ -1,398 +0,0 @@
|
||||
/* (C) 2011 Viktor Lofgren
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modifications:
|
||||
*
|
||||
* - Removed using namespace std from header
|
||||
* - Changed Parameter container type from std::set to std::list to presume order
|
||||
* - Changed arguments of Parameters to be a seperated arguments on the command line
|
||||
* - Make the choice of receiving arguments or not in subclasses of CommonParameter
|
||||
*/
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <climits>
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#ifndef GETOPTPP_H
|
||||
#define GETOPTPP_H
|
||||
|
||||
namespace vlofgren {
|
||||
|
||||
class Parameter;
|
||||
class ParserState;
|
||||
|
||||
class OptionsParser;
|
||||
|
||||
/** Container for a set of parameters */
|
||||
|
||||
class ParameterSet {
|
||||
public:
|
||||
|
||||
/** Find a parameter by short option form */
|
||||
Parameter& operator[](char c) const;
|
||||
|
||||
/** Find a parameter by long option form. */
|
||||
Parameter& operator[](const std::string &s) const;
|
||||
|
||||
/** Factory method that adds a new parameter of
|
||||
* type T to the set.
|
||||
*
|
||||
* This is just for convenience. It allows ParameterSet
|
||||
* to manage the pointers, as well as (usually) making the
|
||||
* code slightly easier to read.
|
||||
*
|
||||
* Do not try to add non-Parameter types lest you will invoke
|
||||
* the wrath of gcc's template error messages.
|
||||
*
|
||||
* @returns The created parameter. The reference is valid
|
||||
* as long as ParameterSet exists.
|
||||
*/
|
||||
template<typename T>
|
||||
T &add(char shortName, const char* longName, const char* description);
|
||||
|
||||
ParameterSet() {}
|
||||
~ParameterSet();
|
||||
protected:
|
||||
friend class OptionsParser;
|
||||
std::list<Parameter*> parameters;
|
||||
|
||||
private:
|
||||
ParameterSet(const ParameterSet& ps);
|
||||
};
|
||||
|
||||
/** getopt()-style parser for command line arguments
|
||||
*
|
||||
* Matches each element in argv against given
|
||||
* parameters, and collects non-parameter arguments
|
||||
* (typically files) in a vector.
|
||||
*
|
||||
*/
|
||||
|
||||
class OptionsParser {
|
||||
public:
|
||||
OptionsParser(const char *programDesc);
|
||||
virtual ~OptionsParser();
|
||||
|
||||
ParameterSet& getParameters();
|
||||
|
||||
/** Parse command line arguments */
|
||||
void parse(int argc, const char* argv[]) throw(std::runtime_error);
|
||||
|
||||
/** Generate a usage screen */
|
||||
void usage() const;
|
||||
|
||||
/** Return the name of the program, as
|
||||
* given by argv[0]
|
||||
*/
|
||||
const std::string& programName() const;
|
||||
|
||||
/** Return a vector of each non-parameter */
|
||||
const std::vector<std::string>& getFiles() const;
|
||||
protected:
|
||||
std::string argv0;
|
||||
std::string fprogramDesc;
|
||||
|
||||
ParameterSet parameters;
|
||||
std::vector<std::string> files;
|
||||
|
||||
friend class ParserState;
|
||||
};
|
||||
|
||||
/**
|
||||
* Corresponds to the state of the parsing, basically just a wrapper
|
||||
* for a const_iterator that handles nicer.
|
||||
*/
|
||||
|
||||
class ParserState {
|
||||
public:
|
||||
const std::string peek() const;
|
||||
const std::string get() const;
|
||||
void advance();
|
||||
bool end() const;
|
||||
protected:
|
||||
ParserState(/*OptionsParser &opts,*/ std::vector<std::string>& args);
|
||||
private:
|
||||
friend class OptionsParser;
|
||||
|
||||
// OptionsParser &opts;
|
||||
const std::vector<std::string> &arguments;
|
||||
std::vector<std::string>::const_iterator iterator;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Abstract base class of all parameters
|
||||
*
|
||||
*/
|
||||
|
||||
class Parameter {
|
||||
public:
|
||||
|
||||
/** Generic exception thrown when a parameter is malformed
|
||||
*/
|
||||
class ParameterRejected : public std::runtime_error {
|
||||
public:
|
||||
ParameterRejected(const std::string& s) : std::runtime_error(s) {}
|
||||
ParameterRejected() : runtime_error("") {}
|
||||
};
|
||||
|
||||
/** Exception thrown when a parameter did not expect an argument */
|
||||
class UnexpectedArgument : public ParameterRejected {
|
||||
public:
|
||||
UnexpectedArgument(const std::string &s) : ParameterRejected(s) {}
|
||||
UnexpectedArgument() {}
|
||||
};
|
||||
|
||||
/** Exception thrown when a parameter expected an argument */
|
||||
class ExpectedArgument : public ParameterRejected {
|
||||
public:
|
||||
ExpectedArgument(const std::string &s) : ParameterRejected(s) {}
|
||||
ExpectedArgument() {}
|
||||
};
|
||||
|
||||
Parameter(char shortOption, const std::string & longOption, const std::string & description);
|
||||
|
||||
virtual ~Parameter();
|
||||
|
||||
/** Test whether the parameter has been set */
|
||||
virtual bool isSet() const = 0;
|
||||
|
||||
/** This parameter's line in OptionsParser::usage() */
|
||||
virtual std::string usageLine() const = 0;
|
||||
|
||||
/** Description of the parameter (rightmost field in OptionsParser::usage()) */
|
||||
const std::string& description() const;
|
||||
|
||||
/** The long name of this parameter (e.g. "--option"), without the dash. */
|
||||
const std::string& longOption() const;
|
||||
|
||||
/** Check if this parameters has a short option */
|
||||
bool hasShortOption() const;
|
||||
|
||||
/** The short name of this parameter (e.g. "-o"), without the dash. */
|
||||
char shortOption() const;
|
||||
|
||||
protected:
|
||||
|
||||
/** Receive a potential parameter from the parser (and determien if it's ours)
|
||||
*
|
||||
* The parser will pass each potential parameter through it's registered parameters'
|
||||
* receive function.
|
||||
*
|
||||
* @throw ParameterRejected if the parameter belongs to us, but is malformed somehow.
|
||||
*
|
||||
* @param state Allows access to the current argument. This is a fairly powerful
|
||||
* iterator that technically allows for more complex grammar than what is
|
||||
* presently used.
|
||||
*/
|
||||
virtual int receive(ParserState& state) throw(ParameterRejected) = 0;
|
||||
|
||||
friend class OptionsParser;
|
||||
|
||||
char fshortOption;
|
||||
const std::string flongOption;
|
||||
const std::string fdescription;
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
*
|
||||
* Abstract base class of all parameters
|
||||
*
|
||||
*/
|
||||
|
||||
class Switchable;
|
||||
|
||||
/** Base class for most parameter implementations.
|
||||
*
|
||||
* It parses the argument in receive() and if it matches,
|
||||
* calls receiveSwitch() or receiveArgument() which are implemented
|
||||
* in child classes.
|
||||
*
|
||||
* The SwitchingBehavior mixin determines what happens if the argument
|
||||
* is set multiple times.
|
||||
*/
|
||||
|
||||
template<typename SwitchingBehavior=Switchable>
|
||||
class CommonParameter : public Parameter, protected SwitchingBehavior {
|
||||
public:
|
||||
|
||||
/** Test whether the parameter has been set */
|
||||
virtual bool isSet() const;
|
||||
|
||||
CommonParameter(char shortOption, const char *longOption,
|
||||
const char* description);
|
||||
virtual ~CommonParameter();
|
||||
|
||||
virtual std::string usageLine() const;
|
||||
|
||||
protected:
|
||||
/** Parse the argument given by state, and dispatch either
|
||||
* receiveSwitch() or receiveArgument() accordingly.
|
||||
*
|
||||
* @param state The current argument being parsed.
|
||||
* @return The number of parameters taken from the input
|
||||
*/
|
||||
virtual int receive(ParserState& state) throw(ParameterRejected) = 0;
|
||||
};
|
||||
|
||||
/** This class (used as a mixin) defines how a parameter
|
||||
* behaves when switched on, specifically when switched on multiple times.
|
||||
*
|
||||
*/
|
||||
class Switchable {
|
||||
public:
|
||||
class SwitchingError : public Parameter::ParameterRejected {};
|
||||
|
||||
/** Test whether the parameter has been set */
|
||||
virtual bool isSet() const;
|
||||
|
||||
/** Set the parameter
|
||||
*
|
||||
*/
|
||||
virtual void set() throw (SwitchingError) = 0;
|
||||
|
||||
virtual ~Switchable();
|
||||
Switchable();
|
||||
protected:
|
||||
bool fset;
|
||||
};
|
||||
|
||||
/** Switching behavior that does not complain when set multiple times. */
|
||||
class MultiSwitchable : public Switchable {
|
||||
public:
|
||||
virtual ~MultiSwitchable();
|
||||
virtual void set() throw(SwitchingError);
|
||||
|
||||
};
|
||||
|
||||
/** Switching behavior that allows switching only once.
|
||||
*
|
||||
* This is typically what you want if your parameter has an argument.
|
||||
*
|
||||
*/
|
||||
class UniquelySwitchable : public Switchable {
|
||||
public:
|
||||
|
||||
virtual ~UniquelySwitchable();
|
||||
|
||||
/** Set the parameter
|
||||
*
|
||||
* @throw SwitchingError Thrown if the parameter is already set.
|
||||
*/
|
||||
virtual void set() throw (SwitchingError);
|
||||
};
|
||||
|
||||
/** Switching behavior that makes possible allows presettable parameters,
|
||||
* that is, it can either be set by the program, or by a command line argument,
|
||||
* and the command-line part is UniquelySwitchable, but the program part
|
||||
* is MultiSwitchable (and is set by preset())
|
||||
*
|
||||
*
|
||||
*/
|
||||
class PresettableUniquelySwitchable : public UniquelySwitchable {
|
||||
public:
|
||||
|
||||
/** Test whether the parameter has been set OR preset */
|
||||
virtual bool isSet() const;
|
||||
|
||||
/** Call if the parameter has been set.
|
||||
*
|
||||
* @throw SwitchingError thrown if the parameter is already set
|
||||
* (doesn't care if it's been pre-set)
|
||||
*/
|
||||
virtual void set() throw (Switchable::SwitchingError);
|
||||
|
||||
/** Call if the parameter has been preset */
|
||||
virtual void preset();
|
||||
|
||||
virtual ~PresettableUniquelySwitchable();
|
||||
private:
|
||||
MultiSwitchable fpreset;
|
||||
};
|
||||
|
||||
/* Parameter that does not take an argument, and throws an exception
|
||||
* if an argument is given */
|
||||
|
||||
template<typename SwitchingBehavior=MultiSwitchable>
|
||||
class SwitchParameter : public CommonParameter<SwitchingBehavior> {
|
||||
public:
|
||||
SwitchParameter(char shortOption, const char *longOption,
|
||||
const char* description);
|
||||
virtual ~SwitchParameter();
|
||||
|
||||
protected:
|
||||
virtual int receive(ParserState& state) throw(Parameter::ParameterRejected);
|
||||
};
|
||||
|
||||
/** Plain-Old-Data parameter. Performs input validation.
|
||||
*
|
||||
* Currently only supports int, long and double, but extending
|
||||
* it to other types (even non-POD) is as easy as partial template specialization.
|
||||
*
|
||||
* Specifically, you need to specialize validate().
|
||||
*/
|
||||
|
||||
template<typename T, typename SwitchingBehavior=PresettableUniquelySwitchable>
|
||||
class PODParameter : public CommonParameter<SwitchingBehavior> {
|
||||
public:
|
||||
PODParameter(char shortOption, const char *longOption,
|
||||
const char* description);
|
||||
virtual ~PODParameter();
|
||||
|
||||
/* Retreive the value of the argument. Throws an exception if
|
||||
* the value hasn't been set (test with isSet())
|
||||
*/
|
||||
T getValue() const;
|
||||
|
||||
/** Type-casting operator, for convenience. */
|
||||
operator T() const;
|
||||
|
||||
/** Set a default value for this parameter */
|
||||
virtual void setDefault(T value);
|
||||
|
||||
std::string usageLine() const;
|
||||
protected:
|
||||
virtual int receive(ParserState& state) throw(Parameter::ParameterRejected);
|
||||
|
||||
/** Validation function for the data type.
|
||||
*
|
||||
* @throw ParameterRejected if the argument does not conform to this data type.
|
||||
* @return the value corresponding to the argument.
|
||||
*/
|
||||
virtual T validate(const std::string& s) throw (Parameter::ParameterRejected);
|
||||
|
||||
T value;
|
||||
};
|
||||
|
||||
|
||||
typedef PODParameter<int> IntParameter;
|
||||
typedef PODParameter<long> LongParameter;
|
||||
typedef PODParameter<double> DoubleParameter;
|
||||
typedef PODParameter<std::string> StringParameter;
|
||||
|
||||
#include "parameter.include.cc"
|
||||
|
||||
} //namespace
|
||||
|
||||
#endif
|
@ -1,177 +0,0 @@
|
||||
/* (C) 2011 Viktor Lofgren
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef GETOPTPP_H
|
||||
|
||||
|
||||
/* This file contains template voodoo, and due to the unique way GCC handles
|
||||
* templates, it needs to be included as a header (and it -is-). Do not attempt to
|
||||
* compile this file directly!
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
T &ParameterSet::add(char shortName, const char* longName, const char* description) {
|
||||
T* p = new T(shortName, longName, description);
|
||||
parameters.push_back(p);
|
||||
return *p;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Class CommonParameter implementation
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
template<typename SwitchingBehavior>
|
||||
CommonParameter<SwitchingBehavior>::~CommonParameter() {}
|
||||
|
||||
template<typename SwitchingBehavior>
|
||||
CommonParameter<SwitchingBehavior>::CommonParameter(char shortOption, const char *longOption,
|
||||
const char* description) : Parameter(shortOption, longOption, description) {}
|
||||
|
||||
template<typename SwitchingBehavior>
|
||||
bool CommonParameter<SwitchingBehavior>::isSet() const{
|
||||
return SwitchingBehavior::isSet();
|
||||
}
|
||||
|
||||
template<typename SwitchingBehavior>
|
||||
std::string CommonParameter<SwitchingBehavior>::usageLine() const {
|
||||
std::stringstream strstr;
|
||||
|
||||
if (hasShortOption())
|
||||
{
|
||||
strstr << "-" << shortOption() << ", ";
|
||||
}
|
||||
else
|
||||
{
|
||||
strstr << " ";
|
||||
}
|
||||
strstr.width(20);
|
||||
strstr << std::left << "--" + longOption();
|
||||
|
||||
return strstr.str();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Class SwitchParameter
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
template<typename SwitchingBehavior>
|
||||
SwitchParameter<SwitchingBehavior>::SwitchParameter(char shortOption, const char *longOption,
|
||||
const char* description) : CommonParameter<SwitchingBehavior>(shortOption, longOption, description) {}
|
||||
template<typename SwitchingBehavior>
|
||||
SwitchParameter<SwitchingBehavior>::~SwitchParameter() {}
|
||||
|
||||
template<typename SwitchingBehavior>
|
||||
int SwitchParameter<SwitchingBehavior>::receive(ParserState& state) throw(Parameter::ParameterRejected) {
|
||||
|
||||
const std::string arg = state.get();
|
||||
|
||||
if(arg.at(0) != '-') return false;
|
||||
|
||||
if ((arg.at(1) == '-' && arg.substr(2) == this->longOption()) ||
|
||||
(this->hasShortOption() && arg.at(1) == this->shortOption() && arg.length() == 2))
|
||||
{
|
||||
this->set();
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* PODParameter stuff
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
template<typename T, typename SwitchingBehavior>
|
||||
PODParameter<T, SwitchingBehavior>::PODParameter(char shortOption, const char *longOption,
|
||||
const char* description) : CommonParameter<PresettableUniquelySwitchable>(shortOption, longOption, description) {}
|
||||
|
||||
template<typename T, typename SwitchingBehavior>
|
||||
PODParameter<T, SwitchingBehavior>::~PODParameter() {}
|
||||
|
||||
template<typename T, typename SwitchingBehavior>
|
||||
PODParameter<T, SwitchingBehavior>::operator T() const { return getValue(); }
|
||||
|
||||
template<typename T, typename SwitchingBehavior>
|
||||
void PODParameter<T, SwitchingBehavior>::setDefault(T value) {
|
||||
PresettableUniquelySwitchable::preset();
|
||||
this->value = value;
|
||||
}
|
||||
|
||||
template<typename T, typename SwitchingBehavior>
|
||||
T PODParameter<T, SwitchingBehavior>::getValue() const {
|
||||
if(!this->isSet()) {
|
||||
throw std::runtime_error(
|
||||
std::string("Attempting to retreive the argument of parameter") + this->longOption() + " but it hasn't been set!");
|
||||
}
|
||||
return value;
|
||||
|
||||
}
|
||||
|
||||
template<typename T, typename SwitchingBehavior>
|
||||
std::string PODParameter<T, SwitchingBehavior>::usageLine() const {
|
||||
std::stringstream strstr;
|
||||
|
||||
if (this->hasShortOption())
|
||||
{
|
||||
strstr << "-" << this->shortOption() << ", ";
|
||||
}
|
||||
else
|
||||
{
|
||||
strstr << " ";
|
||||
}
|
||||
strstr.width(20);
|
||||
strstr << std::left << "--" + this->longOption() + " <arg>";
|
||||
|
||||
return strstr.str();
|
||||
}
|
||||
|
||||
template<typename T, typename SwitchingBehavior>
|
||||
int PODParameter<T, SwitchingBehavior>::receive(ParserState& state) throw(Parameter::ParameterRejected) {
|
||||
|
||||
const std::string arg = state.get();
|
||||
|
||||
if(arg.at(0) != '-') return false;
|
||||
|
||||
if((arg.at(1) == '-' && arg.substr(2) == this->longOption()) ||
|
||||
(this->hasShortOption() && arg.at(1) == this->shortOption() && arg.length() == 2))
|
||||
{
|
||||
// retrieve the argument
|
||||
std::string arg1 = state.peek();
|
||||
if (arg1.length() == 0)
|
||||
{
|
||||
throw Parameter::ExpectedArgument(arg + ": expected an argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
this->set();
|
||||
value = this->validate(arg1);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
BIN
dependencies/wjwwood-serial-master-20131105.zip
vendored
BIN
dependencies/wjwwood-serial-master-20131105.zip
vendored
Binary file not shown.
3
doc/.gitignore
vendored
Normal file
3
doc/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/hyperion-build-doc.sh
|
||||
/hyperion.doxygen
|
||||
/html/
|
35
include/commandline/BooleanOption.h
Normal file
35
include/commandline/BooleanOption.h
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef HYPERION_BOOLEANOPTION_H
|
||||
#define HYPERION_BOOLEANOPTION_H
|
||||
|
||||
|
||||
#include <QtCore>
|
||||
#include "Option.h"
|
||||
|
||||
namespace commandline
|
||||
{
|
||||
|
||||
class BooleanOption: public Option
|
||||
{
|
||||
public:
|
||||
BooleanOption(const QString &name,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString()
|
||||
)
|
||||
: Option(name, description, QString(), QString())
|
||||
{}
|
||||
BooleanOption(const QStringList &names,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString()
|
||||
)
|
||||
: Option(names, description, QString(), QString())
|
||||
{}
|
||||
BooleanOption(const QCommandLineOption &other)
|
||||
: Option(other)
|
||||
{}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //HYPERION_BOOLEANOPTION_H
|
41
include/commandline/ColorOption.h
Normal file
41
include/commandline/ColorOption.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef HYPERION_COLOROPTION_H
|
||||
#define HYPERION_COLOROPTION_H
|
||||
|
||||
#include "Option.h"
|
||||
#include <QColor>
|
||||
#include <QCommandLineParser>
|
||||
|
||||
namespace commandline
|
||||
{
|
||||
|
||||
class ColorOption: public Option
|
||||
{
|
||||
protected:
|
||||
QColor _color;
|
||||
public:
|
||||
ColorOption(const QString &name,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString()
|
||||
)
|
||||
: Option(name, description, valueName, defaultValue)
|
||||
{}
|
||||
ColorOption(const QStringList &names,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString()
|
||||
)
|
||||
: Option(names, description, valueName, defaultValue)
|
||||
{}
|
||||
ColorOption(const QCommandLineOption &other)
|
||||
: Option(other)
|
||||
{}
|
||||
|
||||
virtual bool validate(Parser & parser, QString & value) override;
|
||||
QColor getColor(Parser &parser)
|
||||
{ return _color; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //HYPERION_COLOROPTION_H
|
41
include/commandline/ColorsOption.h
Normal file
41
include/commandline/ColorsOption.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef HYPERION_COLORSOPTION_H
|
||||
#define HYPERION_COLORSOPTION_H
|
||||
|
||||
#include "Option.h"
|
||||
#include <QColor>
|
||||
#include <QCommandLineParser>
|
||||
|
||||
namespace commandline
|
||||
{
|
||||
|
||||
class ColorsOption: public Option
|
||||
{
|
||||
protected:
|
||||
QList<QColor> _colors;
|
||||
public:
|
||||
ColorsOption(const QString &name,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString()
|
||||
)
|
||||
: Option(name, description, valueName, defaultValue)
|
||||
{}
|
||||
ColorsOption(const QStringList &names,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString()
|
||||
)
|
||||
: Option(names, description, valueName, defaultValue)
|
||||
{}
|
||||
ColorsOption(const QCommandLineOption &other)
|
||||
: Option(other)
|
||||
{}
|
||||
|
||||
virtual bool validate(Parser & parser, QString & value) override;
|
||||
QList<QColor> &getColors(Parser &parser)
|
||||
{ return _colors; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //HYPERION_COLOROPTION_H
|
40
include/commandline/DoubleOption.h
Normal file
40
include/commandline/DoubleOption.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef HYPERION_DOUBLECOMMANDLINEOPTION_H
|
||||
#define HYPERION_DOUBLECOMMANDLINEOPTION_H
|
||||
|
||||
#include <QtCore>
|
||||
#include "ValidatorOption.h"
|
||||
|
||||
namespace commandline
|
||||
{
|
||||
|
||||
class DoubleOption: public ValidatorOption
|
||||
{
|
||||
protected:
|
||||
double _double;
|
||||
public:
|
||||
DoubleOption(const QString &name,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString(),
|
||||
double minimum = -INFINITY, double maximum = INFINITY, int decimals = 1000)
|
||||
: ValidatorOption(name, description, valueName, defaultValue)
|
||||
{ setValidator(new QDoubleValidator(minimum, maximum, decimals)); }
|
||||
DoubleOption(const QStringList &names,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString(),
|
||||
double minimum = -INFINITY, double maximum = INFINITY, int decimals = 1000)
|
||||
: ValidatorOption(names, description, valueName, defaultValue)
|
||||
{ setValidator(new QDoubleValidator(minimum, maximum, decimals)); }
|
||||
DoubleOption(const QCommandLineOption &other,
|
||||
double minimum = -INFINITY, double maximum = INFINITY, int decimals = 1000)
|
||||
: ValidatorOption(other)
|
||||
{ setValidator(new QDoubleValidator(minimum, maximum, decimals)); }
|
||||
|
||||
double getDouble(Parser &parser, bool *ok = 0);
|
||||
double *getDoublePtr(Parser &parser, bool *ok = 0);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //HYPERION_DOUBLECOMMANDLINEOPTION_H
|
41
include/commandline/ImageOption.h
Normal file
41
include/commandline/ImageOption.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef HYPERION_IMAGEOPTION_H
|
||||
#define HYPERION_IMAGEOPTION_H
|
||||
|
||||
#include "Option.h"
|
||||
#include <QImage>
|
||||
#include <QCommandLineParser>
|
||||
|
||||
namespace commandline
|
||||
{
|
||||
|
||||
class ImageOption: public Option
|
||||
{
|
||||
protected:
|
||||
QImage _image;
|
||||
public:
|
||||
ImageOption(const QString &name,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString()
|
||||
)
|
||||
: Option(name, description, valueName, defaultValue)
|
||||
{}
|
||||
ImageOption(const QStringList &names,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString()
|
||||
)
|
||||
: Option(names, description, valueName, defaultValue)
|
||||
{}
|
||||
ImageOption(const QCommandLineOption &other)
|
||||
: Option(other)
|
||||
{}
|
||||
|
||||
virtual bool validate(Parser & parser, QString & value) override;
|
||||
QImage &getImage(Parser &parser)
|
||||
{ return _image; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //HYPERION_IMAGEOPTION_H
|
41
include/commandline/IntOption.h
Normal file
41
include/commandline/IntOption.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef HYPERION_INTCOMMANDLINEOPTION_H
|
||||
#define HYPERION_INTCOMMANDLINEOPTION_H
|
||||
|
||||
#include <limits>
|
||||
#include <QtCore>
|
||||
#include "ValidatorOption.h"
|
||||
|
||||
namespace commandline
|
||||
{
|
||||
|
||||
class IntOption: public ValidatorOption
|
||||
{
|
||||
protected:
|
||||
int _int;
|
||||
public:
|
||||
IntOption(const QString &name,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString(),
|
||||
int minimum = std::numeric_limits<int>::min(), int maximum = std::numeric_limits<int>::max())
|
||||
: ValidatorOption(name, description, valueName, defaultValue)
|
||||
{ setValidator(new QIntValidator(minimum, maximum)); }
|
||||
IntOption(const QStringList &names,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString(),
|
||||
int minimum = std::numeric_limits<int>::min(), int maximum = std::numeric_limits<int>::max())
|
||||
: ValidatorOption(names, description, valueName, defaultValue)
|
||||
{ setValidator(new QIntValidator(minimum, maximum)); }
|
||||
IntOption(const QCommandLineOption &other,
|
||||
int minimum = std::numeric_limits<int>::min(), int maximum = std::numeric_limits<int>::max())
|
||||
: ValidatorOption(other)
|
||||
{ setValidator(new QIntValidator(minimum, maximum)); }
|
||||
|
||||
int getInt(Parser &parser, bool *ok = 0, int base = 10);
|
||||
int *getIntPtr(Parser &parser, bool *ok = 0, int base = 10);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //HYPERION_INTCOMMANDLINEOPTION_H
|
49
include/commandline/Option.h
Normal file
49
include/commandline/Option.h
Normal file
@ -0,0 +1,49 @@
|
||||
#ifndef HYPERION_OPTION_H
|
||||
#define HYPERION_OPTION_H
|
||||
|
||||
#include <QCommandLineOption>
|
||||
#include <QCommandLineParser>
|
||||
|
||||
namespace commandline
|
||||
{
|
||||
|
||||
class Parser;
|
||||
|
||||
/* Note, this class and all it's derivatives store the validated results for caching. This means that unlike the
|
||||
* regular QCommandLineOption it is _not_ idempotent! */
|
||||
class Option: public QCommandLineOption
|
||||
{
|
||||
protected:
|
||||
QString _error;
|
||||
public:
|
||||
Option(const QString &name,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString::null,
|
||||
const QString &defaultValue = QString()
|
||||
)
|
||||
: QCommandLineOption(name, description, valueName, defaultValue)
|
||||
{}
|
||||
Option(const QStringList &names,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString::null,
|
||||
const QString &defaultValue = QString()
|
||||
)
|
||||
: QCommandLineOption(names, description, valueName, defaultValue)
|
||||
{}
|
||||
Option(const QCommandLineOption &other)
|
||||
: QCommandLineOption(other)
|
||||
{}
|
||||
|
||||
virtual bool validate(Parser &parser, QString &value);
|
||||
QString name()
|
||||
{ return this->names().last();}
|
||||
QString getError()
|
||||
{ return this->_error; }
|
||||
QString value(Parser &parser);
|
||||
std::string getStdString(Parser &parser);
|
||||
std::wstring getStdWString(Parser &parser);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //HYPERION_OPTION_H
|
120
include/commandline/Parser.h
Normal file
120
include/commandline/Parser.h
Normal file
@ -0,0 +1,120 @@
|
||||
#ifndef HYPERION_COMMANDLINEPARSER_H
|
||||
#define HYPERION_COMMANDLINEPARSER_H
|
||||
|
||||
#include <QtCore>
|
||||
#include <QtGui>
|
||||
#include "ColorOption.h"
|
||||
#include "ColorsOption.h"
|
||||
#include "DoubleOption.h"
|
||||
#include "ImageOption.h"
|
||||
#include "IntOption.h"
|
||||
#include "Option.h"
|
||||
#include "RegularExpressionOption.h"
|
||||
#include "SwitchOption.h"
|
||||
#include "ValidatorOption.h"
|
||||
#include "BooleanOption.h"
|
||||
|
||||
namespace commandline
|
||||
{
|
||||
|
||||
class Parser : public QObject
|
||||
{
|
||||
protected:
|
||||
QHash<QString, Option *> _options;
|
||||
QString _errorText;
|
||||
/* No public inheritance because we need to modify a few methods */
|
||||
QCommandLineParser _parser;
|
||||
|
||||
QStringList _getNames(const char shortOption, const QString longOption);
|
||||
QString _getDescription(const QString description, const QString default_=QString());
|
||||
|
||||
public:
|
||||
bool parse(const QStringList &arguments);
|
||||
void process(const QStringList &arguments);
|
||||
void process(const QCoreApplication &app);
|
||||
QString errorText() const;
|
||||
|
||||
template<class OptionT, class ... Args>
|
||||
OptionT &add(
|
||||
const char shortOption,
|
||||
const QString longOption,
|
||||
const QString description,
|
||||
const QString default_,
|
||||
Args ... args)
|
||||
{
|
||||
OptionT * option = new OptionT(
|
||||
_getNames(shortOption, longOption),
|
||||
_getDescription(description, default_),
|
||||
longOption,
|
||||
default_,
|
||||
args...);
|
||||
addOption(option);
|
||||
return *option;
|
||||
}
|
||||
|
||||
/* gcc does not support default arguments for variadic templates which
|
||||
* makes this method necessary */
|
||||
template<class OptionT>
|
||||
OptionT &add(
|
||||
const char shortOption,
|
||||
const QString longOption,
|
||||
const QString description,
|
||||
const QString default_ = QString())
|
||||
{
|
||||
OptionT * option = new OptionT(
|
||||
_getNames(shortOption, longOption),
|
||||
_getDescription(description, default_),
|
||||
longOption,
|
||||
default_);
|
||||
addOption(option);
|
||||
return *option;
|
||||
}
|
||||
|
||||
Parser(QString description=QString())
|
||||
{if(description.size())setApplicationDescription(description);};
|
||||
QCommandLineOption addHelpOption()
|
||||
{ return _parser.addHelpOption(); }
|
||||
bool addOption(Option &option);
|
||||
bool addOption(Option *option);
|
||||
void addPositionalArgument(const QString &name, const QString &description, const QString &syntax = QString())
|
||||
{ _parser.addPositionalArgument(name, description, syntax); }
|
||||
QCommandLineOption addVersionOption()
|
||||
{ return _parser.addVersionOption(); }
|
||||
QString applicationDescription() const
|
||||
{ return _parser.applicationDescription(); }
|
||||
void clearPositionalArguments()
|
||||
{ _parser.clearPositionalArguments(); }
|
||||
QString helpText() const
|
||||
{ return _parser.helpText(); }
|
||||
bool isSet(const QString &name) const
|
||||
{ return _parser.isSet(name); }
|
||||
bool isSet(const Option &option) const
|
||||
{ return _parser.isSet(option); }
|
||||
bool isSet(const Option *option) const
|
||||
{ return _parser.isSet(*option); }
|
||||
QStringList optionNames() const
|
||||
{ return _parser.optionNames(); }
|
||||
QStringList positionalArguments() const
|
||||
{ return _parser.positionalArguments(); }
|
||||
void setApplicationDescription(const QString &description)
|
||||
{ _parser.setApplicationDescription(description); }
|
||||
void setSingleDashWordOptionMode(QCommandLineParser::SingleDashWordOptionMode singleDashWordOptionMode)
|
||||
{ _parser.setSingleDashWordOptionMode(singleDashWordOptionMode); }
|
||||
void showHelp(int exitCode = 0)
|
||||
{ _parser.showHelp(exitCode); }
|
||||
QStringList unknownOptionNames() const
|
||||
{ return _parser.unknownOptionNames(); }
|
||||
QString value(const QString &optionName) const
|
||||
{ return _parser.value(optionName); }
|
||||
QString value(const Option &option) const
|
||||
{ return _parser.value(option); }
|
||||
QStringList values(const QString &optionName) const
|
||||
{ return _parser.values(optionName); }
|
||||
QStringList values(const Option &option) const
|
||||
{ return _parser.values(option); }
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //HYPERION_COMMANDLINEPARSER_H
|
71
include/commandline/RegularExpressionOption.h
Normal file
71
include/commandline/RegularExpressionOption.h
Normal file
@ -0,0 +1,71 @@
|
||||
#ifndef HYPERION_REGULAREXPRESSIONCOMMANDLINEOPTION_H
|
||||
#define HYPERION_REGULAREXPRESSIONCOMMANDLINEOPTION_H
|
||||
|
||||
#include <QtCore>
|
||||
#include <QRegularExpression>
|
||||
#include "ValidatorOption.h"
|
||||
|
||||
namespace commandline
|
||||
{
|
||||
|
||||
class RegularExpressionOption: public ValidatorOption
|
||||
{
|
||||
public:
|
||||
RegularExpressionOption(const QString &name,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString())
|
||||
: ValidatorOption(name, description, valueName, defaultValue)
|
||||
{}
|
||||
RegularExpressionOption(const QStringList &names,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString())
|
||||
: ValidatorOption(names, description, valueName, defaultValue)
|
||||
{}
|
||||
RegularExpressionOption(const QCommandLineOption &other)
|
||||
: ValidatorOption(other)
|
||||
{}
|
||||
|
||||
RegularExpressionOption(const QString &name,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString(),
|
||||
const QRegularExpression &expression = QRegularExpression())
|
||||
: ValidatorOption(name, description, valueName, defaultValue)
|
||||
{ setValidator(new QRegularExpressionValidator(expression)); }
|
||||
RegularExpressionOption(const QStringList &names,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString(),
|
||||
const QRegularExpression &expression = QRegularExpression())
|
||||
: ValidatorOption(names, description, valueName, defaultValue)
|
||||
{ setValidator(new QRegularExpressionValidator(expression)); }
|
||||
RegularExpressionOption(const QCommandLineOption &other,
|
||||
const QRegularExpression &expression = QRegularExpression())
|
||||
: ValidatorOption(other)
|
||||
{ setValidator(new QRegularExpressionValidator(expression)); }
|
||||
|
||||
RegularExpressionOption(const QString &name,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString(),
|
||||
const QString &expression = QString())
|
||||
: ValidatorOption(name, description, valueName, defaultValue)
|
||||
{ setValidator(new QRegularExpressionValidator(QRegularExpression(expression))); }
|
||||
RegularExpressionOption(const QStringList &names,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString(),
|
||||
const QString &expression = QString())
|
||||
: ValidatorOption(names, description, valueName, defaultValue)
|
||||
{ setValidator(new QRegularExpressionValidator(QRegularExpression(expression))); }
|
||||
RegularExpressionOption(const QCommandLineOption &other,
|
||||
const QString &expression = QString())
|
||||
: ValidatorOption(other)
|
||||
{ setValidator(new QRegularExpressionValidator(QRegularExpression(expression))); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //HYPERION_REGULAREXPRESSIONCOMMANDLINEOPTION_H
|
45
include/commandline/SwitchOption.h
Normal file
45
include/commandline/SwitchOption.h
Normal file
@ -0,0 +1,45 @@
|
||||
#ifndef HYPERION_SWITCHCOMMANDLINEOPTION_H
|
||||
#define HYPERION_SWITCHCOMMANDLINEOPTION_H
|
||||
|
||||
#include <QtCore>
|
||||
#include "Option.h"
|
||||
|
||||
namespace commandline
|
||||
{
|
||||
|
||||
template <class T>
|
||||
class SwitchOption: public Option
|
||||
{
|
||||
protected:
|
||||
QMap<QString, T> _switches;
|
||||
public:
|
||||
SwitchOption(const QString &name,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString(),
|
||||
const QMap<QString, T> &switches=QMap<QString, T>())
|
||||
: Option(name, description, valueName, defaultValue), _switches(switches)
|
||||
{}
|
||||
SwitchOption(const QStringList &names,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString(),
|
||||
const QMap<QString, T> &switches=QMap<QString, T>())
|
||||
: Option(names, description, valueName, defaultValue), _switches(switches)
|
||||
{}
|
||||
SwitchOption(const QCommandLineOption &other, const QMap<QString, T> &switches)
|
||||
: Option(other), _switches(switches)
|
||||
{}
|
||||
|
||||
const QMap<QString, T> &getSwitches() const{return _switches;};
|
||||
virtual bool validate(Parser &parser, QString &switch_) override{return hasSwitch(switch_);}
|
||||
bool hasSwitch(const QString &switch_){return _switches.contains(switch_.toLower());}
|
||||
void setSwitches(const QMap<QString, T> &_switches){this->_switches = _switches;}
|
||||
void addSwitch(const QString &switch_, T value=T()){_switches[switch_.toLower()] = value;}
|
||||
void removeSwitch(const QString &switch_){_switches.remove(switch_.toLower());}
|
||||
T & switchValue(Parser & parser){return _switches[value(parser).toLower()];}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //HYPERION_SWITCHCOMMANDLINEOPTION_H
|
42
include/commandline/ValidatorOption.h
Normal file
42
include/commandline/ValidatorOption.h
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef HYPERION_COMMANDLINEOPTION_H
|
||||
#define HYPERION_COMMANDLINEOPTION_H
|
||||
|
||||
#include <QtCore>
|
||||
#include <QtGui>
|
||||
#include <commandline/Option.h>
|
||||
|
||||
namespace commandline
|
||||
{
|
||||
|
||||
class ValidatorOption: public Option
|
||||
{
|
||||
protected:
|
||||
const QValidator *validator;
|
||||
virtual void setValidator(const QValidator *validator);
|
||||
public:
|
||||
ValidatorOption(const QString &name,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString(),
|
||||
const QValidator *validator = nullptr)
|
||||
: Option(name, description, valueName, defaultValue), validator(validator)
|
||||
{}
|
||||
ValidatorOption(const QStringList &names,
|
||||
const QString &description = QString(),
|
||||
const QString &valueName = QString(),
|
||||
const QString &defaultValue = QString(),
|
||||
const QValidator *validator = nullptr)
|
||||
: Option(names, description, valueName, defaultValue), validator(validator)
|
||||
{}
|
||||
ValidatorOption(const QCommandLineOption &other,
|
||||
const QValidator *validator = nullptr)
|
||||
: Option(other), validator(validator)
|
||||
{}
|
||||
|
||||
virtual const QValidator *getValidator() const;
|
||||
virtual bool validate(Parser & parser, QString &value) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //HYPERION_COMMANDLINEOPTION_H
|
@ -16,7 +16,7 @@ class ProtoConnectionWrapper : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ProtoConnectionWrapper(const std::string & address, int priority, int duration_ms, bool skipProtoReply);
|
||||
ProtoConnectionWrapper(const QString &address, int priority, int duration_ms, bool skipProtoReply);
|
||||
virtual ~ProtoConnectionWrapper();
|
||||
|
||||
signals:
|
||||
|
@ -4,6 +4,7 @@ SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include)
|
||||
SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc)
|
||||
|
||||
add_subdirectory(hyperion)
|
||||
add_subdirectory(commandline)
|
||||
add_subdirectory(blackborder)
|
||||
add_subdirectory(jsonserver)
|
||||
add_subdirectory(protoserver)
|
||||
|
3
libsrc/commandline/BooleanOption.cpp
Normal file
3
libsrc/commandline/BooleanOption.cpp
Normal file
@ -0,0 +1,3 @@
|
||||
#include "commandline/BooleanOption.h"
|
||||
|
||||
using namespace commandline;
|
42
libsrc/commandline/CMakeLists.txt
Normal file
42
libsrc/commandline/CMakeLists.txt
Normal file
@ -0,0 +1,42 @@
|
||||
# Define the current source locations
|
||||
set(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/commandline)
|
||||
set(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/commandline)
|
||||
|
||||
set(Parser_HEADERS
|
||||
${CURRENT_HEADER_DIR}/ColorOption.h
|
||||
${CURRENT_HEADER_DIR}/ColorsOption.h
|
||||
${CURRENT_HEADER_DIR}/DoubleOption.h
|
||||
${CURRENT_HEADER_DIR}/ImageOption.h
|
||||
${CURRENT_HEADER_DIR}/IntOption.h
|
||||
${CURRENT_HEADER_DIR}/Option.h
|
||||
${CURRENT_HEADER_DIR}/Parser.h
|
||||
${CURRENT_HEADER_DIR}/RegularExpressionOption.h
|
||||
${CURRENT_HEADER_DIR}/SwitchOption.h
|
||||
${CURRENT_HEADER_DIR}/ValidatorOption.h
|
||||
${CURRENT_HEADER_DIR}/BooleanOption.h
|
||||
)
|
||||
|
||||
set(Parser_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/ColorOption.cpp
|
||||
${CURRENT_SOURCE_DIR}/ColorsOption.cpp
|
||||
${CURRENT_SOURCE_DIR}/DoubleOption.cpp
|
||||
${CURRENT_SOURCE_DIR}/ImageOption.cpp
|
||||
${CURRENT_SOURCE_DIR}/IntOption.cpp
|
||||
${CURRENT_SOURCE_DIR}/Option.cpp
|
||||
${CURRENT_SOURCE_DIR}/Parser.cpp
|
||||
${CURRENT_SOURCE_DIR}/RegularExpressionOption.cpp
|
||||
${CURRENT_SOURCE_DIR}/SwitchOption.cpp
|
||||
${CURRENT_SOURCE_DIR}/ValidatorOption.cpp
|
||||
${CURRENT_SOURCE_DIR}/BooleanOption.cpp
|
||||
)
|
||||
|
||||
add_library(commandline
|
||||
${Parser_HEADERS}
|
||||
${Parser_SOURCES}
|
||||
)
|
||||
|
||||
qt5_use_modules(commandline Gui)
|
||||
|
||||
target_link_libraries(commandline
|
||||
hyperion
|
||||
)
|
30
libsrc/commandline/ColorOption.cpp
Normal file
30
libsrc/commandline/ColorOption.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include <QRegularExpression>
|
||||
#include "commandline/ColorOption.h"
|
||||
#include "commandline/Parser.h"
|
||||
|
||||
using namespace commandline;
|
||||
|
||||
bool ColorOption::validate(Parser & parser, QString & value)
|
||||
{
|
||||
// Check if we can create the color by name
|
||||
_color = QColor(value);
|
||||
if (_color.isValid()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// check if we can create the color by hex RRGGBB getColors
|
||||
_color = QColor(QString("#%1").arg(value));
|
||||
if (_color.isValid()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!parser.isSet(*this)){
|
||||
// Return true if no value is available
|
||||
return true;
|
||||
}
|
||||
|
||||
QStringList error;
|
||||
_error = QString("Invalid color. A color is specified by a six lettered RRGGBB hex getColors or one of the following names:\n\t- %1").arg(QColor::colorNames().join("\n\t- "));
|
||||
|
||||
return false;
|
||||
}
|
37
libsrc/commandline/ColorsOption.cpp
Normal file
37
libsrc/commandline/ColorsOption.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include <QRegularExpression>
|
||||
#include "commandline/ColorsOption.h"
|
||||
#include "commandline/Parser.h"
|
||||
|
||||
using namespace commandline;
|
||||
|
||||
bool ColorsOption::validate(Parser & parser, QString & value)
|
||||
{
|
||||
// Clear any old results
|
||||
_colors.clear();
|
||||
|
||||
// Check if we can create the color by name
|
||||
QColor color(value);
|
||||
if (color.isValid()) {
|
||||
_colors.push_back(color);
|
||||
return true;
|
||||
}
|
||||
|
||||
// check if we can create the color by hex RRGGBB getColors
|
||||
QRegularExpression hexRe("^([0-9A-F]{6})+$", QRegularExpression::CaseInsensitiveOption);
|
||||
QRegularExpressionMatch match = hexRe.match(value);
|
||||
if(match.hasMatch()) {
|
||||
Q_FOREACH(const QString m, match.capturedTexts()){
|
||||
_colors.push_back(QColor(QString("#%1").arg(m)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!parser.isSet(*this)){
|
||||
// Return true if no value is available
|
||||
return true;
|
||||
}
|
||||
|
||||
_error = QString("Invalid color. A color is specified by a six lettered RRGGBB hex getColors or one of the following names:\n\t- %1").arg(QColor::colorNames().join("\n\t- "));
|
||||
|
||||
return false;
|
||||
}
|
20
libsrc/commandline/DoubleOption.cpp
Normal file
20
libsrc/commandline/DoubleOption.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include "commandline/DoubleOption.h"
|
||||
#include "commandline/Parser.h"
|
||||
|
||||
using namespace commandline;
|
||||
|
||||
double DoubleOption::getDouble(Parser &parser, bool *ok)
|
||||
{
|
||||
_double = value(parser).toDouble(ok);
|
||||
return _double;
|
||||
}
|
||||
|
||||
double *DoubleOption::getDoublePtr(Parser &parser, bool *ok)
|
||||
{
|
||||
if (parser.isSet(this)) {
|
||||
getDouble(parser, ok);
|
||||
return &_double;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
18
libsrc/commandline/ImageOption.cpp
Normal file
18
libsrc/commandline/ImageOption.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include "commandline/ImageOption.h"
|
||||
|
||||
using namespace commandline;
|
||||
|
||||
bool ImageOption::validate(Parser & parser, QString & value)
|
||||
{
|
||||
if(value.size()){
|
||||
_image = QImage(value);
|
||||
|
||||
if (_image.isNull())
|
||||
{
|
||||
_error = QString("File %1 could not be opened as image").arg(value);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
20
libsrc/commandline/IntOption.cpp
Normal file
20
libsrc/commandline/IntOption.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include "commandline/IntOption.h"
|
||||
#include "commandline/Parser.h"
|
||||
|
||||
using namespace commandline;
|
||||
|
||||
int IntOption::getInt(Parser &parser, bool *ok, int base)
|
||||
{
|
||||
_int = value(parser).toInt(ok, base);
|
||||
return _int;
|
||||
}
|
||||
|
||||
int *IntOption::getIntPtr(Parser &parser, bool *ok, int base)
|
||||
{
|
||||
if (parser.isSet(this)) {
|
||||
getInt(parser, ok, base);
|
||||
return &_int;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
26
libsrc/commandline/Option.cpp
Normal file
26
libsrc/commandline/Option.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "commandline/Option.h"
|
||||
#include "commandline/Parser.h"
|
||||
|
||||
using namespace commandline;
|
||||
|
||||
bool Option::validate(Parser & parser, QString &value)
|
||||
{
|
||||
/* By default everything is accepted */
|
||||
return true;
|
||||
}
|
||||
|
||||
QString Option::value(Parser &parser)
|
||||
{
|
||||
return parser.value(*this);
|
||||
}
|
||||
|
||||
std::string Option::getStdString(Parser &parser)
|
||||
{
|
||||
return value(parser).toStdString();
|
||||
}
|
||||
|
||||
std::wstring Option::getStdWString(Parser &parser)
|
||||
{
|
||||
return value(parser).toStdWString();
|
||||
}
|
||||
|
90
libsrc/commandline/Parser.cpp
Normal file
90
libsrc/commandline/Parser.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
#include <QtDebug>
|
||||
#include <QtGui>
|
||||
#include "commandline/Parser.h"
|
||||
|
||||
using namespace commandline;
|
||||
|
||||
bool Parser::parse(const QStringList &arguments)
|
||||
{
|
||||
if (!_parser.parse(arguments)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Q_FOREACH(Option * option, _options) {
|
||||
QString value = this->value(*option);
|
||||
if (!option->validate(*this, value)) {
|
||||
const QString error = option->getError();
|
||||
if (error.size()) {
|
||||
_errorText = tr("%1 is not a valid option for %2\n%3").arg(value, option->name(), error);
|
||||
}
|
||||
else {
|
||||
_errorText = tr("%1 is not a valid option for %2").arg(value, option->name());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Parser::process(const QStringList &arguments)
|
||||
{
|
||||
_parser.process(arguments);
|
||||
if (!parse(arguments)) {
|
||||
|
||||
fprintf(stdout, "%s", qPrintable(tr("Error: %1").arg(_errorText)));
|
||||
showHelp(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::process(const QCoreApplication &app)
|
||||
{
|
||||
Q_UNUSED(app);
|
||||
process(QCoreApplication::arguments());
|
||||
}
|
||||
|
||||
QString Parser::errorText() const
|
||||
{
|
||||
if (_errorText.size()) {
|
||||
return _errorText;
|
||||
}
|
||||
else {
|
||||
return _parser.errorText();
|
||||
}
|
||||
}
|
||||
|
||||
bool Parser::addOption(Option &option)
|
||||
{
|
||||
return addOption(&option);
|
||||
}
|
||||
|
||||
bool Parser::addOption(Option * const option)
|
||||
{
|
||||
_options[option->name()] = option;
|
||||
return _parser.addOption(*option);
|
||||
}
|
||||
QStringList Parser::_getNames(const char shortOption, const QString longOption)
|
||||
{
|
||||
QStringList names;
|
||||
if (shortOption != 0x0) {
|
||||
names << QString(shortOption);
|
||||
}
|
||||
if (longOption.size()) {
|
||||
names << longOption;
|
||||
}
|
||||
return names;
|
||||
}
|
||||
QString Parser::_getDescription(const QString description, const QString default_)
|
||||
{
|
||||
/* Add the translations if available */
|
||||
QString formattedDescription(tr(qPrintable(description)));
|
||||
|
||||
/* Fill in the default if needed */
|
||||
if (default_.size()) {
|
||||
if(!formattedDescription.contains("%1")){
|
||||
formattedDescription += " [default: %1]";
|
||||
}
|
||||
formattedDescription = formattedDescription.arg(default_);
|
||||
}
|
||||
return formattedDescription;
|
||||
}
|
||||
|
4
libsrc/commandline/RegularExpressionOption.cpp
Normal file
4
libsrc/commandline/RegularExpressionOption.cpp
Normal file
@ -0,0 +1,4 @@
|
||||
#include "commandline/RegularExpressionOption.h"
|
||||
|
||||
using namespace commandline;
|
||||
|
5
libsrc/commandline/SwitchOption.cpp
Normal file
5
libsrc/commandline/SwitchOption.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "commandline/SwitchOption.h"
|
||||
|
||||
using namespace commandline;
|
||||
|
||||
|
25
libsrc/commandline/ValidatorOption.cpp
Normal file
25
libsrc/commandline/ValidatorOption.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include "commandline/ValidatorOption.h"
|
||||
#include "commandline/Parser.h"
|
||||
|
||||
using namespace commandline;
|
||||
|
||||
bool ValidatorOption::validate(Parser & parser, QString & value)
|
||||
{
|
||||
if (parser.isSet(*this) || !defaultValues().empty()) {
|
||||
int pos = 0;
|
||||
validator->fixup(value);
|
||||
return validator->validate(value, pos) == QValidator::Acceptable;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const QValidator *ValidatorOption::getValidator() const
|
||||
{
|
||||
return validator;
|
||||
}
|
||||
void ValidatorOption::setValidator(const QValidator *validator)
|
||||
{
|
||||
ValidatorOption::validator = validator;
|
||||
}
|
||||
|
@ -562,13 +562,16 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &, const st
|
||||
const std::list<ActiveEffectDefinition> & activeEffectsDefinitions = _hyperion->getActiveEffects();
|
||||
for (const ActiveEffectDefinition & activeEffectDefinition : activeEffectsDefinitions)
|
||||
{
|
||||
Json::Value activeEffect;
|
||||
activeEffect["script"] = activeEffectDefinition.script;
|
||||
activeEffect["priority"] = activeEffectDefinition.priority;
|
||||
activeEffect["timeout"] = activeEffectDefinition.timeout;
|
||||
activeEffect["args"] = activeEffectDefinition.args;
|
||||
|
||||
activeEffects.append(activeEffect);
|
||||
if (activeEffectDefinition.priority != PriorityMuxer::LOWEST_PRIORITY -1)
|
||||
{
|
||||
Json::Value activeEffect;
|
||||
activeEffect["script"] = activeEffectDefinition.script;
|
||||
activeEffect["priority"] = activeEffectDefinition.priority;
|
||||
activeEffect["timeout"] = activeEffectDefinition.timeout;
|
||||
activeEffect["args"] = activeEffectDefinition.args;
|
||||
|
||||
activeEffects.append(activeEffect);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////
|
||||
|
@ -15,12 +15,12 @@ include_directories(
|
||||
# Group the headers that go through the MOC compiler
|
||||
SET(Leddevice_QT_HEADERS
|
||||
${CURRENT_HEADER_DIR}/LedDevice.h
|
||||
${CURRENT_SOURCE_DIR}/LedRs232Device.h
|
||||
${CURRENT_SOURCE_DIR}/ProviderRs232.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceAdalight.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceAdalightApa102.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceAtmoOrb.h
|
||||
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.h
|
||||
${CURRENT_SOURCE_DIR}/LedHIDDevice.h
|
||||
${CURRENT_SOURCE_DIR}/ProviderHID.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceRawHID.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.h
|
||||
)
|
||||
@ -36,7 +36,7 @@ SET(Leddevice_HEADERS
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceFile.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceUdpRaw.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceUdpE131.h
|
||||
${CURRENT_SOURCE_DIR}/LedUdpDevice.h
|
||||
${CURRENT_SOURCE_DIR}/ProviderUdp.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTpm2net.h
|
||||
@ -47,8 +47,8 @@ SET(Leddevice_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/LedDevice.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceFactory.cpp
|
||||
|
||||
${CURRENT_SOURCE_DIR}/LedRs232Device.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedHIDDevice.cpp
|
||||
${CURRENT_SOURCE_DIR}/ProviderRs232.cpp
|
||||
${CURRENT_SOURCE_DIR}/ProviderHID.cpp
|
||||
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceAdalight.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceAdalightApa102.cpp
|
||||
@ -63,7 +63,7 @@ SET(Leddevice_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceUdpRaw.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceUdpE131.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedUdpDevice.cpp
|
||||
${CURRENT_SOURCE_DIR}/ProviderUdp.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.cpp
|
||||
@ -74,7 +74,7 @@ SET(Leddevice_SOURCES
|
||||
if(ENABLE_SPIDEV)
|
||||
SET(Leddevice_HEADERS
|
||||
${Leddevice_HEADERS}
|
||||
${CURRENT_SOURCE_DIR}/LedSpiDevice.h
|
||||
${CURRENT_SOURCE_DIR}/ProviderSpi.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceLpd6803.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceLpd8806.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceP9813.h
|
||||
@ -85,7 +85,7 @@ if(ENABLE_SPIDEV)
|
||||
)
|
||||
SET(Leddevice_SOURCES
|
||||
${Leddevice_SOURCES}
|
||||
${CURRENT_SOURCE_DIR}/LedSpiDevice.cpp
|
||||
${CURRENT_SOURCE_DIR}/ProviderSpi.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceLpd6803.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceLpd8806.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceP9813.cpp
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "LedDeviceAPA102.h"
|
||||
|
||||
LedDeviceAPA102::LedDeviceAPA102(const Json::Value &deviceConfig)
|
||||
: LedSpiDevice(deviceConfig)
|
||||
: ProviderSpi(deviceConfig)
|
||||
{
|
||||
_latchTime_ns = 500000;
|
||||
}
|
||||
|
@ -4,13 +4,13 @@
|
||||
#include <string>
|
||||
|
||||
// hyperion incluse
|
||||
#include "LedSpiDevice.h"
|
||||
#include "ProviderSpi.h"
|
||||
#include <json/json.h>
|
||||
|
||||
///
|
||||
/// Implementation of the LedDevice interface for writing to APA102 led device.
|
||||
///
|
||||
class LedDeviceAPA102 : public LedSpiDevice
|
||||
class LedDeviceAPA102 : public ProviderSpi
|
||||
{
|
||||
public:
|
||||
///
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <leddevice/LedDevice.h>
|
||||
|
||||
LedDeviceAdalight::LedDeviceAdalight(const Json::Value &deviceConfig)
|
||||
: LedRs232Device(deviceConfig)
|
||||
: ProviderRs232(deviceConfig)
|
||||
, _timer()
|
||||
{
|
||||
// setup the timer
|
||||
|
@ -7,12 +7,12 @@
|
||||
#include <QTimer>
|
||||
|
||||
// hyperion include
|
||||
#include "LedRs232Device.h"
|
||||
#include "ProviderRs232.h"
|
||||
|
||||
///
|
||||
/// Implementation of the LedDevice interface for writing to an Adalight led device.
|
||||
///
|
||||
class LedDeviceAdalight : public LedRs232Device
|
||||
class LedDeviceAdalight : public ProviderRs232
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "LedDeviceAtmo.h"
|
||||
|
||||
LedDeviceAtmo::LedDeviceAtmo(const Json::Value &deviceConfig)
|
||||
: LedRs232Device(deviceConfig)
|
||||
: ProviderRs232(deviceConfig)
|
||||
{
|
||||
_ledBuffer.resize(4 + 5*3); // 4-byte header, 5 RGB values
|
||||
_ledBuffer[0] = 0xFF; // Startbyte
|
||||
|
@ -4,12 +4,12 @@
|
||||
#include <string>
|
||||
|
||||
// hyperion incluse
|
||||
#include "LedRs232Device.h"
|
||||
#include "ProviderRs232.h"
|
||||
|
||||
///
|
||||
/// Implementation of the LedDevice interface for writing to serial device using tpm2 protocol.
|
||||
///
|
||||
class LedDeviceAtmo : public LedRs232Device
|
||||
class LedDeviceAtmo : public ProviderRs232
|
||||
{
|
||||
public:
|
||||
///
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "LedDeviceLpd6803.h"
|
||||
|
||||
LedDeviceLpd6803::LedDeviceLpd6803(const Json::Value &deviceConfig)
|
||||
: LedSpiDevice(deviceConfig)
|
||||
: ProviderSpi(deviceConfig)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
// Local hyperion incluse
|
||||
#include "LedSpiDevice.h"
|
||||
#include "ProviderSpi.h"
|
||||
|
||||
///
|
||||
/// Implementation of the LedDevice interface for writing to LDP6803 led device.
|
||||
@ -14,7 +14,7 @@
|
||||
/// (R, G and B in the above illustration) making 16 bits per led. Total bytes = 4 + (2 x number of
|
||||
/// leds)
|
||||
///
|
||||
class LedDeviceLpd6803 : public LedSpiDevice
|
||||
class LedDeviceLpd6803 : public ProviderSpi
|
||||
{
|
||||
public:
|
||||
///
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "LedDeviceLpd8806.h"
|
||||
|
||||
LedDeviceLpd8806::LedDeviceLpd8806(const Json::Value &deviceConfig)
|
||||
: LedSpiDevice(deviceConfig)
|
||||
: ProviderSpi(deviceConfig)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
// Local hyperion incluse
|
||||
#include "LedSpiDevice.h"
|
||||
#include "ProviderSpi.h"
|
||||
|
||||
///
|
||||
/// Implementation of the LedDevice interface for writing to LPD8806 led device.
|
||||
@ -75,7 +75,7 @@
|
||||
///
|
||||
/// The number of zeroes in the 'clear data' is (#led/32 + 1)bytes (or *8 for bits)
|
||||
///
|
||||
class LedDeviceLpd8806 : public LedSpiDevice
|
||||
class LedDeviceLpd8806 : public ProviderSpi
|
||||
{
|
||||
public:
|
||||
///
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "LedDeviceP9813.h"
|
||||
|
||||
LedDeviceP9813::LedDeviceP9813(const Json::Value &deviceConfig)
|
||||
: LedSpiDevice(deviceConfig)
|
||||
: ProviderSpi(deviceConfig)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -4,12 +4,12 @@
|
||||
#include <string>
|
||||
|
||||
// hyperion include
|
||||
#include "LedSpiDevice.h"
|
||||
#include "ProviderSpi.h"
|
||||
|
||||
///
|
||||
/// Implementation of the LedDevice interface for writing to P9813 led device.
|
||||
///
|
||||
class LedDeviceP9813 : public LedSpiDevice
|
||||
class LedDeviceP9813 : public ProviderSpi
|
||||
{
|
||||
public:
|
||||
///
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
// Use out report HID device
|
||||
LedDevicePaintpack::LedDevicePaintpack(const Json::Value &deviceConfig)
|
||||
: LedHIDDevice(deviceConfig)
|
||||
: ProviderHID(deviceConfig)
|
||||
{
|
||||
_useFeature = false;
|
||||
}
|
||||
|
@ -4,12 +4,12 @@
|
||||
#include <vector>
|
||||
|
||||
// Hyperion includes
|
||||
#include "LedHIDDevice.h"
|
||||
#include "ProviderHID.h"
|
||||
|
||||
///
|
||||
/// LedDevice implementation for a paintpack device ()
|
||||
///
|
||||
class LedDevicePaintpack : public LedHIDDevice
|
||||
class LedDevicePaintpack : public ProviderHID
|
||||
{
|
||||
public:
|
||||
///
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
// Use feature report HID device
|
||||
LedDeviceRawHID::LedDeviceRawHID(const Json::Value &deviceConfig)
|
||||
: LedHIDDevice(deviceConfig)
|
||||
: ProviderHID(deviceConfig)
|
||||
, _timer()
|
||||
{
|
||||
_useFeature = true;
|
||||
|
@ -7,12 +7,12 @@
|
||||
#include <QTimer>
|
||||
|
||||
// hyperion include
|
||||
#include "LedHIDDevice.h"
|
||||
#include "ProviderHID.h"
|
||||
|
||||
///
|
||||
/// Implementation of the LedDevice interface for writing to an RawHID led device.
|
||||
///
|
||||
class LedDeviceRawHID : public LedHIDDevice
|
||||
class LedDeviceRawHID : public ProviderHID
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -18,7 +18,7 @@ struct FrameSpec
|
||||
};
|
||||
|
||||
LedDeviceSedu::LedDeviceSedu(const Json::Value &deviceConfig)
|
||||
: LedRs232Device(deviceConfig)
|
||||
: ProviderRs232(deviceConfig)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
@ -4,12 +4,12 @@
|
||||
#include <string>
|
||||
|
||||
// hyperion incluse
|
||||
#include "LedRs232Device.h"
|
||||
#include "ProviderRs232.h"
|
||||
|
||||
///
|
||||
/// Implementation of the LedDevice interface for writing to SEDU led device.
|
||||
///
|
||||
class LedDeviceSedu : public LedRs232Device
|
||||
class LedDeviceSedu : public ProviderRs232
|
||||
{
|
||||
public:
|
||||
///
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "LedDeviceSk6812SPI.h"
|
||||
|
||||
LedDeviceSk6812SPI::LedDeviceSk6812SPI(const Json::Value &deviceConfig)
|
||||
: LedSpiDevice(deviceConfig)
|
||||
: ProviderSpi(deviceConfig)
|
||||
, bitpair_to_byte {
|
||||
0b10001000,
|
||||
0b10001100,
|
||||
@ -32,7 +32,7 @@ LedDevice* LedDeviceSk6812SPI::construct(const Json::Value &deviceConfig)
|
||||
|
||||
bool LedDeviceSk6812SPI::setConfig(const Json::Value &deviceConfig)
|
||||
{
|
||||
LedSpiDevice::setConfig(deviceConfig);
|
||||
ProviderSpi::setConfig(deviceConfig);
|
||||
_whiteAlgorithm = deviceConfig.get("white_algorithm","").asString();
|
||||
|
||||
return true;
|
||||
|
@ -4,12 +4,12 @@
|
||||
#include <string>
|
||||
|
||||
// hyperion incluse
|
||||
#include "LedSpiDevice.h"
|
||||
#include "ProviderSpi.h"
|
||||
|
||||
///
|
||||
/// Implementation of the LedDevice interface for writing to Sk6801 led device.
|
||||
///
|
||||
class LedDeviceSk6812SPI : public LedSpiDevice
|
||||
class LedDeviceSk6812SPI : public ProviderSpi
|
||||
{
|
||||
public:
|
||||
///
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include <json/json.h>
|
||||
|
||||
LedDeviceTpm2::LedDeviceTpm2(const Json::Value &deviceConfig)
|
||||
: LedRs232Device(deviceConfig)
|
||||
: ProviderRs232(deviceConfig)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -4,12 +4,12 @@
|
||||
#include <string>
|
||||
|
||||
// hyperion incluse
|
||||
#include "LedRs232Device.h"
|
||||
#include "ProviderRs232.h"
|
||||
|
||||
///
|
||||
/// Implementation of the LedDevice interface for writing to serial device using tpm2 protocol.
|
||||
///
|
||||
class LedDeviceTpm2 : public LedRs232Device
|
||||
class LedDeviceTpm2 : public ProviderRs232
|
||||
{
|
||||
public:
|
||||
///
|
||||
|
@ -9,11 +9,14 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <QHostInfo>
|
||||
#include <QUuid>
|
||||
|
||||
// hyperion local includes
|
||||
#include "LedDeviceUdpE131.h"
|
||||
|
||||
LedDeviceUdpE131::LedDeviceUdpE131(const Json::Value &deviceConfig)
|
||||
: LedUdpDevice(deviceConfig)
|
||||
: ProviderUdp(deviceConfig)
|
||||
|
||||
{
|
||||
setConfig(deviceConfig);
|
||||
@ -21,9 +24,20 @@ LedDeviceUdpE131::LedDeviceUdpE131(const Json::Value &deviceConfig)
|
||||
|
||||
bool LedDeviceUdpE131::setConfig(const Json::Value &deviceConfig)
|
||||
{
|
||||
LedUdpDevice::setConfig(deviceConfig);
|
||||
ProviderUdp::setConfig(deviceConfig);
|
||||
_LatchTime_ns = deviceConfig.get("latchtime",104000).asInt();
|
||||
_e131_universe = deviceConfig.get("universe",1).asInt();
|
||||
_e131_source_name = deviceConfig.get("source-name","hyperion on "+QHostInfo::localHostName().toStdString()).asString();
|
||||
QString _json_cid = QString::fromStdString(deviceConfig.get("cid","").asString());
|
||||
|
||||
if (_json_cid.isEmpty())
|
||||
{
|
||||
_e131_cid = QUuid::createUuid();
|
||||
Debug( _log, "e131 no cid found, generated %s", _e131_cid.toString().toStdString().c_str());
|
||||
} else {
|
||||
_e131_cid = QUuid(_json_cid);
|
||||
Debug( _log, "e131 cid found, using %s", _e131_cid.toString().toStdString().c_str());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -33,8 +47,6 @@ LedDevice* LedDeviceUdpE131::construct(const Json::Value &deviceConfig)
|
||||
return new LedDeviceUdpE131(deviceConfig);
|
||||
}
|
||||
|
||||
#define CID "hyperion!\0"
|
||||
#define SOURCE_NAME "hyperion on hostname\0"
|
||||
|
||||
// populates the headers
|
||||
void LedDeviceUdpE131::prepare(const unsigned this_universe, const unsigned this_dmxChannelCount)
|
||||
@ -47,12 +59,12 @@ void LedDeviceUdpE131::prepare(const unsigned this_universe, const unsigned this
|
||||
memcpy (e131_packet.acn_id, _acn_id, 12);
|
||||
e131_packet.root_flength = htons(0x7000 | (110+this_dmxChannelCount) );
|
||||
e131_packet.root_vector = htonl(VECTOR_ROOT_E131_DATA);
|
||||
memcpy (e131_packet.cid, CID, sizeof(CID) );
|
||||
memcpy (e131_packet.cid, _e131_cid.toRfc4122().constData() , sizeof(e131_packet.cid) );
|
||||
|
||||
/* Frame Layer */
|
||||
e131_packet.frame_flength = htons(0x7000 | (88+this_dmxChannelCount));
|
||||
e131_packet.frame_vector = htonl(VECTOR_E131_DATA_PACKET);
|
||||
memcpy (e131_packet.source_name, SOURCE_NAME, sizeof(SOURCE_NAME));
|
||||
snprintf (e131_packet.source_name, sizeof(e131_packet.source_name), "%s", _e131_source_name.c_str() );
|
||||
e131_packet.priority = 100;
|
||||
e131_packet.reserved = htons(0);
|
||||
e131_packet.options = 0; // Bit 7 = Preview_Data
|
||||
|
@ -4,7 +4,9 @@
|
||||
#include <string>
|
||||
|
||||
// hyperion includes
|
||||
#include "LedUdpDevice.h"
|
||||
#include "ProviderUdp.h"
|
||||
|
||||
#include <QUuid>
|
||||
|
||||
/*
|
||||
*
|
||||
@ -55,12 +57,12 @@ typedef union {
|
||||
uint8_t acn_id[12];
|
||||
uint16_t root_flength;
|
||||
uint32_t root_vector;
|
||||
uint8_t cid[16];
|
||||
char cid[16];
|
||||
|
||||
/* Frame Layer */
|
||||
uint16_t frame_flength;
|
||||
uint32_t frame_vector;
|
||||
uint8_t source_name[64];
|
||||
char source_name[64];
|
||||
uint8_t priority;
|
||||
uint16_t reserved;
|
||||
uint8_t sequence_number;
|
||||
@ -96,7 +98,7 @@ typedef union {
|
||||
///
|
||||
/// Implementation of the LedDevice interface for sending led colors via udp/E1.31 packets
|
||||
///
|
||||
class LedDeviceUdpE131 : public LedUdpDevice
|
||||
class LedDeviceUdpE131 : public ProviderUdp
|
||||
{
|
||||
public:
|
||||
///
|
||||
@ -135,4 +137,6 @@ private:
|
||||
uint8_t _e131_seq = 0;
|
||||
uint8_t _e131_universe = 1;
|
||||
uint8_t _acn_id[12] = {0x41, 0x53, 0x43, 0x2d, 0x45, 0x31, 0x2e, 0x31, 0x37, 0x00, 0x00, 0x00 };
|
||||
std::string _e131_source_name;
|
||||
QUuid _e131_cid;
|
||||
};
|
||||
|
@ -12,14 +12,14 @@
|
||||
#include "LedDeviceUdpRaw.h"
|
||||
|
||||
LedDeviceUdpRaw::LedDeviceUdpRaw(const Json::Value &deviceConfig)
|
||||
: LedUdpDevice(deviceConfig)
|
||||
: ProviderUdp(deviceConfig)
|
||||
{
|
||||
setConfig(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceUdpRaw::setConfig(const Json::Value &deviceConfig)
|
||||
{
|
||||
LedUdpDevice::setConfig(deviceConfig);
|
||||
ProviderUdp::setConfig(deviceConfig);
|
||||
_LatchTime_ns = deviceConfig.get("latchtime",500000).asInt();
|
||||
|
||||
return true;
|
||||
|
@ -4,12 +4,12 @@
|
||||
#include <string>
|
||||
|
||||
// hyperion incluse
|
||||
#include "LedUdpDevice.h"
|
||||
#include "ProviderUdp.h"
|
||||
|
||||
///
|
||||
/// Implementation of the LedDevice interface for sending led colors via udp.
|
||||
///
|
||||
class LedDeviceUdpRaw : public LedUdpDevice
|
||||
class LedDeviceUdpRaw : public ProviderUdp
|
||||
{
|
||||
public:
|
||||
///
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "LedDeviceWs2801.h"
|
||||
|
||||
LedDeviceWs2801::LedDeviceWs2801(const Json::Value &deviceConfig)
|
||||
: LedSpiDevice(deviceConfig)
|
||||
: ProviderSpi(deviceConfig)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -4,12 +4,12 @@
|
||||
#include <string>
|
||||
|
||||
// hyperion incluse
|
||||
#include "LedSpiDevice.h"
|
||||
#include "ProviderSpi.h"
|
||||
|
||||
///
|
||||
/// Implementation of the LedDevice interface for writing to Ws2801 led device.
|
||||
///
|
||||
class LedDeviceWs2801 : public LedSpiDevice
|
||||
class LedDeviceWs2801 : public ProviderSpi
|
||||
{
|
||||
public:
|
||||
///
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "LedDeviceWs2812SPI.h"
|
||||
|
||||
LedDeviceWs2812SPI::LedDeviceWs2812SPI(const Json::Value &deviceConfig)
|
||||
: LedSpiDevice(deviceConfig)
|
||||
: ProviderSpi(deviceConfig)
|
||||
, bitpair_to_byte {
|
||||
0b10001000,
|
||||
0b10001100,
|
||||
|
@ -4,12 +4,12 @@
|
||||
#include <string>
|
||||
|
||||
// hyperion incluse
|
||||
#include "LedSpiDevice.h"
|
||||
#include "ProviderSpi.h"
|
||||
|
||||
///
|
||||
/// Implementation of the LedDevice interface for writing to Ws2801 led device.
|
||||
///
|
||||
class LedDeviceWs2812SPI : public LedSpiDevice
|
||||
class LedDeviceWs2812SPI : public ProviderSpi
|
||||
{
|
||||
public:
|
||||
///
|
||||
|
@ -1,75 +0,0 @@
|
||||
|
||||
// STL includes
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
// Linux includes
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <QStringList>
|
||||
#include <QUdpSocket>
|
||||
#include <QHostInfo>
|
||||
|
||||
// Local Hyperion includes
|
||||
#include "LedUdpDevice.h"
|
||||
|
||||
LedUdpDevice::LedUdpDevice(const Json::Value &deviceConfig)
|
||||
: LedDevice()
|
||||
, _LatchTime_ns(-1)
|
||||
{
|
||||
setConfig(deviceConfig);
|
||||
_udpSocket = new QUdpSocket();
|
||||
}
|
||||
|
||||
LedUdpDevice::~LedUdpDevice()
|
||||
{
|
||||
_udpSocket->close();
|
||||
}
|
||||
|
||||
bool LedUdpDevice::setConfig(const Json::Value &deviceConfig)
|
||||
{
|
||||
QHostInfo info = QHostInfo::fromName( QString::fromStdString(deviceConfig["output"].asString()) );
|
||||
if (info.addresses().isEmpty())
|
||||
{
|
||||
throw("invalid target address");
|
||||
}
|
||||
_address = info.addresses().first();
|
||||
_port = deviceConfig["port"].asUInt();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int LedUdpDevice::open()
|
||||
{
|
||||
QHostAddress localAddress = QHostAddress::Any;
|
||||
quint16 localPort = 0;
|
||||
|
||||
WarningIf( !_udpSocket->bind(localAddress, localPort), _log, "Couldnt bind local address: %s", strerror(errno));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LedUdpDevice::writeBytes(const unsigned size, const uint8_t * data)
|
||||
{
|
||||
|
||||
qint64 retVal = _udpSocket->writeDatagram((const char *)data,size,_address,_port);
|
||||
|
||||
if (retVal >= 0 && _LatchTime_ns > 0)
|
||||
{
|
||||
// The 'latch' time for latching the shifted-value into the leds
|
||||
timespec latchTime;
|
||||
latchTime.tv_sec = 0;
|
||||
latchTime.tv_nsec = _LatchTime_ns;
|
||||
|
||||
// Sleep to latch the leds (only if write succesfull)
|
||||
nanosleep(&latchTime, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning( _log, "Error sending: %s", strerror(errno));
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
@ -7,9 +7,9 @@
|
||||
#include <QTimer>
|
||||
|
||||
// Local Hyperion includes
|
||||
#include "LedHIDDevice.h"
|
||||
#include "ProviderHID.h"
|
||||
|
||||
LedHIDDevice::LedHIDDevice(const Json::Value &deviceConfig)
|
||||
ProviderHID::ProviderHID(const Json::Value &deviceConfig)
|
||||
: _useFeature(false)
|
||||
, _deviceHandle(nullptr)
|
||||
, _blockedForDelay(false)
|
||||
@ -17,7 +17,7 @@ LedHIDDevice::LedHIDDevice(const Json::Value &deviceConfig)
|
||||
setConfig(deviceConfig);
|
||||
}
|
||||
|
||||
LedHIDDevice::~LedHIDDevice()
|
||||
ProviderHID::~ProviderHID()
|
||||
{
|
||||
if (_deviceHandle != nullptr)
|
||||
{
|
||||
@ -28,7 +28,7 @@ LedHIDDevice::~LedHIDDevice()
|
||||
hid_exit();
|
||||
}
|
||||
|
||||
bool LedHIDDevice::setConfig(const Json::Value &deviceConfig)
|
||||
bool ProviderHID::setConfig(const Json::Value &deviceConfig)
|
||||
{
|
||||
_delayAfterConnect_ms = deviceConfig.get("delayAfterConnect", 0 ).asInt();
|
||||
auto VendorIdString = deviceConfig.get("VID", "0x2341").asString();
|
||||
@ -41,7 +41,7 @@ bool LedHIDDevice::setConfig(const Json::Value &deviceConfig)
|
||||
return true;
|
||||
}
|
||||
|
||||
int LedHIDDevice::open()
|
||||
int ProviderHID::open()
|
||||
{
|
||||
// Initialize the usb context
|
||||
int error = hid_init();
|
||||
@ -97,7 +97,7 @@ int LedHIDDevice::open()
|
||||
}
|
||||
|
||||
|
||||
int LedHIDDevice::writeBytes(const unsigned size, const uint8_t * data)
|
||||
int ProviderHID::writeBytes(const unsigned size, const uint8_t * data)
|
||||
{
|
||||
if (_blockedForDelay) {
|
||||
return 0;
|
||||
@ -156,7 +156,7 @@ int LedHIDDevice::writeBytes(const unsigned size, const uint8_t * data)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void LedHIDDevice::unblockAfterDelay()
|
||||
void ProviderHID::unblockAfterDelay()
|
||||
{
|
||||
Debug(_log,"Device unblocked");
|
||||
_blockedForDelay = false;
|
@ -9,9 +9,9 @@
|
||||
#include <leddevice/LedDevice.h>
|
||||
|
||||
///
|
||||
/// The LedHIDDevice implements an abstract base-class for LedDevices using an HID-device.
|
||||
/// The ProviderHID implements an abstract base-class for LedDevices using an HID-device.
|
||||
///
|
||||
class LedHIDDevice : public LedDevice
|
||||
class ProviderHID : public LedDevice
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -21,12 +21,12 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedHIDDevice(const Json::Value &deviceConfig);
|
||||
ProviderHID(const Json::Value &deviceConfig);
|
||||
|
||||
///
|
||||
/// Destructor of the LedDevice; closes the output device if it is open
|
||||
///
|
||||
virtual ~LedHIDDevice();
|
||||
virtual ~ProviderHID();
|
||||
|
||||
///
|
||||
/// Sets configuration
|
@ -7,9 +7,9 @@
|
||||
#include <QTimer>
|
||||
|
||||
// Local Hyperion includes
|
||||
#include "LedRs232Device.h"
|
||||
#include "ProviderRs232.h"
|
||||
|
||||
LedRs232Device::LedRs232Device(const Json::Value &deviceConfig)
|
||||
ProviderRs232::ProviderRs232(const Json::Value &deviceConfig)
|
||||
: _rs232Port(this)
|
||||
, _blockedForDelay(false)
|
||||
, _stateChanged(true)
|
||||
@ -18,7 +18,7 @@ LedRs232Device::LedRs232Device(const Json::Value &deviceConfig)
|
||||
connect(&_rs232Port, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(error(QSerialPort::SerialPortError)));
|
||||
}
|
||||
|
||||
bool LedRs232Device::setConfig(const Json::Value &deviceConfig)
|
||||
bool ProviderRs232::setConfig(const Json::Value &deviceConfig)
|
||||
{
|
||||
closeDevice();
|
||||
_deviceName = deviceConfig["output"].asString();
|
||||
@ -28,7 +28,7 @@ bool LedRs232Device::setConfig(const Json::Value &deviceConfig)
|
||||
return true;
|
||||
}
|
||||
|
||||
void LedRs232Device::error(QSerialPort::SerialPortError error)
|
||||
void ProviderRs232::error(QSerialPort::SerialPortError error)
|
||||
{
|
||||
if ( error != QSerialPort::NoError )
|
||||
{
|
||||
@ -64,13 +64,13 @@ void LedRs232Device::error(QSerialPort::SerialPortError error)
|
||||
}
|
||||
}
|
||||
|
||||
LedRs232Device::~LedRs232Device()
|
||||
ProviderRs232::~ProviderRs232()
|
||||
{
|
||||
disconnect(&_rs232Port, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(error(QSerialPort::SerialPortError)));
|
||||
closeDevice();
|
||||
}
|
||||
|
||||
void LedRs232Device::closeDevice()
|
||||
void ProviderRs232::closeDevice()
|
||||
{
|
||||
if (_rs232Port.isOpen())
|
||||
{
|
||||
@ -79,7 +79,7 @@ void LedRs232Device::closeDevice()
|
||||
}
|
||||
}
|
||||
|
||||
int LedRs232Device::open()
|
||||
int ProviderRs232::open()
|
||||
{
|
||||
Info(_log, "Opening UART: %s", _deviceName.c_str());
|
||||
_rs232Port.setPortName(_deviceName.c_str());
|
||||
@ -88,7 +88,7 @@ int LedRs232Device::open()
|
||||
}
|
||||
|
||||
|
||||
bool LedRs232Device::tryOpen()
|
||||
bool ProviderRs232::tryOpen()
|
||||
{
|
||||
if ( ! _rs232Port.isOpen() )
|
||||
{
|
||||
@ -116,7 +116,7 @@ bool LedRs232Device::tryOpen()
|
||||
}
|
||||
|
||||
|
||||
int LedRs232Device::writeBytes(const unsigned size, const uint8_t * data)
|
||||
int ProviderRs232::writeBytes(const unsigned size, const uint8_t * data)
|
||||
{
|
||||
if (_blockedForDelay)
|
||||
{
|
||||
@ -143,7 +143,7 @@ int LedRs232Device::writeBytes(const unsigned size, const uint8_t * data)
|
||||
}
|
||||
|
||||
|
||||
void LedRs232Device::unblockAfterDelay()
|
||||
void ProviderRs232::unblockAfterDelay()
|
||||
{
|
||||
Debug(_log, "Device unblocked");
|
||||
_blockedForDelay = false;
|
@ -7,9 +7,9 @@
|
||||
#include <leddevice/LedDevice.h>
|
||||
|
||||
///
|
||||
/// The LedRs232Device implements an abstract base-class for LedDevices using a RS232-device.
|
||||
/// The ProviderRs232 implements an abstract base-class for LedDevices using a RS232-device.
|
||||
///
|
||||
class LedRs232Device : public LedDevice
|
||||
class ProviderRs232 : public LedDevice
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -19,7 +19,7 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedRs232Device(const Json::Value &deviceConfig);
|
||||
ProviderRs232(const Json::Value &deviceConfig);
|
||||
|
||||
///
|
||||
/// Sets configuration
|
||||
@ -31,7 +31,7 @@ public:
|
||||
///
|
||||
/// Destructor of the LedDevice; closes the output device if it is open
|
||||
///
|
||||
virtual ~LedRs232Device();
|
||||
virtual ~ProviderRs232();
|
||||
|
||||
///
|
||||
/// Opens and configures the output device
|
@ -10,11 +10,11 @@
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
// Local Hyperion includes
|
||||
#include "LedSpiDevice.h"
|
||||
#include "ProviderSpi.h"
|
||||
#include <utils/Logger.h>
|
||||
|
||||
|
||||
LedSpiDevice::LedSpiDevice(const Json::Value &deviceConfig)
|
||||
ProviderSpi::ProviderSpi(const Json::Value &deviceConfig)
|
||||
: LedDevice()
|
||||
, _fid(-1)
|
||||
{
|
||||
@ -23,14 +23,14 @@ LedSpiDevice::LedSpiDevice(const Json::Value &deviceConfig)
|
||||
Debug(_log, "_spiDataInvert %d, _spiMode %d", _spiDataInvert, _spiMode);
|
||||
}
|
||||
|
||||
LedSpiDevice::~LedSpiDevice()
|
||||
ProviderSpi::~ProviderSpi()
|
||||
{
|
||||
// close(_fid);
|
||||
}
|
||||
|
||||
bool LedSpiDevice::setConfig(const Json::Value &deviceConfig)
|
||||
bool ProviderSpi::setConfig(const Json::Value &deviceConfig)
|
||||
{
|
||||
_deviceName = deviceConfig.get("output","/dev/spidev.0.0").asString();
|
||||
_deviceName = deviceConfig.get("output","/dev/spidev0.0").asString();
|
||||
_baudRate_Hz = deviceConfig.get("rate",1000000).asInt();
|
||||
_latchTime_ns = deviceConfig.get("latchtime",0).asInt();
|
||||
_spiMode = deviceConfig.get("spimode",SPI_MODE_0).asInt();
|
||||
@ -39,7 +39,7 @@ bool LedSpiDevice::setConfig(const Json::Value &deviceConfig)
|
||||
return true;
|
||||
}
|
||||
|
||||
int LedSpiDevice::open()
|
||||
int ProviderSpi::open()
|
||||
{
|
||||
const int bitsPerWord = 8;
|
||||
|
||||
@ -69,7 +69,7 @@ int LedSpiDevice::open()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LedSpiDevice::writeBytes(const unsigned size, const uint8_t * data)
|
||||
int ProviderSpi::writeBytes(const unsigned size, const uint8_t * data)
|
||||
{
|
||||
if (_fid < 0)
|
||||
{
|
@ -7,9 +7,9 @@
|
||||
#include <leddevice/LedDevice.h>
|
||||
|
||||
///
|
||||
/// The LedSpiDevice implements an abstract base-class for LedDevices using the SPI-device.
|
||||
/// The ProviderSpi implements an abstract base-class for LedDevices using the SPI-device.
|
||||
///
|
||||
class LedSpiDevice : public LedDevice
|
||||
class ProviderSpi : public LedDevice
|
||||
{
|
||||
public:
|
||||
///
|
||||
@ -17,7 +17,7 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedSpiDevice(const Json::Value &deviceConfig);
|
||||
ProviderSpi(const Json::Value &deviceConfig);
|
||||
|
||||
///
|
||||
/// Sets configuration
|
||||
@ -29,7 +29,7 @@ public:
|
||||
///
|
||||
/// Destructor of the LedDevice; closes the output device if it is open
|
||||
///
|
||||
virtual ~LedSpiDevice();
|
||||
virtual ~ProviderSpi();
|
||||
|
||||
///
|
||||
/// Opens and configures the output device
|
86
libsrc/leddevice/ProviderUdp.cpp
Normal file
86
libsrc/leddevice/ProviderUdp.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
|
||||
// STL includes
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
// Linux includes
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <QStringList>
|
||||
#include <QUdpSocket>
|
||||
#include <QHostInfo>
|
||||
|
||||
// Local Hyperion includes
|
||||
#include "ProviderUdp.h"
|
||||
|
||||
ProviderUdp::ProviderUdp(const Json::Value &deviceConfig)
|
||||
: LedDevice()
|
||||
, _LatchTime_ns(-1)
|
||||
{
|
||||
setConfig(deviceConfig);
|
||||
_udpSocket = new QUdpSocket();
|
||||
}
|
||||
|
||||
ProviderUdp::~ProviderUdp()
|
||||
{
|
||||
_udpSocket->close();
|
||||
}
|
||||
|
||||
bool ProviderUdp::setConfig(const Json::Value &deviceConfig)
|
||||
{
|
||||
if (_address.setAddress( QString::fromStdString(deviceConfig["host"].asString()) ) )
|
||||
{
|
||||
Debug( _log, "Successfully parsed %s as an ip address.", deviceConfig["host"].asString().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug( _log, "Failed to parse %s as an ip address.", deviceConfig["host"].asString().c_str());
|
||||
QHostInfo info = QHostInfo::fromName( QString::fromStdString(deviceConfig["host"].asString()) );
|
||||
if (info.addresses().isEmpty())
|
||||
{
|
||||
Debug( _log, "Failed to parse %s as a hostname.", deviceConfig["host"].asString().c_str());
|
||||
throw std::runtime_error("invalid target address");
|
||||
}
|
||||
Debug( _log, "Successfully parsed %s as a hostname.", deviceConfig["host"].asString().c_str());
|
||||
_address = info.addresses().first();
|
||||
}
|
||||
_port = deviceConfig["port"].asUInt();
|
||||
Debug( _log, "UDP using %s:%d", _address.toString().toStdString().c_str() , _port );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int ProviderUdp::open()
|
||||
{
|
||||
QHostAddress localAddress = QHostAddress::Any;
|
||||
quint16 localPort = 0;
|
||||
|
||||
WarningIf( !_udpSocket->bind(localAddress, localPort), _log, "Could not bind local address: %s", strerror(errno));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ProviderUdp::writeBytes(const unsigned size, const uint8_t * data)
|
||||
{
|
||||
|
||||
qint64 retVal = _udpSocket->writeDatagram((const char *)data,size,_address,_port);
|
||||
|
||||
if (retVal >= 0 && _LatchTime_ns > 0)
|
||||
{
|
||||
// The 'latch' time for latching the shifted-value into the leds
|
||||
timespec latchTime;
|
||||
latchTime.tv_sec = 0;
|
||||
latchTime.tv_nsec = _LatchTime_ns;
|
||||
|
||||
// Sleep to latch the leds (only if write succesfull)
|
||||
nanosleep(&latchTime, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning( _log, "Error sending: %s", strerror(errno));
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
@ -7,9 +7,9 @@
|
||||
#include <utils/Logger.h>
|
||||
|
||||
///
|
||||
/// The LedUdpDevice implements an abstract base-class for LedDevices using the SPI-device.
|
||||
/// The ProviderUdp implements an abstract base-class for LedDevices using the SPI-device.
|
||||
///
|
||||
class LedUdpDevice : public LedDevice
|
||||
class ProviderUdp : public LedDevice
|
||||
{
|
||||
public:
|
||||
///
|
||||
@ -17,12 +17,12 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedUdpDevice(const Json::Value &deviceConfig);
|
||||
ProviderUdp(const Json::Value &deviceConfig);
|
||||
|
||||
///
|
||||
/// Destructor of the LedDevice; closes the output device if it is open
|
||||
///
|
||||
virtual ~LedUdpDevice();
|
||||
virtual ~ProviderUdp();
|
||||
|
||||
///
|
||||
/// Sets configuration
|
@ -1,10 +1,13 @@
|
||||
// protoserver includes
|
||||
#include "protoserver/ProtoConnectionWrapper.h"
|
||||
|
||||
ProtoConnectionWrapper::ProtoConnectionWrapper(const std::string & address, int priority, int duration_ms, bool skipProtoReply)
|
||||
ProtoConnectionWrapper::ProtoConnectionWrapper(const QString &address,
|
||||
int priority,
|
||||
int duration_ms,
|
||||
bool skipProtoReply)
|
||||
: _priority(priority)
|
||||
, _duration_ms(duration_ms)
|
||||
, _connection(address)
|
||||
, _connection(address.toStdString())
|
||||
{
|
||||
_connection.setSkipReply(skipProtoReply);
|
||||
connect(&_connection, SIGNAL(setGrabbingMode(GrabbingMode)), this, SIGNAL(setGrabbingMode(GrabbingMode)));
|
||||
|
@ -30,7 +30,7 @@ add_executable(${PROJECT_NAME}
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
getoptPlusPlus
|
||||
commandline
|
||||
blackborder
|
||||
hyperion-utils
|
||||
protoserver
|
||||
|
@ -4,20 +4,16 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QImage>
|
||||
|
||||
// getoptPlusPLus includes
|
||||
#include <getoptPlusPlus/getoptpp.h>
|
||||
|
||||
#include <protoserver/ProtoConnectionWrapper.h>
|
||||
#include "AmlogicWrapper.h"
|
||||
|
||||
#include "HyperionConfig.h"
|
||||
#include <utils/Logger.h>
|
||||
#include <commandline/Parser.h>
|
||||
|
||||
|
||||
using namespace vlofgren;
|
||||
using namespace commandline;
|
||||
|
||||
// save the image as screenshot
|
||||
void saveScreenshot(const char * filename, const Image<ColorRgb> & image)
|
||||
void saveScreenshot(QString filename, const Image<ColorRgb> & image)
|
||||
{
|
||||
// store as PNG
|
||||
QImage pngImage((const uint8_t *) image.memptr(), image.width(), image.height(), 3*image.width(), QImage::Format_RGB888);
|
||||
@ -35,50 +31,30 @@ int main(int argc, char ** argv)
|
||||
|
||||
try
|
||||
{
|
||||
// create the option parser and initialize all parameters
|
||||
OptionsParser optionParser("AmLogic capture application for Hyperion");
|
||||
ParameterSet & parameters = optionParser.getParameters();
|
||||
// create the option parser and initialize all parser
|
||||
Parser parser("AmLogic capture application for Hyperion");
|
||||
|
||||
IntParameter & argFps = parameters.add<IntParameter> ('f', "framerate", "Capture frame rate [default: 10]");
|
||||
IntParameter & argWidth = parameters.add<IntParameter> (0x0, "width", "Width of the captured image [default: 128]");
|
||||
IntParameter & argHeight = parameters.add<IntParameter> (0x0, "height", "Height of the captured image [default: 128]");
|
||||
SwitchParameter<> & argScreenshot = parameters.add<SwitchParameter<>> (0x0, "screenshot", "Take a single screenshot, save it to file and quit");
|
||||
StringParameter & argAddress = parameters.add<StringParameter> ('a', "address", "Set the address of the hyperion server [default: 127.0.0.1:19445]");
|
||||
IntParameter & argPriority = parameters.add<IntParameter> ('p', "priority", "Use the provided priority channel (the lower the number, the higher the priority) [default: 800]");
|
||||
SwitchParameter<> & argSkipReply = parameters.add<SwitchParameter<>> (0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
|
||||
SwitchParameter<> & argHelp = parameters.add<SwitchParameter<>> ('h', "help", "Show this help message and exit");
|
||||
|
||||
// set defaults
|
||||
argFps.setDefault(10);
|
||||
argWidth.setDefault(160);
|
||||
argHeight.setDefault(160);
|
||||
argAddress.setDefault("127.0.0.1:19445");
|
||||
argPriority.setDefault(800);
|
||||
IntOption & argFps = parser.add<IntOption> ('f', "framerate", "Capture frame rate [default: %1]", "10");
|
||||
IntOption & argWidth = parser.add<IntOption> (0x0, "width", "Width of the captured image [default: %1]", "160", 160, 4096);
|
||||
IntOption & argHeight = parser.add<IntOption> (0x0, "height", "Height of the captured image [default: %1]", "160", 160, 4096);
|
||||
BooleanOption & argScreenshot = parser.add<BooleanOption> (0x0, "screenshot", "Take a single screenshot, save it to file and quit");
|
||||
Option & argAddress = parser.add<Option> ('a', "address", "Set the address of the hyperion server [default: %1]", "127.0.0.1:19445");
|
||||
IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (the lower the number, the higher the priority) [default: %1]", "800");
|
||||
BooleanOption & argSkipReply = parser.add<BooleanOption> (0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
|
||||
BooleanOption & argHelp = parser.add<BooleanOption> ('h', "help", "Show this help message and exit");
|
||||
|
||||
// parse all options
|
||||
optionParser.parse(argc, const_cast<const char **>(argv));
|
||||
parser.process(app);
|
||||
|
||||
// check if we need to display the usage. exit if we do.
|
||||
if (argHelp.isSet())
|
||||
if (parser.isSet(argHelp))
|
||||
{
|
||||
optionParser.usage();
|
||||
return 0;
|
||||
parser.showHelp(0);
|
||||
}
|
||||
|
||||
int width = argWidth.getValue();
|
||||
int height = argHeight.getValue();
|
||||
if (width < 160 || height < 160)
|
||||
{
|
||||
Warning(Logger::getInstance("AMLOGIC"), "Minimum width and height is 160");
|
||||
AmlogicWrapper amlWrapper(argWidth.getInt(parser), argHeight.getInt(parser), 1000 / argFps.getInt(parser));
|
||||
|
||||
width = std::max(160, width);
|
||||
height = std::max(160, height);
|
||||
}
|
||||
|
||||
int grabInterval = 1000 / argFps.getValue();
|
||||
AmlogicWrapper amlWrapper(argWidth.getValue(),argHeight.getValue(),grabInterval);
|
||||
|
||||
if (argScreenshot.isSet())
|
||||
if (parser.isSet(argScreenshot))
|
||||
{
|
||||
// Capture a single screenshot and finish
|
||||
const Image<ColorRgb> & screenshot = amlWrapper.getScreenshot();
|
||||
@ -87,7 +63,7 @@ int main(int argc, char ** argv)
|
||||
else
|
||||
{
|
||||
// Create the Proto-connection with hyperiond
|
||||
ProtoConnectionWrapper protoWrapper(argAddress.getValue(), argPriority.getValue(), 1000, argSkipReply.isSet());
|
||||
ProtoConnectionWrapper protoWrapper(argAddress.value(parser), argPriority.getInt(parser), 1000, parser.isSet(argSkipReply));
|
||||
|
||||
// Connect the screen capturing to the proto processing
|
||||
QObject::connect(&amlWrapper, SIGNAL(sig_screenshot(const Image<ColorRgb> &)), &protoWrapper, SLOT(receiveImage(Image<ColorRgb>)));
|
||||
|
@ -31,7 +31,7 @@ add_executable( ${PROJECT_NAME}
|
||||
)
|
||||
|
||||
target_link_libraries( ${PROJECT_NAME}
|
||||
getoptPlusPlus
|
||||
commandline
|
||||
blackborder
|
||||
hyperion-utils
|
||||
protoserver
|
||||
|
@ -3,18 +3,16 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QImage>
|
||||
|
||||
// getoptPlusPLus includes
|
||||
#include <getoptPlusPlus/getoptpp.h>
|
||||
|
||||
#include <protoserver/ProtoConnectionWrapper.h>
|
||||
#include "DispmanxWrapper.h"
|
||||
|
||||
#include "HyperionConfig.h"
|
||||
#include <commandline/Parser.h>
|
||||
|
||||
using namespace vlofgren;
|
||||
using namespace commandline;
|
||||
|
||||
// save the image as screenshot
|
||||
void saveScreenshot(const char * filename, const Image<ColorRgb> & image)
|
||||
void saveScreenshot(QString filename, const Image<ColorRgb> & image)
|
||||
{
|
||||
// store as PNG
|
||||
QImage pngImage((const uint8_t *) image.memptr(), image.width(), image.height(), 3*image.width(), QImage::Format_RGB888);
|
||||
@ -33,71 +31,58 @@ int main(int argc, char ** argv)
|
||||
try
|
||||
{
|
||||
// create the option parser and initialize all parameters
|
||||
OptionsParser optionParser("Dispmanx capture application for Hyperion");
|
||||
ParameterSet & parameters = optionParser.getParameters();
|
||||
Parser parser("Dispmanx capture application for Hyperion");
|
||||
|
||||
IntParameter & argFps = parameters.add<IntParameter> ('f', "framerate", "Capture frame rate [default: 10]");
|
||||
IntParameter & argWidth = parameters.add<IntParameter> (0x0, "width", "The width of the grabbed frames [pixels]");
|
||||
IntParameter & argHeight = parameters.add<IntParameter> (0x0, "height", "The height of the grabbed frames");
|
||||
IntOption & argFps = parser.add<IntOption> ('f', "framerate", "Capture frame rate [default: %1]", "10");
|
||||
IntOption & argWidth = parser.add<IntOption> (0x0, "width", "Width of the captured image [default: %1]", "64", 32, 4096);
|
||||
IntOption & argHeight = parser.add<IntOption> (0x0, "height", "Height of the captured image [default: %1]", "64", 32, 4096);
|
||||
|
||||
SwitchParameter<> & argScreenshot = parameters.add<SwitchParameter<>> (0x0, "screenshot", "Take a single screenshot, save it to file and quit");
|
||||
StringParameter & argAddress = parameters.add<StringParameter> ('a', "address", "Set the address of the hyperion server [default: 127.0.0.1:19445]");
|
||||
IntParameter & argPriority = parameters.add<IntParameter> ('p', "priority", "Use the provided priority channel (the lower the number, the higher the priority) [default: 800]");
|
||||
SwitchParameter<> & argSkipReply = parameters.add<SwitchParameter<>> (0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
|
||||
SwitchParameter<> & argHelp = parameters.add<SwitchParameter<>> ('h', "help", "Show this help message and exit");
|
||||
BooleanOption & argScreenshot = parser.add<BooleanOption> (0x0, "screenshot", "Take a single screenshot, save it to file and quit");
|
||||
Option & argAddress = parser.add<Option> ('a', "address", "Set the address of the hyperion server [default: %1]", "127.0.0.1:19445");
|
||||
IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (the lower the number, the higher the priority) [default: %1]", "800");
|
||||
BooleanOption & argSkipReply = parser.add<BooleanOption> (0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
|
||||
BooleanOption & argHelp = parser.add<BooleanOption> ('h', "help", "Show this help message and exit");
|
||||
|
||||
IntParameter & argCropLeft = parameters.add<IntParameter> (0x0, "crop-left", "pixels to remove on left after grabbing");
|
||||
IntParameter & argCropRight = parameters.add<IntParameter> (0x0, "crop-right", "pixels to remove on right after grabbing");
|
||||
IntParameter & argCropTop = parameters.add<IntParameter> (0x0, "crop-top", "pixels to remove on top after grabbing");
|
||||
IntParameter & argCropBottom = parameters.add<IntParameter> (0x0, "crop-bottom", "pixels to remove on bottom after grabbing");
|
||||
IntOption & argCropLeft = parser.add<IntOption> (0x0, "crop-left", "pixels to remove on left after grabbing");
|
||||
IntOption & argCropRight = parser.add<IntOption> (0x0, "crop-right", "pixels to remove on right after grabbing");
|
||||
IntOption & argCropTop = parser.add<IntOption> (0x0, "crop-top", "pixels to remove on top after grabbing");
|
||||
IntOption & argCropBottom = parser.add<IntOption> (0x0, "crop-bottom", "pixels to remove on bottom after grabbing");
|
||||
|
||||
SwitchParameter<> & arg3DSBS = parameters.add<SwitchParameter<>> (0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side");
|
||||
SwitchParameter<> & arg3DTAB = parameters.add<SwitchParameter<>> (0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom");
|
||||
|
||||
// set defaults
|
||||
argFps.setDefault(10);
|
||||
argWidth.setDefault(64);
|
||||
argHeight.setDefault(64);
|
||||
argAddress.setDefault("127.0.0.1:19445");
|
||||
argPriority.setDefault(800);
|
||||
|
||||
argCropLeft.setDefault(0);
|
||||
argCropRight.setDefault(0);
|
||||
argCropTop.setDefault(0);
|
||||
argCropBottom.setDefault(0);
|
||||
BooleanOption & arg3DSBS = parser.add<BooleanOption> (0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side");
|
||||
BooleanOption & arg3DTAB = parser.add<BooleanOption> (0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom");
|
||||
|
||||
// parse all options
|
||||
optionParser.parse(argc, const_cast<const char **>(argv));
|
||||
parser.process(app);
|
||||
|
||||
VideoMode videoMode = VIDEO_2D;
|
||||
|
||||
if (arg3DSBS.isSet())
|
||||
if (parser.isSet(arg3DSBS))
|
||||
{
|
||||
videoMode = VIDEO_3DSBS;
|
||||
}
|
||||
else if (arg3DTAB.isSet())
|
||||
else if (parser.isSet(arg3DTAB))
|
||||
{
|
||||
videoMode = VIDEO_3DTAB;
|
||||
}
|
||||
|
||||
// check if we need to display the usage. exit if we do.
|
||||
if (argHelp.isSet())
|
||||
if (parser.isSet(argHelp))
|
||||
{
|
||||
optionParser.usage();
|
||||
return 0;
|
||||
parser.showHelp(1);
|
||||
}
|
||||
|
||||
// Create the dispmanx grabbing stuff
|
||||
int grabInterval = 1000 / argFps.getValue();
|
||||
DispmanxWrapper dispmanxWrapper(argWidth.getValue(),argHeight.getValue(),
|
||||
DispmanxWrapper dispmanxWrapper(
|
||||
argWidth.getInt(parser),
|
||||
argHeight.getInt(parser),
|
||||
videoMode,
|
||||
std::max(0, argCropLeft.getValue()),
|
||||
std::max(0, argCropRight.getValue()),
|
||||
std::max(0, argCropTop.getValue()),
|
||||
std::max(0, argCropBottom.getValue()),
|
||||
grabInterval);
|
||||
argCropLeft.getInt(parser),
|
||||
argCropRight.getInt(parser),
|
||||
argCropTop.getInt(parser),
|
||||
argCropBottom.getInt(parser),
|
||||
1000 / argFps.getInt(parser));
|
||||
|
||||
if (argScreenshot.isSet())
|
||||
if (parser.isSet(argScreenshot))
|
||||
{
|
||||
// Capture a single screenshot and finish
|
||||
const Image<ColorRgb> & screenshot = dispmanxWrapper.getScreenshot();
|
||||
@ -106,7 +91,7 @@ int main(int argc, char ** argv)
|
||||
else
|
||||
{
|
||||
// Create the Proto-connection with hyperiond
|
||||
ProtoConnectionWrapper protoWrapper(argAddress.getValue(), argPriority.getValue(), 1000, argSkipReply.isSet());
|
||||
ProtoConnectionWrapper protoWrapper(argAddress.value(parser), argPriority.getInt(parser), 1000, parser.isSet(argSkipReply));
|
||||
|
||||
// Connect the screen capturing to the proto processing
|
||||
QObject::connect(&dispmanxWrapper, SIGNAL(sig_screenshot(const Image<ColorRgb> &)), &protoWrapper, SLOT(receiveImage(Image<ColorRgb>)));
|
||||
|
@ -30,7 +30,7 @@ add_executable( ${PROJECT_NAME}
|
||||
)
|
||||
|
||||
target_link_libraries( ${PROJECT_NAME}
|
||||
getoptPlusPlus
|
||||
commandline
|
||||
blackborder
|
||||
hyperion-utils
|
||||
protoserver
|
||||
|
@ -4,16 +4,14 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QImage>
|
||||
|
||||
// getoptPlusPLus includes
|
||||
#include <getoptPlusPlus/getoptpp.h>
|
||||
|
||||
#include <protoserver/ProtoConnectionWrapper.h>
|
||||
#include "FramebufferWrapper.h"
|
||||
#include <commandline/Parser.h>
|
||||
|
||||
using namespace vlofgren;
|
||||
using namespace commandline;
|
||||
|
||||
// save the image as screenshot
|
||||
void saveScreenshot(const char * filename, const Image<ColorRgb> & image)
|
||||
void saveScreenshot(QString filename, const Image<ColorRgb> & image)
|
||||
{
|
||||
// store as PNG
|
||||
QImage pngImage((const uint8_t *) image.memptr(), image.width(), image.height(), 3*image.width(), QImage::Format_RGB888);
|
||||
@ -27,50 +25,30 @@ int main(int argc, char ** argv)
|
||||
try
|
||||
{
|
||||
// create the option parser and initialize all parameters
|
||||
OptionsParser optionParser("FrameBuffer capture application for Hyperion");
|
||||
ParameterSet & parameters = optionParser.getParameters();
|
||||
Parser parser("FrameBuffer capture application for Hyperion");
|
||||
|
||||
StringParameter & argDevice = parameters.add<StringParameter> ('d', "device", "Set the video device [default: /dev/video0]");
|
||||
IntParameter & argFps = parameters.add<IntParameter> ('f', "framerate", "Capture frame rate [default: 10]");
|
||||
IntParameter & argWidth = parameters.add<IntParameter> (0x0, "width", "Width of the captured image [default: 128]");
|
||||
IntParameter & argHeight = parameters.add<IntParameter> (0x0, "height", "Height of the captured image [default: 128]");
|
||||
SwitchParameter<> & argScreenshot = parameters.add<SwitchParameter<>> (0x0, "screenshot", "Take a single screenshot, save it to file and quit");
|
||||
StringParameter & argAddress = parameters.add<StringParameter> ('a', "address", "Set the address of the hyperion server [default: 127.0.0.1:19445]");
|
||||
IntParameter & argPriority = parameters.add<IntParameter> ('p', "priority", "Use the provided priority channel (the lower the number, the higher the priority) [default: 800]");
|
||||
SwitchParameter<> & argSkipReply = parameters.add<SwitchParameter<>> (0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
|
||||
SwitchParameter<> & argHelp = parameters.add<SwitchParameter<>> ('h', "help", "Show this help message and exit");
|
||||
|
||||
// set defaults
|
||||
argFps.setDefault(10);
|
||||
argWidth.setDefault(160);
|
||||
argHeight.setDefault(160);
|
||||
argAddress.setDefault("127.0.0.1:19445");
|
||||
argPriority.setDefault(800);
|
||||
argDevice.setDefault("/dev/video0");
|
||||
Option & argDevice = parser.add<Option> ('d', "device", "Set the video device [default: %1]", "/dev/video0");
|
||||
IntOption & argFps = parser.add<IntOption> ('f', "framerate", "Capture frame rate [default: %1]", "10");
|
||||
IntOption & argWidth = parser.add<IntOption> (0x0, "width", "Width of the captured image [default: %1]", "160", 160, 4096);
|
||||
IntOption & argHeight = parser.add<IntOption> (0x0, "height", "Height of the captured image [default: %1]", "160", 160, 4096);
|
||||
BooleanOption & argScreenshot = parser.add<BooleanOption> (0x0, "screenshot", "Take a single screenshot, save it to file and quit");
|
||||
Option & argAddress = parser.add<Option> ('a', "address", "Set the address of the hyperion server [default: %1]", "127.0.0.1:19445");
|
||||
IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (the lower the number, the higher the priority) [default: %1]", "800");
|
||||
BooleanOption & argSkipReply = parser.add<BooleanOption> (0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
|
||||
BooleanOption & argHelp = parser.add<BooleanOption> ('h', "help", "Show this help message and exit");
|
||||
|
||||
// parse all options
|
||||
optionParser.parse(argc, const_cast<const char **>(argv));
|
||||
parser.process(app);
|
||||
|
||||
// check if we need to display the usage. exit if we do.
|
||||
if (argHelp.isSet())
|
||||
if (parser.isSet(argHelp))
|
||||
{
|
||||
optionParser.usage();
|
||||
return 0;
|
||||
parser.showHelp(0);
|
||||
}
|
||||
|
||||
int width = argWidth.getValue();
|
||||
int height = argHeight.getValue();
|
||||
if (width < 160 || height < 160)
|
||||
{
|
||||
Warning(Logger::getInstance("FRAMEBUFFER"), "Minimum width and height is 160");
|
||||
width = std::max(160, width);
|
||||
height = std::max(160, height);
|
||||
}
|
||||
|
||||
int grabInterval = 1000 / argFps.getValue();
|
||||
FramebufferWrapper fbWrapper(argDevice.getValue(), argWidth.getValue(), argHeight.getValue(), grabInterval);
|
||||
FramebufferWrapper fbWrapper(argDevice.getStdString(parser), argWidth.getInt(parser), argHeight.getInt(parser), 1000 / argFps.getInt(parser));
|
||||
|
||||
if (argScreenshot.isSet())
|
||||
if (parser.isSet(argScreenshot))
|
||||
{
|
||||
// Capture a single screenshot and finish
|
||||
const Image<ColorRgb> & screenshot = fbWrapper.getScreenshot();
|
||||
@ -79,7 +57,7 @@ int main(int argc, char ** argv)
|
||||
else
|
||||
{
|
||||
// Create the Proto-connection with hyperiond
|
||||
ProtoConnectionWrapper protoWrapper(argAddress.getValue(), argPriority.getValue(), 1000, argSkipReply.isSet());
|
||||
ProtoConnectionWrapper protoWrapper(argAddress.value(parser), argPriority.getInt(parser), 1000, parser.isSet(argSkipReply));
|
||||
|
||||
// Connect the screen capturing to the proto processing
|
||||
QObject::connect(&fbWrapper, SIGNAL(sig_screenshot(const Image<ColorRgb> &)), &protoWrapper, SLOT(receiveImage(Image<ColorRgb>)));
|
||||
|
@ -30,7 +30,7 @@ add_executable( ${PROJECT_NAME}
|
||||
)
|
||||
|
||||
target_link_libraries( ${PROJECT_NAME}
|
||||
getoptPlusPlus
|
||||
commandline
|
||||
blackborder
|
||||
hyperion-utils
|
||||
protoserver
|
||||
|
@ -4,16 +4,14 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QImage>
|
||||
|
||||
// getoptPlusPLus includes
|
||||
#include <getoptPlusPlus/getoptpp.h>
|
||||
|
||||
#include <protoserver/ProtoConnectionWrapper.h>
|
||||
#include "OsxWrapper.h"
|
||||
#include <commandline/Parser.h>
|
||||
|
||||
using namespace vlofgren;
|
||||
using namespace commandline;
|
||||
|
||||
// save the image as screenshot
|
||||
void saveScreenshot(const char * filename, const Image<ColorRgb> & image)
|
||||
void saveScreenshot(QString filename, const Image<ColorRgb> & image)
|
||||
{
|
||||
// store as PNG
|
||||
QImage pngImage((const uint8_t *) image.memptr(), image.width(), image.height(), 3*image.width(), QImage::Format_RGB888);
|
||||
@ -27,69 +25,53 @@ int main(int argc, char ** argv)
|
||||
try
|
||||
{
|
||||
// create the option parser and initialize all parameters
|
||||
OptionsParser optionParser("OSX capture application for Hyperion");
|
||||
ParameterSet & parameters = optionParser.getParameters();
|
||||
Parser parser("OSX capture application for Hyperion");
|
||||
|
||||
IntParameter & argDisplay = parameters.add<IntParameter> ('d', "display", "Set the display to capture [default: 0]");
|
||||
IntParameter & argFps = parameters.add<IntParameter> ('f', "framerate", "Capture frame rate [default: 10]");
|
||||
IntParameter & argWidth = parameters.add<IntParameter> (0x0, "width", "Width of the captured image [default: 128]");
|
||||
IntParameter & argHeight = parameters.add<IntParameter> (0x0, "height", "Height of the captured image [default: 128]");
|
||||
SwitchParameter<> & argScreenshot = parameters.add<SwitchParameter<>> (0x0, "screenshot", "Take a single screenshot, save it to file and quit");
|
||||
StringParameter & argAddress = parameters.add<StringParameter> ('a', "address", "Set the address of the hyperion server [default: 127.0.0.1:19445]");
|
||||
IntParameter & argPriority = parameters.add<IntParameter> ('p', "priority", "Use the provided priority channel (the lower the number, the higher the priority) [default: 800]");
|
||||
SwitchParameter<> & argSkipReply = parameters.add<SwitchParameter<>> (0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
|
||||
SwitchParameter<> & argHelp = parameters.add<SwitchParameter<>> ('h', "help", "Show this help message and exit");
|
||||
Option & argDisplay = parser.add<Option> ('d', "display", "Set the display to capture [default: %1]");
|
||||
IntOption & argFps = parser.add<IntOption> ('f', "framerate", "Capture frame rate [default: %1]", "10", 1, 600);
|
||||
IntOption & argWidth = parser.add<IntOption> (0x0, "width", "Width of the captured image [default: %1]", "160", 160, 4096);
|
||||
IntOption & argHeight = parser.add<IntOption> (0x0, "height", "Height of the captured image [default: %1]", "160", 160, 4096);
|
||||
BooleanOption & argScreenshot = parser.add<BooleanOption> (0x0, "screenshot", "Take a single screenshot, save it to file and quit");
|
||||
Option & argAddress = parser.add<Option> ('a', "address", "Set the address of the hyperion server [default: %1]", "127.0.0.1:19445");
|
||||
IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (the lower the number, the higher the priority) [default: %1]", "800");
|
||||
BooleanOption & argSkipReply = parser.add<BooleanOption> (0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
|
||||
BooleanOption & argHelp = parser.add<BooleanOption> ('h', "help", "Show this help message and exit");
|
||||
|
||||
// set defaults
|
||||
argFps.setDefault(10);
|
||||
argWidth.setDefault(160);
|
||||
argHeight.setDefault(160);
|
||||
argAddress.setDefault("127.0.0.1:19445");
|
||||
argPriority.setDefault(800);
|
||||
argDisplay.setDefault(0);
|
||||
|
||||
// parse all options
|
||||
optionParser.parse(argc, const_cast<const char **>(argv));
|
||||
// parse all arguments
|
||||
parser.process(app);
|
||||
|
||||
// check if we need to display the usage. exit if we do.
|
||||
if (argHelp.isSet())
|
||||
if (parser.isSet(argHelp))
|
||||
{
|
||||
optionParser.usage();
|
||||
return 0;
|
||||
parser.showHelp(0);
|
||||
}
|
||||
|
||||
int width = argWidth.getValue();
|
||||
int height = argHeight.getValue();
|
||||
if (width < 160 || height < 160)
|
||||
{
|
||||
Warning(Logger::getInstance("OSXGRABBER"), "Minimum width and height is 160");
|
||||
width = std::max(160, width);
|
||||
height = std::max(160, height);
|
||||
}
|
||||
|
||||
int grabInterval = 1000 / argFps.getValue();
|
||||
OsxWrapper osxWrapper(argDisplay.getValue(), argWidth.getValue(), argHeight.getValue(), grabInterval);
|
||||
OsxWrapper osxWrapper
|
||||
(parser.isSet(argDisplay), argWidth.getInt(parser), argHeight.getInt(parser), 1000 / argFps.getInt(parser));
|
||||
|
||||
if (argScreenshot.isSet())
|
||||
{
|
||||
// Capture a single screenshot and finish
|
||||
const Image<ColorRgb> & screenshot = osxWrapper.getScreenshot();
|
||||
saveScreenshot("screenshot.png", screenshot);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create the Proto-connection with hyperiond
|
||||
ProtoConnectionWrapper protoWrapper(argAddress.getValue(), argPriority.getValue(), 1000, argSkipReply.isSet());
|
||||
if (parser.isSet(argScreenshot)) {
|
||||
// Capture a single screenshot and finish
|
||||
const Image<ColorRgb> &screenshot = osxWrapper.getScreenshot();
|
||||
saveScreenshot("screenshot.png", screenshot);
|
||||
}
|
||||
else {
|
||||
// Create the Proto-connection with hyperiond
|
||||
ProtoConnectionWrapper protoWrapper
|
||||
(argAddress.value(parser), argPriority.getInt(parser), 1000, parser.isSet(argSkipReply));
|
||||
|
||||
// Connect the screen capturing to the proto processing
|
||||
QObject::connect(&osxWrapper, SIGNAL(sig_screenshot(const Image<ColorRgb> &)), &protoWrapper, SLOT(receiveImage(Image<ColorRgb>)));
|
||||
// Connect the screen capturing to the proto processing
|
||||
QObject::connect(&osxWrapper,
|
||||
SIGNAL(sig_screenshot(
|
||||
const Image<ColorRgb> &)),
|
||||
&protoWrapper,
|
||||
SLOT(receiveImage(Image<ColorRgb>)));
|
||||
|
||||
// Start the capturing
|
||||
osxWrapper.start();
|
||||
// Start the capturing
|
||||
osxWrapper.start();
|
||||
|
||||
// Start the application
|
||||
app.exec();
|
||||
}
|
||||
// Start the application
|
||||
app.exec();
|
||||
}
|
||||
}
|
||||
catch (const std::runtime_error & e)
|
||||
{
|
||||
|
@ -15,9 +15,7 @@ ENDIF()
|
||||
include_directories(${QT_INCLUDES})
|
||||
|
||||
set(hyperion-remote_HEADERS
|
||||
CustomParameter.h
|
||||
JsonConnection.h
|
||||
ColorTransformValues.h)
|
||||
JsonConnection.h)
|
||||
|
||||
set(hyperion-remote_SOURCES
|
||||
hyperion-remote.cpp
|
||||
@ -28,8 +26,8 @@ add_executable(${PROJECT_NAME}
|
||||
${hyperion-remote_SOURCES})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
commandline
|
||||
jsoncpp
|
||||
getoptPlusPlus
|
||||
${QT_LIBRARIES})
|
||||
|
||||
qt5_use_modules(${PROJECT_NAME} Gui Core Network)
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user