Some timings added.

This commit is contained in:
Blaz Kristan 2023-07-03 21:13:01 +02:00
parent c9ef034ab8
commit 66616e1cab
3 changed files with 41 additions and 19 deletions

View File

@ -1219,6 +1219,9 @@ uint8_t WS2812FX::estimateCurrentAndLimitBri() {
}
void WS2812FX::show(void) {
static unsigned long sumMicros = 0, sumCurrent = 0;
static size_t calls = 0;
unsigned long microsStart = micros();
// avoid race condition, caputre _callback value
show_callback callback = _callback;
@ -1226,6 +1229,7 @@ void WS2812FX::show(void) {
uint8_t busBrightness = estimateCurrentAndLimitBri();
busses.setBrightness(busBrightness);
sumCurrent += micros() - microsStart;
// some buses send asynchronously and this method will return before
// all of the data has been sent.
@ -1237,6 +1241,13 @@ void WS2812FX::show(void) {
if (diff > 0) fpsCurr = 1000 / diff;
_cumulativeFps = (3 * _cumulativeFps + fpsCurr) >> 2;
_lastShow = now;
sumMicros += micros() - microsStart;
if (++calls == 100) {
DEBUG_PRINTF("show calls: %d micros: %lu avg: %lu (current: %lu avg: %lu)\n", calls, sumMicros, sumMicros/calls, sumCurrent, sumCurrent/calls);
sumMicros = sumCurrent = 0;
calls = 0;
}
}
/**

View File

@ -116,7 +116,7 @@ BusDigital::BusDigital(BusConfig &bc, uint8_t nr, const ColorOrderMap &com) : Bu
_colorOrder = bc.colorOrder;
_iType = PolyBus::getI(bc.type, _pins, nr);
if (_iType == I_NONE) return;
if (useGlobalLedBuffer && !allocData(_len * (hasWhite() + 3*hasRGB()))) return; //warning: hardcoded channel count
if (useGlobalLedBuffer && !allocData(_len * (Bus::hasWhite(_type) + 3*Bus::hasRGB(_type)))) return; //warning: hardcoded channel count
uint16_t lenToCreate = _len;
if (bc.type == TYPE_WS2812_1CH_X3) lenToCreate = NUM_ICS_WS2812_1CH_3X(_len); // only needs a third of "RGB" LEDs for NeoPixelBus
_busPtr = PolyBus::create(_iType, _pins, lenToCreate + _skip, nr, _frequencykHz);
@ -126,9 +126,12 @@ BusDigital::BusDigital(BusConfig &bc, uint8_t nr, const ColorOrderMap &com) : Bu
void BusDigital::show() {
if (!_valid) return;
static unsigned long sumMicros = 0;
static size_t calls = 0;
unsigned long microsStart = micros();
PolyBus::setBrightness(_busPtr, _iType, _bri);
if (useGlobalLedBuffer) {
size_t channels = hasWhite() + 3*hasRGB();
size_t channels = Bus::hasWhite(_type) + 3*Bus::hasRGB(_type);
for (size_t i=0; i<_len; i++) {
size_t offset = i*channels;
uint8_t co = _colorOrderMap.getPixelColorOrder(i+_start, _colorOrder);
@ -140,7 +143,7 @@ void BusDigital::show() {
case 2: c = RGBW32(_data[offset-2], _data[offset-1], _data[offset] , 0); break;
}
} else {
c = RGBW32(_data[offset],_data[offset+1],_data[offset+2],(hasWhite()?_data[offset+3]:0));
c = RGBW32(_data[offset],_data[offset+1],_data[offset+2],(Bus::hasWhite(_type)?_data[offset+3]:0));
}
uint16_t pix = i;
if (reversed) pix = _len - pix -1;
@ -152,6 +155,12 @@ void BusDigital::show() {
}
PolyBus::show(_busPtr, _iType);
PolyBus::setBrightness(_busPtr, _iType, 255); // restore full brightness at bus level (setting unscaled pixel color)
sumMicros += micros() - microsStart;
if (++calls == 100) {
DEBUG_PRINTF("Bus calls: %d micros: %lu avg: %lu\n", calls, sumMicros, sumMicros/calls);
sumMicros = 0;
calls = 0;
}
}
bool BusDigital::canShow() {
@ -172,25 +181,25 @@ void BusDigital::setBrightness(uint8_t b) {
//If LEDs are skipped, it is possible to use the first as a status LED.
//TODO only show if no new show due in the next 50ms
void BusDigital::setStatusPixel(uint32_t c) {
if (_valid && _skip && canShow()) {
if (_valid && _skip) {
PolyBus::setPixelColor(_busPtr, _iType, 0, c, _colorOrderMap.getPixelColorOrder(_start, _colorOrder));
PolyBus::show(_busPtr, _iType);
if (canShow()) PolyBus::show(_busPtr, _iType);
}
}
void IRAM_ATTR BusDigital::setPixelColor(uint16_t pix, uint32_t c) {
if (!_valid) return;
if (hasWhite()) c = autoWhiteCalc(c);
if (Bus::hasWhite(_type)) c = autoWhiteCalc(c);
if (_cct >= 1900) c = colorBalanceFromKelvin(_cct, c); //color correction from CCT
if (useGlobalLedBuffer) {
size_t channels = hasWhite() + 3*hasRGB();
size_t channels = Bus::hasWhite(_type) + 3*Bus::hasRGB(_type);
size_t offset = pix*channels;
if (hasRGB()) {
if (Bus::hasRGB(_type)) {
_data[offset++] = R(c);
_data[offset++] = G(c);
_data[offset++] = B(c);
}
if (hasWhite()) _data[offset] = W(c);
if (Bus::hasWhite(_type)) _data[offset] = W(c);
} else {
if (reversed) pix = _len - pix -1;
else pix += _skip;
@ -212,13 +221,13 @@ void IRAM_ATTR BusDigital::setPixelColor(uint16_t pix, uint32_t c) {
uint32_t BusDigital::getPixelColor(uint16_t pix) {
if (!_valid) return 0;
if (useGlobalLedBuffer) {
size_t channels = hasWhite() + 3*hasRGB();
size_t channels = Bus::hasWhite(_type) + 3*Bus::hasRGB(_type);
size_t offset = pix*channels;
uint32_t c;
if (!hasRGB()) {
if (!Bus::hasRGB(_type)) {
c = RGBW32(_data[offset], _data[offset], _data[offset], _data[offset]);
} else {
c = RGBW32(_data[offset], _data[offset+1], _data[offset+2], hasWhite() ? _data[offset+3] : 0);
c = RGBW32(_data[offset], _data[offset+1], _data[offset+2], Bus::hasWhite(_type) ? _data[offset+3] : 0);
}
return c;
} else {
@ -469,7 +478,7 @@ BusNetwork::BusNetwork(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWhite) {
void BusNetwork::setPixelColor(uint16_t pix, uint32_t c) {
if (!_valid || pix >= _len) return;
if (hasWhite()) c = autoWhiteCalc(c);
if (_rgbw) c = autoWhiteCalc(c);
if (_cct >= 1900) c = colorBalanceFromKelvin(_cct, c); //color correction from CCT
uint16_t offset = pix * _UDPchannels;
_data[offset] = R(c);

View File

@ -130,20 +130,22 @@ class Bus {
inline bool isOffRefreshRequired() { return _needsRefresh; }
bool containsPixel(uint16_t pix) { return pix >= _start && pix < _start+_len; }
virtual bool hasRGB() {
if ((_type >= TYPE_WS2812_1CH && _type <= TYPE_WS2812_WWA) || _type == TYPE_ANALOG_1CH || _type == TYPE_ANALOG_2CH || _type == TYPE_ONOFF) return false;
virtual bool hasRGB(void) { return Bus::hasRGB(_type); }
static bool hasRGB(uint8_t type) {
if ((type >= TYPE_WS2812_1CH && type <= TYPE_WS2812_WWA) || type == TYPE_ANALOG_1CH || type == TYPE_ANALOG_2CH || type == TYPE_ONOFF) return false;
return true;
}
virtual bool hasWhite() { return Bus::hasWhite(_type); }
virtual bool hasWhite(void) { return Bus::hasWhite(_type); }
static bool hasWhite(uint8_t type) {
if ((type >= TYPE_WS2812_1CH && type <= TYPE_WS2812_WWA) || type == TYPE_SK6812_RGBW || type == TYPE_TM1814) return true; // digital types with white channel
if (type > TYPE_ONOFF && type <= TYPE_ANALOG_5CH && type != TYPE_ANALOG_3CH) return true; // analog types with white channel
if (type == TYPE_NET_DDP_RGBW) return true; // network types with white channel
return false;
}
virtual bool hasCCT() {
if (_type == TYPE_WS2812_2CH_X3 || _type == TYPE_WS2812_WWA ||
_type == TYPE_ANALOG_2CH || _type == TYPE_ANALOG_5CH) return true;
virtual bool hasCCT(void) { return Bus::hasCCT(_type); }
static bool hasCCT(uint8_t type) {
if (type == TYPE_WS2812_2CH_X3 || type == TYPE_WS2812_WWA ||
type == TYPE_ANALOG_2CH || type == TYPE_ANALOG_5CH) return true;
return false;
}
static void setCCT(uint16_t cct) {