mirror of
				https://github.com/hyperion-project/hyperion.ng.git
				synced 2025-03-01 10:33:28 +00:00 
			
		
		
		
	Added Raw HID device
Former-commit-id: bd36530b6b63959ee4d83693e396cbb0af70ddb3
This commit is contained in:
		@@ -18,6 +18,8 @@ SET(Leddevice_QT_HEADERS
 | 
				
			|||||||
		${CURRENT_SOURCE_DIR}/LedDeviceAdalightApa102.h
 | 
							${CURRENT_SOURCE_DIR}/LedDeviceAdalightApa102.h
 | 
				
			||||||
		${CURRENT_SOURCE_DIR}/LedDeviceAmbiLed.h
 | 
							${CURRENT_SOURCE_DIR}/LedDeviceAmbiLed.h
 | 
				
			||||||
		${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.h
 | 
							${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.h
 | 
				
			||||||
 | 
							${CURRENT_SOURCE_DIR}/LedHIDDevice.h
 | 
				
			||||||
 | 
							${CURRENT_SOURCE_DIR}/LedDeviceRawHID.h
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SET(Leddevice_HEADERS
 | 
					SET(Leddevice_HEADERS
 | 
				
			||||||
@@ -39,10 +41,12 @@ SET(Leddevice_SOURCES
 | 
				
			|||||||
		${CURRENT_SOURCE_DIR}/LedDeviceFactory.cpp
 | 
							${CURRENT_SOURCE_DIR}/LedDeviceFactory.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		${CURRENT_SOURCE_DIR}/LedRs232Device.cpp
 | 
							${CURRENT_SOURCE_DIR}/LedRs232Device.cpp
 | 
				
			||||||
 | 
							${CURRENT_SOURCE_DIR}/LedHIDDevice.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		${CURRENT_SOURCE_DIR}/LedDeviceAdalight.cpp
 | 
							${CURRENT_SOURCE_DIR}/LedDeviceAdalight.cpp
 | 
				
			||||||
		${CURRENT_SOURCE_DIR}/LedDeviceAdalightApa102.cpp
 | 
							${CURRENT_SOURCE_DIR}/LedDeviceAdalightApa102.cpp
 | 
				
			||||||
		${CURRENT_SOURCE_DIR}/LedDeviceAmbiLed.cpp
 | 
							${CURRENT_SOURCE_DIR}/LedDeviceAmbiLed.cpp
 | 
				
			||||||
 | 
							${CURRENT_SOURCE_DIR}/LedDeviceRawHID.cpp
 | 
				
			||||||
		${CURRENT_SOURCE_DIR}/LedDeviceLightpack.cpp
 | 
							${CURRENT_SOURCE_DIR}/LedDeviceLightpack.cpp
 | 
				
			||||||
		${CURRENT_SOURCE_DIR}/LedDeviceMultiLightpack.cpp
 | 
							${CURRENT_SOURCE_DIR}/LedDeviceMultiLightpack.cpp
 | 
				
			||||||
		${CURRENT_SOURCE_DIR}/LedDevicePaintpack.cpp
 | 
							${CURRENT_SOURCE_DIR}/LedDevicePaintpack.cpp
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,6 +23,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "LedDeviceAdalight.h"
 | 
					#include "LedDeviceAdalight.h"
 | 
				
			||||||
#include "LedDeviceAmbiLed.h"
 | 
					#include "LedDeviceAmbiLed.h"
 | 
				
			||||||
 | 
					#include "LedDeviceRawHID.h"
 | 
				
			||||||
#include "LedDeviceLightpack.h"
 | 
					#include "LedDeviceLightpack.h"
 | 
				
			||||||
#include "LedDeviceMultiLightpack.h"
 | 
					#include "LedDeviceMultiLightpack.h"
 | 
				
			||||||
#include "LedDevicePaintpack.h"
 | 
					#include "LedDevicePaintpack.h"
 | 
				
			||||||
@@ -147,6 +148,21 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
 | 
				
			|||||||
		device = deviceTinkerforge;
 | 
							device = deviceTinkerforge;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
						else if (type == "rawhid")
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							const int delay_ms        = deviceConfig["delayAfterConnect"].asInt();
 | 
				
			||||||
 | 
							auto VendorIdString       = deviceConfig.get("VID", "0x2341").asString();
 | 
				
			||||||
 | 
							auto ProductIdString      = deviceConfig.get("PID", "0x8036").asString();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Convert HEX values to integer
 | 
				
			||||||
 | 
							auto VendorId = std::stoul(VendorIdString, nullptr, 16);
 | 
				
			||||||
 | 
							auto ProductId = std::stoul(ProductIdString, nullptr, 16);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							LedDeviceRawHID* deviceHID = new LedDeviceRawHID(VendorId, ProductId, delay_ms);
 | 
				
			||||||
 | 
							deviceHID->open();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							device = deviceHID;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	else if (type == "lightpack")
 | 
						else if (type == "lightpack")
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		const std::string output = deviceConfig.get("output", "").asString();
 | 
							const std::string output = deviceConfig.get("output", "").asString();
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										57
									
								
								libsrc/leddevice/LedDeviceRawHID.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								libsrc/leddevice/LedDeviceRawHID.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,57 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					// STL includes
 | 
				
			||||||
 | 
					#include <cstring>
 | 
				
			||||||
 | 
					#include <cstdio>
 | 
				
			||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Linux includes
 | 
				
			||||||
 | 
					#include <fcntl.h>
 | 
				
			||||||
 | 
					#include <sys/ioctl.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// hyperion local includes
 | 
				
			||||||
 | 
					#include "LedDeviceRawHID.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Use feature report HID device
 | 
				
			||||||
 | 
					LedDeviceRawHID::LedDeviceRawHID(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms) :
 | 
				
			||||||
 | 
						LedHIDDevice(VendorId, ProductId, delayAfterConnect_ms, true),
 | 
				
			||||||
 | 
						_ledBuffer(0),
 | 
				
			||||||
 | 
						_timer()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						// setup the timer
 | 
				
			||||||
 | 
						_timer.setSingleShot(false);
 | 
				
			||||||
 | 
						_timer.setInterval(5000);
 | 
				
			||||||
 | 
						connect(&_timer, SIGNAL(timeout()), this, SLOT(rewriteLeds()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// start the timer
 | 
				
			||||||
 | 
						_timer.start();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int LedDeviceRawHID::write(const std::vector<ColorRgb> & ledValues)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						// Resize buffer if required
 | 
				
			||||||
 | 
						if (_ledBuffer.size() < ledValues.size() * 3) {
 | 
				
			||||||
 | 
							_ledBuffer.resize(3 * ledValues.size());
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// restart the timer
 | 
				
			||||||
 | 
						_timer.start();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// write data
 | 
				
			||||||
 | 
						memcpy(_ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
 | 
				
			||||||
 | 
						return writeBytes(_ledBuffer.size(), _ledBuffer.data());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int LedDeviceRawHID::switchOff()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						// restart the timer
 | 
				
			||||||
 | 
						_timer.start();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// write data
 | 
				
			||||||
 | 
						std::fill(_ledBuffer.begin(), _ledBuffer.end(), uint8_t(0));
 | 
				
			||||||
 | 
						return writeBytes(_ledBuffer.size(), _ledBuffer.data());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void LedDeviceRawHID::rewriteLeds()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						writeBytes(_ledBuffer.size(), _ledBuffer.data());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										48
									
								
								libsrc/leddevice/LedDeviceRawHID.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								libsrc/leddevice/LedDeviceRawHID.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,48 @@
 | 
				
			|||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// STL includes
 | 
				
			||||||
 | 
					#include <string>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Qt includes
 | 
				
			||||||
 | 
					#include <QTimer>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// hyperion include
 | 
				
			||||||
 | 
					#include "LedHIDDevice.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					///
 | 
				
			||||||
 | 
					/// Implementation of the LedDevice interface for writing to an RawHID led device.
 | 
				
			||||||
 | 
					///
 | 
				
			||||||
 | 
					class LedDeviceRawHID : public LedHIDDevice
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						Q_OBJECT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
						///
 | 
				
			||||||
 | 
						/// Constructs the LedDevice for attached RawHID device
 | 
				
			||||||
 | 
						///
 | 
				
			||||||
 | 
						LedDeviceRawHID(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						///
 | 
				
			||||||
 | 
						/// 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 slots:
 | 
				
			||||||
 | 
						/// Write the last data to the leds again
 | 
				
			||||||
 | 
						void rewriteLeds();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
						/// The buffer containing the packed RGB values
 | 
				
			||||||
 | 
						std::vector<uint8_t> _ledBuffer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/// Timer object which makes sure that led data is written at a minimum rate
 | 
				
			||||||
 | 
						/// The RawHID device will switch off when it does not receive data at least
 | 
				
			||||||
 | 
						/// every 15 seconds
 | 
				
			||||||
 | 
						QTimer _timer;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
		Reference in New Issue
	
	Block a user