mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Adalight device added
Former-commit-id: d9b9a146b39ba83fada52de2b6076dde7e44b151
This commit is contained in:
42
libsrc/hyperion/device/LedDeviceAdalight.cpp
Normal file
42
libsrc/hyperion/device/LedDeviceAdalight.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
// STL includes
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
|
||||
// Linux includes
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
// hyperion local includes
|
||||
#include "LedDeviceAdalight.h"
|
||||
|
||||
LedDeviceAdalight::LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate) :
|
||||
LedRs232Device(outputDevice, baudrate),
|
||||
_ledBuffer(0)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
int LedDeviceAdalight::write(const std::vector<RgbColor> &ledValues)
|
||||
{
|
||||
if (_ledBuffer.size() == 0)
|
||||
{
|
||||
_ledBuffer.resize(6 + 3*ledValues.size());
|
||||
_ledBuffer[0] = 'A';
|
||||
_ledBuffer[1] = 'd';
|
||||
_ledBuffer[2] = 'a';
|
||||
_ledBuffer[3] = ((ledValues.size() - 1) >> 8) & 0xFF; // LED count high byte
|
||||
_ledBuffer[4] = (ledValues.size() - 1) & 0xFF; // LED count low byte
|
||||
_ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum
|
||||
}
|
||||
|
||||
memcpy(6 + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
|
||||
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||
}
|
||||
|
||||
int LedDeviceAdalight::switchOff()
|
||||
{
|
||||
memset(6 + _ledBuffer.data(), 0, _ledBuffer.size()-6);
|
||||
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||
}
|
37
libsrc/hyperion/device/LedDeviceAdalight.h
Normal file
37
libsrc/hyperion/device/LedDeviceAdalight.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <string>
|
||||
|
||||
// hyperion incluse
|
||||
#include "LedRs232Device.h"
|
||||
|
||||
///
|
||||
/// Implementation of the LedDevice interface for writing to an Adalight led device.
|
||||
///
|
||||
class LedDeviceAdalight : public LedRs232Device
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs the LedDevice for attached Adalight device
|
||||
///
|
||||
/// @param outputDevice The name of the output device (eg '/dev/ttyS0')
|
||||
/// @param baudrate The used baudrate for writing to the output device
|
||||
///
|
||||
LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate);
|
||||
|
||||
///
|
||||
/// 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<RgbColor> &ledValues);
|
||||
|
||||
/// Switch the leds off
|
||||
virtual int switchOff();
|
||||
|
||||
private:
|
||||
/// The buffer containing the packed RGB values
|
||||
std::vector<uint8_t> _ledBuffer;
|
||||
};
|
@@ -15,7 +15,7 @@ public:
|
||||
///
|
||||
/// Constructs the LedDevice for attached via SEDU device
|
||||
///
|
||||
/// @param outputDevice The name of the output device (eg '/etc/ttyS0')
|
||||
/// @param outputDevice The name of the output device (eg '/dev/ttyS0')
|
||||
/// @param baudrate The used baudrate for writing to the output device
|
||||
///
|
||||
LedDeviceSedu(const std::string& outputDevice, const unsigned baudrate);
|
||||
|
@@ -48,9 +48,9 @@ int LedRs232Device::writeBytes(const unsigned size, const uint8_t * data)
|
||||
return -1;
|
||||
}
|
||||
|
||||
//for (int i = 0; i < 20; ++i)
|
||||
// std::cout << std::hex << (int)data[i] << " ";
|
||||
//std::cout << std::endl;
|
||||
// for (int i = 0; i < 20; ++i)
|
||||
// std::cout << std::hex << (int)data[i] << " ";
|
||||
// std::cout << std::endl;
|
||||
|
||||
try
|
||||
{
|
||||
|
Reference in New Issue
Block a user