Skip to content

Commit

Permalink
Refactor to process blacklisted LEDs with less resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Lord-Grey committed Aug 25, 2023
1 parent 77a213d commit 8f3a1cc
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 25 deletions.
44 changes: 32 additions & 12 deletions include/hyperion/LedString.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ inline ColorOrder stringToColorOrder(const QString & order)
}

///
/// The Led structure contains the definition of the image portion used to determine a single led's
/// The Led structure contains the definition of the image portion used to determine a single LED's
/// color.
/// @verbatim
/// |--------------------image--|
Expand All @@ -90,46 +90,66 @@ inline ColorOrder stringToColorOrder(const QString & order)
///
struct Led
{
/// The minimum vertical scan line included for this leds color
/// The minimum vertical scan line included for this LEDs color
double minX_frac;
/// The maximum vertical scan line included for this leds color
/// The maximum vertical scan line included for this LEDs color
double maxX_frac;
/// The minimum horizontal scan line included for this leds color
/// The minimum horizontal scan line included for this LEDs color
double minY_frac;
/// The maximum horizontal scan line included for this leds color
/// The maximum horizontal scan line included for this LEDs color
double maxY_frac;
/// A Led at {0,0,0,0} is not visible and therefore treated as blacklisted
/// A LEDs at {0,0,0,0} is not visible and therefore treated as blacklisted
bool isBlacklisted {false};
/// the color order
ColorOrder colorOrder;
};

///
/// The LedString contains the image integration information of the leds
/// The LedString contains the image integration information of the LEDs
///
class LedString
{
public:
///
/// Returns the led specifications
/// Returns the LED specifications
///
/// @return The list with led specifications
///
std::vector<Led>& leds();

///
/// Returns the led specifications
/// Returns the LED specifications
///
/// @return The list with led specifications
///
const std::vector<Led>& leds() const;

bool hasBlackListedLeds {false};
///
/// Returns the IDs of blacklisted LEDs
///
/// @return ID List of blacklisted LEDs
///
std::vector<int>& blacklistedLedIds();

///
/// Returns the IDs of blacklisted LEDs
///
/// @return ID List of blacklisted LEDs
///
const std::vector<int>& blacklistedLedIds() const;

///
/// Check, if teh layout has blacklisted LEDs configured
///
/// @return True, if blacklisted LEDs are configured
///
bool hasBlackListedLeds ();

static LedString createLedString(const QJsonArray& ledConfigArray, const ColorOrder deviceOrder);

private:
/// The list with led specifications
/// The list with LED specifications
std::vector<Led> _leds;

/// The list containing IDs of blacklisted LED
std::vector<int> _blacklistedLedIds;
};
16 changes: 7 additions & 9 deletions libsrc/hyperion/Hyperion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,20 +671,18 @@ void Hyperion::update()
else
{
_ledBuffer = priorityInfo.ledColors;
}

if (_ledString.hasBlackListedLeds)
{
auto ledIter = _ledString.leds().begin();
for (ColorRgb& color : _ledBuffer)
if (ledIter != _ledString.leds().end())
if (_ledString.hasBlackListedLeds())
{
for (int id : _ledString.blacklistedLedIds())
{
if ((*ledIter).isBlacklisted)
if (id > _ledBuffer.size()-1)
{
color = ColorRgb::BLACK;
break;
}
++ledIter;
_ledBuffer.at(id) = ColorRgb::BLACK;
}
}
}

// emit rawLedColors before transform
Expand Down
27 changes: 24 additions & 3 deletions libsrc/hyperion/LedString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ const std::vector<Led>& LedString::leds() const
return _leds;
}

std::vector<int>& LedString::blacklistedLedIds()
{
return _blacklistedLedIds;
}

const std::vector<int>& LedString::blacklistedLedIds() const
{
return _blacklistedLedIds;
}

bool LedString::hasBlackListedLeds()
{

if (_blacklistedLedIds.size() > 0)
{
return true;
}
else
{
return false;
}
}

/**
* Construct the 'led-string' with the integration area definition per led and the color
* ordering of the RGB channels
Expand All @@ -31,8 +54,6 @@ LedString LedString::createLedString(const QJsonArray& ledConfigArray, const Col
LedString ledString;
const QString deviceOrderStr = colorOrderToString(deviceOrder);

ledString.hasBlackListedLeds = false;

for (signed i = 0; i < ledConfigArray.size(); ++i)
{
const QJsonObject& ledConfig = ledConfigArray[i].toObject();
Expand Down Expand Up @@ -63,7 +84,7 @@ LedString LedString::createLedString(const QJsonArray& ledConfigArray, const Col
)
{
led.isBlacklisted = true;
ledString.hasBlackListedLeds |= led.isBlacklisted;
ledString.blacklistedLedIds().push_back(i);
}
ledString.leds().push_back(led);
}
Expand Down
2 changes: 1 addition & 1 deletion test/TestImage2LedsMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main()
return -1;
}

const LedString ledString = hyperion::createLedString(config["leds"].toArray(), hyperion::createColorOrder(config["device"].toObject()));
const LedString ledString = LedString::createLedString(config["leds"].toArray(), hyperion::createColorOrder(config["device"].toObject()));

const ColorRgb testColor = {64, 123, 12};

Expand Down

0 comments on commit 8f3a1cc

Please sign in to comment.