mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Updated constructor of ws2811 to contain chip configuration
Former-commit-id: 330056ce83edb3e7fa4d36961a52f8d413e289bb
This commit is contained in:
parent
bd6e0f0d2a
commit
90150b06dc
@ -49,10 +49,17 @@ LedDevice* Hyperion::createDevice(const Json::Value& deviceConfig)
|
|||||||
}
|
}
|
||||||
else if (type == "ws2811")
|
else if (type == "ws2811")
|
||||||
{
|
{
|
||||||
const std::string type = deviceConfig["type"].asString();
|
const std::string output = deviceConfig["output"].asString();
|
||||||
const std::string output = deviceConfig["output"].asString();
|
const std::string outputSpeed = deviceConfig["output"].asString();
|
||||||
|
const std::string timingOption = deviceConfig["timingOption"].asString();
|
||||||
|
|
||||||
LedDeviceWs2811 * deviceWs2811 = new LedDeviceWs2811(output);
|
ws2811::SpeedMode speedMode = (outputSpeed == "high")? ws2811::highspeed : ws2811::lowspeed;
|
||||||
|
if (outputSpeed != "high" && outputSpeed != "low")
|
||||||
|
{
|
||||||
|
std::cerr << "Incorrect speed-mode selected for WS2811: " << outputSpeed << " != {'high', 'low'}" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
LedDeviceWs2811 * deviceWs2811 = new LedDeviceWs2811(output, ws2811::fromString(timingOption, ws2811::option_2855), speedMode);
|
||||||
deviceWs2811->open();
|
deviceWs2811->open();
|
||||||
|
|
||||||
device = deviceWs2811;
|
device = deviceWs2811;
|
||||||
|
@ -133,10 +133,13 @@ ws2811::ByteSignal ws2811::translate(SignalTiming ledOption, uint8_t byte)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
LedDeviceWs2811::LedDeviceWs2811(const std::string & deviceName) :
|
LedDeviceWs2811::LedDeviceWs2811(
|
||||||
LedRs232Device(deviceName, ws2811::getBaudrate(ws2811::highspeed))
|
const std::string & outputDevice,
|
||||||
|
const ws2811::SignalTiming signalTiming,
|
||||||
|
const ws2811::SpeedMode speedMode) :
|
||||||
|
LedRs232Device(outputDevice, ws2811::getBaudrate(speedMode))
|
||||||
{
|
{
|
||||||
fillEncodeTable(ws2811::option_2882);
|
fillEncodeTable(signalTiming);
|
||||||
}
|
}
|
||||||
|
|
||||||
int LedDeviceWs2811::write(const std::vector<ColorRgb> & ledValues)
|
int LedDeviceWs2811::write(const std::vector<ColorRgb> & ledValues)
|
||||||
|
@ -8,9 +8,9 @@
|
|||||||
|
|
||||||
namespace ws2811
|
namespace ws2811
|
||||||
{
|
{
|
||||||
/**
|
///
|
||||||
* Enumaration of known signal timings
|
/// Enumaration of known signal timings
|
||||||
*/
|
///
|
||||||
enum SignalTiming
|
enum SignalTiming
|
||||||
{
|
{
|
||||||
option_3755,
|
option_3755,
|
||||||
@ -20,15 +20,18 @@ namespace ws2811
|
|||||||
not_a_signaltiming
|
not_a_signaltiming
|
||||||
};
|
};
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Enumaration of the possible speeds on which the ws2811 can operate.
|
||||||
|
///
|
||||||
enum SpeedMode
|
enum SpeedMode
|
||||||
{
|
{
|
||||||
lowspeed,
|
lowspeed,
|
||||||
highspeed
|
highspeed
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Enumeration of the signal 'parts' (T 0 high, T 1 high, T 0 low, T 1 low).
|
/// Enumeration of the signal 'parts' (T 0 high, T 1 high, T 0 low, T 1 low).
|
||||||
*/
|
///
|
||||||
enum TimeOption
|
enum TimeOption
|
||||||
{
|
{
|
||||||
T0H,
|
T0H,
|
||||||
@ -37,9 +40,9 @@ namespace ws2811
|
|||||||
T1L
|
T1L
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Structure holding the signal for a signle byte
|
/// Structure holding the signal for a signle byte
|
||||||
*/
|
///
|
||||||
struct ByteSignal
|
struct ByteSignal
|
||||||
{
|
{
|
||||||
uint8_t bit_1;
|
uint8_t bit_1;
|
||||||
@ -54,52 +57,52 @@ namespace ws2811
|
|||||||
// Make sure the structure is exatly the length we require
|
// Make sure the structure is exatly the length we require
|
||||||
static_assert(sizeof(ByteSignal) == 8, "Incorrect sizeof ByteSignal (expected 8)");
|
static_assert(sizeof(ByteSignal) == 8, "Incorrect sizeof ByteSignal (expected 8)");
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Translates a string to a signal timing
|
/// Translates a string to a signal timing
|
||||||
*
|
///
|
||||||
* @param signalTiming The string specifying the signal timing
|
/// @param signalTiming The string specifying the signal timing
|
||||||
* @param defaultValue The default value (used if the string does not match any known timing)
|
/// @param defaultValue The default value (used if the string does not match any known timing)
|
||||||
*
|
///
|
||||||
* @return The SignalTiming (or not_a_signaltiming if it did not match)
|
/// @return The SignalTiming (or not_a_signaltiming if it did not match)
|
||||||
*/
|
///
|
||||||
SignalTiming fromString(const std::string& signalTiming, const SignalTiming defaultValue);
|
SignalTiming fromString(const std::string& signalTiming, const SignalTiming defaultValue);
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Returns the required baudrate for a specific signal-timing
|
/// Returns the required baudrate for a specific signal-timing
|
||||||
*
|
///
|
||||||
* @param SpeedMode The WS2811/WS2812 speed mode (WS2812b only has highspeed)
|
/// @param SpeedMode The WS2811/WS2812 speed mode (WS2812b only has highspeed)
|
||||||
*
|
///
|
||||||
* @return The required baudrate for the signal timing
|
/// @return The required baudrate for the signal timing
|
||||||
*/
|
///
|
||||||
unsigned getBaudrate(const SpeedMode speedMode);
|
unsigned getBaudrate(const SpeedMode speedMode);
|
||||||
|
|
||||||
/**
|
///
|
||||||
* The number of 'signal units' (bits) For the subpart of a specific timing scheme
|
/// The number of 'signal units' (bits) For the subpart of a specific timing scheme
|
||||||
*
|
///
|
||||||
* @param timing The controller option
|
/// @param timing The controller option
|
||||||
* @param option The signal part
|
/// @param option The signal part
|
||||||
*/
|
///
|
||||||
unsigned getLength(const SignalTiming timing, const TimeOption option);
|
unsigned getLength(const SignalTiming timing, const TimeOption option);
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Constructs a 'bit' based signal with defined 'high' length (and implicite defined 'low'
|
/// Constructs a 'bit' based signal with defined 'high' length (and implicite defined 'low'
|
||||||
* length. The signal is based on a 10bits bytes (incl. high startbit and low stopbit). The
|
/// length. The signal is based on a 10bits bytes (incl. high startbit and low stopbit). The
|
||||||
* total length of the high is given as parameter:<br>
|
/// total length of the high is given as parameter:<br>
|
||||||
* lenHigh=7 => |-------|___| => 1 1111 1100 0 => 252 (start and stop bit are implicite)
|
/// lenHigh=7 => |-------|___| => 1 1111 1100 0 => 252 (start and stop bit are implicite)
|
||||||
*
|
///
|
||||||
* @param lenHigh The total length of the 'high' length (incl start-bit)
|
/// @param lenHigh The total length of the 'high' length (incl start-bit)
|
||||||
* @return The byte representing the high-low signal
|
/// @return The byte representing the high-low signal
|
||||||
*/
|
///
|
||||||
uint8_t bitToSignal(unsigned lenHigh);
|
uint8_t bitToSignal(unsigned lenHigh);
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Translate a byte into signal levels for a specific WS2811 option
|
/// Translate a byte into signal levels for a specific WS2811 option
|
||||||
*
|
///
|
||||||
* @param ledOption The WS2811 configuration
|
/// @param ledOption The WS2811 configuration
|
||||||
* @param byte The byte to translate
|
/// @param byte The byte to translate
|
||||||
*
|
///
|
||||||
* @return The signal for the given byte (one byte per bit)
|
/// @return The signal for the given byte (one byte per bit)
|
||||||
*/
|
///
|
||||||
ByteSignal translate(SignalTiming ledOption, uint8_t byte);
|
ByteSignal translate(SignalTiming ledOption, uint8_t byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,9 +113,10 @@ public:
|
|||||||
/// Constructs the LedDevice with Ws2811 attached via a serial port
|
/// Constructs the LedDevice with Ws2811 attached via a serial port
|
||||||
///
|
///
|
||||||
/// @param outputDevice The name of the output device (eg '/dev/ttyS0')
|
/// @param outputDevice The name of the output device (eg '/dev/ttyS0')
|
||||||
/// @param fastDevice The used baudrate for writing to the output device
|
/// @param signalTiming The timing scheme used by the Ws2811 chip
|
||||||
|
/// @param speedMode The speed modus of the Ws2811 chip
|
||||||
///
|
///
|
||||||
LedDeviceWs2811(const std::string& outputDevice);
|
LedDeviceWs2811(const std::string& outputDevice, const ws2811::SignalTiming signalTiming, const ws2811::SpeedMode speedMode);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Writes the led color values to the led-device
|
/// Writes the led color values to the led-device
|
||||||
@ -128,8 +132,14 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Fill the byte encoding table (_byteToSignalTable) for the specific timing option
|
||||||
|
///
|
||||||
|
/// @param ledOption The timing option
|
||||||
|
///
|
||||||
void fillEncodeTable(const ws2811::SignalTiming ledOption);
|
void fillEncodeTable(const ws2811::SignalTiming ledOption);
|
||||||
/** Translation table of byte to signal */
|
|
||||||
|
/// Translation table of byte to signal///
|
||||||
std::vector<ws2811::ByteSignal> _byteToSignalTable;
|
std::vector<ws2811::ByteSignal> _byteToSignalTable;
|
||||||
|
|
||||||
/// The buffer containing the packed RGB values
|
/// The buffer containing the packed RGB values
|
||||||
|
Loading…
Reference in New Issue
Block a user