hyperion.ng/libsrc/leddevice/LedDeviceFactory.cpp
penfold42 f96b0143a8 [untested] added Sk6822 led device support (#397)
* Adding support for sk6822 timing
This isnt complete, but should be a good starting point for others to learn from.

1) Here is where the led device source is located:

cd libsrc/leddevice

2) Find the files that need changing:

root@loungepi:libsrc/leddevice# grep -ri 2812spi *
CMakeLists.txt:         ${CURRENT_SOURCE_DIR}/LedDeviceWs2812SPI.h
CMakeLists.txt:         ${CURRENT_SOURCE_DIR}/LedDeviceWs2812SPI.cpp
LedDeviceFactory.cpp:   #include "LedDeviceWs2812SPI.h"
LedDeviceFactory.cpp:   REGISTER(Ws2812SPI);
LedDeviceSchemas.qrc:           <file alias="schema-ws2812spi">schemas/schema-ws2812spi.json</file>
LedDeviceWs2812SPI.cpp:#include "LedDeviceWs2812SPI.h"
LedDeviceWs2812SPI.cpp:LedDeviceWs2812SPI::LedDeviceWs2812SPI(const QJsonObject &deviceConfig)
LedDeviceWs2812SPI.cpp:LedDevice* LedDeviceWs2812SPI::construct(const QJsonObject &deviceConfig)
LedDeviceWs2812SPI.cpp: return new LedDeviceWs2812SPI(deviceConfig);
LedDeviceWs2812SPI.cpp:bool LedDeviceWs2812SPI::init(const QJsonObject &deviceConfig)
LedDeviceWs2812SPI.cpp:int LedDeviceWs2812SPI::write(const std::vector<ColorRgb> &ledValues)
LedDeviceWs2812SPI.h:class LedDeviceWs2812SPI : public ProviderSpi
LedDeviceWs2812SPI.h:   LedDeviceWs2812SPI(const QJsonObject &deviceConfig);

3) Copy the existing files as a starting point:

cp LedDeviceWs2812SPI.cpp LedDeviceSk6822SPI.cpp
cp LedDeviceWs2812SPI.h LedDeviceSk6822SPI.h
cp schemas/schema-ws2812spi.json schemas/schema-sk6822spi.json

4) Do some search and replacing:

:%s/Ws2812SPI/Sk6822SPI/g

5) edit the other files (see the diffs in this commit)

* Added wait time and reset time

* Fixed up debugging output and commented it out.
2017-02-14 09:33:28 +01:00

152 lines
3.5 KiB
C++
Executable File

// Stl includes
#include <string>
#include <sstream>
#include <algorithm>
#include <exception>
#include <map>
// Build configuration
#include <HyperionConfig.h>
// Leddevice includes
#include <leddevice/LedDeviceFactory.h>
#include <utils/Logger.h>
#include <leddevice/LedDevice.h>
// Local Leddevice includes
#ifdef ENABLE_SPIDEV
#include "LedDeviceLpd6803.h"
#include "LedDeviceLpd8806.h"
#include "LedDeviceP9813.h"
#include "LedDeviceWs2801.h"
#include "LedDeviceWs2812SPI.h"
#include "LedDeviceSk6812SPI.h"
#include "LedDeviceSk6822SPI.h"
#include "LedDeviceAPA102.h"
#endif
#ifdef ENABLE_TINKERFORGE
#include "LedDeviceTinkerforge.h"
#endif
#include "LedDeviceAdalight.h"
#include "LedDeviceRawHID.h"
#include "LedDeviceLightpack.h"
#include "LedDeviceMultiLightpack.h"
#include "LedDevicePaintpack.h"
#include "LedDevicePiBlaster.h"
#include "LedDeviceSedu.h"
#include "LedDeviceDMX.h"
#include "LedDeviceFile.h"
#include "LedDeviceFadeCandy.h"
#include "LedDeviceTpm2net.h"
#include "LedDeviceUdpRaw.h"
#include "LedDeviceUdpE131.h"
#include "LedDeviceHyperionUsbasp.h"
#include "LedDevicePhilipsHue.h"
#include "LedDeviceTpm2.h"
#include "LedDeviceAtmo.h"
#include "LedDeviceAtmoOrb.h"
#include "LedDeviceUdpH801.h"
#ifdef ENABLE_WS281XPWM
#include "LedDeviceWS281x.h"
#endif
LedDevice * LedDeviceFactory::construct(const QJsonObject & deviceConfig, const int ledCount)
{
Logger * log = Logger::getInstance("LedDevice");
QJsonDocument config(deviceConfig);
QString ss(config.toJson(QJsonDocument::Indented));
Info(log, "configuration: %s ", ss.toUtf8().constData());
std::string type = deviceConfig["type"].toString("UNSPECIFIED").toStdString();
std::transform(type.begin(), type.end(), type.begin(), ::tolower);
// set amount of led to leddevice
LedDevice::setLedCount(ledCount);
#define REGISTER(className) LedDevice::addToDeviceMap(QString(#className).toLower().toStdString(), LedDevice##className::construct);
// rs232 devices
REGISTER(Adalight);
REGISTER(Sedu);
REGISTER(DMX);
REGISTER(Tpm2);
REGISTER(Atmo);
// spi devices
#ifdef ENABLE_SPIDEV
REGISTER(APA102);
REGISTER(Lpd6803);
REGISTER(Lpd8806);
REGISTER(P9813);
REGISTER(Ws2801);
REGISTER(Ws2812SPI);
REGISTER(Sk6812SPI);
REGISTER(Sk6822SPI);
#endif
// pwm devices
#ifdef ENABLE_WS281XPWM
REGISTER(WS281x);
#endif
// network lights
REGISTER(FadeCandy);
REGISTER(Tpm2net);
REGISTER(UdpRaw);
REGISTER(UdpE131);
REGISTER(UdpH801);
REGISTER(PhilipsHue);
REGISTER(AtmoOrb);
#ifdef ENABLE_TINKERFORGE
REGISTER(Tinkerforge);
#endif
// direct usb
REGISTER(HyperionUsbasp);
REGISTER(RawHID);
REGISTER(Paintpack);
REGISTER(Lightpack);
REGISTER(MultiLightpack);
// other
REGISTER(File);
REGISTER(PiBlaster);
#undef REGISTER
const LedDeviceRegistry& devList = LedDevice::getDeviceMap();
LedDevice* device = nullptr;
try
{
for ( auto dev: devList)
{
if (dev.first == type)
{
device = dev.second(deviceConfig);
LedDevice::setActiveDevice(dev.first);
Info(log,"LedDevice '%s' configured.", dev.first.c_str());
break;
}
}
if (device == nullptr)
{
Error(log, "Dummy device used, because configured device '%s' is unknown", type.c_str() );
throw std::runtime_error("unknown device");
}
}
catch(std::exception& e)
{
Error(log, "Dummy device used, because configured device '%s' throws error '%s'", type.c_str(), e.what());
const QJsonObject dummyDeviceConfig;
device = LedDeviceFile::construct(QJsonObject());
}
device->open();
return device;
}