mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Merge branch 'master' of https://github.com/penfold42/hyperion
merge to local Former-commit-id: ebba9a31b2139201b75dc098eba8c8ee9d630ebf
This commit is contained in:
commit
3bd03e73ff
@ -37,6 +37,9 @@ message(STATUS "ENABLE_WS2812BPWM = " ${ENABLE_WS2812BPWM})
|
|||||||
option(ENABLE_X11 "Enable the X11 grabber" OFF)
|
option(ENABLE_X11 "Enable the X11 grabber" OFF)
|
||||||
message(STATUS "ENABLE_X11 = " ${ENABLE_X11})
|
message(STATUS "ENABLE_X11 = " ${ENABLE_X11})
|
||||||
|
|
||||||
|
option(ENABLE_QT5 "Enable QT5" OFF)
|
||||||
|
message(STATUS "ENABLE_QT5 = " ${ENABLE_QT5})
|
||||||
|
|
||||||
if(ENABLE_V4L2 AND NOT ENABLE_PROTOBUF)
|
if(ENABLE_V4L2 AND NOT ENABLE_PROTOBUF)
|
||||||
message(FATAL_ERROR "V4L2 grabber requires PROTOBUF. Disable V4L2 or enable PROTOBUF")
|
message(FATAL_ERROR "V4L2 grabber requires PROTOBUF. Disable V4L2 or enable PROTOBUF")
|
||||||
endif(ENABLE_V4L2 AND NOT ENABLE_PROTOBUF)
|
endif(ENABLE_V4L2 AND NOT ENABLE_PROTOBUF)
|
||||||
@ -53,6 +56,10 @@ if(ENABLE_OSX AND ENABLE_DISPMANX)
|
|||||||
message(FATAL_ERROR "dispmanx grabber and osx grabber cannot be used at the same time")
|
message(FATAL_ERROR "dispmanx grabber and osx grabber cannot be used at the same time")
|
||||||
endif(ENABLE_OSX AND ENABLE_DISPMANX)
|
endif(ENABLE_OSX AND ENABLE_DISPMANX)
|
||||||
|
|
||||||
|
#if(ENABLE_QT5)
|
||||||
|
# TODO vs ENABLE_QT4?
|
||||||
|
#endif(ENABLE_QT5)
|
||||||
|
|
||||||
# Createt the configuration file
|
# Createt the configuration file
|
||||||
# configure a header file to pass some of the CMake settings
|
# configure a header file to pass some of the CMake settings
|
||||||
# to the source code
|
# to the source code
|
||||||
@ -61,8 +68,14 @@ include_directories("${PROJECT_BINARY_DIR}")
|
|||||||
|
|
||||||
# Add project specific cmake modules (find, etc)
|
# Add project specific cmake modules (find, etc)
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
ADD_DEFINITIONS ( -DENABLE_QT5 )
|
||||||
|
#find_package(Qt5Widgets)
|
||||||
|
else(ENABLE_QT5)
|
||||||
# Add specific cmake modules to find qt4 (default version finds first available QT which might not be qt4)
|
# Add specific cmake modules to find qt4 (default version finds first available QT which might not be qt4)
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/qt4)
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/qt4)
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
# Define the global output path of binaries
|
# Define the global output path of binaries
|
||||||
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
|
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
|
||||||
@ -85,15 +98,27 @@ set(CMAKE_BUILD_TYPE "Debug")
|
|||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall")
|
||||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -std=c++11 -Wall")
|
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -std=c++11 -Wall")
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
#find_package(Qt5Core REQUIRED)
|
||||||
|
find_package(Qt5 COMPONENTS Core Gui Widgets Network REQUIRED)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
|
||||||
|
# set(CMAKE_CXX_FLAGS "-fPIC")
|
||||||
|
else(ENABLE_QT5)
|
||||||
# Configure the use of QT4
|
# Configure the use of QT4
|
||||||
find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork REQUIRED QUIET)
|
find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork REQUIRED QUIET)
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
#add libusb and pthreads
|
#add libusb and pthreads
|
||||||
find_package(libusb-1.0 REQUIRED)
|
find_package(libusb-1.0 REQUIRED)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
#include(${QT_USE_FILE})
|
||||||
|
add_definitions(${QT_DEFINITIONS})
|
||||||
|
else(ENABLE_QT5)
|
||||||
include(${QT_USE_FILE})
|
include(${QT_USE_FILE})
|
||||||
add_definitions(${QT_DEFINITIONS})
|
add_definitions(${QT_DEFINITIONS})
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
# TODO[TvdZ]: This linking directory should only be added if we are cross compiling
|
# TODO[TvdZ]: This linking directory should only be added if we are cross compiling
|
||||||
if(NOT APPLE)
|
if(NOT APPLE)
|
||||||
link_directories(${CMAKE_FIND_ROOT_PATH}/lib/arm-linux-gnueabihf)
|
link_directories(${CMAKE_FIND_ROOT_PATH}/lib/arm-linux-gnueabihf)
|
||||||
|
@ -355,15 +355,30 @@
|
|||||||
/// The black border configuration, contains the following items:
|
/// The black border configuration, contains the following items:
|
||||||
/// * enable : true if the detector should be activated
|
/// * enable : true if the detector should be activated
|
||||||
/// * threshold : Value below which a pixel is regarded as black (value between 0.0 and 1.0)
|
/// * threshold : Value below which a pixel is regarded as black (value between 0.0 and 1.0)
|
||||||
|
/// * unknownFrameCnt : Number of frames without any detection before the border is set to 0 (default 600) - optional
|
||||||
|
/// * borderFrameCnt : Number of frames before a consistent detected border gets set (default 50) - optional
|
||||||
|
/// * maxInconsistentCnt : Number of inconsistent frames that are ignored before a new border gets a chance to proof consistency - optional
|
||||||
|
/// * blurRemoveCnt : Number of pixels that get removed from the detected border to cut away blur (default 1) - optional
|
||||||
|
/// * mode : Border detection mode (values "default","classic","osd") - optional
|
||||||
|
|
||||||
"blackborderdetector" :
|
"blackborderdetector" :
|
||||||
{
|
{
|
||||||
"enable" : true,
|
"enable" : true,
|
||||||
"threshold" : 0.01
|
"threshold" : 0.01,
|
||||||
|
"unknownFrameCnt": 600,
|
||||||
|
"borderFrameCnt" : 50,
|
||||||
|
"maxInconsistentCnt" : 10,
|
||||||
|
"blurRemoveCnt": 1,
|
||||||
|
"mode" : "default"
|
||||||
},
|
},
|
||||||
|
|
||||||
/// The configuration of the effect engine, contains the following items:
|
/// The configuration of the effect engine, contains the following items:
|
||||||
/// * paths : An array with absolute location(s) of directories with effects
|
/// * paths : An array with absolute location(s) of directories with effects
|
||||||
/// * bootsequence : The effect selected as 'boot sequence'
|
/// * bootsequence : The effect selected as 'boot sequence'
|
||||||
|
/// * effect : name of the effect you want to start. Set to empty if no effect wanted
|
||||||
|
/// * color : switch to static color after effect is done
|
||||||
|
/// * duration_ms : duration of boot effect in ms. 0 means effect stays forever
|
||||||
|
/// * priority : priority of boot effect and static color
|
||||||
"effects" :
|
"effects" :
|
||||||
{
|
{
|
||||||
"paths" :
|
"paths" :
|
||||||
@ -374,8 +389,10 @@
|
|||||||
|
|
||||||
"bootsequence" :
|
"bootsequence" :
|
||||||
{
|
{
|
||||||
"effect" : "Rainbow swirl fast",
|
"color" : [0,0,0],
|
||||||
"duration_ms" : 3000
|
"effect" : "Rainbow swirl fast",
|
||||||
|
"duration_ms" : 3000,
|
||||||
|
"priority" : 0
|
||||||
},
|
},
|
||||||
|
|
||||||
/// The configuration for the frame-grabber, contains the following items:
|
/// The configuration for the frame-grabber, contains the following items:
|
||||||
|
@ -359,6 +359,10 @@
|
|||||||
/// The configuration of the effect engine, contains the following items:
|
/// The configuration of the effect engine, contains the following items:
|
||||||
/// * paths : An array with absolute location(s) of directories with effects
|
/// * paths : An array with absolute location(s) of directories with effects
|
||||||
/// * bootsequence : The effect selected as 'boot sequence'
|
/// * bootsequence : The effect selected as 'boot sequence'
|
||||||
|
/// * effect : name of the effect you want to start. Set to empty if no effect wanted
|
||||||
|
/// * color : switch to static color after effect is done
|
||||||
|
/// * duration_ms : duration of boot effect in ms. 0 means effect stays forever
|
||||||
|
/// * priority : priority of boot effect and static color
|
||||||
"effects" :
|
"effects" :
|
||||||
{
|
{
|
||||||
"paths" :
|
"paths" :
|
||||||
@ -369,8 +373,10 @@
|
|||||||
|
|
||||||
"bootsequence" :
|
"bootsequence" :
|
||||||
{
|
{
|
||||||
"effect" : "Rainbow swirl fast",
|
"color" : [0,0,0],
|
||||||
"duration_ms" : 3000
|
"effect" : "Rainbow swirl fast",
|
||||||
|
"duration_ms" : 3000,
|
||||||
|
"priority" : 900
|
||||||
},
|
},
|
||||||
|
|
||||||
/// The configuration for the frame-grabber, contains the following items:
|
/// The configuration for the frame-grabber, contains the following items:
|
||||||
|
BIN
dependencies/LightberryHDUSBAPA1021.1.zip
vendored
Normal file
BIN
dependencies/LightberryHDUSBAPA1021.1.zip
vendored
Normal file
Binary file not shown.
274
dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino
vendored
Normal file
274
dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino
vendored
Normal file
@ -0,0 +1,274 @@
|
|||||||
|
// Arduino "bridge" code between host computer and WS2801-based digital
|
||||||
|
// RGB LED pixels (e.g. Adafruit product ID #322). Intended for use
|
||||||
|
// with USB-native boards such as Teensy or Adafruit 32u4 Breakout;
|
||||||
|
// works on normal serial Arduinos, but throughput is severely limited.
|
||||||
|
// LED data is streamed, not buffered, making this suitable for larger
|
||||||
|
// installations (e.g. video wall, etc.) than could otherwise be held
|
||||||
|
// in the Arduino's limited RAM.
|
||||||
|
|
||||||
|
// Some effort is put into avoiding buffer underruns (where the output
|
||||||
|
// side becomes starved of data). The WS2801 latch protocol, being
|
||||||
|
// delay-based, could be inadvertently triggered if the USB bus or CPU
|
||||||
|
// is swamped with other tasks. This code buffers incoming serial data
|
||||||
|
// and introduces intentional pauses if there's a threat of the buffer
|
||||||
|
// draining prematurely. The cost of this complexity is somewhat
|
||||||
|
// reduced throughput, the gain is that most visual glitches are
|
||||||
|
// avoided (though ultimately a function of the load on the USB bus and
|
||||||
|
// host CPU, and out of our control).
|
||||||
|
|
||||||
|
// LED data and clock lines are connected to the Arduino's SPI output.
|
||||||
|
// On traditional Arduino boards, SPI data out is digital pin 11 and
|
||||||
|
// clock is digital pin 13. On both Teensy and the 32u4 Breakout,
|
||||||
|
// data out is pin B2, clock is B1. LEDs should be externally
|
||||||
|
// powered -- trying to run any more than just a few off the Arduino's
|
||||||
|
// 5V line is generally a Bad Idea. LED ground should also be
|
||||||
|
// connected to Arduino ground.
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
// This file is part of Adalight.
|
||||||
|
|
||||||
|
// Adalight is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of
|
||||||
|
// the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
// Adalight 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 Lesser General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with Adalight. If not, see
|
||||||
|
// <http://www.gnu.org/licenses/>.
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
// LED pin for Adafruit 32u4 Breakout Board:
|
||||||
|
//#define LED_DDR DDRE
|
||||||
|
//#define LED_PORT PORTE
|
||||||
|
//#define LED_PIN _BV(PORTE6)
|
||||||
|
// LED pin for Teensy:
|
||||||
|
//#define LED_DDR DDRD
|
||||||
|
//#define LED_PORT PORTD
|
||||||
|
//#define LED_PIN _BV(PORTD6)
|
||||||
|
// LED pin for Arduino:
|
||||||
|
#define LED_DDR DDRB
|
||||||
|
#define LED_PORT PORTB
|
||||||
|
#define LED_PIN _BV(PORTB5)
|
||||||
|
|
||||||
|
// A 'magic word' (along with LED count & checksum) precedes each block
|
||||||
|
// of LED data; this assists the microcontroller in syncing up with the
|
||||||
|
// host-side software and properly issuing the latch (host I/O is
|
||||||
|
// likely buffered, making usleep() unreliable for latch). You may see
|
||||||
|
// an initial glitchy frame or two until the two come into alignment.
|
||||||
|
// The magic word can be whatever sequence you like, but each character
|
||||||
|
// should be unique, and frequent pixel values like 0 and 255 are
|
||||||
|
// avoided -- fewer false positives. The host software will need to
|
||||||
|
// generate a compatible header: immediately following the magic word
|
||||||
|
// are three bytes: a 16-bit count of the number of LEDs (high byte
|
||||||
|
// first) followed by a simple checksum value (high byte XOR low byte
|
||||||
|
// XOR 0x55). LED data follows, 3 bytes per LED, in order R, G, B,
|
||||||
|
// where 0 = off and 255 = max brightness.
|
||||||
|
|
||||||
|
static const uint8_t magic[] = {'A', 'd', 'a'};
|
||||||
|
#define MAGICSIZE sizeof(magic)
|
||||||
|
#define HEADERSIZE (MAGICSIZE + 3)
|
||||||
|
|
||||||
|
#define MODE_HEADER 0
|
||||||
|
#define MODE_HOLD 1
|
||||||
|
#define MODE_DATA 2
|
||||||
|
|
||||||
|
#define DATA_LED A5
|
||||||
|
#define SPI_LED A3
|
||||||
|
|
||||||
|
// If no serial data is received for a while, the LEDs are shut off
|
||||||
|
// automatically. This avoids the annoying "stuck pixel" look when
|
||||||
|
// quitting LED display programs on the host computer.
|
||||||
|
static const unsigned long serialTimeout = 15000; // 15 seconds
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
// Dirty trick: the circular buffer for serial data is 256 bytes,
|
||||||
|
// and the "in" and "out" indices are unsigned 8-bit types -- this
|
||||||
|
// much simplifies the cases where in/out need to "wrap around" the
|
||||||
|
// beginning/end of the buffer. Otherwise there'd be a ton of bit-
|
||||||
|
// masking and/or conditional code every time one of these indices
|
||||||
|
// needs to change, slowing things down tremendously.
|
||||||
|
uint8_t
|
||||||
|
buffer[256],
|
||||||
|
indexIn = 0,
|
||||||
|
indexOut = 0,
|
||||||
|
mode = MODE_HEADER,
|
||||||
|
hi, lo, chk, i, spiFlag;
|
||||||
|
int16_t
|
||||||
|
bytesBuffered = 0,
|
||||||
|
hold = 0,
|
||||||
|
c;
|
||||||
|
int32_t
|
||||||
|
bytesRemaining;
|
||||||
|
unsigned long
|
||||||
|
startTime,
|
||||||
|
lastByteTime,
|
||||||
|
lastAckTime,
|
||||||
|
t;
|
||||||
|
bool
|
||||||
|
data_in_led = false,
|
||||||
|
spi_out_led = false;
|
||||||
|
|
||||||
|
LED_DDR |= LED_PIN; // Enable output for LED
|
||||||
|
LED_PORT &= ~LED_PIN; // LED off
|
||||||
|
pinMode(DATA_LED, OUTPUT); //data in led
|
||||||
|
pinMode(SPI_LED, OUTPUT); //data out led
|
||||||
|
|
||||||
|
Serial.begin(115200); // Teensy/32u4 disregards baud rate; is OK!
|
||||||
|
|
||||||
|
SPI.begin();
|
||||||
|
SPI.setBitOrder(MSBFIRST);
|
||||||
|
SPI.setDataMode(SPI_MODE0);
|
||||||
|
SPI.setClockDivider(SPI_CLOCK_DIV8); // 2Mhz
|
||||||
|
|
||||||
|
// Issue test pattern to LEDs on startup. This helps verify that
|
||||||
|
// wiring between the Arduino and LEDs is correct. Not knowing the
|
||||||
|
// actual number of LEDs connected, this sets all of them (well, up
|
||||||
|
// to the first 25,000, so as not to be TOO time consuming) to red,
|
||||||
|
// green, blue, then off. Once you're confident everything is working
|
||||||
|
// end-to-end, it's OK to comment this out and reprogram the Arduino.
|
||||||
|
uint8_t testcolor[] = { 0, 0, 0, 255, 0, 0 };
|
||||||
|
for (char n = 3; n >= 0; n--) {
|
||||||
|
for (int i = 0; i < 4; i++) { //Start Frame
|
||||||
|
for (SPDR = 0x00; !(SPSR & _BV(SPIF)); );
|
||||||
|
}
|
||||||
|
for (c = 0; c < 25000; c++) {
|
||||||
|
for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness byte
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
for (SPDR = testcolor[n + i]; !(SPSR & _BV(SPIF)); ); //BGR
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 4; i++) { //Stop Frame
|
||||||
|
for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); );
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(1); // One millisecond pause = latch
|
||||||
|
}
|
||||||
|
digitalWrite(SPI_LED, spi_out_led = !spi_out_led);
|
||||||
|
|
||||||
|
Serial.print("Ada\n"); // Send ACK string to host
|
||||||
|
|
||||||
|
startTime = micros();
|
||||||
|
lastByteTime = lastAckTime = millis();
|
||||||
|
|
||||||
|
// loop() is avoided as even that small bit of function overhead
|
||||||
|
// has a measurable impact on this code's overall throughput.
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
digitalWrite(DATA_LED, LOW);
|
||||||
|
digitalWrite(SPI_LED, LOW);
|
||||||
|
// Implementation is a simple finite-state machine.
|
||||||
|
// Regardless of mode, check for serial input each time:
|
||||||
|
t = millis();
|
||||||
|
if ((bytesBuffered < 256) && ((c = Serial.read()) >= 0)) {
|
||||||
|
buffer[indexIn++] = c;
|
||||||
|
bytesBuffered++;
|
||||||
|
lastByteTime = lastAckTime = t; // Reset timeout counters
|
||||||
|
} else {
|
||||||
|
// No data received. If this persists, send an ACK packet
|
||||||
|
// to host once every second to alert it to our presence.
|
||||||
|
if ((t - lastAckTime) > 1000) {
|
||||||
|
Serial.print("Ada\n"); // Send ACK string to host
|
||||||
|
lastAckTime = t; // Reset counter
|
||||||
|
}
|
||||||
|
// If no data received for an extended time, turn off all LEDs.
|
||||||
|
if ((t - lastByteTime) > serialTimeout) {
|
||||||
|
for (i = 0; i < 4; i++) { //Start Frame
|
||||||
|
for (SPDR = 0x00; !(SPSR & _BV(SPIF)); );
|
||||||
|
}
|
||||||
|
for (c = 0; c < 25000; c++) {
|
||||||
|
for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness Byte
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
for (SPDR = 0x00; !(SPSR & _BV(SPIF)); ); //BGR
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i = 0; i < 4; i++) { //Stop Frame
|
||||||
|
for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); );
|
||||||
|
}
|
||||||
|
delay(1); // One millisecond pause = latch
|
||||||
|
lastByteTime = t; // Reset counter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (mode) {
|
||||||
|
|
||||||
|
case MODE_HEADER:
|
||||||
|
|
||||||
|
// In header-seeking mode. Is there enough data to check?
|
||||||
|
if (bytesBuffered >= HEADERSIZE) {
|
||||||
|
// Indeed. Check for a 'magic word' match.
|
||||||
|
for (i = 0; (i < MAGICSIZE) && (buffer[indexOut++] == magic[i++]););
|
||||||
|
if (i == MAGICSIZE) {
|
||||||
|
// Magic word matches. Now how about the checksum?
|
||||||
|
hi = buffer[indexOut++];
|
||||||
|
lo = buffer[indexOut++];
|
||||||
|
chk = buffer[indexOut++];
|
||||||
|
if (chk == (hi ^ lo ^ 0x55)) {
|
||||||
|
// Checksum looks valid. Get 16-bit LED count, add 1
|
||||||
|
// (# LEDs is always > 0) and multiply by 3 for R,G,B.
|
||||||
|
bytesRemaining = 4L * (256L * (long)hi + (long)lo) + 4L + (256L * (long)hi + (long)lo + 15) / 16;
|
||||||
|
bytesBuffered -= 3;
|
||||||
|
spiFlag = 0; // No data out yet
|
||||||
|
mode = MODE_HOLD; // Proceed to latch wait mode
|
||||||
|
digitalWrite(DATA_LED, data_in_led = !data_in_led);
|
||||||
|
} else {
|
||||||
|
// Checksum didn't match; search resumes after magic word.
|
||||||
|
indexOut -= 3; // Rewind
|
||||||
|
}
|
||||||
|
} // else no header match. Resume at first mismatched byte.
|
||||||
|
bytesBuffered -= i;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MODE_HOLD:
|
||||||
|
|
||||||
|
// Ostensibly "waiting for the latch from the prior frame
|
||||||
|
// to complete" mode, but may also revert to this mode when
|
||||||
|
// underrun prevention necessitates a delay.
|
||||||
|
|
||||||
|
if ((micros() - startTime) < hold) break; // Still holding; keep buffering
|
||||||
|
|
||||||
|
// Latch/delay complete. Advance to data-issuing mode...
|
||||||
|
LED_PORT &= ~LED_PIN; // LED off
|
||||||
|
mode = MODE_DATA; // ...and fall through (no break):
|
||||||
|
|
||||||
|
case MODE_DATA:
|
||||||
|
digitalWrite(SPI_LED, spi_out_led = !spi_out_led);
|
||||||
|
while (spiFlag && !(SPSR & _BV(SPIF))); // Wait for prior byte
|
||||||
|
if (bytesRemaining > 0) {
|
||||||
|
if (bytesBuffered > 0) {
|
||||||
|
SPDR = buffer[indexOut++]; // Issue next byte
|
||||||
|
bytesBuffered--;
|
||||||
|
bytesRemaining--;
|
||||||
|
spiFlag = 1;
|
||||||
|
}
|
||||||
|
// If serial buffer is threatening to underrun, start
|
||||||
|
// introducing progressively longer pauses to allow more
|
||||||
|
// data to arrive (up to a point).
|
||||||
|
if ((bytesBuffered < 32) && (bytesRemaining > bytesBuffered)) {
|
||||||
|
startTime = micros();
|
||||||
|
hold = 100 + (32 - bytesBuffered) * 10;
|
||||||
|
mode = MODE_HOLD;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// End of data -- issue latch:
|
||||||
|
startTime = micros();
|
||||||
|
hold = 1000; // Latch duration = 1000 uS
|
||||||
|
LED_PORT |= LED_PIN; // LED on
|
||||||
|
mode = MODE_HEADER; // Begin next header search
|
||||||
|
}
|
||||||
|
} // end switch
|
||||||
|
} // end for(;;)
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
// Not used. See note in setup() function.
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
3785db40d7232275fbc00b20e627280e0e057f99
|
471d676fb66aa53e3b10d887a1d9e6d3b4afea90
|
@ -1 +1 @@
|
|||||||
0769228a95e4a0d4b2ed6649f21ddf70b43773d6
|
5c164e4ff52076a530461cdf6966943d52cd39df
|
@ -1 +1 @@
|
|||||||
7e53ee35b7258e7d58d96514701a50014a98da31
|
d2bf44cca4e7753b53acc2ebbdb933ba8f74f93f
|
@ -1 +1 @@
|
|||||||
36d03bb18626fa0faea8aabf6426e571eab4f719
|
7936b39302bec31b18f11a321ba6904c12b5c3ec
|
@ -1 +1 @@
|
|||||||
6f86ceeb6650e527d179cf7153e0beada3b73889
|
774c67bd8e4e46d2ebf9c223a38fdfd93cae1100
|
79
doc/datasheets/fadecandy_opc_protocol.md
Normal file
79
doc/datasheets/fadecandy_opc_protocol.md
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
Fadecandy: Open Pixel Control Protocol
|
||||||
|
======================================
|
||||||
|
|
||||||
|
The Fadecandy Server (`fcserver`) operates as a bridge between LED controllers attached over USB, and visual effects that communicate via a TCP socket.
|
||||||
|
|
||||||
|
The primary protocol supported by `fcserver` is [Open Pixel Control](http://openpixelcontrol.org), a super simple way to send RGB values over a socket. We support the standard Open Pixel Control commands, as well as some Fadecandy extensions.
|
||||||
|
|
||||||
|
Socket
|
||||||
|
------
|
||||||
|
|
||||||
|
Open Pixel Control uses a TCP socket, by default on port 7890. For the best performance, remember to set TCP_NODELAY socket option.
|
||||||
|
|
||||||
|
Command Format
|
||||||
|
--------------
|
||||||
|
|
||||||
|
All OPC commands follow the same general format. All multi-byte values in Open Pixel Control are in network byte order, high byte followed by low byte.
|
||||||
|
|
||||||
|
Channel | Command | Length (N) | Data
|
||||||
|
---------- | --------- | ---------- | --------------------------
|
||||||
|
1 byte | 1 byte | 2 bytes | N bytes of message data
|
||||||
|
|
||||||
|
Set Pixel Colors
|
||||||
|
----------------
|
||||||
|
|
||||||
|
Video data arrives in a **Set Pixel Colors** command:
|
||||||
|
|
||||||
|
Byte | **Set Pixel Colors** command
|
||||||
|
------ | --------------------------------
|
||||||
|
0 | Channel Number
|
||||||
|
1 | Command (0x00)
|
||||||
|
2 - 3 | Data length
|
||||||
|
4 | Pixel #0, Red
|
||||||
|
5 | Pixel #0, Green
|
||||||
|
6 | Pixel #0, Blue
|
||||||
|
7 | Pixel #1, Red
|
||||||
|
8 | Pixel #1, Green
|
||||||
|
9 | Pixel #1, Blue
|
||||||
|
… | …
|
||||||
|
|
||||||
|
As soon as a complete Set Pixel Colors command is received, a new frame of video will be broadcast simultaneously to all attached Fadecandy devices.
|
||||||
|
|
||||||
|
Set Global Color Correction
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
The color correction data (from the 'color' configuration key) can also be changed at runtime, by sending a new blob of JSON text in a Fadecandy-specific command. Fadecandy's 16-bit System ID for Open Pixel Control's System Exclusive (0xFF) command is **0x0001**.
|
||||||
|
|
||||||
|
Byte | **Set Global Color Correction** command
|
||||||
|
------ | ------------------------------------------
|
||||||
|
0 | Channel Number (0x00, reserved)
|
||||||
|
1 | Command (0xFF, System Exclusive)
|
||||||
|
2 - 3 | Data length (JSON Length + 4)
|
||||||
|
4 - 5 | System ID (0x0001, Fadecandy)
|
||||||
|
6 - 7 | SysEx ID (0x0001, Set Global Color Correction)
|
||||||
|
8 - … | JSON Text
|
||||||
|
|
||||||
|
Set Firmware Configuration
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
The firmware supports some runtime configuration options. Any OPC client can send a new firmware configuration packet using this command. If the supplied data is shorter than the firmware's configuration buffer, only the provided bytes will be changed.
|
||||||
|
|
||||||
|
Byte | **Set Firmware Configuration** command
|
||||||
|
------ | ------------------------------------------
|
||||||
|
0 | Channel Number (0x00, reserved)
|
||||||
|
1 | Command (0xFF, System Exclusive)
|
||||||
|
2 - 3 | Data length (Configuration Length + 4)
|
||||||
|
4 - 5 | System ID (0x0001, Fadecandy)
|
||||||
|
6 - 7 | SysEx ID (0x0002, Set Firmware Configuration)
|
||||||
|
8 - … | Configuration Data
|
||||||
|
|
||||||
|
Current firmwares support the following configuration options:
|
||||||
|
|
||||||
|
Byte Offset | Bits | Description
|
||||||
|
----------- | ------ | ------------
|
||||||
|
0 | 7 … 4 | (reserved)
|
||||||
|
0 | 3 | Manual LED control bit
|
||||||
|
0 | 2 | 0 = LED shows USB activity, 1 = LED under manual control
|
||||||
|
0 | 1 | Disable keyframe interpolation
|
||||||
|
0 | 0 | Disable dithering
|
||||||
|
1 … 62 | 7 … 0 | (reserved)
|
12
effects/police-lights-single.json
Normal file
12
effects/police-lights-single.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name" : "Police Lights Single",
|
||||||
|
"script" : "police.py",
|
||||||
|
"args" :
|
||||||
|
{
|
||||||
|
"rotation-time" : 1.5,
|
||||||
|
"color_one" : [ 255, 0, 0 ],
|
||||||
|
"color_two" : [ 0, 0, 255 ],
|
||||||
|
"colors_count" : 10,
|
||||||
|
"reverse" : false
|
||||||
|
}
|
||||||
|
}
|
11
effects/police-lights-solid.json
Normal file
11
effects/police-lights-solid.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name" : "Police Lights Solid",
|
||||||
|
"script" : "police.py",
|
||||||
|
"args" :
|
||||||
|
{
|
||||||
|
"rotation-time" : 1.0,
|
||||||
|
"color_one" : [ 255, 0, 0 ],
|
||||||
|
"color_two" : [ 0, 0, 255 ],
|
||||||
|
"reverse" : false
|
||||||
|
}
|
||||||
|
}
|
46
effects/police.py
Normal file
46
effects/police.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import hyperion
|
||||||
|
import time
|
||||||
|
import colorsys
|
||||||
|
|
||||||
|
# Get the parameters
|
||||||
|
rotationTime = float(hyperion.args.get('rotation-time', 2.0))
|
||||||
|
colorOne = hyperion.args.get('color_one', (255,0,0))
|
||||||
|
colorTwo = hyperion.args.get('color_two', (0,0,255))
|
||||||
|
colorsCount = hyperion.args.get('colors_count', hyperion.ledCount/2)
|
||||||
|
reverse = bool(hyperion.args.get('reverse', False))
|
||||||
|
|
||||||
|
# Check parameters
|
||||||
|
rotationTime = max(0.1, rotationTime)
|
||||||
|
colorsCount = min(hyperion.ledCount/2, colorsCount)
|
||||||
|
|
||||||
|
# Initialize the led data
|
||||||
|
hsv1 = colorsys.rgb_to_hsv(colorOne[0]/255.0, colorOne[1]/255.0, colorOne[2]/255.0)
|
||||||
|
hsv2 = colorsys.rgb_to_hsv(colorTwo[0]/255.0, colorTwo[1]/255.0, colorTwo[2]/255.0)
|
||||||
|
colorBlack = (0,0,0)
|
||||||
|
ledData = bytearray()
|
||||||
|
for i in range(hyperion.ledCount):
|
||||||
|
if i <= colorsCount:
|
||||||
|
rgb = colorsys.hsv_to_rgb(hsv1[0], hsv1[1], hsv1[2])
|
||||||
|
elif (i >= hyperion.ledCount/2-1) & (i < (hyperion.ledCount/2) + colorsCount):
|
||||||
|
rgb = colorsys.hsv_to_rgb(hsv2[0], hsv2[1], hsv2[2])
|
||||||
|
else:
|
||||||
|
rgb = colorBlack
|
||||||
|
ledData += bytearray((int(255*rgb[0]), int(255*rgb[1]), int(255*rgb[2])))
|
||||||
|
|
||||||
|
# Calculate the sleep time and rotation increment
|
||||||
|
increment = 3
|
||||||
|
sleepTime = rotationTime / hyperion.ledCount
|
||||||
|
while sleepTime < 0.05:
|
||||||
|
increment *= 2
|
||||||
|
sleepTime *= 2
|
||||||
|
increment %= hyperion.ledCount
|
||||||
|
|
||||||
|
# Switch direction if needed
|
||||||
|
if reverse:
|
||||||
|
increment = -increment
|
||||||
|
|
||||||
|
# Start the write data loop
|
||||||
|
while not hyperion.abort():
|
||||||
|
hyperion.setColor(ledData)
|
||||||
|
ledData = ledData[-increment:] + ledData[:-increment]
|
||||||
|
time.sleep(sleepTime)
|
8
effects/x-mas.json
Normal file
8
effects/x-mas.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name" : "X-Mas",
|
||||||
|
"script" : "x-mas.py",
|
||||||
|
"args" :
|
||||||
|
{
|
||||||
|
"sleepTime" : 0.75
|
||||||
|
}
|
||||||
|
}
|
28
effects/x-mas.py
Normal file
28
effects/x-mas.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import hyperion
|
||||||
|
import time
|
||||||
|
import colorsys
|
||||||
|
|
||||||
|
# Get the parameters
|
||||||
|
sleepTime = float(hyperion.args.get('sleepTime', 1.0))
|
||||||
|
|
||||||
|
# Initialize the led data
|
||||||
|
ledDataOdd = bytearray()
|
||||||
|
for i in range(hyperion.ledCount):
|
||||||
|
if i%2 == 0:
|
||||||
|
ledDataOdd += bytearray((int(255), int(0), int(0)))
|
||||||
|
else:
|
||||||
|
ledDataOdd += bytearray((int(255), int(255), int(255)))
|
||||||
|
|
||||||
|
ledDataEven = bytearray()
|
||||||
|
for i in range(hyperion.ledCount):
|
||||||
|
if i%2 == 0:
|
||||||
|
ledDataEven += bytearray((int(255), int(255), int(255)))
|
||||||
|
else:
|
||||||
|
ledDataEven += bytearray((int(255), int(0), int(0)))
|
||||||
|
|
||||||
|
# Start the write data loop
|
||||||
|
while not hyperion.abort():
|
||||||
|
hyperion.setColor(ledDataOdd)
|
||||||
|
time.sleep(sleepTime)
|
||||||
|
hyperion.setColor(ledDataEven)
|
||||||
|
time.sleep(sleepTime)
|
@ -49,7 +49,7 @@ namespace hyperion
|
|||||||
/// Constructs a black-border detector
|
/// Constructs a black-border detector
|
||||||
/// @param[in] blackborderThreshold The threshold which the blackborder detector should use
|
/// @param[in] blackborderThreshold The threshold which the blackborder detector should use
|
||||||
///
|
///
|
||||||
BlackBorderDetector(uint8_t blackborderThreshold);
|
BlackBorderDetector(double threshold);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Performs the actual black-border detection on the given image
|
/// Performs the actual black-border detection on the given image
|
||||||
@ -58,8 +58,69 @@ namespace hyperion
|
|||||||
///
|
///
|
||||||
/// @return The detected (or not detected) black border info
|
/// @return The detected (or not detected) black border info
|
||||||
///
|
///
|
||||||
|
|
||||||
|
uint8_t calculateThreshold(double blackborderThreshold);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// default detection mode (3lines 4side detection)
|
||||||
template <typename Pixel_T>
|
template <typename Pixel_T>
|
||||||
BlackBorder process(const Image<Pixel_T> & image)
|
BlackBorder process(const Image<Pixel_T> & image)
|
||||||
|
{
|
||||||
|
// test center and 33%, 66% of width/heigth
|
||||||
|
// 33 and 66 will check left and top
|
||||||
|
// center will check right and bottom sids
|
||||||
|
int width = image.width();
|
||||||
|
int height = image.height();
|
||||||
|
int width33percent = width / 3;
|
||||||
|
int height33percent = height / 3;
|
||||||
|
int width66percent = width33percent * 2;
|
||||||
|
int height66percent = height33percent * 2;
|
||||||
|
int xCenter = width / 2;
|
||||||
|
int yCenter = height / 2;
|
||||||
|
|
||||||
|
|
||||||
|
int firstNonBlackXPixelIndex = -1;
|
||||||
|
int firstNonBlackYPixelIndex = -1;
|
||||||
|
|
||||||
|
// find first X pixel of the image
|
||||||
|
for (int x = 0; x < width33percent; ++x)
|
||||||
|
{
|
||||||
|
const Pixel_T & color1 = image( (width - 1 - x), yCenter); // right side center line check
|
||||||
|
const Pixel_T & color2 = image(x, height33percent);
|
||||||
|
const Pixel_T & color3 = image(x, height66percent);
|
||||||
|
if (!isBlack(color1) || !isBlack(color2) || !isBlack(color3))
|
||||||
|
{
|
||||||
|
firstNonBlackXPixelIndex = x;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// find first Y pixel of the image
|
||||||
|
for (int y = 0; y < height33percent; ++y)
|
||||||
|
{
|
||||||
|
const Pixel_T & color1 = image(xCenter, (height - 1 - y)); // bottom center line check
|
||||||
|
const Pixel_T & color2 = image(width33percent, y );
|
||||||
|
const Pixel_T & color3 = image(width66percent, y);
|
||||||
|
if (!isBlack(color1) || !isBlack(color2) || !isBlack(color3))
|
||||||
|
{
|
||||||
|
firstNonBlackYPixelIndex = y;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct result
|
||||||
|
BlackBorder detectedBorder;
|
||||||
|
detectedBorder.unknown = firstNonBlackXPixelIndex == -1 || firstNonBlackYPixelIndex == -1;
|
||||||
|
detectedBorder.horizontalSize = firstNonBlackYPixelIndex;
|
||||||
|
detectedBorder.verticalSize = firstNonBlackXPixelIndex;
|
||||||
|
return detectedBorder;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// classic detection mode (topleft single line mode)
|
||||||
|
template <typename Pixel_T>
|
||||||
|
BlackBorder process_classic(const Image<Pixel_T> & image)
|
||||||
{
|
{
|
||||||
// only test the topleft third of the image
|
// only test the topleft third of the image
|
||||||
int width = image.width() /3;
|
int width = image.width() /3;
|
||||||
@ -112,6 +173,63 @@ namespace hyperion
|
|||||||
return detectedBorder;
|
return detectedBorder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// osd detection mode (find x then y at detected x to avoid changes by osd overlays)
|
||||||
|
template <typename Pixel_T>
|
||||||
|
BlackBorder process_osd(const Image<Pixel_T> & image)
|
||||||
|
{
|
||||||
|
// find X position at height33 and height66 we check from the left side, Ycenter will check from right side
|
||||||
|
// then we try to find a pixel at this X position from top and bottom and right side from top
|
||||||
|
int width = image.width();
|
||||||
|
int height = image.height();
|
||||||
|
int width33percent = width / 3;
|
||||||
|
int height33percent = height / 3;
|
||||||
|
// int width66percent = width33percent * 2;
|
||||||
|
int height66percent = height33percent * 2;
|
||||||
|
// int xCenter = width / 2;
|
||||||
|
int yCenter = height / 2;
|
||||||
|
|
||||||
|
|
||||||
|
int firstNonBlackXPixelIndex = -1;
|
||||||
|
int firstNonBlackYPixelIndex = -1;
|
||||||
|
|
||||||
|
// find first X pixel of the image
|
||||||
|
int x;
|
||||||
|
for (x = 0; x < width33percent; ++x)
|
||||||
|
{
|
||||||
|
const Pixel_T & color1 = image( (width - 1 - x), yCenter); // right side center line check
|
||||||
|
const Pixel_T & color2 = image(x, height33percent);
|
||||||
|
const Pixel_T & color3 = image(x, height66percent);
|
||||||
|
if (!isBlack(color1) || !isBlack(color2) || !isBlack(color3))
|
||||||
|
{
|
||||||
|
firstNonBlackXPixelIndex = x;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// find first Y pixel of the image
|
||||||
|
for (int y = 0; y < height33percent; ++y)
|
||||||
|
{
|
||||||
|
const Pixel_T & color1 = image(x, (height - 1 - y)); // left side bottom check
|
||||||
|
const Pixel_T & color2 = image(x, y );// left side top check
|
||||||
|
const Pixel_T & color3 = image( (width - 1 - x), y); // right side top check
|
||||||
|
if (!isBlack(color1) || !isBlack(color2) || !isBlack(color3))
|
||||||
|
{
|
||||||
|
firstNonBlackYPixelIndex = y;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct result
|
||||||
|
BlackBorder detectedBorder;
|
||||||
|
detectedBorder.unknown = firstNonBlackXPixelIndex == -1 || firstNonBlackYPixelIndex == -1;
|
||||||
|
detectedBorder.horizontalSize = firstNonBlackYPixelIndex;
|
||||||
|
detectedBorder.verticalSize = firstNonBlackXPixelIndex;
|
||||||
|
return detectedBorder;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -131,5 +249,6 @@ namespace hyperion
|
|||||||
private:
|
private:
|
||||||
/// Threshold for the blackborder detector [0 .. 255]
|
/// Threshold for the blackborder detector [0 .. 255]
|
||||||
const uint8_t _blackborderThreshold;
|
const uint8_t _blackborderThreshold;
|
||||||
|
|
||||||
};
|
};
|
||||||
} // end namespace hyperion
|
} // end namespace hyperion
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// Jsoncpp includes
|
||||||
|
#include <json/json.h>
|
||||||
// Local Hyperion includes
|
// Local Hyperion includes
|
||||||
#include "BlackBorderDetector.h"
|
#include "BlackBorderDetector.h"
|
||||||
|
|
||||||
@ -23,11 +25,7 @@ namespace hyperion
|
|||||||
/// outer pixels is blurred (black and color combined due to image scaling))
|
/// outer pixels is blurred (black and color combined due to image scaling))
|
||||||
/// @param[in] blackborderThreshold The threshold which the blackborder detector should use
|
/// @param[in] blackborderThreshold The threshold which the blackborder detector should use
|
||||||
///
|
///
|
||||||
BlackBorderProcessor(
|
BlackBorderProcessor(const Json::Value &blackborderConfig);
|
||||||
const unsigned unknownFrameCnt,
|
|
||||||
const unsigned borderFrameCnt,
|
|
||||||
const unsigned blurRemoveCnt,
|
|
||||||
uint8_t blackborderThreshold);
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Return the current (detected) border
|
/// Return the current (detected) border
|
||||||
@ -48,7 +46,14 @@ namespace hyperion
|
|||||||
bool process(const Image<Pixel_T> & image)
|
bool process(const Image<Pixel_T> & image)
|
||||||
{
|
{
|
||||||
// get the border for the single image
|
// get the border for the single image
|
||||||
BlackBorder imageBorder = _detector.process(image);
|
BlackBorder imageBorder;
|
||||||
|
if (_detectionMode == "default") {
|
||||||
|
imageBorder = _detector.process(image);
|
||||||
|
} else if (_detectionMode == "classic") {
|
||||||
|
imageBorder = _detector.process_classic(image);
|
||||||
|
} else if (_detectionMode == "osd") {
|
||||||
|
imageBorder = _detector.process_osd(image);
|
||||||
|
}
|
||||||
// add blur to the border
|
// add blur to the border
|
||||||
if (imageBorder.horizontalSize > 0)
|
if (imageBorder.horizontalSize > 0)
|
||||||
{
|
{
|
||||||
@ -80,9 +85,15 @@ namespace hyperion
|
|||||||
/// The number of horizontal/vertical borders detected before it becomes the current border
|
/// The number of horizontal/vertical borders detected before it becomes the current border
|
||||||
const unsigned _borderSwitchCnt;
|
const unsigned _borderSwitchCnt;
|
||||||
|
|
||||||
|
// The number of frames that are "ignored" before a new border gets set as _previousDetectedBorder
|
||||||
|
const unsigned _maxInconsistentCnt;
|
||||||
|
|
||||||
/// The number of pixels to increase a detected border for removing blury pixels
|
/// The number of pixels to increase a detected border for removing blury pixels
|
||||||
unsigned _blurRemoveCnt;
|
unsigned _blurRemoveCnt;
|
||||||
|
|
||||||
|
/// The border detection mode
|
||||||
|
const std::string _detectionMode;
|
||||||
|
|
||||||
/// The blackborder detector
|
/// The blackborder detector
|
||||||
BlackBorderDetector _detector;
|
BlackBorderDetector _detector;
|
||||||
|
|
||||||
@ -94,5 +105,8 @@ namespace hyperion
|
|||||||
|
|
||||||
/// The number of frame the previous detected border matched the incomming border
|
/// The number of frame the previous detected border matched the incomming border
|
||||||
unsigned _consistentCnt;
|
unsigned _consistentCnt;
|
||||||
|
/// The number of frame the previous detected border NOT matched the incomming border
|
||||||
|
unsigned _inconsistentCnt;
|
||||||
|
|
||||||
};
|
};
|
||||||
} // end namespace hyperion
|
} // end namespace hyperion
|
||||||
|
@ -7,6 +7,11 @@
|
|||||||
// X11 includes
|
// X11 includes
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
|
#include <X11/extensions/Xrender.h>
|
||||||
|
#include <X11/extensions/XShm.h>
|
||||||
|
#include <sys/ipc.h>
|
||||||
|
#include <sys/shm.h>
|
||||||
|
|
||||||
class X11Grabber
|
class X11Grabber
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -17,6 +22,8 @@ public:
|
|||||||
|
|
||||||
int open();
|
int open();
|
||||||
|
|
||||||
|
bool Setup();
|
||||||
|
|
||||||
Image<ColorRgb> & grab();
|
Image<ColorRgb> & grab();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -27,13 +34,23 @@ private:
|
|||||||
int _cropTop;
|
int _cropTop;
|
||||||
int _cropBottom;
|
int _cropBottom;
|
||||||
|
|
||||||
|
XImage* _xImage;
|
||||||
|
XShmSegmentInfo _shminfo;
|
||||||
|
|
||||||
/// Reference to the X11 display (nullptr if not opened)
|
/// Reference to the X11 display (nullptr if not opened)
|
||||||
Display * _x11Display;
|
Display* _x11Display;
|
||||||
|
Window _window;
|
||||||
|
XWindowAttributes _windowAttr;
|
||||||
|
|
||||||
unsigned _screenWidth;
|
unsigned _screenWidth;
|
||||||
unsigned _screenHeight;
|
unsigned _screenHeight;
|
||||||
|
unsigned _croppedWidth;
|
||||||
|
unsigned _croppedHeight;
|
||||||
|
|
||||||
Image<ColorRgb> _image;
|
Image<ColorRgb> _image;
|
||||||
|
|
||||||
|
void freeResources();
|
||||||
|
void setupResources();
|
||||||
|
|
||||||
int updateScreenDimensions();
|
int updateScreenDimensions();
|
||||||
};
|
};
|
||||||
|
@ -106,7 +106,7 @@ private:
|
|||||||
/// @param[in] enableBlackBorderDetector Flag indicating if the blacborder detector should be enabled
|
/// @param[in] enableBlackBorderDetector Flag indicating if the blacborder detector should be enabled
|
||||||
/// @param[in] blackborderThreshold The threshold which the blackborder detector should use
|
/// @param[in] blackborderThreshold The threshold which the blackborder detector should use
|
||||||
///
|
///
|
||||||
ImageProcessor(const LedString &ledString, bool enableBlackBorderDetector, uint8_t blackborderThreshold);
|
ImageProcessor(const LedString &ledString, const Json::Value &blackborderConfig);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Performs black-border detection (if enabled) on the given image
|
/// Performs black-border detection (if enabled) on the given image
|
||||||
|
@ -33,7 +33,7 @@ public:
|
|||||||
/// @param[in] enableBlackBorderDetector Flag indicating if the blacborder detector should be enabled
|
/// @param[in] enableBlackBorderDetector Flag indicating if the blacborder detector should be enabled
|
||||||
/// @param[in] blackborderThreshold The threshold which the blackborder detector should use
|
/// @param[in] blackborderThreshold The threshold which the blackborder detector should use
|
||||||
///
|
///
|
||||||
void init(const LedString& ledString, bool enableBlackBorderDetector, double blackborderThreshold);
|
void init(const LedString& ledString, const Json::Value &blackborderConfig);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Creates a new ImageProcessor. The onwership of the processor is transferred to the caller.
|
/// Creates a new ImageProcessor. The onwership of the processor is transferred to the caller.
|
||||||
@ -46,9 +46,6 @@ private:
|
|||||||
/// The Led-string specification
|
/// The Led-string specification
|
||||||
LedString _ledString;
|
LedString _ledString;
|
||||||
|
|
||||||
/// Flag indicating if the black border detector should be used
|
// Reference to the blackborder json configuration values
|
||||||
bool _enableBlackBorderDetector;
|
Json::Value _blackborderConfig;
|
||||||
|
|
||||||
/// Threshold for the blackborder detector [0 .. 255]
|
|
||||||
uint8_t _blackborderThreshold;
|
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,26 @@
|
|||||||
|
#include <iostream>
|
||||||
// BlackBorders includes
|
// BlackBorders includes
|
||||||
#include <blackborder/BlackBorderDetector.h>
|
#include <blackborder/BlackBorderDetector.h>
|
||||||
|
|
||||||
using namespace hyperion;
|
using namespace hyperion;
|
||||||
|
|
||||||
BlackBorderDetector::BlackBorderDetector(uint8_t blackborderThreshold) :
|
BlackBorderDetector::BlackBorderDetector(double threshold) :
|
||||||
_blackborderThreshold(blackborderThreshold)
|
_blackborderThreshold(calculateThreshold(threshold))
|
||||||
{
|
{
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t BlackBorderDetector::calculateThreshold(double threshold)
|
||||||
|
{
|
||||||
|
int rgbThreshold = int(std::ceil(threshold * 255));
|
||||||
|
if (rgbThreshold < 0)
|
||||||
|
rgbThreshold = 0;
|
||||||
|
else if (rgbThreshold > 255)
|
||||||
|
rgbThreshold = 255;
|
||||||
|
|
||||||
|
uint8_t blackborderThreshold = uint8_t(rgbThreshold);
|
||||||
|
|
||||||
|
std::cout << "Black border threshold set to " << threshold << " (" << int(blackborderThreshold) << ")" << std::endl;
|
||||||
|
|
||||||
|
return blackborderThreshold;
|
||||||
|
}
|
||||||
|
@ -1,21 +1,31 @@
|
|||||||
|
//*
|
||||||
|
#include <iostream>
|
||||||
|
/*
|
||||||
|
#include <iomanip>
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
using std::setw;
|
||||||
|
using std::left;
|
||||||
|
//*/
|
||||||
// Blackborder includes
|
// Blackborder includes
|
||||||
#include <blackborder/BlackBorderProcessor.h>
|
#include <blackborder/BlackBorderProcessor.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace hyperion;
|
using namespace hyperion;
|
||||||
|
|
||||||
BlackBorderProcessor::BlackBorderProcessor(const unsigned unknownFrameCnt,
|
BlackBorderProcessor::BlackBorderProcessor(const Json::Value &blackborderConfig) :
|
||||||
const unsigned borderFrameCnt,
|
_unknownSwitchCnt(blackborderConfig.get("unknownFrameCnt", 600).asUInt()),
|
||||||
const unsigned blurRemoveCnt,
|
_borderSwitchCnt(blackborderConfig.get("borderFrameCnt", 50).asUInt()),
|
||||||
uint8_t blackborderThreshold) :
|
_maxInconsistentCnt(blackborderConfig.get("maxInconsistentCnt", 10).asUInt()),
|
||||||
_unknownSwitchCnt(unknownFrameCnt),
|
_blurRemoveCnt(blackborderConfig.get("blurRemoveCnt", 1).asUInt()),
|
||||||
_borderSwitchCnt(borderFrameCnt),
|
_detectionMode(blackborderConfig.get("mode", "default").asString()),
|
||||||
_blurRemoveCnt(blurRemoveCnt),
|
_detector(blackborderConfig.get("threshold", 0.01).asDouble()),
|
||||||
_detector(blackborderThreshold),
|
|
||||||
_currentBorder({true, -1, -1}),
|
_currentBorder({true, -1, -1}),
|
||||||
_previousDetectedBorder({true, -1, -1}),
|
_previousDetectedBorder({true, -1, -1}),
|
||||||
_consistentCnt(0)
|
_consistentCnt(0),
|
||||||
|
_inconsistentCnt(10)
|
||||||
{
|
{
|
||||||
|
std::cout << "DETECTION MODE:" << _detectionMode << std::endl;
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,13 +36,35 @@ BlackBorder BlackBorderProcessor::getCurrentBorder() const
|
|||||||
|
|
||||||
bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
|
bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
|
||||||
{
|
{
|
||||||
|
// the new changes ignore false small borders (no reset of consistance)
|
||||||
|
// as long as the previous stable state returns within 10 frames
|
||||||
|
// and will only switch to a new border if it is realy detected stable >50 frames
|
||||||
|
|
||||||
|
// sometimes the grabber delivers "bad" frames with a smaller black border (looks like random number every few frames and even when freezing the image)
|
||||||
|
// maybe some interferences of the power supply or bad signal causing this effect - not exactly sure what causes it but changing the power supply of the converter significantly increased that "random" effect on my system
|
||||||
|
// (you can check with the debug output below or if you want i can provide some output logs)
|
||||||
|
// this "random effect" caused the old algorithm to switch to that smaller border immediatly, resulting in a too small border being detected
|
||||||
|
// makes it look like the border detectionn is not working - since the new 3 line detection algorithm is more precise this became a problem specialy in dark scenes
|
||||||
|
// wisc
|
||||||
|
|
||||||
|
// std::cout << "c: " << setw(2) << _currentBorder.verticalSize << " " << setw(2) << _currentBorder.horizontalSize << " p: " << setw(2) << _previousDetectedBorder.verticalSize << " " << setw(2) << _previousDetectedBorder.horizontalSize << " n: " << setw(2) << newDetectedBorder.verticalSize << " " << setw(2) << newDetectedBorder.horizontalSize << " c:i " << setw(2) << _consistentCnt << ":" << setw(2) << _inconsistentCnt << std::endl;
|
||||||
|
|
||||||
// set the consistency counter
|
// set the consistency counter
|
||||||
if (newDetectedBorder == _previousDetectedBorder)
|
if (newDetectedBorder == _previousDetectedBorder)
|
||||||
{
|
{
|
||||||
++_consistentCnt;
|
++_consistentCnt;
|
||||||
|
_inconsistentCnt = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
++_inconsistentCnt;
|
||||||
|
if (_inconsistentCnt <= _maxInconsistentCnt)// only few inconsistent frames
|
||||||
|
{
|
||||||
|
//discard the newDetectedBorder -> keep the consistent count for previousDetectedBorder
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// the inconsistency threshold is reached
|
||||||
|
// -> give the newDetectedBorder a chance to proof that its consistent
|
||||||
_previousDetectedBorder = newDetectedBorder;
|
_previousDetectedBorder = newDetectedBorder;
|
||||||
_consistentCnt = 0;
|
_consistentCnt = 0;
|
||||||
}
|
}
|
||||||
@ -41,6 +73,7 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
|
|||||||
if (_currentBorder == newDetectedBorder)
|
if (_currentBorder == newDetectedBorder)
|
||||||
{
|
{
|
||||||
// No change required
|
// No change required
|
||||||
|
_inconsistentCnt = 0; // we have found a consistent border -> reset _inconsistentCnt
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,21 +95,6 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
|
|||||||
_currentBorder = newDetectedBorder;
|
_currentBorder = newDetectedBorder;
|
||||||
borderChanged = true;
|
borderChanged = true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// apply smaller borders immediately
|
|
||||||
if (newDetectedBorder.verticalSize < _currentBorder.verticalSize)
|
|
||||||
{
|
|
||||||
_currentBorder.verticalSize = newDetectedBorder.verticalSize;
|
|
||||||
borderChanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize)
|
|
||||||
{
|
|
||||||
_currentBorder.horizontalSize = newDetectedBorder.horizontalSize;
|
|
||||||
borderChanged = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return borderChanged;
|
return borderChanged;
|
||||||
|
@ -59,13 +59,16 @@ void BoblightClientConnection::readData()
|
|||||||
while(bytes > 0)
|
while(bytes > 0)
|
||||||
{
|
{
|
||||||
// create message string (strip the newline)
|
// create message string (strip the newline)
|
||||||
|
#ifdef ENABLE_QT5
|
||||||
|
QString message = QString::fromLatin1(_receiveBuffer.data(), bytes-1);
|
||||||
|
#else
|
||||||
QString message = QString::fromAscii(_receiveBuffer.data(), bytes-1);
|
QString message = QString::fromAscii(_receiveBuffer.data(), bytes-1);
|
||||||
|
#endif
|
||||||
// remove message data from buffer
|
// remove message data from buffer
|
||||||
_receiveBuffer = _receiveBuffer.mid(bytes);
|
_receiveBuffer = _receiveBuffer.mid(bytes);
|
||||||
|
|
||||||
// handle message
|
// handle trimmed message
|
||||||
handleMessage(message);
|
handleMessage(message.trimmed());
|
||||||
|
|
||||||
// drop messages if the buffer is too full
|
// drop messages if the buffer is too full
|
||||||
if (_receiveBuffer.size() > 100*1024)
|
if (_receiveBuffer.size() > 100*1024)
|
||||||
@ -132,9 +135,15 @@ void BoblightClientConnection::handleMessage(const QString & message)
|
|||||||
{
|
{
|
||||||
if (messageParts[3] == "rgb" && messageParts.size() == 7)
|
if (messageParts[3] == "rgb" && messageParts.size() == 7)
|
||||||
{
|
{
|
||||||
|
// replace decimal comma with decimal point
|
||||||
|
messageParts[4].replace(',', '.');
|
||||||
|
messageParts[5].replace(',', '.');
|
||||||
|
messageParts[6].replace(',', '.');
|
||||||
|
|
||||||
bool rc1, rc2, rc3;
|
bool rc1, rc2, rc3;
|
||||||
uint8_t red = qMax(0, qMin(255, int(255 * messageParts[4].toFloat(&rc1))));
|
uint8_t red = qMax(0, qMin(255, int(255 * messageParts[4].toFloat(&rc1))));
|
||||||
|
|
||||||
|
// check for correct locale should not be needed anymore - please check!
|
||||||
if (!rc1)
|
if (!rc1)
|
||||||
{
|
{
|
||||||
// maybe a locale issue. switch to a locale with a comma instead of a dot as decimal seperator (or vice versa)
|
// maybe a locale issue. switch to a locale with a comma instead of a dot as decimal seperator (or vice versa)
|
||||||
|
@ -17,7 +17,11 @@ set(BoblightServer_SOURCES
|
|||||||
${CURRENT_SOURCE_DIR}/BoblightClientConnection.cpp
|
${CURRENT_SOURCE_DIR}/BoblightClientConnection.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
qt5_wrap_cpp(BoblightServer_HEADERS_MOC ${BoblightServer_QT_HEADERS})
|
||||||
|
else(ENABLE_QT5)
|
||||||
qt4_wrap_cpp(BoblightServer_HEADERS_MOC ${BoblightServer_QT_HEADERS})
|
qt4_wrap_cpp(BoblightServer_HEADERS_MOC ${BoblightServer_QT_HEADERS})
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
add_library(boblightserver
|
add_library(boblightserver
|
||||||
${BoblightServer_HEADERS}
|
${BoblightServer_HEADERS}
|
||||||
@ -26,6 +30,10 @@ add_library(boblightserver
|
|||||||
${BoblightServer_HEADERS_MOC}
|
${BoblightServer_HEADERS_MOC}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
qt5_use_modules(boblightserver Widgets)
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
target_link_libraries(boblightserver
|
target_link_libraries(boblightserver
|
||||||
hyperion
|
hyperion
|
||||||
hyperion-utils
|
hyperion-utils
|
||||||
|
@ -27,9 +27,13 @@ SET(EffectEngineSOURCES
|
|||||||
|
|
||||||
set(EffectEngine_RESOURCES ${CURRENT_SOURCE_DIR}/EffectEngine.qrc)
|
set(EffectEngine_RESOURCES ${CURRENT_SOURCE_DIR}/EffectEngine.qrc)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
QT5_WRAP_CPP(EffectEngineHEADERS_MOC ${EffectEngineQT_HEADERS})
|
||||||
|
qt5_add_resources(EffectEngine_RESOURCES_RCC ${EffectEngine_RESOURCES} OPTIONS "-no-compress")
|
||||||
|
else(ENABLE_QT5)
|
||||||
QT4_WRAP_CPP(EffectEngineHEADERS_MOC ${EffectEngineQT_HEADERS})
|
QT4_WRAP_CPP(EffectEngineHEADERS_MOC ${EffectEngineQT_HEADERS})
|
||||||
|
|
||||||
qt4_add_resources(EffectEngine_RESOURCES_RCC ${EffectEngine_RESOURCES} OPTIONS "-no-compress")
|
qt4_add_resources(EffectEngine_RESOURCES_RCC ${EffectEngine_RESOURCES} OPTIONS "-no-compress")
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
add_library(effectengine
|
add_library(effectengine
|
||||||
${EffectEngineHEADERS}
|
${EffectEngineHEADERS}
|
||||||
@ -39,6 +43,10 @@ add_library(effectengine
|
|||||||
${EffectEngineSOURCES}
|
${EffectEngineSOURCES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
qt5_use_modules(effectengine Widgets)
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
target_link_libraries(effectengine
|
target_link_libraries(effectengine
|
||||||
hyperion
|
hyperion
|
||||||
jsoncpp
|
jsoncpp
|
||||||
|
@ -75,7 +75,11 @@ const std::list<EffectDefinition> &EffectEngine::getEffects() const
|
|||||||
|
|
||||||
bool EffectEngine::loadEffectDefinition(const std::string &path, const std::string &effectConfigFile, EffectDefinition & effectDefinition)
|
bool EffectEngine::loadEffectDefinition(const std::string &path, const std::string &effectConfigFile, EffectDefinition & effectDefinition)
|
||||||
{
|
{
|
||||||
|
#ifdef ENABLE_QT5
|
||||||
|
std::string fileName = path + QDir::separator().toLatin1() + effectConfigFile;
|
||||||
|
#else
|
||||||
std::string fileName = path + QDir::separator().toAscii() + effectConfigFile;
|
std::string fileName = path + QDir::separator().toAscii() + effectConfigFile;
|
||||||
|
#endif
|
||||||
std::ifstream file(fileName.c_str());
|
std::ifstream file(fileName.c_str());
|
||||||
|
|
||||||
if (!file.is_open())
|
if (!file.is_open())
|
||||||
@ -110,7 +114,11 @@ bool EffectEngine::loadEffectDefinition(const std::string &path, const std::stri
|
|||||||
|
|
||||||
// setup the definition
|
// setup the definition
|
||||||
effectDefinition.name = config["name"].asString();
|
effectDefinition.name = config["name"].asString();
|
||||||
|
#ifdef ENABLE_QT5
|
||||||
|
effectDefinition.script = path + QDir::separator().toLatin1() + config["script"].asString();
|
||||||
|
#else
|
||||||
effectDefinition.script = path + QDir::separator().toAscii() + config["script"].asString();
|
effectDefinition.script = path + QDir::separator().toAscii() + config["script"].asString();
|
||||||
|
#endif
|
||||||
effectDefinition.args = config["args"];
|
effectDefinition.args = config["args"];
|
||||||
|
|
||||||
// return succes
|
// return succes
|
||||||
|
@ -15,7 +15,11 @@ SET(AmlogicSOURCES
|
|||||||
${CURRENT_SOURCE_DIR}/AmlogicGrabber.cpp
|
${CURRENT_SOURCE_DIR}/AmlogicGrabber.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
QT5_WRAP_CPP(AmlogicHEADERS_MOC ${AmlogicQT_HEADERS})
|
||||||
|
else(ENABLE_QT5)
|
||||||
QT4_WRAP_CPP(AmlogicHEADERS_MOC ${AmlogicQT_HEADERS})
|
QT4_WRAP_CPP(AmlogicHEADERS_MOC ${AmlogicQT_HEADERS})
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
add_library(amlogic-grabber
|
add_library(amlogic-grabber
|
||||||
${AmlogicHEADERS}
|
${AmlogicHEADERS}
|
||||||
|
@ -21,7 +21,11 @@ SET(DispmanxGrabberSOURCES
|
|||||||
${CURRENT_SOURCE_DIR}/DispmanxFrameGrabber.cpp
|
${CURRENT_SOURCE_DIR}/DispmanxFrameGrabber.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
QT5_WRAP_CPP(DispmanxGrabberHEADERS_MOC ${DispmanxGrabberQT_HEADERS})
|
||||||
|
else(ENABLE_QT5)
|
||||||
QT4_WRAP_CPP(DispmanxGrabberHEADERS_MOC ${DispmanxGrabberQT_HEADERS})
|
QT4_WRAP_CPP(DispmanxGrabberHEADERS_MOC ${DispmanxGrabberQT_HEADERS})
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
add_library(dispmanx-grabber
|
add_library(dispmanx-grabber
|
||||||
${DispmanxGrabberHEADERS}
|
${DispmanxGrabberHEADERS}
|
||||||
|
@ -21,7 +21,11 @@ SET(FramebufferGrabberSOURCES
|
|||||||
${CURRENT_SOURCE_DIR}/FramebufferFrameGrabber.cpp
|
${CURRENT_SOURCE_DIR}/FramebufferFrameGrabber.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
QT5_WRAP_CPP(FramebufferGrabberHEADERS_MOC ${FramebufferGrabberQT_HEADERS})
|
||||||
|
else(ENABLE_QT5)
|
||||||
QT4_WRAP_CPP(FramebufferGrabberHEADERS_MOC ${FramebufferGrabberQT_HEADERS})
|
QT4_WRAP_CPP(FramebufferGrabberHEADERS_MOC ${FramebufferGrabberQT_HEADERS})
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
add_library(framebuffer-grabber
|
add_library(framebuffer-grabber
|
||||||
${FramebufferGrabberHEADERS}
|
${FramebufferGrabberHEADERS}
|
||||||
|
@ -16,7 +16,11 @@ SET(OsxGrabberSOURCES
|
|||||||
${CURRENT_SOURCE_DIR}/OsxFrameGrabber.cpp
|
${CURRENT_SOURCE_DIR}/OsxFrameGrabber.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
QT5_WRAP_CPP(OsxGrabberHEADERS_MOC ${OsxGrabberQT_HEADERS})
|
||||||
|
else(ENABLE_QT5)
|
||||||
QT4_WRAP_CPP(OsxGrabberHEADERS_MOC ${OsxGrabberQT_HEADERS})
|
QT4_WRAP_CPP(OsxGrabberHEADERS_MOC ${OsxGrabberQT_HEADERS})
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
add_library(osx-grabber
|
add_library(osx-grabber
|
||||||
${OsxGrabberHEADERS}
|
${OsxGrabberHEADERS}
|
||||||
|
@ -16,7 +16,11 @@ SET(V4L2_SOURCES
|
|||||||
${CURRENT_SOURCE_DIR}/V4L2Wrapper.cpp
|
${CURRENT_SOURCE_DIR}/V4L2Wrapper.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
QT5_WRAP_CPP(V4L2_HEADERS_MOC ${V4L2_QT_HEADERS})
|
||||||
|
else(ENABLE_QT5)
|
||||||
QT4_WRAP_CPP(V4L2_HEADERS_MOC ${V4L2_QT_HEADERS})
|
QT4_WRAP_CPP(V4L2_HEADERS_MOC ${V4L2_QT_HEADERS})
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
add_library(v4l2-grabber
|
add_library(v4l2-grabber
|
||||||
${V4L2_HEADERS}
|
${V4L2_HEADERS}
|
||||||
@ -25,6 +29,10 @@ add_library(v4l2-grabber
|
|||||||
${V4L2_HEADERS_MOC}
|
${V4L2_HEADERS_MOC}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
qt5_use_modules(v4l2-grabber Widgets)
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
target_link_libraries(v4l2-grabber
|
target_link_libraries(v4l2-grabber
|
||||||
hyperion
|
hyperion
|
||||||
${QT_LIBRARIES}
|
${QT_LIBRARIES}
|
||||||
|
@ -22,7 +22,11 @@ SET(X11_SOURCES
|
|||||||
${CURRENT_SOURCE_DIR}/X11Grabber.cpp
|
${CURRENT_SOURCE_DIR}/X11Grabber.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
QT5_WRAP_CPP(X11_HEADERS_MOC ${X11_QT_HEADERS})
|
||||||
|
else(ENABLE_QT5)
|
||||||
QT4_WRAP_CPP(X11_HEADERS_MOC ${X11_QT_HEADERS})
|
QT4_WRAP_CPP(X11_HEADERS_MOC ${X11_QT_HEADERS})
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
add_library(x11-grabber
|
add_library(x11-grabber
|
||||||
${X11_HEADERS}
|
${X11_HEADERS}
|
||||||
|
@ -17,82 +17,116 @@ X11Grabber::X11Grabber(int cropLeft, int cropRight, int cropTop, int cropBottom,
|
|||||||
_x11Display(nullptr),
|
_x11Display(nullptr),
|
||||||
_screenWidth(0),
|
_screenWidth(0),
|
||||||
_screenHeight(0),
|
_screenHeight(0),
|
||||||
|
_croppedWidth(0),
|
||||||
|
_croppedHeight(0),
|
||||||
_image(0,0)
|
_image(0,0)
|
||||||
{
|
{
|
||||||
_imageResampler.setHorizontalPixelDecimation(horizontalPixelDecimation);
|
_imageResampler.setHorizontalPixelDecimation(horizontalPixelDecimation);
|
||||||
_imageResampler.setVerticalPixelDecimation(verticalPixelDecimation);
|
_imageResampler.setVerticalPixelDecimation(verticalPixelDecimation);
|
||||||
_imageResampler.setCropping(0, 0, 0, 0); // cropping is performed by XGetImage
|
_imageResampler.setCropping(0, 0, 0, 0); // cropping is performed by XShmGetImage
|
||||||
}
|
}
|
||||||
|
|
||||||
X11Grabber::~X11Grabber()
|
X11Grabber::~X11Grabber()
|
||||||
{
|
{
|
||||||
if (_x11Display != nullptr)
|
if (_x11Display != nullptr)
|
||||||
{
|
{
|
||||||
|
freeResources();
|
||||||
XCloseDisplay(_x11Display);
|
XCloseDisplay(_x11Display);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int X11Grabber::open()
|
void X11Grabber::freeResources()
|
||||||
{
|
{
|
||||||
const char * display_name = nullptr;
|
// Cleanup allocated resources of the X11 grab
|
||||||
_x11Display = XOpenDisplay(display_name);
|
XShmDetach(_x11Display, &_shminfo);
|
||||||
|
XDestroyImage(_xImage);
|
||||||
|
shmdt(_shminfo.shmaddr);
|
||||||
|
shmctl(_shminfo.shmid, IPC_RMID, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void X11Grabber::setupResources()
|
||||||
|
{
|
||||||
|
_xImage = XShmCreateImage(_x11Display, _windowAttr.visual,
|
||||||
|
_windowAttr.depth, ZPixmap, NULL, &_shminfo,
|
||||||
|
_croppedWidth, _croppedHeight);
|
||||||
|
|
||||||
|
_shminfo.shmid = shmget(IPC_PRIVATE, _xImage->bytes_per_line * _xImage->height, IPC_CREAT|0777);
|
||||||
|
_shminfo.shmaddr = _xImage->data = (char*)shmat(_shminfo.shmid,0,0);
|
||||||
|
_shminfo.readOnly = False;
|
||||||
|
|
||||||
|
XShmAttach(_x11Display, &_shminfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool X11Grabber::Setup()
|
||||||
|
{
|
||||||
|
_x11Display = XOpenDisplay(NULL);
|
||||||
if (_x11Display == nullptr)
|
if (_x11Display == nullptr)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to open the default X11-display" << std::endl;
|
std::cerr << "Unable to open display";
|
||||||
return -1;
|
if (getenv("DISPLAY"))
|
||||||
}
|
std::cerr << " " << std::string(getenv("DISPLAY")) << std::endl;
|
||||||
|
else
|
||||||
|
std::cerr << ". DISPLAY environment variable not set" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
_window = DefaultRootWindow(_x11Display);
|
||||||
}
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Image<ColorRgb> & X11Grabber::grab()
|
Image<ColorRgb> & X11Grabber::grab()
|
||||||
{
|
{
|
||||||
if (_x11Display == nullptr)
|
|
||||||
{
|
|
||||||
open();
|
|
||||||
}
|
|
||||||
|
|
||||||
updateScreenDimensions();
|
updateScreenDimensions();
|
||||||
|
|
||||||
const unsigned croppedWidth = _screenWidth - _cropLeft - _cropRight;
|
XShmGetImage(_x11Display, _window, _xImage, _cropLeft, _cropTop, 0x00FFFFFF);
|
||||||
const unsigned croppedHeight = _screenHeight - _cropTop - _cropBottom;
|
if (_xImage == nullptr)
|
||||||
|
|
||||||
// Capture the current screen
|
|
||||||
XImage * xImage = XGetImage(_x11Display, DefaultRootWindow(_x11Display), _cropLeft, _cropTop, croppedWidth, croppedHeight, AllPlanes, ZPixmap);
|
|
||||||
if (xImage == nullptr)
|
|
||||||
{
|
{
|
||||||
std::cerr << "Grab failed" << std::endl;
|
std::cerr << "Grab failed" << std::endl;
|
||||||
return _image;
|
return _image;
|
||||||
}
|
}
|
||||||
|
|
||||||
_imageResampler.processImage(reinterpret_cast<const uint8_t *>(xImage->data), xImage->width, xImage->height, xImage->bytes_per_line, PIXELFORMAT_BGR32, _image);
|
_imageResampler.processImage(reinterpret_cast<const uint8_t *>(_xImage->data), _xImage->width, _xImage->height, _xImage->bytes_per_line, PIXELFORMAT_BGR32, _image);
|
||||||
|
|
||||||
// Cleanup allocated resources of the X11 grab
|
|
||||||
XDestroyImage(xImage);
|
|
||||||
|
|
||||||
return _image;
|
return _image;
|
||||||
}
|
}
|
||||||
|
|
||||||
int X11Grabber::updateScreenDimensions()
|
int X11Grabber::updateScreenDimensions()
|
||||||
{
|
{
|
||||||
XWindowAttributes window_attributes_return;
|
const Status status = XGetWindowAttributes(_x11Display, _window, &_windowAttr);
|
||||||
const Status status = XGetWindowAttributes(_x11Display, DefaultRootWindow(_x11Display), &window_attributes_return);
|
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to obtain window attributes" << std::endl;
|
std::cerr << "Failed to obtain window attributes" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_screenWidth == unsigned(window_attributes_return.width) && _screenHeight == unsigned(window_attributes_return.height))
|
if (_screenWidth == unsigned(_windowAttr.width) && _screenHeight == unsigned(_windowAttr.height))
|
||||||
{
|
{
|
||||||
// No update required
|
// No update required
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Update of screen resolution: [" << _screenWidth << "x" << _screenHeight <<"] => ";
|
std::cout << "Update of screen resolution: [" << _screenWidth << "x" << _screenHeight <<"] => ";
|
||||||
_screenWidth = window_attributes_return.width;
|
|
||||||
_screenHeight = window_attributes_return.height;
|
if (_screenWidth || _screenHeight)
|
||||||
|
freeResources();
|
||||||
|
|
||||||
|
_screenWidth = _windowAttr.width;
|
||||||
|
_screenHeight = _windowAttr.height;
|
||||||
|
|
||||||
std::cout << "[" << _screenWidth << "x" << _screenHeight <<"]" << std::endl;
|
std::cout << "[" << _screenWidth << "x" << _screenHeight <<"]" << std::endl;
|
||||||
|
|
||||||
|
if (_screenWidth > unsigned(_cropLeft + _cropRight))
|
||||||
|
_croppedWidth = _screenWidth - _cropLeft - _cropRight;
|
||||||
|
else
|
||||||
|
_croppedWidth = _screenWidth;
|
||||||
|
|
||||||
|
if (_screenHeight > unsigned(_cropTop + _cropBottom))
|
||||||
|
_croppedHeight = _screenHeight - _cropTop - _cropBottom;
|
||||||
|
else
|
||||||
|
_croppedHeight = _screenHeight;
|
||||||
|
|
||||||
|
setupResources();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -36,9 +36,13 @@ set(Hyperion_RESOURCES
|
|||||||
${CURRENT_SOURCE_DIR}/resource.qrc
|
${CURRENT_SOURCE_DIR}/resource.qrc
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
QT5_WRAP_CPP(Hyperion_HEADERS_MOC ${Hyperion_QT_HEADERS})
|
||||||
|
QT5_ADD_RESOURCES(Hyperion_RESOURCES_RCC ${Hyperion_RESOURCES} OPTIONS "-no-compress")
|
||||||
|
else(ENABLE_QT5)
|
||||||
QT4_WRAP_CPP(Hyperion_HEADERS_MOC ${Hyperion_QT_HEADERS})
|
QT4_WRAP_CPP(Hyperion_HEADERS_MOC ${Hyperion_QT_HEADERS})
|
||||||
|
|
||||||
QT4_ADD_RESOURCES(Hyperion_RESOURCES_RCC ${Hyperion_RESOURCES} OPTIONS "-no-compress")
|
QT4_ADD_RESOURCES(Hyperion_RESOURCES_RCC ${Hyperion_RESOURCES} OPTIONS "-no-compress")
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
add_library(hyperion
|
add_library(hyperion
|
||||||
${Hyperion_HEADERS}
|
${Hyperion_HEADERS}
|
||||||
@ -48,6 +52,10 @@ add_library(hyperion
|
|||||||
${Hyperion_RESOURCES_RCC}
|
${Hyperion_RESOURCES_RCC}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
qt5_use_modules(hyperion Widgets)
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
target_link_libraries(hyperion
|
target_link_libraries(hyperion
|
||||||
blackborder
|
blackborder
|
||||||
hyperion-utils
|
hyperion-utils
|
||||||
|
@ -282,8 +282,8 @@ Hyperion::Hyperion(const Json::Value &jsonConfig) :
|
|||||||
// initialize the image processor factory
|
// initialize the image processor factory
|
||||||
ImageProcessorFactory::getInstance().init(
|
ImageProcessorFactory::getInstance().init(
|
||||||
_ledString,
|
_ledString,
|
||||||
jsonConfig["blackborderdetector"].get("enable", true).asBool(),
|
jsonConfig["blackborderdetector"]
|
||||||
jsonConfig["blackborderdetector"].get("threshold", 0.01).asDouble());
|
);
|
||||||
|
|
||||||
// initialize the color smoothing filter
|
// initialize the color smoothing filter
|
||||||
_device = createColorSmoothing(jsonConfig["color"]["smoothing"], _device);
|
_device = createColorSmoothing(jsonConfig["color"]["smoothing"], _device);
|
||||||
|
@ -8,10 +8,11 @@
|
|||||||
|
|
||||||
using namespace hyperion;
|
using namespace hyperion;
|
||||||
|
|
||||||
ImageProcessor::ImageProcessor(const LedString& ledString, bool enableBlackBorderDetector, uint8_t blackborderThreshold) :
|
//ImageProcessor::ImageProcessor(const LedString& ledString, bool enableBlackBorderDetector, uint8_t blackborderThreshold) :
|
||||||
|
ImageProcessor::ImageProcessor(const LedString& ledString, const Json::Value & blackborderConfig) :
|
||||||
_ledString(ledString),
|
_ledString(ledString),
|
||||||
_enableBlackBorderRemoval(enableBlackBorderDetector),
|
_enableBlackBorderRemoval(blackborderConfig.get("enable", true).asBool()),
|
||||||
_borderProcessor(new BlackBorderProcessor(600, 50, 1, blackborderThreshold)),
|
_borderProcessor(new BlackBorderProcessor(blackborderConfig) ),
|
||||||
_imageToLeds(nullptr)
|
_imageToLeds(nullptr)
|
||||||
{
|
{
|
||||||
// empty
|
// empty
|
||||||
|
@ -13,25 +13,13 @@ ImageProcessorFactory& ImageProcessorFactory::getInstance()
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageProcessorFactory::init(const LedString& ledString, bool enableBlackBorderDetector, double blackborderThreshold)
|
void ImageProcessorFactory::init(const LedString& ledString, const Json::Value & blackborderConfig)
|
||||||
{
|
{
|
||||||
_ledString = ledString;
|
_ledString = ledString;
|
||||||
_enableBlackBorderDetector = enableBlackBorderDetector;
|
_blackborderConfig = blackborderConfig;
|
||||||
|
|
||||||
int threshold = int(std::ceil(blackborderThreshold * 255));
|
|
||||||
if (threshold < 0)
|
|
||||||
threshold = 0;
|
|
||||||
else if (threshold > 255)
|
|
||||||
threshold = 255;
|
|
||||||
_blackborderThreshold = uint8_t(threshold);
|
|
||||||
|
|
||||||
if (_enableBlackBorderDetector)
|
|
||||||
{
|
|
||||||
std::cout << "Black border threshold set to " << blackborderThreshold << " (" << int(_blackborderThreshold) << ")" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageProcessor* ImageProcessorFactory::newImageProcessor() const
|
ImageProcessor* ImageProcessorFactory::newImageProcessor() const
|
||||||
{
|
{
|
||||||
return new ImageProcessor(_ledString, _enableBlackBorderDetector, _blackborderThreshold);
|
return new ImageProcessor(_ledString, _blackborderConfig);
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,13 @@ set(JsonServer_SOURCES
|
|||||||
set(JsonServer_RESOURCES
|
set(JsonServer_RESOURCES
|
||||||
${CURRENT_SOURCE_DIR}/JsonSchemas.qrc
|
${CURRENT_SOURCE_DIR}/JsonSchemas.qrc
|
||||||
)
|
)
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
qt5_wrap_cpp(JsonServer_HEADERS_MOC ${JsonServer_QT_HEADERS})
|
||||||
|
qt5_add_resources(JsonServer_RESOURCES_RCC ${JsonServer_RESOURCES} OPTIONS "-no-compress")
|
||||||
|
else(ENABLE_QT5)
|
||||||
qt4_wrap_cpp(JsonServer_HEADERS_MOC ${JsonServer_QT_HEADERS})
|
qt4_wrap_cpp(JsonServer_HEADERS_MOC ${JsonServer_QT_HEADERS})
|
||||||
|
|
||||||
qt4_add_resources(JsonServer_RESOURCES_RCC ${JsonServer_RESOURCES} OPTIONS "-no-compress")
|
qt4_add_resources(JsonServer_RESOURCES_RCC ${JsonServer_RESOURCES} OPTIONS "-no-compress")
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
add_library(jsonserver
|
add_library(jsonserver
|
||||||
${JsonServer_HEADERS}
|
${JsonServer_HEADERS}
|
||||||
@ -34,6 +37,10 @@ add_library(jsonserver
|
|||||||
${JsonServer_RESOURCES_RCC}
|
${JsonServer_RESOURCES_RCC}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
qt5_use_modules(jsonserver Widgets Network)
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
target_link_libraries(jsonserver
|
target_link_libraries(jsonserver
|
||||||
hyperion
|
hyperion
|
||||||
hyperion-utils
|
hyperion-utils
|
||||||
|
@ -20,6 +20,8 @@ SET(Leddevice_QT_HEADERS
|
|||||||
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.h
|
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.h
|
||||||
${CURRENT_SOURCE_DIR}/LedHIDDevice.h
|
${CURRENT_SOURCE_DIR}/LedHIDDevice.h
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceRawHID.h
|
${CURRENT_SOURCE_DIR}/LedDeviceRawHID.h
|
||||||
|
${CURRENT_SOURCE_DIR}/LedDeviceTest.h
|
||||||
|
${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.h
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(Leddevice_HEADERS
|
SET(Leddevice_HEADERS
|
||||||
@ -32,6 +34,7 @@ SET(Leddevice_HEADERS
|
|||||||
${CURRENT_SOURCE_DIR}/LedDevicePiBlaster.h
|
${CURRENT_SOURCE_DIR}/LedDevicePiBlaster.h
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceSedu.h
|
${CURRENT_SOURCE_DIR}/LedDeviceSedu.h
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceTest.h
|
${CURRENT_SOURCE_DIR}/LedDeviceTest.h
|
||||||
|
${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.h
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceUdp.h
|
${CURRENT_SOURCE_DIR}/LedDeviceUdp.h
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h
|
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.h
|
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.h
|
||||||
@ -54,6 +57,7 @@ SET(Leddevice_SOURCES
|
|||||||
${CURRENT_SOURCE_DIR}/LedDevicePiBlaster.cpp
|
${CURRENT_SOURCE_DIR}/LedDevicePiBlaster.cpp
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceSedu.cpp
|
${CURRENT_SOURCE_DIR}/LedDeviceSedu.cpp
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceTest.cpp
|
${CURRENT_SOURCE_DIR}/LedDeviceTest.cpp
|
||||||
|
${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.cpp
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceUdp.cpp
|
${CURRENT_SOURCE_DIR}/LedDeviceUdp.cpp
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.cpp
|
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.cpp
|
||||||
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.cpp
|
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.cpp
|
||||||
@ -104,8 +108,12 @@ if(ENABLE_TINKERFORGE)
|
|||||||
)
|
)
|
||||||
endif(ENABLE_TINKERFORGE)
|
endif(ENABLE_TINKERFORGE)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
QT5_WRAP_CPP(Leddevice_HEADERS_MOC ${Leddevice_QT_HEADERS})
|
||||||
|
else(ENABLE_QT5)
|
||||||
QT4_WRAP_CPP(Leddevice_HEADERS_MOC ${Leddevice_QT_HEADERS})
|
QT4_WRAP_CPP(Leddevice_HEADERS_MOC ${Leddevice_QT_HEADERS})
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
|
|
||||||
add_library(leddevice
|
add_library(leddevice
|
||||||
${Leddevice_HEADERS}
|
${Leddevice_HEADERS}
|
||||||
@ -114,9 +122,13 @@ add_library(leddevice
|
|||||||
${Leddevice_SOURCES}
|
${Leddevice_SOURCES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
qt5_use_modules(leddevice Widgets Network)
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
target_link_libraries(leddevice
|
target_link_libraries(leddevice
|
||||||
hyperion-utils
|
hyperion-utils
|
||||||
serialport
|
serialport
|
||||||
${LIBUSB_1_LIBRARIES} #apt-get install libusb-1.0-0-dev
|
${LIBUSB_1_LIBRARIES} #apt-get install libusb-1.0-0-dev
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
${QT_LIBRARIES}
|
${QT_LIBRARIES}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
|
|
||||||
// STL includes
|
// STL includes
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
// Linux includes
|
// Linux includes
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -19,27 +17,46 @@ LedDeviceAPA102::LedDeviceAPA102(const std::string& outputDevice, const unsigned
|
|||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||||
|
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||||
|
|
||||||
|
#define APA102_START_FRAME_BYTES 4
|
||||||
|
#define APA102_LED_BYTES 4
|
||||||
|
#define APA102_END_FRAME_BITS_MIN 32
|
||||||
|
#define APA102_END_FRAME_BITS(leds) MAX((((leds-1)/2)+1),APA102_END_FRAME_BITS_MIN)
|
||||||
|
#define APA102_END_FRAME_BYTES(leds) (((APA102_END_FRAME_BITS(leds)-1)/8)+1)
|
||||||
|
#define APA102_LED_HEADER 0xe0
|
||||||
|
#define APA102_LED_MAX_INTENSITY 0x1f
|
||||||
|
|
||||||
int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues)
|
int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues)
|
||||||
{
|
{
|
||||||
const unsigned int startFrameSize = 4;
|
const unsigned int startFrameSize = APA102_START_FRAME_BYTES;
|
||||||
const unsigned int endFrameSize = std::max<unsigned int>(((ledValues.size() + 15) / 16), 4);
|
const unsigned int ledsCount = ledValues.size() ;
|
||||||
const unsigned int mLedCount = (ledValues.size() * 4) + startFrameSize + endFrameSize;
|
const unsigned int ledsSize = ledsCount * APA102_LED_BYTES ;
|
||||||
if(_ledBuffer.size() != mLedCount){
|
const unsigned int endFrameBits = APA102_END_FRAME_BITS(ledsCount) ;
|
||||||
_ledBuffer.resize(mLedCount, 0xFF);
|
const unsigned int endFrameSize = APA102_END_FRAME_BYTES(ledsCount) ;
|
||||||
_ledBuffer[0] = 0x00;
|
const unsigned int transferSize = startFrameSize + ledsSize + endFrameSize ;
|
||||||
_ledBuffer[1] = 0x00;
|
|
||||||
_ledBuffer[2] = 0x00;
|
if(_ledBuffer.size() != transferSize){
|
||||||
_ledBuffer[3] = 0x00;
|
_ledBuffer.resize(transferSize, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned iLed=1; iLed<=ledValues.size(); ++iLed) {
|
unsigned idx = 0, i;
|
||||||
const ColorRgb& rgb = ledValues[iLed-1];
|
for (i=0; i<APA102_START_FRAME_BYTES; i++) {
|
||||||
_ledBuffer[iLed*4] = 0xFF;
|
_ledBuffer[idx++] = 0x00 ;
|
||||||
_ledBuffer[iLed*4+1] = rgb.red;
|
|
||||||
_ledBuffer[iLed*4+2] = rgb.green;
|
|
||||||
_ledBuffer[iLed*4+3] = rgb.blue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i=0; i<ledsCount; i++) {
|
||||||
|
const ColorRgb& rgb = ledValues[i];
|
||||||
|
|
||||||
|
_ledBuffer[idx++] = APA102_LED_HEADER + APA102_LED_MAX_INTENSITY;
|
||||||
|
_ledBuffer[idx++] = rgb.red;
|
||||||
|
_ledBuffer[idx++] = rgb.green;
|
||||||
|
_ledBuffer[idx++] = rgb.blue;
|
||||||
|
}
|
||||||
|
for(i=0; i<endFrameSize; i++)
|
||||||
|
_ledBuffer[idx++] = 0x00 ;
|
||||||
|
|
||||||
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
// Linux includes
|
// Linux includes
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -13,30 +12,38 @@
|
|||||||
#include "LedDeviceAdalightApa102.h"
|
#include "LedDeviceAdalightApa102.h"
|
||||||
|
|
||||||
LedDeviceAdalightApa102::LedDeviceAdalightApa102(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) :
|
LedDeviceAdalightApa102::LedDeviceAdalightApa102(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) :
|
||||||
LedDeviceAdalight(outputDevice, baudrate, delayAfterConnect_ms),
|
LedRs232Device(outputDevice, baudrate, delayAfterConnect_ms),
|
||||||
_ledBuffer(0),
|
_ledBuffer(0),
|
||||||
_timer()
|
_timer()
|
||||||
{
|
{
|
||||||
|
// setup the timer
|
||||||
|
_timer.setSingleShot(false);
|
||||||
|
_timer.setInterval(5000);
|
||||||
|
connect(&_timer, SIGNAL(timeout()), this, SLOT(rewriteLeds()));
|
||||||
|
|
||||||
|
// start the timer
|
||||||
|
_timer.start();
|
||||||
}
|
}
|
||||||
//comparing to ws2801 adalight, the following changes were needed:
|
//comparing to ws2801 adalight, the following changes were needed:
|
||||||
// 1- differnt data frame (4 bytes instead of 3)
|
// 1- differnt data frame (4 bytes instead of 3)
|
||||||
// 2 - in order to accomodate point 1 above, number of leds sent to adalight is increased by 1/3rd
|
// 2 - in order to accomodate point 1 above, number of leds sent to adalight is increased by 1/3rd
|
||||||
int LedDeviceAdalightApa102::write(const std::vector<ColorRgb> & ledValues)
|
int LedDeviceAdalightApa102::write(const std::vector<ColorRgb> & ledValues)
|
||||||
{
|
{
|
||||||
|
ledCount = ledValues.size();
|
||||||
const unsigned int startFrameSize = 4;
|
const unsigned int startFrameSize = 4;
|
||||||
const unsigned int endFrameSize = std::max<unsigned int>(((ledValues.size() + 15) / 16), 4);
|
const unsigned int endFrameSize = std::max<unsigned int>(((ledCount + 15) / 16), 4);
|
||||||
const unsigned int mLedCount = (ledValues.size() * 4) + startFrameSize + endFrameSize;
|
const unsigned int mLedCount = (ledCount * 4) + startFrameSize + endFrameSize;
|
||||||
if(_ledBuffer.size() != mLedCount){
|
if(_ledBuffer.size() != mLedCount+6){
|
||||||
_ledBuffer.resize(mLedCount, 0xFF);
|
_ledBuffer.resize(mLedCount+6, 0x00);
|
||||||
_ledBuffer[0] = 'A';
|
_ledBuffer[0] = 'A';
|
||||||
_ledBuffer[1] = 'd';
|
_ledBuffer[1] = 'd';
|
||||||
_ledBuffer[2] = 'a';
|
_ledBuffer[2] = 'a';
|
||||||
_ledBuffer[3] = (((unsigned int)(ledValues.size() * 1.33) - 1) >> 8) & 0xFF; // LED count high byte
|
_ledBuffer[3] = (((unsigned int)(ledValues.size())) >> 8) & 0xFF; // LED count high byte
|
||||||
_ledBuffer[4] = ((unsigned int)(ledValues.size() * 1.33) - 1) & 0xFF; // LED count low byte
|
_ledBuffer[4] = ((unsigned int)(ledValues.size())) & 0xFF; // LED count low byte
|
||||||
_ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum
|
_ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned iLed=1; iLed<=ledValues.size(); iLed++) {
|
for (unsigned iLed=1; iLed<=ledCount; iLed++) {
|
||||||
const ColorRgb& rgb = ledValues[iLed-1];
|
const ColorRgb& rgb = ledValues[iLed-1];
|
||||||
_ledBuffer[iLed*4+6] = 0xFF;
|
_ledBuffer[iLed*4+6] = 0xFF;
|
||||||
_ledBuffer[iLed*4+1+6] = rgb.red;
|
_ledBuffer[iLed*4+1+6] = rgb.red;
|
||||||
@ -51,4 +58,25 @@ int LedDeviceAdalightApa102::write(const std::vector<ColorRgb> & ledValues)
|
|||||||
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LedDeviceAdalightApa102::switchOff()
|
||||||
|
{
|
||||||
|
for (unsigned iLed=1; iLed<=ledCount; iLed++) {
|
||||||
|
_ledBuffer[iLed*4+6] = 0xFF;
|
||||||
|
_ledBuffer[iLed*4+1+6] = 0x00;
|
||||||
|
_ledBuffer[iLed*4+2+6] = 0x00;
|
||||||
|
_ledBuffer[iLed*4+3+6] = 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
|
// restart the timer
|
||||||
|
_timer.start();
|
||||||
|
|
||||||
|
// write data
|
||||||
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void LedDeviceAdalightApa102::rewriteLeds()
|
||||||
|
{
|
||||||
|
writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
// hyperion incluse
|
// hyperion incluse
|
||||||
#include "LedDeviceAdalight.h"
|
#include "LedRs232Device.h"
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Implementation of the LedDevice interface for writing to an Adalight led device for APA102.
|
/// Implementation of the LedDevice interface for writing to an Adalight led device for APA102.
|
||||||
///
|
///
|
||||||
class LedDeviceAdalightApa102 : public LedDeviceAdalight
|
class LedDeviceAdalightApa102 : public LedRs232Device
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -32,13 +32,17 @@ public:
|
|||||||
/// @return Zero on succes else negative
|
/// @return Zero on succes else negative
|
||||||
///
|
///
|
||||||
virtual int write(const std::vector<ColorRgb> & ledValues);
|
virtual int write(const std::vector<ColorRgb> & ledValues);
|
||||||
|
virtual int switchOff();
|
||||||
|
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
/// Write the last data to the leds again
|
||||||
|
void rewriteLeds();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// The buffer containing the packed RGB values
|
/// The buffer containing the packed RGB values
|
||||||
std::vector<uint8_t> _ledBuffer;
|
std::vector<uint8_t> _ledBuffer;
|
||||||
|
unsigned int ledCount;
|
||||||
/// Timer object which makes sure that led data is written at a minimum rate
|
/// Timer object which makes sure that led data is written at a minimum rate
|
||||||
/// The Adalight device will switch off when it does not receive data at least
|
/// The Adalight device will switch off when it does not receive data at least
|
||||||
/// every 15 seconds
|
/// every 15 seconds
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "LedDevicePiBlaster.h"
|
#include "LedDevicePiBlaster.h"
|
||||||
#include "LedDeviceSedu.h"
|
#include "LedDeviceSedu.h"
|
||||||
#include "LedDeviceTest.h"
|
#include "LedDeviceTest.h"
|
||||||
|
#include "LedDeviceFadeCandy.h"
|
||||||
#include "LedDeviceUdp.h"
|
#include "LedDeviceUdp.h"
|
||||||
#include "LedDeviceHyperionUsbasp.h"
|
#include "LedDeviceHyperionUsbasp.h"
|
||||||
#include "LedDevicePhilipsHue.h"
|
#include "LedDevicePhilipsHue.h"
|
||||||
@ -245,6 +246,13 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
|
|||||||
const std::string output = deviceConfig["output"].asString();
|
const std::string output = deviceConfig["output"].asString();
|
||||||
device = new LedDeviceTest(output);
|
device = new LedDeviceTest(output);
|
||||||
}
|
}
|
||||||
|
else if (type == "fadecandy")
|
||||||
|
{
|
||||||
|
const std::string host = deviceConfig.get("output", "127.0.0.1").asString();
|
||||||
|
const uint16_t port = deviceConfig.get("port", 7890).asInt();
|
||||||
|
const uint16_t channel = deviceConfig.get("channel", 0).asInt();
|
||||||
|
device = new LedDeviceFadeCandy(host, port, channel);
|
||||||
|
}
|
||||||
else if (type == "udp")
|
else if (type == "udp")
|
||||||
{
|
{
|
||||||
const std::string output = deviceConfig["output"].asString();
|
const std::string output = deviceConfig["output"].asString();
|
||||||
|
90
libsrc/leddevice/LedDeviceFadeCandy.cpp
Executable file
90
libsrc/leddevice/LedDeviceFadeCandy.cpp
Executable file
@ -0,0 +1,90 @@
|
|||||||
|
#include "LedDeviceFadeCandy.h"
|
||||||
|
|
||||||
|
static const ssize_t MAX_NUM_LEDS = 10000; // OPC can handle 21845 leds - in theory, fadecandy device should handle 10000 leds
|
||||||
|
static const ssize_t OPC_SET_PIXELS = 0; // OPC command codes
|
||||||
|
static const ssize_t OPC_HEADER_SIZE = 4; // OPC header size
|
||||||
|
|
||||||
|
|
||||||
|
LedDeviceFadeCandy::LedDeviceFadeCandy(const std::string& host, const uint16_t port, const unsigned channel) :
|
||||||
|
_host(host), _port(port), _channel(channel)
|
||||||
|
{
|
||||||
|
_opc_data.resize( OPC_HEADER_SIZE );
|
||||||
|
_opc_data[0] = channel;
|
||||||
|
_opc_data[1] = OPC_SET_PIXELS;
|
||||||
|
_opc_data[2] = 0;
|
||||||
|
_opc_data[3] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LedDeviceFadeCandy::~LedDeviceFadeCandy()
|
||||||
|
{
|
||||||
|
_client.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool LedDeviceFadeCandy::isConnected()
|
||||||
|
{
|
||||||
|
return _client.state() == QAbstractSocket::ConnectedState;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool LedDeviceFadeCandy::tryConnect()
|
||||||
|
{
|
||||||
|
if ( _client.state() == QAbstractSocket::UnconnectedState ) {
|
||||||
|
_client.connectToHost( _host.c_str(), _port);
|
||||||
|
if ( _client.waitForConnected(1000) )
|
||||||
|
qDebug("fadecandy/opc: connected to %s:%i on channel %i", _host.c_str(), _port, _channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
return isConnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int LedDeviceFadeCandy::write( const std::vector<ColorRgb> & ledValues )
|
||||||
|
{
|
||||||
|
ssize_t nrLedValues = ledValues.size();
|
||||||
|
ssize_t led_data_size = nrLedValues * 3; // 3 color bytes
|
||||||
|
ssize_t opc_data_size = led_data_size + OPC_HEADER_SIZE;
|
||||||
|
|
||||||
|
if (nrLedValues > MAX_NUM_LEDS)
|
||||||
|
{
|
||||||
|
std::cerr << "fadecandy/opc: Invalid attempt to write led values. Not more than " << MAX_NUM_LEDS << " leds are allowed." << std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( opc_data_size != _opc_data.size() )
|
||||||
|
_opc_data.resize( opc_data_size );
|
||||||
|
|
||||||
|
_opc_data[2] = led_data_size >> 8;
|
||||||
|
_opc_data[3] = led_data_size & 0xff;
|
||||||
|
|
||||||
|
uint idx = OPC_HEADER_SIZE;
|
||||||
|
for (const ColorRgb& color : ledValues)
|
||||||
|
{
|
||||||
|
_opc_data[idx ] = unsigned( color.red );
|
||||||
|
_opc_data[idx+1] = unsigned( color.green );
|
||||||
|
_opc_data[idx+2] = unsigned( color.blue );
|
||||||
|
idx += 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ( transferData()<0 ? -1 : 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int LedDeviceFadeCandy::transferData()
|
||||||
|
{
|
||||||
|
if ( isConnected() || tryConnect() )
|
||||||
|
return _client.write( _opc_data, _opc_data.size() );
|
||||||
|
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int LedDeviceFadeCandy::switchOff()
|
||||||
|
{
|
||||||
|
for ( int idx=OPC_HEADER_SIZE; idx < _opc_data.size(); idx++ )
|
||||||
|
_opc_data[idx] = 0;
|
||||||
|
|
||||||
|
return ( transferData()<0 ? -1 : 0 );
|
||||||
|
}
|
||||||
|
|
71
libsrc/leddevice/LedDeviceFadeCandy.h
Executable file
71
libsrc/leddevice/LedDeviceFadeCandy.h
Executable file
@ -0,0 +1,71 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// STL/Qt includes
|
||||||
|
#include <fstream>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QTcpSocket>
|
||||||
|
|
||||||
|
// Leddevice includes
|
||||||
|
#include <leddevice/LedDevice.h>
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Implementation of the LedDevice interface for sending to
|
||||||
|
/// fadecandy/opc-server via network by using the 'open pixel control' protocol.
|
||||||
|
///
|
||||||
|
class LedDeviceFadeCandy : public QObject, public LedDevice
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
///
|
||||||
|
/// Constructs the LedDevice for fadecandy/opc server
|
||||||
|
///
|
||||||
|
/// @param host The ip address/host name of fadecandy/opc server
|
||||||
|
/// @param port The port to use (fadecandy default is 7890)
|
||||||
|
///
|
||||||
|
LedDeviceFadeCandy(const std::string& host, const uint16_t port, const unsigned channel);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Destructor of the LedDevice; closes the tcp client
|
||||||
|
///
|
||||||
|
virtual ~LedDeviceFadeCandy();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Writes the led color values to the led-device
|
||||||
|
///
|
||||||
|
/// @param ledValues The color-value per led
|
||||||
|
/// @return Zero on succes else negative
|
||||||
|
///
|
||||||
|
virtual int write(const std::vector<ColorRgb> & ledValues);
|
||||||
|
|
||||||
|
/// Switch the leds off
|
||||||
|
virtual int switchOff();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTcpSocket _client;
|
||||||
|
const std::string _host;
|
||||||
|
const uint16_t _port;
|
||||||
|
const unsigned _channel;
|
||||||
|
QByteArray _opc_data;
|
||||||
|
|
||||||
|
/// try to establish connection to opc server, if not connected yet
|
||||||
|
///
|
||||||
|
/// @return true if connection is established
|
||||||
|
///
|
||||||
|
bool tryConnect();
|
||||||
|
|
||||||
|
/// return the conenction state
|
||||||
|
///
|
||||||
|
/// @return True if connection established
|
||||||
|
///
|
||||||
|
bool isConnected();
|
||||||
|
|
||||||
|
|
||||||
|
/// transfer current opc_data buffer to opc server
|
||||||
|
///
|
||||||
|
/// @return amount of transfered bytes. -1 error while transfering, -2 error while connecting
|
||||||
|
///
|
||||||
|
int transferData();
|
||||||
|
|
||||||
|
};
|
@ -6,9 +6,8 @@
|
|||||||
|
|
||||||
// qt includes
|
// qt includes
|
||||||
#include <QtCore/qmath.h>
|
#include <QtCore/qmath.h>
|
||||||
#include <QUrl>
|
|
||||||
#include <QHttpRequestHeader>
|
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
@ -144,14 +143,14 @@ LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output, const std::s
|
|||||||
int transitiontime, std::vector<unsigned int> lightIds) :
|
int transitiontime, std::vector<unsigned int> lightIds) :
|
||||||
host(output.c_str()), username(username.c_str()), switchOffOnBlack(switchOffOnBlack), transitiontime(
|
host(output.c_str()), username(username.c_str()), switchOffOnBlack(switchOffOnBlack), transitiontime(
|
||||||
transitiontime), lightIds(lightIds) {
|
transitiontime), lightIds(lightIds) {
|
||||||
http = new QHttp(host);
|
manager = new QNetworkAccessManager();
|
||||||
timer.setInterval(3000);
|
timer.setInterval(3000);
|
||||||
timer.setSingleShot(true);
|
timer.setSingleShot(true);
|
||||||
connect(&timer, SIGNAL(timeout()), this, SLOT(restoreStates()));
|
connect(&timer, SIGNAL(timeout()), this, SLOT(restoreStates()));
|
||||||
}
|
}
|
||||||
|
|
||||||
LedDevicePhilipsHue::~LedDevicePhilipsHue() {
|
LedDevicePhilipsHue::~LedDevicePhilipsHue() {
|
||||||
delete http;
|
delete manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
|
int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
|
||||||
@ -216,33 +215,29 @@ int LedDevicePhilipsHue::switchOff() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LedDevicePhilipsHue::put(QString route, QString content) {
|
void LedDevicePhilipsHue::put(QString route, QString content) {
|
||||||
QString url = QString("/api/%1/%2").arg(username).arg(route);
|
QString url = QString("http://%1/api/%2/%3").arg(host).arg(username).arg(route);
|
||||||
QHttpRequestHeader header("PUT", url);
|
|
||||||
header.setValue("Host", host);
|
|
||||||
header.setValue("Accept-Encoding", "identity");
|
|
||||||
header.setValue("Connection", "keep-alive");
|
|
||||||
header.setValue("Content-Length", QString("%1").arg(content.size()));
|
|
||||||
QEventLoop loop;
|
|
||||||
// Connect requestFinished signal to quit slot of the loop.
|
|
||||||
loop.connect(http, SIGNAL(requestFinished(int, bool)), SLOT(quit()));
|
|
||||||
// Perfrom request
|
// Perfrom request
|
||||||
http->request(header, content.toAscii());
|
QNetworkRequest request(url);
|
||||||
|
QNetworkReply* reply = manager->put(request, content.toLatin1());
|
||||||
|
// Connect finished signal to quit slot of the loop.
|
||||||
|
QEventLoop loop;
|
||||||
|
loop.connect(reply, SIGNAL(finished()), SLOT(quit()));
|
||||||
// Go into the loop until the request is finished.
|
// Go into the loop until the request is finished.
|
||||||
loop.exec();
|
loop.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray LedDevicePhilipsHue::get(QString route) {
|
QByteArray LedDevicePhilipsHue::get(QString route) {
|
||||||
QString url = QString("/api/%1/%2").arg(username).arg(route);
|
QString url = QString("http://%1/api/%2/%3").arg(host).arg(username).arg(route);
|
||||||
// Event loop to block until request finished.
|
|
||||||
QEventLoop loop;
|
|
||||||
// Connect requestFinished signal to quit slot of the loop.
|
|
||||||
loop.connect(http, SIGNAL(requestFinished(int, bool)), SLOT(quit()));
|
|
||||||
// Perfrom request
|
// Perfrom request
|
||||||
http->get(url);
|
QNetworkRequest request(url);
|
||||||
|
QNetworkReply* reply = manager->get(request);
|
||||||
|
// Connect requestFinished signal to quit slot of the loop.
|
||||||
|
QEventLoop loop;
|
||||||
|
loop.connect(reply, SIGNAL(finished()), SLOT(quit()));
|
||||||
// Go into the loop until the request is finished.
|
// Go into the loop until the request is finished.
|
||||||
loop.exec();
|
loop.exec();
|
||||||
// Read all data of the response.
|
// Read all data of the response.
|
||||||
return http->readAll();
|
return reply->readAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LedDevicePhilipsHue::getStateRoute(unsigned int lightId) {
|
QString LedDevicePhilipsHue::getStateRoute(unsigned int lightId) {
|
||||||
|
@ -6,9 +6,8 @@
|
|||||||
// Qt includes
|
// Qt includes
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QHttp>
|
#include <QNetworkAccessManager>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
// Leddevice includes
|
// Leddevice includes
|
||||||
#include <leddevice/LedDevice.h>
|
#include <leddevice/LedDevice.h>
|
||||||
|
|
||||||
@ -164,8 +163,8 @@ private:
|
|||||||
QString host;
|
QString host;
|
||||||
/// User name for the API ("newdeveloper")
|
/// User name for the API ("newdeveloper")
|
||||||
QString username;
|
QString username;
|
||||||
/// Qhttp object for sending requests.
|
/// QNetworkAccessManager object for sending requests.
|
||||||
QHttp* http;
|
QNetworkAccessManager* manager;
|
||||||
/// Use timer to reset lights when we got into "GRABBINGMODE_OFF".
|
/// Use timer to reset lights when we got into "GRABBINGMODE_OFF".
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
///
|
///
|
||||||
|
@ -34,7 +34,11 @@ protobuf_generate_cpp(ProtoServer_PROTO_SRCS ProtoServer_PROTO_HDRS
|
|||||||
${ProtoServer_PROTOS}
|
${ProtoServer_PROTOS}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
qt5_wrap_cpp(ProtoServer_HEADERS_MOC ${ProtoServer_QT_HEADERS})
|
||||||
|
else(ENABLE_QT5)
|
||||||
qt4_wrap_cpp(ProtoServer_HEADERS_MOC ${ProtoServer_QT_HEADERS})
|
qt4_wrap_cpp(ProtoServer_HEADERS_MOC ${ProtoServer_QT_HEADERS})
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
add_library(protoserver
|
add_library(protoserver
|
||||||
${ProtoServer_HEADERS}
|
${ProtoServer_HEADERS}
|
||||||
@ -45,6 +49,9 @@ add_library(protoserver
|
|||||||
${ProtoServer_PROTO_SRCS}
|
${ProtoServer_PROTO_SRCS}
|
||||||
${ProtoServer_PROTO_HDRS}
|
${ProtoServer_PROTO_HDRS}
|
||||||
)
|
)
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
qt5_use_modules(protoserver Widgets)
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
target_link_libraries(protoserver
|
target_link_libraries(protoserver
|
||||||
hyperion
|
hyperion
|
||||||
|
@ -15,7 +15,11 @@ SET(XBMCVideoChecker_SOURCES
|
|||||||
${CURRENT_SOURCE_DIR}/XBMCVideoChecker.cpp
|
${CURRENT_SOURCE_DIR}/XBMCVideoChecker.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
QT5_WRAP_CPP(XBMCVideoChecker_HEADERS_MOC ${XBMCVideoChecker_QT_HEADERS})
|
||||||
|
else(ENABLE_QT5)
|
||||||
QT4_WRAP_CPP(XBMCVideoChecker_HEADERS_MOC ${XBMCVideoChecker_QT_HEADERS})
|
QT4_WRAP_CPP(XBMCVideoChecker_HEADERS_MOC ${XBMCVideoChecker_QT_HEADERS})
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
add_library(xbmcvideochecker
|
add_library(xbmcvideochecker
|
||||||
${XBMCVideoChecker_HEADERS}
|
${XBMCVideoChecker_HEADERS}
|
||||||
@ -24,6 +28,10 @@ add_library(xbmcvideochecker
|
|||||||
${XBMCVideoChecker_SOURCES}
|
${XBMCVideoChecker_SOURCES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
qt5_use_modules(xbmcvideochecker Widgets)
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
target_link_libraries(xbmcvideochecker
|
target_link_libraries(xbmcvideochecker
|
||||||
hyperion
|
hyperion
|
||||||
${QT_LIBRARIES})
|
${QT_LIBRARIES})
|
||||||
|
@ -23,7 +23,11 @@ set(Hyperion_AML_SOURCES
|
|||||||
hyperion-aml.cpp
|
hyperion-aml.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
QT5_WRAP_CPP(Hyperion_AML_HEADERS_MOC ${Hyperion_AML_QT_HEADERS})
|
||||||
|
else(ENABLE_QT5)
|
||||||
QT4_WRAP_CPP(Hyperion_AML_HEADERS_MOC ${Hyperion_AML_QT_HEADERS})
|
QT4_WRAP_CPP(Hyperion_AML_HEADERS_MOC ${Hyperion_AML_QT_HEADERS})
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
add_executable(hyperion-amlogic
|
add_executable(hyperion-amlogic
|
||||||
${Hyperion_AML_HEADERS}
|
${Hyperion_AML_HEADERS}
|
||||||
|
@ -3,7 +3,13 @@ cmake_minimum_required(VERSION 2.8)
|
|||||||
project(hyperion-remote)
|
project(hyperion-remote)
|
||||||
|
|
||||||
# find Qt4
|
# find Qt4
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
find_package(Qt5 COMPONENTS Core Gui Widgets Network REQUIRED)
|
||||||
|
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
|
||||||
|
# set(CMAKE_CXX_FLAGS "-fPIC")
|
||||||
|
else(ENABLE_QT5)
|
||||||
find_package(Qt4 REQUIRED QtCore QtGui QtNetwork)
|
find_package(Qt4 REQUIRED QtCore QtGui QtNetwork)
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
# The following I do not undrstand completely...
|
# The following I do not undrstand completely...
|
||||||
# libQtCore.so uses some hardcoded library path inside which are incorrect after copying the file RPi file system
|
# libQtCore.so uses some hardcoded library path inside which are incorrect after copying the file RPi file system
|
||||||
@ -25,6 +31,10 @@ add_executable(hyperion-remote
|
|||||||
${hyperion-remote_HEADERS}
|
${hyperion-remote_HEADERS}
|
||||||
${hyperion-remote_SOURCES})
|
${hyperion-remote_SOURCES})
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
qt5_use_modules(hyperion-remote Widgets Network)
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
target_link_libraries(hyperion-remote
|
target_link_libraries(hyperion-remote
|
||||||
jsoncpp
|
jsoncpp
|
||||||
getoptPlusPlus
|
getoptPlusPlus
|
||||||
|
@ -43,8 +43,13 @@ int main(int argc, char * argv[])
|
|||||||
// create the option parser and initialize all parameters
|
// create the option parser and initialize all parameters
|
||||||
OptionsParser optionParser("Simple application to send a command to hyperion using the Json interface");
|
OptionsParser optionParser("Simple application to send a command to hyperion using the Json interface");
|
||||||
ParameterSet & parameters = optionParser.getParameters();
|
ParameterSet & parameters = optionParser.getParameters();
|
||||||
|
#ifdef ENABLE_QT5
|
||||||
|
StringParameter & argAddress = parameters.add<StringParameter> ('a', "address" , QString("Set the address of the hyperion server [default: %1]").arg(defaultServerAddress).toLatin1().constData());
|
||||||
|
IntParameter & argPriority = parameters.add<IntParameter> ('p', "priority" , QString("Use to the provided priority channel (the lower the number, the higher the priority) [default: %1]").arg(defaultPriority).toLatin1().constData());
|
||||||
|
#else
|
||||||
StringParameter & argAddress = parameters.add<StringParameter> ('a', "address" , QString("Set the address of the hyperion server [default: %1]").arg(defaultServerAddress).toAscii().constData());
|
StringParameter & argAddress = parameters.add<StringParameter> ('a', "address" , QString("Set the address of the hyperion server [default: %1]").arg(defaultServerAddress).toAscii().constData());
|
||||||
IntParameter & argPriority = parameters.add<IntParameter> ('p', "priority" , QString("Use to the provided priority channel (the lower the number, the higher the priority) [default: %1]").arg(defaultPriority).toAscii().constData());
|
IntParameter & argPriority = parameters.add<IntParameter> ('p', "priority" , QString("Use to the provided priority channel (the lower the number, the higher the priority) [default: %1]").arg(defaultPriority).toAscii().constData());
|
||||||
|
#endif
|
||||||
IntParameter & argDuration = parameters.add<IntParameter> ('d', "duration" , "Specify how long the leds should be switched on in millseconds [default: infinity]");
|
IntParameter & argDuration = parameters.add<IntParameter> ('d', "duration" , "Specify how long the leds should be switched on in millseconds [default: infinity]");
|
||||||
ColorParameter & argColor = parameters.add<ColorParameter> ('c', "color" , "Set all leds to a constant color (either RRGGBB hex value or a color name. The color may be repeated multiple time like: RRGGBBRRGGBB)");
|
ColorParameter & argColor = parameters.add<ColorParameter> ('c', "color" , "Set all leds to a constant color (either RRGGBB hex value or a color name. The color may be repeated multiple time like: RRGGBBRRGGBB)");
|
||||||
ImageParameter & argImage = parameters.add<ImageParameter> ('i', "image" , "Set the leds to the colors according to the given image file");
|
ImageParameter & argImage = parameters.add<ImageParameter> ('i', "image" , "Set the leds to the colors according to the given image file");
|
||||||
|
@ -3,7 +3,14 @@ cmake_minimum_required(VERSION 2.8)
|
|||||||
project(hyperion-v4l2)
|
project(hyperion-v4l2)
|
||||||
|
|
||||||
# find Qt4
|
# find Qt4
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
find_package(Qt5Widgets REQUIRED)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
|
||||||
|
# set(CMAKE_CXX_FLAGS "-fPIC")
|
||||||
|
else(ENABLE_QT5)
|
||||||
find_package(Qt4 REQUIRED QtCore QtGui QtNetwork)
|
find_package(Qt4 REQUIRED QtCore QtGui QtNetwork)
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/../../libsrc/protoserver
|
${CMAKE_CURRENT_BINARY_DIR}/../../libsrc/protoserver
|
||||||
@ -24,8 +31,11 @@ set(Hyperion_V4L2_SOURCES
|
|||||||
hyperion-v4l2.cpp
|
hyperion-v4l2.cpp
|
||||||
ScreenshotHandler.cpp
|
ScreenshotHandler.cpp
|
||||||
)
|
)
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
QT5_WRAP_CPP(Hyperion_V4L2_MOC_SOURCES ${Hyperion_V4L2_QT_HEADERS})
|
||||||
|
else(ENABLE_QT5)
|
||||||
QT4_WRAP_CPP(Hyperion_V4L2_MOC_SOURCES ${Hyperion_V4L2_QT_HEADERS})
|
QT4_WRAP_CPP(Hyperion_V4L2_MOC_SOURCES ${Hyperion_V4L2_QT_HEADERS})
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
add_executable(hyperion-v4l2
|
add_executable(hyperion-v4l2
|
||||||
${Hyperion_V4L2_HEADERS}
|
${Hyperion_V4L2_HEADERS}
|
||||||
|
@ -4,8 +4,12 @@ cmake_minimum_required(VERSION 2.8)
|
|||||||
# Set the project name
|
# Set the project name
|
||||||
project(hyperion-x11)
|
project(hyperion-x11)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
find_package(Qt5Widgets REQUIRED)
|
||||||
|
else(ENABLE_QT5)
|
||||||
# find Qt4
|
# find Qt4
|
||||||
find_package(Qt4 REQUIRED QtCore QtGui QtNetwork)
|
find_package(Qt4 REQUIRED QtCore QtGui QtNetwork)
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
# Find X11
|
# Find X11
|
||||||
find_package(X11 REQUIRED)
|
find_package(X11 REQUIRED)
|
||||||
@ -28,7 +32,11 @@ set(Hyperion_X11_SOURCES
|
|||||||
X11Wrapper.cpp
|
X11Wrapper.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
QT5_WRAP_CPP(Hyperion_X11_HEADERS_MOC ${Hyperion_X11_QT_HEADERS})
|
||||||
|
else(ENABLE_QT5)
|
||||||
QT4_WRAP_CPP(Hyperion_X11_HEADERS_MOC ${Hyperion_X11_QT_HEADERS})
|
QT4_WRAP_CPP(Hyperion_X11_HEADERS_MOC ${Hyperion_X11_QT_HEADERS})
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
add_executable(hyperion-x11
|
add_executable(hyperion-x11
|
||||||
${Hyperion_X11_HEADERS}
|
${Hyperion_X11_HEADERS}
|
||||||
@ -46,7 +54,11 @@ target_link_libraries(hyperion-x11
|
|||||||
pthread
|
pthread
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
qt5_use_modules(hyperion-x11 Widgets Core Gui Network)
|
||||||
|
else(ENABLE_QT5)
|
||||||
qt4_use_modules(hyperion-x11
|
qt4_use_modules(hyperion-x11
|
||||||
Core
|
Core
|
||||||
Gui
|
Gui
|
||||||
Network)
|
Network)
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
@ -29,6 +29,11 @@ void X11Wrapper::stop()
|
|||||||
_timer.stop();
|
_timer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool X11Wrapper::displayInit()
|
||||||
|
{
|
||||||
|
return _grabber.Setup();
|
||||||
|
}
|
||||||
|
|
||||||
void X11Wrapper::capture()
|
void X11Wrapper::capture()
|
||||||
{
|
{
|
||||||
const Image<ColorRgb> & screenshot = _grabber.grab();
|
const Image<ColorRgb> & screenshot = _grabber.grab();
|
||||||
|
@ -20,6 +20,8 @@ public:
|
|||||||
|
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
bool displayInit();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void sig_screenshot(const Image<ColorRgb> & screenshot);
|
void sig_screenshot(const Image<ColorRgb> & screenshot);
|
||||||
|
|
||||||
|
@ -78,6 +78,9 @@ int main(int argc, char ** argv)
|
|||||||
argSizeDecimation.getValue(), // horizontal decimation
|
argSizeDecimation.getValue(), // horizontal decimation
|
||||||
argSizeDecimation.getValue()); // vertical decimation
|
argSizeDecimation.getValue()); // vertical decimation
|
||||||
|
|
||||||
|
if (!x11Wrapper.displayInit())
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (argScreenshot.isSet())
|
if (argScreenshot.isSet())
|
||||||
{
|
{
|
||||||
// Capture a single screenshot and finish
|
// Capture a single screenshot and finish
|
||||||
|
@ -126,20 +126,34 @@ int main(int argc, char** argv)
|
|||||||
// Get the parameters for the bootsequence
|
// Get the parameters for the bootsequence
|
||||||
const std::string effectName = effectConfig["effect"].asString();
|
const std::string effectName = effectConfig["effect"].asString();
|
||||||
const unsigned duration_ms = effectConfig["duration_ms"].asUInt();
|
const unsigned duration_ms = effectConfig["duration_ms"].asUInt();
|
||||||
const int priority = 0;
|
const int priority = effectConfig["priority"].asUInt();
|
||||||
|
const int bootcolor_priority = (priority > 990) ? priority+1 : 990;
|
||||||
|
|
||||||
hyperion.setColor(priority+1, ColorRgb::BLACK, duration_ms, false);
|
if ( ! effectConfig["color"].isNull() && effectConfig["color"].isArray() && effectConfig["color"].size() == 3 )
|
||||||
|
{
|
||||||
|
ColorRgb boot_color = {
|
||||||
|
(uint8_t)effectConfig["color"][0].asUInt(),
|
||||||
|
(uint8_t)effectConfig["color"][1].asUInt(),
|
||||||
|
(uint8_t)effectConfig["color"][2].asUInt()
|
||||||
|
};
|
||||||
|
|
||||||
|
hyperion.setColor(bootcolor_priority, boot_color, 0, false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hyperion.setColor(bootcolor_priority, ColorRgb::BLACK, duration_ms, false);
|
||||||
|
}
|
||||||
|
|
||||||
if (effectConfig.isMember("args"))
|
if (effectConfig.isMember("args"))
|
||||||
{
|
{
|
||||||
const Json::Value effectConfigArgs = effectConfig["args"];
|
const Json::Value effectConfigArgs = effectConfig["args"];
|
||||||
if (hyperion.setEffect(effectName, effectConfigArgs, priority, duration_ms) == 0)
|
if (hyperion.setEffect(effectName, effectConfigArgs, priority, duration_ms) == 0)
|
||||||
{
|
{
|
||||||
std::cout << "Boot sequence(" << effectName << ") with user-defined arguments created and started" << std::endl;
|
std::cout << "Boot sequence(" << effectName << ") with user-defined arguments created and started" << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "Failed to start boot sequence: " << effectName << " with user-defined arguments" << std::endl;
|
std::cout << "Failed to start boot sequence: " << effectName << " with user-defined arguments" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -53,10 +53,19 @@ add_executable(test_qtscreenshot TestQtScreenshot.cpp)
|
|||||||
target_link_libraries(test_qtscreenshot
|
target_link_libraries(test_qtscreenshot
|
||||||
${QT_LIBRARIES})
|
${QT_LIBRARIES})
|
||||||
|
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
qt5_use_modules(test_qregexp Widgets)
|
||||||
|
qt5_use_modules(test_qtscreenshot Widgets)
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
if(ENABLE_X11)
|
if(ENABLE_X11)
|
||||||
# Find X11
|
# Find X11
|
||||||
find_package(X11 REQUIRED)
|
find_package(X11 REQUIRED)
|
||||||
|
|
||||||
add_executable(test_x11performance TestX11Performance.cpp)
|
add_executable(test_x11performance TestX11Performance.cpp)
|
||||||
target_link_libraries(test_x11performance ${X11_LIBRARIES} ${QT_LIBRARIES})
|
target_link_libraries(test_x11performance ${X11_LIBRARIES} ${QT_LIBRARIES})
|
||||||
|
if(ENABLE_QT5)
|
||||||
|
qt5_use_modules(test_x11performance Widgets)
|
||||||
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
endif(ENABLE_X11)
|
endif(ENABLE_X11)
|
||||||
|
@ -29,7 +29,7 @@ Image<ColorRgb> createImage(unsigned width, unsigned height, unsigned topBorder,
|
|||||||
{
|
{
|
||||||
for (unsigned y=0; y<image.height(); ++y)
|
for (unsigned y=0; y<image.height(); ++y)
|
||||||
{
|
{
|
||||||
if (y < topBorder || x < leftBorder)
|
if (y < topBorder || y > ( height - topBorder ) || x < leftBorder || x > (width - leftBorder) )
|
||||||
{
|
{
|
||||||
image(x,y) = ColorRgb::BLACK;
|
image(x,y) = ColorRgb::BLACK;
|
||||||
}
|
}
|
||||||
@ -44,11 +44,13 @@ Image<ColorRgb> createImage(unsigned width, unsigned height, unsigned topBorder,
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
unsigned unknownCnt = 600;
|
// unsigned unknownCnt = 600;
|
||||||
unsigned borderCnt = 50;
|
unsigned borderCnt = 50;
|
||||||
unsigned blurCnt = 0;
|
// unsigned blurCnt = 0;
|
||||||
|
Json::Value config;
|
||||||
|
|
||||||
BlackBorderProcessor processor(unknownCnt, borderCnt, blurCnt, 3);
|
// BlackBorderProcessor processor(unknownCnt, borderCnt, blurCnt, 3, config);
|
||||||
|
BlackBorderProcessor processor(config);
|
||||||
|
|
||||||
// Start with 'no border' detection
|
// Start with 'no border' detection
|
||||||
Image<ColorRgb> noBorderImage = createImage(64, 64, 0, 0);
|
Image<ColorRgb> noBorderImage = createImage(64, 64, 0, 0);
|
||||||
@ -86,7 +88,7 @@ int main()
|
|||||||
for (unsigned i=0; i<borderCnt*2; ++i)
|
for (unsigned i=0; i<borderCnt*2; ++i)
|
||||||
{
|
{
|
||||||
bool newBorder = processor.process(horzImage);
|
bool newBorder = processor.process(horzImage);
|
||||||
if (i == borderCnt)
|
if (i == borderCnt+10)// 10 frames till new border gets a chance to proof consistency
|
||||||
{
|
{
|
||||||
if (!newBorder)
|
if (!newBorder)
|
||||||
{
|
{
|
||||||
@ -111,18 +113,42 @@ int main()
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch back (in one shot) to no border
|
for (unsigned i=0; i<borderCnt*2; ++i)
|
||||||
if (!processor.process(noBorderImage) || (processor.getCurrentBorder().unknown != false || processor.getCurrentBorder().horizontalSize != 0 || processor.getCurrentBorder().verticalSize != 0))
|
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to switch back to 'no border' with one image" << std::endl;
|
|
||||||
exit(EXIT_FAILURE);
|
bool newBorder = processor.process(noBorderImage);
|
||||||
|
if (i == borderCnt+10)// 10 frames till new border gets a chance to proof consistency
|
||||||
|
{
|
||||||
|
if (!newBorder)
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to detect 'no border' when required after " << borderCnt << " images" << std::endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (newBorder)
|
||||||
|
{
|
||||||
|
std::cerr << "Incorrectly detected no border, when there in none" << std::endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check switch back to no border
|
||||||
|
if ( (processor.getCurrentBorder().unknown != false || processor.getCurrentBorder().horizontalSize != 0 || processor.getCurrentBorder().verticalSize != 0))
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to switch back to 'no border'" << std::endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Image<ColorRgb> vertImage = createImage(64, 64, 0, borderSize);
|
Image<ColorRgb> vertImage = createImage(64, 64, 0, borderSize);
|
||||||
for (unsigned i=0; i<borderCnt*2; ++i)
|
for (unsigned i=0; i<borderCnt*2; ++i)
|
||||||
{
|
{
|
||||||
bool newBorder = processor.process(vertImage);
|
bool newBorder = processor.process(vertImage);
|
||||||
if (i == borderCnt)
|
if (i == borderCnt+10)// 10 frames till new border gets a chance to proof consistency
|
||||||
{
|
{
|
||||||
if (!newBorder)
|
if (!newBorder)
|
||||||
{
|
{
|
||||||
@ -147,8 +173,8 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Switch back (in one shot) to no border
|
// Switch back (in one shot) to no border
|
||||||
assert(processor.process(noBorderImage));
|
// assert(processor.process(noBorderImage));
|
||||||
assert(processor.getCurrentBorder().verticalSize == 0 && processor.getCurrentBorder().horizontalSize == 0);
|
// assert(processor.getCurrentBorder().verticalSize == 0 && processor.getCurrentBorder().horizontalSize == 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user