LedString.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // STL includes
  2. #include <cstring>
  3. #include <iostream>
  4. // hyperion includes
  5. #include <hyperion/LedString.h>
  6. // QT includes
  7. #include <QJsonObject>
  8. std::vector<Led>& LedString::leds()
  9. {
  10. return _leds;
  11. }
  12. const std::vector<Led>& LedString::leds() const
  13. {
  14. return _leds;
  15. }
  16. std::vector<int>& LedString::blacklistedLedIds()
  17. {
  18. return _blacklistedLedIds;
  19. }
  20. const std::vector<int>& LedString::blacklistedLedIds() const
  21. {
  22. return _blacklistedLedIds;
  23. }
  24. bool LedString::hasBlackListedLeds()
  25. {
  26. if (_blacklistedLedIds.size() > 0)
  27. {
  28. return true;
  29. }
  30. else
  31. {
  32. return false;
  33. }
  34. }
  35. /**
  36. * Construct the 'led-string' with the integration area definition per led and the color
  37. * ordering of the RGB channels
  38. * @param ledsConfig The configuration of the led areas
  39. * @param deviceOrder The default RGB channel ordering
  40. * @return The constructed ledstring
  41. */
  42. LedString LedString::createLedString(const QJsonArray& ledConfigArray, const ColorOrder deviceOrder)
  43. {
  44. LedString ledString;
  45. const QString deviceOrderStr = colorOrderToString(deviceOrder);
  46. for (signed i = 0; i < ledConfigArray.size(); ++i)
  47. {
  48. const QJsonObject& ledConfig = ledConfigArray[i].toObject();
  49. Led led;
  50. led.minX_frac = qMax(0.0, qMin(1.0, ledConfig["hmin"].toDouble()));
  51. led.maxX_frac = qMax(0.0, qMin(1.0, ledConfig["hmax"].toDouble()));
  52. led.minY_frac = qMax(0.0, qMin(1.0, ledConfig["vmin"].toDouble()));
  53. led.maxY_frac = qMax(0.0, qMin(1.0, ledConfig["vmax"].toDouble()));
  54. // Fix if the user swapped min and max
  55. if (led.minX_frac > led.maxX_frac)
  56. {
  57. std::swap(led.minX_frac, led.maxX_frac);
  58. }
  59. if (led.minY_frac > led.maxY_frac)
  60. {
  61. std::swap(led.minY_frac, led.maxY_frac);
  62. }
  63. // Get the order of the rgb channels for this led (default is device order)
  64. led.colorOrder = stringToColorOrder(ledConfig["colorOrder"].toString(deviceOrderStr));
  65. led.isBlacklisted = false;
  66. if (led.minX_frac < std::numeric_limits<double>::epsilon() &&
  67. led.maxX_frac < std::numeric_limits<double>::epsilon() &&
  68. led.minY_frac < std::numeric_limits<double>::epsilon() &&
  69. led.maxY_frac < std::numeric_limits<double>::epsilon()
  70. )
  71. {
  72. led.isBlacklisted = true;
  73. ledString.blacklistedLedIds().push_back(i);
  74. }
  75. ledString.leds().push_back(led);
  76. }
  77. return ledString;
  78. }