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
|
|
|
///
|
|
|
|
/// Structure holding the four output-bytes corresponding to a single input byte
|
|
|
|
///
|
2013-12-23 22:58:54 +01:00
|
|
|
struct ByteSignal
|
|
|
|
{
|
|
|
|
uint8_t bit_12;
|
|
|
|
uint8_t bit_34;
|
|
|
|
uint8_t bit_56;
|
|
|
|
uint8_t bit_78;
|
|
|
|
};
|
2013-12-25 16:37:59 +01:00
|
|
|
/// Translation table from single input-byte to output-bytes
|
2013-12-23 22:58:54 +01:00
|
|
|
std::vector<ByteSignal> _byte2signalTable;
|
|
|
|
|
2013-12-25 16:37:59 +01:00
|
|
|
///
|
|
|
|
/// Fills the translation table (_byte2signalTable)
|
|
|
|
///
|
2013-12-23 22:58:54 +01:00
|
|
|
void fillTable();
|
|
|
|
|
2013-12-25 16:37:59 +01:00
|
|
|
///
|
|
|
|
/// Computes the output bytes that belong to a given input-byte (no table lookup)
|
|
|
|
///
|
|
|
|
/// @param byte The input byte
|
|
|
|
/// @return The four bytes (ByteSignal) for the output signal
|
|
|
|
///
|
2013-12-23 22:58:54 +01:00
|
|
|
ByteSignal byte2Signal(const uint8_t byte) const;
|
|
|
|
|
2013-12-25 16:37:59 +01:00
|
|
|
///
|
|
|
|
/// Translates two bits to a single byte
|
|
|
|
///
|
|
|
|
/// @param bit1 The value of the first bit (1=true, zero=false)
|
|
|
|
/// @param bit1 The value of the ssecond bit (1=true, zero=false)
|
|
|
|
///
|
|
|
|
/// @return The output-byte for the given two bit
|
|
|
|
///
|
2013-12-23 22:58:54 +01:00
|
|
|
uint8_t bits2Signal(const bool bit1, const bool bit2) const;
|
|
|
|
|
2013-12-25 16:37:59 +01:00
|
|
|
///
|
|
|
|
/// The output buffer for writing bytes to the output
|
|
|
|
///
|
2013-12-23 22:58:54 +01:00
|
|
|
std::vector<ByteSignal> _ledBuffer;
|
|
|
|
};
|