Updated constructor of ws2811 to contain chip configuration

Former-commit-id: 330056ce83edb3e7fa4d36961a52f8d413e289bb
This commit is contained in:
T. van der Zwan 2013-12-17 15:59:25 +00:00
parent bd6e0f0d2a
commit 90150b06dc
3 changed files with 76 additions and 56 deletions

View File

@ -49,10 +49,17 @@ LedDevice* Hyperion::createDevice(const Json::Value& deviceConfig)
}
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();
device = deviceWs2811;

View File

@ -133,10 +133,13 @@ ws2811::ByteSignal ws2811::translate(SignalTiming ledOption, uint8_t byte)
return result;
}
LedDeviceWs2811::LedDeviceWs2811(const std::string & deviceName) :
LedRs232Device(deviceName, ws2811::getBaudrate(ws2811::highspeed))
LedDeviceWs2811::LedDeviceWs2811(
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)

View File

@ -8,9 +8,9 @@
namespace ws2811
{
/**
* Enumaration of known signal timings
*/
///
/// Enumaration of known signal timings
///
enum SignalTiming
{
option_3755,
@ -20,15 +20,18 @@ namespace ws2811
not_a_signaltiming
};
///
/// Enumaration of the possible speeds on which the ws2811 can operate.
///
enum SpeedMode
{
lowspeed,
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
{
T0H,
@ -37,9 +40,9 @@ namespace ws2811
T1L
};
/**
* Structure holding the signal for a signle byte
*/
///
/// Structure holding the signal for a signle byte
///
struct ByteSignal
{
uint8_t bit_1;
@ -54,52 +57,52 @@ namespace ws2811
// Make sure the structure is exatly the length we require
static_assert(sizeof(ByteSignal) == 8, "Incorrect sizeof ByteSignal (expected 8)");
/**
* Translates a string to a 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)
*
* @return The SignalTiming (or not_a_signaltiming if it did not match)
*/
///
/// Translates a string to a 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)
///
/// @return The SignalTiming (or not_a_signaltiming if it did not match)
///
SignalTiming fromString(const std::string& signalTiming, const SignalTiming defaultValue);
/**
* Returns the required baudrate for a specific signal-timing
*
* @param SpeedMode The WS2811/WS2812 speed mode (WS2812b only has highspeed)
*
* @return The required baudrate for the signal timing
*/
///
/// Returns the required baudrate for a specific signal-timing
///
/// @param SpeedMode The WS2811/WS2812 speed mode (WS2812b only has highspeed)
///
/// @return The required baudrate for the signal timing
///
unsigned getBaudrate(const SpeedMode speedMode);
/**
* The number of 'signal units' (bits) For the subpart of a specific timing scheme
*
* @param timing The controller option
* @param option The signal part
*/
///
/// The number of 'signal units' (bits) For the subpart of a specific timing scheme
///
/// @param timing The controller option
/// @param option The signal part
///
unsigned getLength(const SignalTiming timing, const TimeOption option);
/**
* 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
* total length of the high is given as parameter:<br>
* 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)
* @return The byte representing the high-low signal
*/
///
/// 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
/// total length of the high is given as parameter:<br>
/// 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)
/// @return The byte representing the high-low signal
///
uint8_t bitToSignal(unsigned lenHigh);
/**
* Translate a byte into signal levels for a specific WS2811 option
*
* @param ledOption The WS2811 configuration
* @param byte The byte to translate
*
* @return The signal for the given byte (one byte per bit)
*/
///
/// Translate a byte into signal levels for a specific WS2811 option
///
/// @param ledOption The WS2811 configuration
/// @param byte The byte to translate
///
/// @return The signal for the given byte (one byte per bit)
///
ByteSignal translate(SignalTiming ledOption, uint8_t byte);
}
@ -110,9 +113,10 @@ public:
/// Constructs the LedDevice with Ws2811 attached via a serial port
///
/// @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
@ -128,8 +132,14 @@ public:
private:
///
/// Fill the byte encoding table (_byteToSignalTable) for the specific timing option
///
/// @param ledOption The timing option
///
void fillEncodeTable(const ws2811::SignalTiming ledOption);
/** Translation table of byte to signal */
/// Translation table of byte to signal///
std::vector<ws2811::ByteSignal> _byteToSignalTable;
/// The buffer containing the packed RGB values