mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Merge branch 'paintpack' into add_effect_engine
Conflicts: libsrc/hyperion/CMakeLists.txt Former-commit-id: c8264fed9cdf560da1621700e105b24977c58b7b
This commit is contained in:
commit
a74801a113
@ -40,6 +40,7 @@ SET(Hyperion_HEADERS
|
||||
${CURRENT_SOURCE_DIR}/device/LedDeviceLpd6803.h
|
||||
${CURRENT_SOURCE_DIR}/device/LedDeviceLpd8806.h
|
||||
${CURRENT_SOURCE_DIR}/device/LedDeviceLightpack.h
|
||||
${CURRENT_SOURCE_DIR}/device/LedDevicePaintpack.h
|
||||
${CURRENT_SOURCE_DIR}/device/LedDeviceMultiLightpack.h
|
||||
)
|
||||
|
||||
@ -65,6 +66,7 @@ SET(Hyperion_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/device/LedDeviceLpd8806.cpp
|
||||
${CURRENT_SOURCE_DIR}/device/LedDeviceAdalight.cpp
|
||||
${CURRENT_SOURCE_DIR}/device/LedDeviceLightpack.cpp
|
||||
${CURRENT_SOURCE_DIR}/device/LedDevicePaintpack.cpp
|
||||
${CURRENT_SOURCE_DIR}/device/LedDeviceMultiLightpack.cpp
|
||||
)
|
||||
|
||||
@ -87,6 +89,7 @@ add_library(hyperion
|
||||
target_link_libraries(hyperion
|
||||
hyperion-utils
|
||||
effectengine
|
||||
hidapi-libusb
|
||||
serialport
|
||||
${LIBUSB_1_LIBRARIES} #apt-get install libusb-1.0-0-dev
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "device/LedDeviceTest.h"
|
||||
#include "device/LedDeviceWs2801.h"
|
||||
#include "device/LedDeviceAdalight.h"
|
||||
#include "device/LedDevicePaintpack.h"
|
||||
#include "device/LedDeviceLightpack.h"
|
||||
#include "device/LedDeviceMultiLightpack.h"
|
||||
|
||||
@ -99,6 +100,13 @@ LedDevice* Hyperion::createDevice(const Json::Value& deviceConfig)
|
||||
|
||||
device = deviceLightpack;
|
||||
}
|
||||
else if (type == "paintpack")
|
||||
{
|
||||
LedDevicePaintpack * devicePainLightpack = new LedDevicePaintpack();
|
||||
devicePainLightpack->open();
|
||||
|
||||
device = devicePainLightpack;
|
||||
}
|
||||
else if (type == "multi-lightpack")
|
||||
{
|
||||
LedDeviceMultiLightpack* deviceLightpack = new LedDeviceMultiLightpack();
|
||||
|
77
libsrc/hyperion/device/LedDevicePaintpack.cpp
Normal file
77
libsrc/hyperion/device/LedDevicePaintpack.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
|
||||
// Hyperion includes
|
||||
#include "LedDevicePaintpack.h"
|
||||
|
||||
LedDevicePaintpack::LedDevicePaintpack() :
|
||||
LedDevice(),
|
||||
_deviceHandle(nullptr)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
int LedDevicePaintpack::open()
|
||||
{
|
||||
// initialize the usb context
|
||||
int error = hid_init();
|
||||
if (error != 0)
|
||||
{
|
||||
std::cerr << "Error while initializing the hidapi context" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "Hidapi initialized" << std::endl;
|
||||
|
||||
// Initialise the paintpack device
|
||||
const unsigned short Paintpack_VendorId = 0x0ebf;
|
||||
const unsigned short Paintpack_ProductId = 0x0025;
|
||||
_deviceHandle = hid_open(Paintpack_VendorId, Paintpack_ProductId, nullptr);
|
||||
if (_deviceHandle == nullptr)
|
||||
{
|
||||
// Failed to open the device
|
||||
std::cerr << "Failed to open HID Paintpakc device " << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
LedDevicePaintpack::~LedDevicePaintpack()
|
||||
{
|
||||
if (_deviceHandle != nullptr)
|
||||
{
|
||||
hid_close(_deviceHandle);
|
||||
_deviceHandle = nullptr;
|
||||
}
|
||||
|
||||
hid_exit();
|
||||
}
|
||||
|
||||
int LedDevicePaintpack::write(const std::vector<ColorRgb>& ledValues)
|
||||
{
|
||||
if (_ledBuffer.size() < 3 + ledValues.size()*3)
|
||||
{
|
||||
_ledBuffer.resize(3 + ledValues.size()*3, uint8_t(0));
|
||||
|
||||
_ledBuffer[0] = 0;
|
||||
_ledBuffer[1] = 3;
|
||||
_ledBuffer[2] = 0;
|
||||
}
|
||||
|
||||
auto bufIt = _ledBuffer.begin()+3;
|
||||
for (const ColorRgb & ledValue : ledValues)
|
||||
{
|
||||
*bufIt = ledValue.red;
|
||||
++bufIt;
|
||||
*bufIt = ledValue.green;
|
||||
++bufIt;
|
||||
*bufIt = ledValue.blue;
|
||||
++bufIt;
|
||||
}
|
||||
|
||||
return hid_write(_deviceHandle, _ledBuffer.data(), _ledBuffer.size());
|
||||
}
|
||||
|
||||
int LedDevicePaintpack::switchOff()
|
||||
{
|
||||
std::fill(_ledBuffer.begin()+3, _ledBuffer.end(), uint8_t(0));
|
||||
return hid_write(_deviceHandle, _ledBuffer.data(), _ledBuffer.size());
|
||||
}
|
59
libsrc/hyperion/device/LedDevicePaintpack.h
Normal file
59
libsrc/hyperion/device/LedDevicePaintpack.h
Normal file
@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <vector>
|
||||
|
||||
// libusb include
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
// Hyperion includes
|
||||
#include <hyperion/LedDevice.h>
|
||||
|
||||
///
|
||||
/// LedDevice implementation for a paintpack device ()
|
||||
///
|
||||
class LedDevicePaintpack : public LedDevice
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructs the paintpack device
|
||||
*/
|
||||
LedDevicePaintpack();
|
||||
|
||||
/**
|
||||
* Destructs the paintpack device, closes USB connection if open
|
||||
*/
|
||||
virtual ~LedDevicePaintpack();
|
||||
|
||||
/**
|
||||
* Opens the Paintpack device
|
||||
*
|
||||
* @return Zero on succes else negative
|
||||
*/
|
||||
int open();
|
||||
|
||||
///
|
||||
/// Writes the RGB-Color values to the leds.
|
||||
///
|
||||
/// @param[in] ledValues The RGB-color per led
|
||||
///
|
||||
/// @return Zero on success else negative
|
||||
///
|
||||
virtual int write(const std::vector<ColorRgb>& ledValues);
|
||||
|
||||
///
|
||||
/// Switch the leds off
|
||||
///
|
||||
/// @return Zero on success else negative
|
||||
///
|
||||
virtual int switchOff();
|
||||
|
||||
private:
|
||||
/// libusb device handle
|
||||
hid_device * _deviceHandle;
|
||||
|
||||
/// buffer for led data
|
||||
std::vector<uint8_t> _ledBuffer;
|
||||
|
||||
|
||||
};
|
Loading…
Reference in New Issue
Block a user