diff --git a/libsrc/leddevice/LedDeviceP9813.cpp b/libsrc/leddevice/LedDeviceP9813.cpp new file mode 100644 index 00000000..457cfe8c --- /dev/null +++ b/libsrc/leddevice/LedDeviceP9813.cpp @@ -0,0 +1,34 @@ + +// STL includes +#include +#include +#include + +// Linux includes +#include +#include + +// hyperion local includes +#include "LedDeviceP9813.h" + +LedDeviceP9813::LedDeviceP9813(const std::string& outputDevice, const unsigned baudrate) : + LedSpiDevice(outputDevice, baudrate, 0), + mLedCount(0) +{ + // empty +} + +int LedDeviceP9813::write(const std::vector &ledValues) +{ + mLedCount = ledValues.size(); + + const unsigned dataLen = ledValues.size() * sizeof(ColorRgb); + const uint8_t * dataPtr = reinterpret_cast(ledValues.data()); + + return writeBytes(dataLen, dataPtr); +} + +int LedDeviceP9813::switchOff() +{ + return write(std::vector(mLedCount, ColorRgb{0,0,0})); +} diff --git a/libsrc/leddevice/LedDeviceP9813.h b/libsrc/leddevice/LedDeviceP9813.h new file mode 100644 index 00000000..3559354b --- /dev/null +++ b/libsrc/leddevice/LedDeviceP9813.h @@ -0,0 +1,39 @@ +#pragma once + +// STL includes +#include + +// hyperion include +#include "LedSpiDevice.h" + +/// +/// Implementation of the LedDevice interface for writing to P9813 led device. +/// +class LedDeviceP9813 : public LedSpiDevice +{ +public: + /// + /// Constructs the LedDevice for a string containing leds of the type P9813 + /// + /// @param outputDevice The name of the output device (eg '/etc/SpiDev.0.0') + /// @param baudrate The used baudrate for writing to the output device + /// + LedDeviceP9813(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 &ledValues); + + /// Switch the leds off + virtual int switchOff(); + +private: + + /// the number of leds + size_t mLedCount; +};