mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
fix more "dos" line endings (#673)
* Removed -HUP so the default -TERM signal is sent instead. - hyperiond only listens for TERM and INT. HUP is often used to get an exe to reread its config Changed pgrep to add '-x' so it wont partial match on the exe name. - I have multiple instances with multiple hyperiond-instance1 names - this ensures the service script only kills the right process * reversing errant change to hyperion.systemd.sh * cleaned up a couple of compiler warnings * moved bitpair_to_byte initialiser to (hopefully) work with older GCC * compiler warning in udp driver removed some tabs in ws2812b.cpp * formatting - spaces to tabs * moved rpi_281x to tag sk6812-v1.0 * moving to my fork of rpi_281x * removed dos line endings * Found some more "dos" line ending files Former-commit-id: c756e3ccc153fd36e23a26eff37a1230bdd4b9b4
This commit is contained in:
parent
4f6ab258ef
commit
e8207cfe31
220
dependencies/CMakeLists.txt
vendored
220
dependencies/CMakeLists.txt
vendored
@ -1,110 +1,110 @@
|
|||||||
add_subdirectory(build/getoptPlusPlus)
|
add_subdirectory(build/getoptPlusPlus)
|
||||||
add_subdirectory(build/hidapi)
|
add_subdirectory(build/hidapi)
|
||||||
add_subdirectory(build/jsoncpp)
|
add_subdirectory(build/jsoncpp)
|
||||||
add_subdirectory(build/serial)
|
add_subdirectory(build/serial)
|
||||||
add_subdirectory(build/tinkerforge)
|
add_subdirectory(build/tinkerforge)
|
||||||
|
|
||||||
if(ENABLE_WS281XPWM)
|
if(ENABLE_WS281XPWM)
|
||||||
add_library(ws281x
|
add_library(ws281x
|
||||||
external/rpi_ws281x/mailbox.c external/rpi_ws281x/ws2811.c
|
external/rpi_ws281x/mailbox.c external/rpi_ws281x/ws2811.c
|
||||||
external/rpi_ws281x/pwm.c external/rpi_ws281x/dma.c
|
external/rpi_ws281x/pwm.c external/rpi_ws281x/dma.c
|
||||||
external/rpi_ws281x/rpihw.c)
|
external/rpi_ws281x/rpihw.c)
|
||||||
endif(ENABLE_WS281XPWM)
|
endif(ENABLE_WS281XPWM)
|
||||||
|
|
||||||
if(ENABLE_PROTOBUF)
|
if(ENABLE_PROTOBUF)
|
||||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared protobuf library")
|
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared protobuf library")
|
||||||
add_subdirectory(external/protobuf)
|
add_subdirectory(external/protobuf)
|
||||||
|
|
||||||
if(CMAKE_CROSSCOMPILING)
|
if(CMAKE_CROSSCOMPILING)
|
||||||
# when crosscompiling import the protoc executable targets from a file generated by a native build
|
# when crosscompiling import the protoc executable targets from a file generated by a native build
|
||||||
option(IMPORT_PROTOC "Protoc export file (protoc_export.cmake) from a native build" "IMPORT_PROTOC-FILE_NOT_FOUND")
|
option(IMPORT_PROTOC "Protoc export file (protoc_export.cmake) from a native build" "IMPORT_PROTOC-FILE_NOT_FOUND")
|
||||||
include(${IMPORT_PROTOC})
|
include(${IMPORT_PROTOC})
|
||||||
else()
|
else()
|
||||||
# export the protoc compiler so it can be used when cross compiling
|
# export the protoc compiler so it can be used when cross compiling
|
||||||
export(TARGETS protoc_compiler FILE "${CMAKE_BINARY_DIR}/protoc_export.cmake")
|
export(TARGETS protoc_compiler FILE "${CMAKE_BINARY_DIR}/protoc_export.cmake")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# define the include for the protobuf library at the parent scope
|
# define the include for the protobuf library at the parent scope
|
||||||
set(PROTOBUF_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf/src")
|
set(PROTOBUF_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf/src")
|
||||||
set(PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS} PARENT_SCOPE)
|
set(PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS} PARENT_SCOPE)
|
||||||
|
|
||||||
# define the protoc executable at the parent scope
|
# define the protoc executable at the parent scope
|
||||||
get_property(PROTOBUF_PROTOC_EXECUTABLE TARGET protoc_compiler PROPERTY LOCATION)
|
get_property(PROTOBUF_PROTOC_EXECUTABLE TARGET protoc_compiler PROPERTY LOCATION)
|
||||||
set(PROTOBUF_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE} PARENT_SCOPE)
|
set(PROTOBUF_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE} PARENT_SCOPE)
|
||||||
message(STATUS "Using protobuf compiler: " ${PROTOBUF_PROTOC_EXECUTABLE})
|
message(STATUS "Using protobuf compiler: " ${PROTOBUF_PROTOC_EXECUTABLE})
|
||||||
|
|
||||||
#=============================================================================
|
#=============================================================================
|
||||||
# Copyright 2009 Kitware, Inc.
|
# Copyright 2009 Kitware, Inc.
|
||||||
# Copyright 2009-2011 Philip Lowman <philip@yhbt.com>
|
# Copyright 2009-2011 Philip Lowman <philip@yhbt.com>
|
||||||
# Copyright 2008 Esben Mose Hansen, Ange Optimization ApS
|
# Copyright 2008 Esben Mose Hansen, Ange Optimization ApS
|
||||||
#
|
#
|
||||||
# Distributed under the OSI-approved BSD License (the "License");
|
# Distributed under the OSI-approved BSD License (the "License");
|
||||||
# see accompanying file Copyright.txt for details.
|
# see accompanying file Copyright.txt for details.
|
||||||
#
|
#
|
||||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
# See the License for more information.
|
# See the License for more information.
|
||||||
#=============================================================================
|
#=============================================================================
|
||||||
# (To distribute this file outside of CMake, substitute the full
|
# (To distribute this file outside of CMake, substitute the full
|
||||||
# License text for the above reference.)
|
# License text for the above reference.)
|
||||||
function(PROTOBUF_GENERATE_CPP SRCS HDRS)
|
function(PROTOBUF_GENERATE_CPP SRCS HDRS)
|
||||||
if(NOT ARGN)
|
if(NOT ARGN)
|
||||||
message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files")
|
message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files")
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(PROTOBUF_GENERATE_CPP_APPEND_PATH)
|
if(PROTOBUF_GENERATE_CPP_APPEND_PATH)
|
||||||
# Create an include path for each file specified
|
# Create an include path for each file specified
|
||||||
foreach(FIL ${ARGN})
|
foreach(FIL ${ARGN})
|
||||||
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
|
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
|
||||||
get_filename_component(ABS_PATH ${ABS_FIL} PATH)
|
get_filename_component(ABS_PATH ${ABS_FIL} PATH)
|
||||||
list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
|
list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
|
||||||
if(${_contains_already} EQUAL -1)
|
if(${_contains_already} EQUAL -1)
|
||||||
list(APPEND _protobuf_include_path -I ${ABS_PATH})
|
list(APPEND _protobuf_include_path -I ${ABS_PATH})
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
else()
|
else()
|
||||||
set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})
|
set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(DEFINED PROTOBUF_IMPORT_DIRS)
|
if(DEFINED PROTOBUF_IMPORT_DIRS)
|
||||||
foreach(DIR ${PROTOBUF_IMPORT_DIRS})
|
foreach(DIR ${PROTOBUF_IMPORT_DIRS})
|
||||||
get_filename_component(ABS_PATH ${DIR} ABSOLUTE)
|
get_filename_component(ABS_PATH ${DIR} ABSOLUTE)
|
||||||
list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
|
list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
|
||||||
if(${_contains_already} EQUAL -1)
|
if(${_contains_already} EQUAL -1)
|
||||||
list(APPEND _protobuf_include_path -I ${ABS_PATH})
|
list(APPEND _protobuf_include_path -I ${ABS_PATH})
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMAKE_CROSSCOMPILING)
|
if(CMAKE_CROSSCOMPILING)
|
||||||
set(PROTOC_DEPENDENCY ${PROTOBUF_PROTOC_EXECUTABLE})
|
set(PROTOC_DEPENDENCY ${PROTOBUF_PROTOC_EXECUTABLE})
|
||||||
else()
|
else()
|
||||||
set(PROTOC_DEPENDENCY protoc_compiler)
|
set(PROTOC_DEPENDENCY protoc_compiler)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(${SRCS})
|
set(${SRCS})
|
||||||
set(${HDRS})
|
set(${HDRS})
|
||||||
foreach(FIL ${ARGN})
|
foreach(FIL ${ARGN})
|
||||||
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
|
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
|
||||||
get_filename_component(FIL_WE ${FIL} NAME_WE)
|
get_filename_component(FIL_WE ${FIL} NAME_WE)
|
||||||
|
|
||||||
list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
|
list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
|
||||||
list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
|
list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
|
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
|
||||||
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
|
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
|
||||||
ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
|
ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
|
||||||
DEPENDS ${ABS_FIL} ${PROTOC_DEPENDENCY}
|
DEPENDS ${ABS_FIL} ${PROTOC_DEPENDENCY}
|
||||||
COMMENT "Running C++ protocol buffer compiler on ${FIL}"
|
COMMENT "Running C++ protocol buffer compiler on ${FIL}"
|
||||||
VERBATIM
|
VERBATIM
|
||||||
)
|
)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
|
set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
|
||||||
set(${SRCS} ${${SRCS}} PARENT_SCOPE)
|
set(${SRCS} ${${SRCS}} PARENT_SCOPE)
|
||||||
set(${HDRS} ${${HDRS}} PARENT_SCOPE)
|
set(${HDRS} ${${HDRS}} PARENT_SCOPE)
|
||||||
endfunction()
|
endfunction()
|
||||||
endif()
|
endif()
|
||||||
|
1260
dependencies/include/tinkerforge/ip_connection.h
vendored
1260
dependencies/include/tinkerforge/ip_connection.h
vendored
File diff suppressed because it is too large
Load Diff
@ -1,52 +1,52 @@
|
|||||||
|
|
||||||
# Define the current source locations
|
# Define the current source locations
|
||||||
set(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/bonjour)
|
set(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/bonjour)
|
||||||
set(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/bonjour)
|
set(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/bonjour)
|
||||||
|
|
||||||
# Group the headers that go through the MOC compiler
|
# Group the headers that go through the MOC compiler
|
||||||
set(Bonjour_QT_HEADERS
|
set(Bonjour_QT_HEADERS
|
||||||
${CURRENT_HEADER_DIR}/bonjourrecord.h
|
${CURRENT_HEADER_DIR}/bonjourrecord.h
|
||||||
${CURRENT_HEADER_DIR}/bonjourserviceregister.h
|
${CURRENT_HEADER_DIR}/bonjourserviceregister.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(Bonjour_HEADERS
|
set(Bonjour_HEADERS
|
||||||
)
|
)
|
||||||
|
|
||||||
set(Bonjour_SOURCES
|
set(Bonjour_SOURCES
|
||||||
${CURRENT_SOURCE_DIR}/bonjourserviceregister.cpp
|
${CURRENT_SOURCE_DIR}/bonjourserviceregister.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(Bonjour_RESOURCES
|
set(Bonjour_RESOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
if(ENABLE_QT5)
|
if(ENABLE_QT5)
|
||||||
qt5_wrap_cpp(Bonjour_HEADERS_MOC ${Bonjour_QT_HEADERS})
|
qt5_wrap_cpp(Bonjour_HEADERS_MOC ${Bonjour_QT_HEADERS})
|
||||||
qt5_add_resources(Bonjour_RESOURCES_RCC ${Bonjour_RESOURCES} OPTIONS "-no-compress")
|
qt5_add_resources(Bonjour_RESOURCES_RCC ${Bonjour_RESOURCES} OPTIONS "-no-compress")
|
||||||
else(ENABLE_QT5)
|
else(ENABLE_QT5)
|
||||||
qt4_wrap_cpp(Bonjour_HEADERS_MOC ${Bonjour_QT_HEADERS})
|
qt4_wrap_cpp(Bonjour_HEADERS_MOC ${Bonjour_QT_HEADERS})
|
||||||
qt4_add_resources(Bonjour_RESOURCES_RCC ${Bonjour_RESOURCES} OPTIONS "-no-compress")
|
qt4_add_resources(Bonjour_RESOURCES_RCC ${Bonjour_RESOURCES} OPTIONS "-no-compress")
|
||||||
endif(ENABLE_QT5)
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
add_library(bonjour
|
add_library(bonjour
|
||||||
${Bonjour_HEADERS}
|
${Bonjour_HEADERS}
|
||||||
${Bonjour_QT_HEADERS}
|
${Bonjour_QT_HEADERS}
|
||||||
${Bonjour_SOURCES}
|
${Bonjour_SOURCES}
|
||||||
${Bonjour_RESOURCES}
|
${Bonjour_RESOURCES}
|
||||||
${Bonjour_HEADERS_MOC}
|
${Bonjour_HEADERS_MOC}
|
||||||
${Bonjour_RESOURCES_RCC}
|
${Bonjour_RESOURCES_RCC}
|
||||||
)
|
)
|
||||||
|
|
||||||
if(ENABLE_QT5)
|
if(ENABLE_QT5)
|
||||||
qt5_use_modules(bonjour Widgets Network)
|
qt5_use_modules(bonjour Widgets Network)
|
||||||
endif(ENABLE_QT5)
|
endif(ENABLE_QT5)
|
||||||
|
|
||||||
target_link_libraries(bonjour
|
target_link_libraries(bonjour
|
||||||
libdns_sd.a
|
libdns_sd.a
|
||||||
libavahi-client.a
|
libavahi-client.a
|
||||||
libavahi-common.a
|
libavahi-common.a
|
||||||
libavahi-core.a
|
libavahi-core.a
|
||||||
libavahi-qt4.a
|
libavahi-qt4.a
|
||||||
libdbus-1.a
|
libdbus-1.a
|
||||||
hyperion
|
hyperion
|
||||||
hyperion-utils
|
hyperion-utils
|
||||||
${QT_LIBRARIES})
|
${QT_LIBRARIES})
|
||||||
|
@ -1,342 +1,342 @@
|
|||||||
// Local-Hyperion includes
|
// Local-Hyperion includes
|
||||||
#include "LedDevicePhilipsHue.h"
|
#include "LedDevicePhilipsHue.h"
|
||||||
|
|
||||||
// jsoncpp includes
|
// jsoncpp includes
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
|
|
||||||
// qt includes
|
// qt includes
|
||||||
#include <QtCore/qmath.h>
|
#include <QtCore/qmath.h>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
bool operator ==(CiColor p1, CiColor p2) {
|
bool operator ==(CiColor p1, CiColor p2) {
|
||||||
return (p1.x == p2.x) && (p1.y == p2.y) && (p1.bri == p2.bri);
|
return (p1.x == p2.x) && (p1.y == p2.y) && (p1.bri == p2.bri);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator !=(CiColor p1, CiColor p2) {
|
bool operator !=(CiColor p1, CiColor p2) {
|
||||||
return !(p1 == p2);
|
return !(p1 == p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
PhilipsHueLight::PhilipsHueLight(unsigned int id, QString originalState, QString modelId) :
|
PhilipsHueLight::PhilipsHueLight(unsigned int id, QString originalState, QString modelId) :
|
||||||
id(id), originalState(originalState) {
|
id(id), originalState(originalState) {
|
||||||
// Hue system model ids (http://www.developers.meethue.com/documentation/supported-lights).
|
// Hue system model ids (http://www.developers.meethue.com/documentation/supported-lights).
|
||||||
// Light strips, color iris, ...
|
// Light strips, color iris, ...
|
||||||
const std::set<QString> GAMUT_A_MODEL_IDS = { "LLC001", "LLC005", "LLC006", "LLC007", "LLC010", "LLC011", "LLC012",
|
const std::set<QString> GAMUT_A_MODEL_IDS = { "LLC001", "LLC005", "LLC006", "LLC007", "LLC010", "LLC011", "LLC012",
|
||||||
"LLC013", "LLC014", "LST001" };
|
"LLC013", "LLC014", "LST001" };
|
||||||
// Hue bulbs, spots, ...
|
// Hue bulbs, spots, ...
|
||||||
const std::set<QString> GAMUT_B_MODEL_IDS = { "LCT001", "LCT002", "LCT003", "LCT007", "LLM001" };
|
const std::set<QString> GAMUT_B_MODEL_IDS = { "LCT001", "LCT002", "LCT003", "LCT007", "LLM001" };
|
||||||
// Hue Lightstrip plus, go ...
|
// Hue Lightstrip plus, go ...
|
||||||
const std::set<QString> GAMUT_C_MODEL_IDS = { "LLC020", "LST002" };
|
const std::set<QString> GAMUT_C_MODEL_IDS = { "LLC020", "LST002" };
|
||||||
// Find id in the sets and set the appropiate color space.
|
// Find id in the sets and set the appropiate color space.
|
||||||
if (GAMUT_A_MODEL_IDS.find(modelId) != GAMUT_A_MODEL_IDS.end()) {
|
if (GAMUT_A_MODEL_IDS.find(modelId) != GAMUT_A_MODEL_IDS.end()) {
|
||||||
colorSpace.red = {0.703f, 0.296f};
|
colorSpace.red = {0.703f, 0.296f};
|
||||||
colorSpace.green = {0.2151f, 0.7106f};
|
colorSpace.green = {0.2151f, 0.7106f};
|
||||||
colorSpace.blue = {0.138f, 0.08f};
|
colorSpace.blue = {0.138f, 0.08f};
|
||||||
} else if (GAMUT_B_MODEL_IDS.find(modelId) != GAMUT_B_MODEL_IDS.end()) {
|
} else if (GAMUT_B_MODEL_IDS.find(modelId) != GAMUT_B_MODEL_IDS.end()) {
|
||||||
colorSpace.red = {0.675f, 0.322f};
|
colorSpace.red = {0.675f, 0.322f};
|
||||||
colorSpace.green = {0.4091f, 0.518f};
|
colorSpace.green = {0.4091f, 0.518f};
|
||||||
colorSpace.blue = {0.167f, 0.04f};
|
colorSpace.blue = {0.167f, 0.04f};
|
||||||
} else if (GAMUT_C_MODEL_IDS.find(modelId) != GAMUT_B_MODEL_IDS.end()) {
|
} else if (GAMUT_C_MODEL_IDS.find(modelId) != GAMUT_B_MODEL_IDS.end()) {
|
||||||
colorSpace.red = {0.675f, 0.322f};
|
colorSpace.red = {0.675f, 0.322f};
|
||||||
colorSpace.green = {0.2151f, 0.7106f};
|
colorSpace.green = {0.2151f, 0.7106f};
|
||||||
colorSpace.blue = {0.167f, 0.04f};
|
colorSpace.blue = {0.167f, 0.04f};
|
||||||
} else {
|
} else {
|
||||||
colorSpace.red = {1.0f, 0.0f};
|
colorSpace.red = {1.0f, 0.0f};
|
||||||
colorSpace.green = {0.0f, 1.0f};
|
colorSpace.green = {0.0f, 1.0f};
|
||||||
colorSpace.blue = {0.0f, 0.0f};
|
colorSpace.blue = {0.0f, 0.0f};
|
||||||
}
|
}
|
||||||
// Initialize black color.
|
// Initialize black color.
|
||||||
black = rgbToCiColor(0.0f, 0.0f, 0.0f);
|
black = rgbToCiColor(0.0f, 0.0f, 0.0f);
|
||||||
// Initialize color with black
|
// Initialize color with black
|
||||||
color = {black.x, black.y, black.bri};
|
color = {black.x, black.y, black.bri};
|
||||||
}
|
}
|
||||||
|
|
||||||
float PhilipsHueLight::crossProduct(CiColor p1, CiColor p2) {
|
float PhilipsHueLight::crossProduct(CiColor p1, CiColor p2) {
|
||||||
return p1.x * p2.y - p1.y * p2.x;
|
return p1.x * p2.y - p1.y * p2.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PhilipsHueLight::isPointInLampsReach(CiColor p) {
|
bool PhilipsHueLight::isPointInLampsReach(CiColor p) {
|
||||||
CiColor v1 = { colorSpace.green.x - colorSpace.red.x, colorSpace.green.y - colorSpace.red.y };
|
CiColor v1 = { colorSpace.green.x - colorSpace.red.x, colorSpace.green.y - colorSpace.red.y };
|
||||||
CiColor v2 = { colorSpace.blue.x - colorSpace.red.x, colorSpace.blue.y - colorSpace.red.y };
|
CiColor v2 = { colorSpace.blue.x - colorSpace.red.x, colorSpace.blue.y - colorSpace.red.y };
|
||||||
CiColor q = { p.x - colorSpace.red.x, p.y - colorSpace.red.y };
|
CiColor q = { p.x - colorSpace.red.x, p.y - colorSpace.red.y };
|
||||||
float s = crossProduct(q, v2) / crossProduct(v1, v2);
|
float s = crossProduct(q, v2) / crossProduct(v1, v2);
|
||||||
float t = crossProduct(v1, q) / crossProduct(v1, v2);
|
float t = crossProduct(v1, q) / crossProduct(v1, v2);
|
||||||
if ((s >= 0.0f) && (t >= 0.0f) && (s + t <= 1.0f)) {
|
if ((s >= 0.0f) && (t >= 0.0f) && (s + t <= 1.0f)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CiColor PhilipsHueLight::getClosestPointToPoint(CiColor a, CiColor b, CiColor p) {
|
CiColor PhilipsHueLight::getClosestPointToPoint(CiColor a, CiColor b, CiColor p) {
|
||||||
CiColor AP = { p.x - a.x, p.y - a.y };
|
CiColor AP = { p.x - a.x, p.y - a.y };
|
||||||
CiColor AB = { b.x - a.x, b.y - a.y };
|
CiColor AB = { b.x - a.x, b.y - a.y };
|
||||||
float ab2 = AB.x * AB.x + AB.y * AB.y;
|
float ab2 = AB.x * AB.x + AB.y * AB.y;
|
||||||
float ap_ab = AP.x * AB.x + AP.y * AB.y;
|
float ap_ab = AP.x * AB.x + AP.y * AB.y;
|
||||||
float t = ap_ab / ab2;
|
float t = ap_ab / ab2;
|
||||||
if (t < 0.0f) {
|
if (t < 0.0f) {
|
||||||
t = 0.0f;
|
t = 0.0f;
|
||||||
} else if (t > 1.0f) {
|
} else if (t > 1.0f) {
|
||||||
t = 1.0f;
|
t = 1.0f;
|
||||||
}
|
}
|
||||||
return {a.x + AB.x * t, a.y + AB.y * t};
|
return {a.x + AB.x * t, a.y + AB.y * t};
|
||||||
}
|
}
|
||||||
|
|
||||||
float PhilipsHueLight::getDistanceBetweenTwoPoints(CiColor p1, CiColor p2) {
|
float PhilipsHueLight::getDistanceBetweenTwoPoints(CiColor p1, CiColor p2) {
|
||||||
// Horizontal difference.
|
// Horizontal difference.
|
||||||
float dx = p1.x - p2.x;
|
float dx = p1.x - p2.x;
|
||||||
// Vertical difference.
|
// Vertical difference.
|
||||||
float dy = p1.y - p2.y;
|
float dy = p1.y - p2.y;
|
||||||
// Absolute value.
|
// Absolute value.
|
||||||
return sqrt(dx * dx + dy * dy);
|
return sqrt(dx * dx + dy * dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
CiColor PhilipsHueLight::rgbToCiColor(float red, float green, float blue) {
|
CiColor PhilipsHueLight::rgbToCiColor(float red, float green, float blue) {
|
||||||
// Apply gamma correction.
|
// Apply gamma correction.
|
||||||
float r = (red > 0.04045f) ? powf((red + 0.055f) / (1.0f + 0.055f), 2.4f) : (red / 12.92f);
|
float r = (red > 0.04045f) ? powf((red + 0.055f) / (1.0f + 0.055f), 2.4f) : (red / 12.92f);
|
||||||
float g = (green > 0.04045f) ? powf((green + 0.055f) / (1.0f + 0.055f), 2.4f) : (green / 12.92f);
|
float g = (green > 0.04045f) ? powf((green + 0.055f) / (1.0f + 0.055f), 2.4f) : (green / 12.92f);
|
||||||
float b = (blue > 0.04045f) ? powf((blue + 0.055f) / (1.0f + 0.055f), 2.4f) : (blue / 12.92f);
|
float b = (blue > 0.04045f) ? powf((blue + 0.055f) / (1.0f + 0.055f), 2.4f) : (blue / 12.92f);
|
||||||
// Convert to XYZ space.
|
// Convert to XYZ space.
|
||||||
float X = r * 0.649926f + g * 0.103455f + b * 0.197109f;
|
float X = r * 0.649926f + g * 0.103455f + b * 0.197109f;
|
||||||
float Y = r * 0.234327f + g * 0.743075f + b * 0.022598f;
|
float Y = r * 0.234327f + g * 0.743075f + b * 0.022598f;
|
||||||
float Z = r * 0.0000000f + g * 0.053077f + b * 1.035763f;
|
float Z = r * 0.0000000f + g * 0.053077f + b * 1.035763f;
|
||||||
// Convert to x,y space.
|
// Convert to x,y space.
|
||||||
float cx = X / (X + Y + Z);
|
float cx = X / (X + Y + Z);
|
||||||
float cy = Y / (X + Y + Z);
|
float cy = Y / (X + Y + Z);
|
||||||
if (std::isnan(cx)) {
|
if (std::isnan(cx)) {
|
||||||
cx = 0.0f;
|
cx = 0.0f;
|
||||||
}
|
}
|
||||||
if (std::isnan(cy)) {
|
if (std::isnan(cy)) {
|
||||||
cy = 0.0f;
|
cy = 0.0f;
|
||||||
}
|
}
|
||||||
// Brightness is simply Y in the XYZ space.
|
// Brightness is simply Y in the XYZ space.
|
||||||
CiColor xy = { cx, cy, Y };
|
CiColor xy = { cx, cy, Y };
|
||||||
// Check if the given XY value is within the color reach of our lamps.
|
// Check if the given XY value is within the color reach of our lamps.
|
||||||
if (!isPointInLampsReach(xy)) {
|
if (!isPointInLampsReach(xy)) {
|
||||||
// It seems the color is out of reach let's find the closes color we can produce with our lamp and send this XY value out.
|
// It seems the color is out of reach let's find the closes color we can produce with our lamp and send this XY value out.
|
||||||
CiColor pAB = getClosestPointToPoint(colorSpace.red, colorSpace.green, xy);
|
CiColor pAB = getClosestPointToPoint(colorSpace.red, colorSpace.green, xy);
|
||||||
CiColor pAC = getClosestPointToPoint(colorSpace.blue, colorSpace.red, xy);
|
CiColor pAC = getClosestPointToPoint(colorSpace.blue, colorSpace.red, xy);
|
||||||
CiColor pBC = getClosestPointToPoint(colorSpace.green, colorSpace.blue, xy);
|
CiColor pBC = getClosestPointToPoint(colorSpace.green, colorSpace.blue, xy);
|
||||||
// Get the distances per point and see which point is closer to our Point.
|
// Get the distances per point and see which point is closer to our Point.
|
||||||
float dAB = getDistanceBetweenTwoPoints(xy, pAB);
|
float dAB = getDistanceBetweenTwoPoints(xy, pAB);
|
||||||
float dAC = getDistanceBetweenTwoPoints(xy, pAC);
|
float dAC = getDistanceBetweenTwoPoints(xy, pAC);
|
||||||
float dBC = getDistanceBetweenTwoPoints(xy, pBC);
|
float dBC = getDistanceBetweenTwoPoints(xy, pBC);
|
||||||
float lowest = dAB;
|
float lowest = dAB;
|
||||||
CiColor closestPoint = pAB;
|
CiColor closestPoint = pAB;
|
||||||
if (dAC < lowest) {
|
if (dAC < lowest) {
|
||||||
lowest = dAC;
|
lowest = dAC;
|
||||||
closestPoint = pAC;
|
closestPoint = pAC;
|
||||||
}
|
}
|
||||||
if (dBC < lowest) {
|
if (dBC < lowest) {
|
||||||
lowest = dBC;
|
lowest = dBC;
|
||||||
closestPoint = pBC;
|
closestPoint = pBC;
|
||||||
}
|
}
|
||||||
// Change the xy value to a value which is within the reach of the lamp.
|
// Change the xy value to a value which is within the reach of the lamp.
|
||||||
xy.x = closestPoint.x;
|
xy.x = closestPoint.x;
|
||||||
xy.y = closestPoint.y;
|
xy.y = closestPoint.y;
|
||||||
}
|
}
|
||||||
return xy;
|
return xy;
|
||||||
}
|
}
|
||||||
|
|
||||||
LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output, const std::string& username, bool switchOffOnBlack,
|
LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output, const std::string& username, bool switchOffOnBlack,
|
||||||
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) {
|
||||||
manager = new QNetworkAccessManager();
|
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 manager;
|
delete manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
|
int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
|
||||||
// Save light states if not done before.
|
// Save light states if not done before.
|
||||||
if (!areStatesSaved()) {
|
if (!areStatesSaved()) {
|
||||||
saveStates((unsigned int) ledValues.size());
|
saveStates((unsigned int) ledValues.size());
|
||||||
switchOn((unsigned int) ledValues.size());
|
switchOn((unsigned int) ledValues.size());
|
||||||
}
|
}
|
||||||
// If there are less states saved than colors given, then maybe something went wrong before.
|
// If there are less states saved than colors given, then maybe something went wrong before.
|
||||||
if (lights.size() != ledValues.size()) {
|
if (lights.size() != ledValues.size()) {
|
||||||
restoreStates();
|
restoreStates();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// Iterate through colors and set light states.
|
// Iterate through colors and set light states.
|
||||||
unsigned int idx = 0;
|
unsigned int idx = 0;
|
||||||
for (const ColorRgb& color : ledValues) {
|
for (const ColorRgb& color : ledValues) {
|
||||||
// Get lamp.
|
// Get lamp.
|
||||||
PhilipsHueLight& lamp = lights.at(idx);
|
PhilipsHueLight& lamp = lights.at(idx);
|
||||||
// Scale colors from [0, 255] to [0, 1] and convert to xy space.
|
// Scale colors from [0, 255] to [0, 1] and convert to xy space.
|
||||||
CiColor xy = lamp.rgbToCiColor(color.red / 255.0f, color.green / 255.0f, color.blue / 255.0f);
|
CiColor xy = lamp.rgbToCiColor(color.red / 255.0f, color.green / 255.0f, color.blue / 255.0f);
|
||||||
// Write color if color has been changed.
|
// Write color if color has been changed.
|
||||||
if (xy != lamp.color) {
|
if (xy != lamp.color) {
|
||||||
// From a color to black.
|
// From a color to black.
|
||||||
if (switchOffOnBlack && lamp.color != lamp.black && xy == lamp.black) {
|
if (switchOffOnBlack && lamp.color != lamp.black && xy == lamp.black) {
|
||||||
put(getStateRoute(lamp.id), QString("{\"on\": false}"));
|
put(getStateRoute(lamp.id), QString("{\"on\": false}"));
|
||||||
}
|
}
|
||||||
// From black to a color
|
// From black to a color
|
||||||
else if (switchOffOnBlack && lamp.color == lamp.black && xy != lamp.black) {
|
else if (switchOffOnBlack && lamp.color == lamp.black && xy != lamp.black) {
|
||||||
// Send adjust color and brightness command in JSON format.
|
// Send adjust color and brightness command in JSON format.
|
||||||
// We have to set the transition time each time.
|
// We have to set the transition time each time.
|
||||||
// Send also command to switch the lamp on.
|
// Send also command to switch the lamp on.
|
||||||
put(getStateRoute(lamp.id),
|
put(getStateRoute(lamp.id),
|
||||||
QString("{\"on\": true, \"xy\": [%1, %2], \"bri\": %3, \"transitiontime\": %4}").arg(xy.x).arg(
|
QString("{\"on\": true, \"xy\": [%1, %2], \"bri\": %3, \"transitiontime\": %4}").arg(xy.x).arg(
|
||||||
xy.y).arg(qRound(xy.bri * 255.0f)).arg(transitiontime));
|
xy.y).arg(qRound(xy.bri * 255.0f)).arg(transitiontime));
|
||||||
}
|
}
|
||||||
// Normal color change.
|
// Normal color change.
|
||||||
else {
|
else {
|
||||||
// Send adjust color and brightness command in JSON format.
|
// Send adjust color and brightness command in JSON format.
|
||||||
// We have to set the transition time each time.
|
// We have to set the transition time each time.
|
||||||
put(getStateRoute(lamp.id),
|
put(getStateRoute(lamp.id),
|
||||||
QString("{\"xy\": [%1, %2], \"bri\": %3, \"transitiontime\": %4}").arg(xy.x).arg(xy.y).arg(
|
QString("{\"xy\": [%1, %2], \"bri\": %3, \"transitiontime\": %4}").arg(xy.x).arg(xy.y).arg(
|
||||||
qRound(xy.bri * 255.0f)).arg(transitiontime));
|
qRound(xy.bri * 255.0f)).arg(transitiontime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Remember last color.
|
// Remember last color.
|
||||||
lamp.color = xy;
|
lamp.color = xy;
|
||||||
// Next light id.
|
// Next light id.
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
timer.start();
|
timer.start();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LedDevicePhilipsHue::switchOff() {
|
int LedDevicePhilipsHue::switchOff() {
|
||||||
timer.stop();
|
timer.stop();
|
||||||
// If light states have been saved before, ...
|
// If light states have been saved before, ...
|
||||||
if (areStatesSaved()) {
|
if (areStatesSaved()) {
|
||||||
// ... restore them.
|
// ... restore them.
|
||||||
restoreStates();
|
restoreStates();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LedDevicePhilipsHue::put(QString route, QString content) {
|
void LedDevicePhilipsHue::put(QString route, QString content) {
|
||||||
QString url = getUrl(route);
|
QString url = getUrl(route);
|
||||||
// Perfrom request
|
// Perfrom request
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
QNetworkReply* reply = manager->put(request, content.toLatin1());
|
QNetworkReply* reply = manager->put(request, content.toLatin1());
|
||||||
// Connect finished signal to quit slot of the loop.
|
// Connect finished signal to quit slot of the loop.
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
loop.connect(reply, SIGNAL(finished()), SLOT(quit()));
|
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();
|
||||||
// Free space.
|
// Free space.
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray LedDevicePhilipsHue::get(QString route) {
|
QByteArray LedDevicePhilipsHue::get(QString route) {
|
||||||
QString url = getUrl(route);
|
QString url = getUrl(route);
|
||||||
// Perfrom request
|
// Perfrom request
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
QNetworkReply* reply = manager->get(request);
|
QNetworkReply* reply = manager->get(request);
|
||||||
// Connect requestFinished signal to quit slot of the loop.
|
// Connect requestFinished signal to quit slot of the loop.
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
loop.connect(reply, SIGNAL(finished()), SLOT(quit()));
|
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.
|
||||||
QByteArray response = reply->readAll();
|
QByteArray response = reply->readAll();
|
||||||
// Free space.
|
// Free space.
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
// Return response
|
// Return response
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LedDevicePhilipsHue::getStateRoute(unsigned int lightId) {
|
QString LedDevicePhilipsHue::getStateRoute(unsigned int lightId) {
|
||||||
return QString("lights/%1/state").arg(lightId);
|
return QString("lights/%1/state").arg(lightId);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LedDevicePhilipsHue::getRoute(unsigned int lightId) {
|
QString LedDevicePhilipsHue::getRoute(unsigned int lightId) {
|
||||||
return QString("lights/%1").arg(lightId);
|
return QString("lights/%1").arg(lightId);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LedDevicePhilipsHue::getUrl(QString route) {
|
QString LedDevicePhilipsHue::getUrl(QString route) {
|
||||||
return QString("http://%1/api/%2/%3").arg(host).arg(username).arg(route);
|
return QString("http://%1/api/%2/%3").arg(host).arg(username).arg(route);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LedDevicePhilipsHue::saveStates(unsigned int nLights) {
|
void LedDevicePhilipsHue::saveStates(unsigned int nLights) {
|
||||||
// Clear saved lamps.
|
// Clear saved lamps.
|
||||||
lights.clear();
|
lights.clear();
|
||||||
// Use json parser to parse reponse.
|
// Use json parser to parse reponse.
|
||||||
Json::Reader reader;
|
Json::Reader reader;
|
||||||
Json::FastWriter writer;
|
Json::FastWriter writer;
|
||||||
// Read light ids if none have been supplied by the user.
|
// Read light ids if none have been supplied by the user.
|
||||||
if (lightIds.size() != nLights) {
|
if (lightIds.size() != nLights) {
|
||||||
lightIds.clear();
|
lightIds.clear();
|
||||||
//
|
//
|
||||||
QByteArray response = get("lights");
|
QByteArray response = get("lights");
|
||||||
Json::Value json;
|
Json::Value json;
|
||||||
if (!reader.parse(QString(response).toStdString(), json)) {
|
if (!reader.parse(QString(response).toStdString(), json)) {
|
||||||
throw std::runtime_error(("No lights found at " + getUrl("lights")).toStdString());
|
throw std::runtime_error(("No lights found at " + getUrl("lights")).toStdString());
|
||||||
}
|
}
|
||||||
// Loop over all children.
|
// Loop over all children.
|
||||||
for (Json::ValueIterator it = json.begin(); it != json.end() && lightIds.size() < nLights; it++) {
|
for (Json::ValueIterator it = json.begin(); it != json.end() && lightIds.size() < nLights; it++) {
|
||||||
int lightId = atoi(it.key().asCString());
|
int lightId = atoi(it.key().asCString());
|
||||||
lightIds.push_back(lightId);
|
lightIds.push_back(lightId);
|
||||||
std::cout << "LedDevicePhilipsHue::saveStates(nLights=" << nLights << "): found light with id " << lightId
|
std::cout << "LedDevicePhilipsHue::saveStates(nLights=" << nLights << "): found light with id " << lightId
|
||||||
<< "." << std::endl;
|
<< "." << std::endl;
|
||||||
}
|
}
|
||||||
// Check if we found enough lights.
|
// Check if we found enough lights.
|
||||||
if (lightIds.size() != nLights) {
|
if (lightIds.size() != nLights) {
|
||||||
throw std::runtime_error(("Not enough lights found at " + getUrl("lights")).toStdString());
|
throw std::runtime_error(("Not enough lights found at " + getUrl("lights")).toStdString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Iterate lights.
|
// Iterate lights.
|
||||||
for (unsigned int i = 0; i < nLights; i++) {
|
for (unsigned int i = 0; i < nLights; i++) {
|
||||||
// Read the response.
|
// Read the response.
|
||||||
QByteArray response = get(getRoute(lightIds.at(i)));
|
QByteArray response = get(getRoute(lightIds.at(i)));
|
||||||
// Parse JSON.
|
// Parse JSON.
|
||||||
Json::Value json;
|
Json::Value json;
|
||||||
if (!reader.parse(QString(response).toStdString(), json)) {
|
if (!reader.parse(QString(response).toStdString(), json)) {
|
||||||
// Error occured, break loop.
|
// Error occured, break loop.
|
||||||
std::cerr << "LedDevicePhilipsHue::saveStates(nLights=" << nLights << "): got invalid response from light "
|
std::cerr << "LedDevicePhilipsHue::saveStates(nLights=" << nLights << "): got invalid response from light "
|
||||||
<< getUrl(getRoute(lightIds.at(i))).toStdString() << "." << std::endl;
|
<< getUrl(getRoute(lightIds.at(i))).toStdString() << "." << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Get state object values which are subject to change.
|
// Get state object values which are subject to change.
|
||||||
Json::Value state(Json::objectValue);
|
Json::Value state(Json::objectValue);
|
||||||
if (!json.isMember("state")) {
|
if (!json.isMember("state")) {
|
||||||
std::cerr << "LedDevicePhilipsHue::saveStates(nLights=" << nLights << "): got no state for light from "
|
std::cerr << "LedDevicePhilipsHue::saveStates(nLights=" << nLights << "): got no state for light from "
|
||||||
<< getUrl(getRoute(lightIds.at(i))).toStdString() << std::endl;
|
<< getUrl(getRoute(lightIds.at(i))).toStdString() << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!json["state"].isMember("on")) {
|
if (!json["state"].isMember("on")) {
|
||||||
std::cerr << "LedDevicePhilipsHue::saveStates(nLights=" << nLights << "): got no valid state from light "
|
std::cerr << "LedDevicePhilipsHue::saveStates(nLights=" << nLights << "): got no valid state from light "
|
||||||
<< getUrl(getRoute(lightIds.at(i))).toStdString() << std::endl;
|
<< getUrl(getRoute(lightIds.at(i))).toStdString() << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
state["on"] = json["state"]["on"];
|
state["on"] = json["state"]["on"];
|
||||||
if (json["state"]["on"] == true) {
|
if (json["state"]["on"] == true) {
|
||||||
state["xy"] = json["state"]["xy"];
|
state["xy"] = json["state"]["xy"];
|
||||||
state["bri"] = json["state"]["bri"];
|
state["bri"] = json["state"]["bri"];
|
||||||
}
|
}
|
||||||
// Determine the model id.
|
// Determine the model id.
|
||||||
QString modelId = QString(writer.write(json["modelid"]).c_str()).trimmed().replace("\"", "");
|
QString modelId = QString(writer.write(json["modelid"]).c_str()).trimmed().replace("\"", "");
|
||||||
QString originalState = QString(writer.write(state).c_str()).trimmed();
|
QString originalState = QString(writer.write(state).c_str()).trimmed();
|
||||||
// Save state object.
|
// Save state object.
|
||||||
lights.push_back(PhilipsHueLight(lightIds.at(i), originalState, modelId));
|
lights.push_back(PhilipsHueLight(lightIds.at(i), originalState, modelId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LedDevicePhilipsHue::switchOn(unsigned int nLights) {
|
void LedDevicePhilipsHue::switchOn(unsigned int nLights) {
|
||||||
for (PhilipsHueLight light : lights) {
|
for (PhilipsHueLight light : lights) {
|
||||||
put(getStateRoute(light.id), "{\"on\": true}");
|
put(getStateRoute(light.id), "{\"on\": true}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LedDevicePhilipsHue::restoreStates() {
|
void LedDevicePhilipsHue::restoreStates() {
|
||||||
for (PhilipsHueLight light : lights) {
|
for (PhilipsHueLight light : lights) {
|
||||||
put(getStateRoute(light.id), light.originalState);
|
put(getStateRoute(light.id), light.originalState);
|
||||||
}
|
}
|
||||||
// Clear saved light states.
|
// Clear saved light states.
|
||||||
lights.clear();
|
lights.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LedDevicePhilipsHue::areStatesSaved() {
|
bool LedDevicePhilipsHue::areStatesSaved() {
|
||||||
return !lights.empty();
|
return !lights.empty();
|
||||||
}
|
}
|
||||||
|
322
test/TestSpi.cpp
322
test/TestSpi.cpp
@ -1,161 +1,161 @@
|
|||||||
|
|
||||||
// STL includes
|
// STL includes
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// Local includes
|
// Local includes
|
||||||
#include <utils/ColorRgb.h>
|
#include <utils/ColorRgb.h>
|
||||||
|
|
||||||
#include "../libsrc/leddevice/LedDeviceWs2801.h"
|
#include "../libsrc/leddevice/LedDeviceWs2801.h"
|
||||||
|
|
||||||
void setColor(char* colorStr)
|
void setColor(char* colorStr)
|
||||||
{
|
{
|
||||||
ColorRgb color = ColorRgb::BLACK;
|
ColorRgb color = ColorRgb::BLACK;
|
||||||
std::cout << "Switching all leds to: ";
|
std::cout << "Switching all leds to: ";
|
||||||
if (strncmp("red", colorStr, 3) == 0)
|
if (strncmp("red", colorStr, 3) == 0)
|
||||||
{
|
{
|
||||||
std::cout << "red";
|
std::cout << "red";
|
||||||
color = ColorRgb::RED;
|
color = ColorRgb::RED;
|
||||||
}
|
}
|
||||||
else if (strncmp("green", colorStr, 5) == 0)
|
else if (strncmp("green", colorStr, 5) == 0)
|
||||||
{
|
{
|
||||||
std::cout << "green";
|
std::cout << "green";
|
||||||
color = ColorRgb::GREEN;
|
color = ColorRgb::GREEN;
|
||||||
}
|
}
|
||||||
else if (strncmp("blue", colorStr, 5) == 0)
|
else if (strncmp("blue", colorStr, 5) == 0)
|
||||||
{
|
{
|
||||||
std::cout << "blue";
|
std::cout << "blue";
|
||||||
color = ColorRgb::BLUE;
|
color = ColorRgb::BLUE;
|
||||||
}
|
}
|
||||||
else if (strncmp("cyan", colorStr, 5) == 0)
|
else if (strncmp("cyan", colorStr, 5) == 0)
|
||||||
{
|
{
|
||||||
std::cout << "cyan";
|
std::cout << "cyan";
|
||||||
}
|
}
|
||||||
else if (strncmp("gray", colorStr, 4) == 0)
|
else if (strncmp("gray", colorStr, 4) == 0)
|
||||||
{
|
{
|
||||||
std::cout << "gray";
|
std::cout << "gray";
|
||||||
}
|
}
|
||||||
else if (strncmp("white", colorStr, 5) == 0)
|
else if (strncmp("white", colorStr, 5) == 0)
|
||||||
{
|
{
|
||||||
std::cout << "white";
|
std::cout << "white";
|
||||||
color = ColorRgb::WHITE;
|
color = ColorRgb::WHITE;
|
||||||
}
|
}
|
||||||
else if (strncmp("black", colorStr, 5) == 0)
|
else if (strncmp("black", colorStr, 5) == 0)
|
||||||
{
|
{
|
||||||
std::cout << "black";
|
std::cout << "black";
|
||||||
color = ColorRgb::BLACK;
|
color = ColorRgb::BLACK;
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
unsigned ledCnt = 50;
|
unsigned ledCnt = 50;
|
||||||
std::vector<ColorRgb> buff(ledCnt, color);
|
std::vector<ColorRgb> buff(ledCnt, color);
|
||||||
|
|
||||||
LedDeviceWs2801 ledDevice("/dev/spidev0.0", 40000);
|
LedDeviceWs2801 ledDevice("/dev/spidev0.0", 40000);
|
||||||
ledDevice.open();
|
ledDevice.open();
|
||||||
ledDevice.write(buff);
|
ledDevice.write(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _running = true;
|
bool _running = true;
|
||||||
void doCircle()
|
void doCircle()
|
||||||
{
|
{
|
||||||
ColorRgb color_1 = ColorRgb::RED;
|
ColorRgb color_1 = ColorRgb::RED;
|
||||||
ColorRgb color_2 = ColorRgb::YELLOW;
|
ColorRgb color_2 = ColorRgb::YELLOW;
|
||||||
|
|
||||||
unsigned ledCnt = 50;
|
unsigned ledCnt = 50;
|
||||||
std::vector<ColorRgb> data(ledCnt, ColorRgb::BLACK);
|
std::vector<ColorRgb> data(ledCnt, ColorRgb::BLACK);
|
||||||
|
|
||||||
LedDeviceWs2801 ledDevice("/dev/spidev0.0", 40000);
|
LedDeviceWs2801 ledDevice("/dev/spidev0.0", 40000);
|
||||||
ledDevice.open();
|
ledDevice.open();
|
||||||
|
|
||||||
timespec loopTime;
|
timespec loopTime;
|
||||||
loopTime.tv_sec = 0;
|
loopTime.tv_sec = 0;
|
||||||
loopTime.tv_nsec = 100000000; // 100 ms
|
loopTime.tv_nsec = 100000000; // 100 ms
|
||||||
|
|
||||||
int curLed_1 = 0;
|
int curLed_1 = 0;
|
||||||
int nextLed_1 = 1;
|
int nextLed_1 = 1;
|
||||||
|
|
||||||
int curLed_2 = 49;
|
int curLed_2 = 49;
|
||||||
int nextLed_2 = 48;
|
int nextLed_2 = 48;
|
||||||
|
|
||||||
|
|
||||||
while (_running)
|
while (_running)
|
||||||
{
|
{
|
||||||
data[curLed_1] = ColorRgb::BLACK;
|
data[curLed_1] = ColorRgb::BLACK;
|
||||||
data[curLed_2] = ColorRgb::BLACK;
|
data[curLed_2] = ColorRgb::BLACK;
|
||||||
|
|
||||||
// Move the current and the next pointer
|
// Move the current and the next pointer
|
||||||
curLed_1 = nextLed_1;
|
curLed_1 = nextLed_1;
|
||||||
curLed_2 = nextLed_2;
|
curLed_2 = nextLed_2;
|
||||||
++nextLed_1;
|
++nextLed_1;
|
||||||
--nextLed_2;
|
--nextLed_2;
|
||||||
if (nextLed_1 == int(ledCnt))
|
if (nextLed_1 == int(ledCnt))
|
||||||
{
|
{
|
||||||
nextLed_1 = 0;
|
nextLed_1 = 0;
|
||||||
}
|
}
|
||||||
if (nextLed_2 < 0)
|
if (nextLed_2 < 0)
|
||||||
{
|
{
|
||||||
nextLed_2 = 49;
|
nextLed_2 = 49;
|
||||||
}
|
}
|
||||||
|
|
||||||
data[curLed_1] = color_1;
|
data[curLed_1] = color_1;
|
||||||
|
|
||||||
data[curLed_2] = color_2;
|
data[curLed_2] = color_2;
|
||||||
|
|
||||||
ledDevice.write(data);
|
ledDevice.write(data);
|
||||||
|
|
||||||
nanosleep(&loopTime, NULL);
|
nanosleep(&loopTime, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch the current leds off
|
// Switch the current leds off
|
||||||
data[curLed_1] = ColorRgb::BLACK;
|
data[curLed_1] = ColorRgb::BLACK;
|
||||||
data[curLed_2] = ColorRgb::BLACK;
|
data[curLed_2] = ColorRgb::BLACK;
|
||||||
|
|
||||||
ledDevice.write(data);
|
ledDevice.write(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
|
||||||
void signal_handler(int signum)
|
void signal_handler(int signum)
|
||||||
{
|
{
|
||||||
_running = false;
|
_running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (sizeof(ColorRgb) != 3)
|
if (sizeof(ColorRgb) != 3)
|
||||||
{
|
{
|
||||||
std::cout << "sizeof(ColorRgb) = " << sizeof(ColorRgb) << std::endl;
|
std::cout << "sizeof(ColorRgb) = " << sizeof(ColorRgb) << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install signal handlers to stop loops
|
// Install signal handlers to stop loops
|
||||||
signal(SIGTERM, &signal_handler);
|
signal(SIGTERM, &signal_handler);
|
||||||
signal(SIGINT, &signal_handler);
|
signal(SIGINT, &signal_handler);
|
||||||
|
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
{
|
{
|
||||||
std::cerr << "Missing argument" << std::endl;
|
std::cerr << "Missing argument" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp("fixed", argv[1], 5) == 0)
|
if (strncmp("fixed", argv[1], 5) == 0)
|
||||||
{
|
{
|
||||||
setColor(argv[2]);
|
setColor(argv[2]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (strncmp("circle", argv[1], 6) == 0)
|
else if (strncmp("circle", argv[1], 6) == 0)
|
||||||
{
|
{
|
||||||
doCircle();
|
doCircle();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "Unknown option: " << argv[1] << std::endl;
|
std::cerr << "Unknown option: " << argv[1] << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user