2013-12-23 22:58:54 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// Hyperion leddevice includes
|
|
|
|
#include "LedRs232Device.h"
|
|
|
|
|
2013-12-25 16:37:59 +01:00
|
|
|
///
|
|
|
|
/// The LedDevice for controlling a string of WS2812B leds. These are controlled over the mini-UART
|
|
|
|
/// of the RPi (/dev/ttyAMA0).
|
|
|
|
///
|
2013-12-23 22:58:54 +01:00
|
|
|
class LedDeviceWs2812b : public LedRs232Device
|
|
|
|
{
|
|
|
|
public:
|
2013-12-25 16:37:59 +01:00
|
|
|
///
|
|
|
|
/// Constructs the device (all required parameters are hardcoded)
|
|
|
|
///
|
2013-12-23 22:58:54 +01:00
|
|
|
LedDeviceWs2812b();
|
|
|
|
|
2013-12-25 16:37:59 +01:00
|
|
|
///
|
|
|
|
/// Write the color data the the WS2812B led string
|
|
|
|
///
|
|
|
|
/// @param ledValues The color data
|
|
|
|
/// @return Zero on succes else negative
|
|
|
|
///
|
2013-12-23 22:58:54 +01:00
|
|
|
virtual int write(const std::vector<ColorRgb> & ledValues);
|
|
|
|
|
2013-12-25 16:37:59 +01:00
|
|
|
///
|
|
|
|
/// Write zero to all leds(that have been written by a previous write operation)
|
|
|
|
///
|
|
|
|
/// @return Zero on succes else negative
|
|
|
|
///
|
2013-12-23 22:58:54 +01:00
|
|
|
virtual int switchOff();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2013-12-25 16:37:59 +01:00
|
|
|
///
|
2013-12-29 20:22:55 +01:00
|
|
|
/// Translate a color to the signal bits. The resulting bits are written to the given memory.
|
2013-12-25 16:37:59 +01:00
|
|
|
///
|
2013-12-29 20:22:55 +01:00
|
|
|
/// @param color The color to translate
|
|
|
|
/// @param signal The pointer at the beginning of the signal to write
|
|
|
|
/// @return The pointer at the end of the written signal
|
2013-12-25 16:37:59 +01:00
|
|
|
///
|
2013-12-29 20:22:55 +01:00
|
|
|
uint8_t * color2signal(const ColorRgb & color, uint8_t * signal);
|
2013-12-23 22:58:54 +01:00
|
|
|
|
2013-12-25 16:37:59 +01:00
|
|
|
///
|
2013-12-29 20:22:55 +01:00
|
|
|
/// Translates three bits to a single byte
|
2013-12-25 16:37:59 +01:00
|
|
|
///
|
|
|
|
/// @param bit1 The value of the first bit (1=true, zero=false)
|
2013-12-29 20:22:55 +01:00
|
|
|
/// @param bit2 The value of the second bit (1=true, zero=false)
|
|
|
|
/// @param bit3 The value of the third bit (1=true, zero=false)
|
2013-12-25 16:37:59 +01:00
|
|
|
///
|
|
|
|
/// @return The output-byte for the given two bit
|
|
|
|
///
|
2013-12-29 20:22:55 +01:00
|
|
|
uint8_t bits2Signal(const bool bit1, const bool bit2, const bool bit3) const;
|
2013-12-23 22:58:54 +01:00
|
|
|
|
2013-12-25 16:37:59 +01:00
|
|
|
///
|
|
|
|
/// The output buffer for writing bytes to the output
|
|
|
|
///
|
2013-12-29 20:22:55 +01:00
|
|
|
std::vector<uint8_t> _ledBuffer;
|
2013-12-23 22:58:54 +01:00
|
|
|
};
|