mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Performance fixes for adalightapa102
Adalightapa102 now inherits from RS232Device. Due to bad initialization, previous CPU usage on RPI1 could reach 60%. ON RPi2 20%. Now its about 3% with grabber in use. Former-commit-id: 7ebb72f503ad74a7768deedf648b9e84c0a7cf3c
This commit is contained in:
parent
e44db34969
commit
e7c9d9decd
@ -12,18 +12,27 @@
|
|||||||
#include "LedDeviceAdalightApa102.h"
|
#include "LedDeviceAdalightApa102.h"
|
||||||
|
|
||||||
LedDeviceAdalightApa102::LedDeviceAdalightApa102(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) :
|
LedDeviceAdalightApa102::LedDeviceAdalightApa102(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) :
|
||||||
LedDeviceAdalight(outputDevice, baudrate, delayAfterConnect_ms),
|
LedRs232Device(outputDevice, baudrate, delayAfterConnect_ms),
|
||||||
_ledBuffer(0),
|
_ledBuffer(0),
|
||||||
_timer()
|
_timer()
|
||||||
{
|
{
|
||||||
|
// setup the timer
|
||||||
|
_timer.setSingleShot(false);
|
||||||
|
_timer.setInterval(5000);
|
||||||
|
connect(&_timer, SIGNAL(timeout()), this, SLOT(rewriteLeds()));
|
||||||
|
|
||||||
|
// start the timer
|
||||||
|
_timer.start();
|
||||||
}
|
}
|
||||||
// see dependencies folder for arduino sketch for APA102
|
//comparing to ws2801 adalight, the following changes were needed:
|
||||||
|
// 1- differnt data frame (4 bytes instead of 3)
|
||||||
|
// 2 - in order to accomodate point 1 above, number of leds sent to adalight is increased by 1/3rd
|
||||||
int LedDeviceAdalightApa102::write(const std::vector<ColorRgb> & ledValues)
|
int LedDeviceAdalightApa102::write(const std::vector<ColorRgb> & ledValues)
|
||||||
{
|
{
|
||||||
ledCount = ledValues.size();
|
ledCount = ledValues.size();
|
||||||
const unsigned int startFrameSize = 4;
|
const unsigned int startFrameSize = 4;
|
||||||
const unsigned int endFrameSize = std::max<unsigned int>(((ledValues.size() + 15) / 16), 4);
|
const unsigned int endFrameSize = std::max<unsigned int>(((ledCount + 15) / 16), 4);
|
||||||
const unsigned int mLedCount = (ledValues.size() * 4) + startFrameSize + endFrameSize;
|
const unsigned int mLedCount = (ledCount * 4) + startFrameSize + endFrameSize;
|
||||||
if(_ledBuffer.size() != mLedCount+6){
|
if(_ledBuffer.size() != mLedCount+6){
|
||||||
_ledBuffer.resize(mLedCount+6, 0x00);
|
_ledBuffer.resize(mLedCount+6, 0x00);
|
||||||
_ledBuffer[0] = 'A';
|
_ledBuffer[0] = 'A';
|
||||||
@ -34,7 +43,7 @@ int LedDeviceAdalightApa102::write(const std::vector<ColorRgb> & ledValues)
|
|||||||
_ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum
|
_ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned iLed=1; iLed<=ledValues.size(); iLed++) {
|
for (unsigned iLed=1; iLed<=ledCount; iLed++) {
|
||||||
const ColorRgb& rgb = ledValues[iLed-1];
|
const ColorRgb& rgb = ledValues[iLed-1];
|
||||||
_ledBuffer[iLed*4+6] = 0xFF;
|
_ledBuffer[iLed*4+6] = 0xFF;
|
||||||
_ledBuffer[iLed*4+1+6] = rgb.red;
|
_ledBuffer[iLed*4+1+6] = rgb.red;
|
||||||
@ -57,11 +66,13 @@ int LedDeviceAdalightApa102::switchOff()
|
|||||||
_ledBuffer[iLed*4+2+6] = 0x00;
|
_ledBuffer[iLed*4+2+6] = 0x00;
|
||||||
_ledBuffer[iLed*4+3+6] = 0x00;
|
_ledBuffer[iLed*4+3+6] = 0x00;
|
||||||
}
|
}
|
||||||
|
|
||||||
// restart the timer
|
// restart the timer
|
||||||
_timer.start();
|
_timer.start();
|
||||||
|
|
||||||
// write data
|
// write data
|
||||||
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LedDeviceAdalightApa102::rewriteLeds()
|
void LedDeviceAdalightApa102::rewriteLeds()
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
// hyperion incluse
|
// hyperion incluse
|
||||||
#include "LedDeviceAdalight.h"
|
#include "LedRs232Device.h"
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Implementation of the LedDevice interface for writing to an Adalight led device for APA102.
|
/// Implementation of the LedDevice interface for writing to an Adalight led device for APA102.
|
||||||
///
|
///
|
||||||
class LedDeviceAdalightApa102 : public LedDeviceAdalight
|
class LedDeviceAdalightApa102 : public LedRs232Device
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user