mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Fix Rotation and refactoring
This commit is contained in:
parent
755c6bc22e
commit
0f3bbdafd9
@ -91,31 +91,10 @@ namespace {
|
|||||||
const char SSDP_NANOLEAF[] = "nanoleaf:nl*";
|
const char SSDP_NANOLEAF[] = "nanoleaf:nl*";
|
||||||
const char SSDP_LIGHTPANELS[] = "nanoleaf_aurora:light";
|
const char SSDP_LIGHTPANELS[] = "nanoleaf_aurora:light";
|
||||||
|
|
||||||
const int ROTATION_STEPS_DEGREE = 15;
|
const double ROTATION_STEPS_DEGREE = 15.0;
|
||||||
|
|
||||||
} //End of constants
|
} //End of constants
|
||||||
|
|
||||||
// Nanoleaf Panel Shapetypes
|
|
||||||
enum SHAPETYPES {
|
|
||||||
TRIANGLE = 0,
|
|
||||||
RHYTM = 1,
|
|
||||||
SQUARE = 2,
|
|
||||||
CONTROL_SQUARE_PRIMARY = 3,
|
|
||||||
CONTROL_SQUARE_PASSIVE = 4,
|
|
||||||
POWER_SUPPLY = 5,
|
|
||||||
HEXAGON_SHAPES = 7,
|
|
||||||
TRIANGE_SHAPES = 8,
|
|
||||||
MINI_TRIANGE_SHAPES = 9,
|
|
||||||
SHAPES_CONTROLLER = 12,
|
|
||||||
ELEMENTS_HEXAGONS = 14,
|
|
||||||
ELEMENTS_HEXAGONS_CORNER = 15,
|
|
||||||
LINES_CONECTOR = 16,
|
|
||||||
LIGHT_LINES = 17,
|
|
||||||
LIGHT_LINES_SINGLZONE = 18,
|
|
||||||
CONTROLLER_CAP = 19,
|
|
||||||
POWER_CONNECTOR = 20
|
|
||||||
};
|
|
||||||
|
|
||||||
// Nanoleaf external control versions
|
// Nanoleaf external control versions
|
||||||
enum EXTCONTROLVERSIONS {
|
enum EXTCONTROLVERSIONS {
|
||||||
EXTCTRLVER_V1 = 1,
|
EXTCTRLVER_V1 = 1,
|
||||||
@ -202,24 +181,39 @@ int LedDeviceNanoleaf::getHwLedCount(const QJsonObject& jsonLayout) const
|
|||||||
|
|
||||||
DebugIf(verbose, _log, "Panel [%d] - Type: [%d]", panelId, panelshapeType);
|
DebugIf(verbose, _log, "Panel [%d] - Type: [%d]", panelId, panelshapeType);
|
||||||
|
|
||||||
// Skip non LED panel types
|
if (hasLEDs(static_cast<SHAPETYPES>(panelshapeType)))
|
||||||
switch (panelshapeType)
|
|
||||||
{
|
{
|
||||||
case SHAPES_CONTROLLER:
|
|
||||||
case LINES_CONECTOR:
|
|
||||||
case CONTROLLER_CAP:
|
|
||||||
case POWER_CONNECTOR:
|
|
||||||
case RHYTM:
|
|
||||||
DebugIf(verbose, _log, "Rhythm/Shape/Lines Controller panel skipped.");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
++hwLedCount;
|
++hwLedCount;
|
||||||
break;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DebugIf(verbose, _log, "Rhythm/Shape/Lines Controller panel skipped.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return hwLedCount;
|
return hwLedCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LedDeviceNanoleaf::hasLEDs(const SHAPETYPES& panelshapeType) const
|
||||||
|
{
|
||||||
|
bool hasLED {true};
|
||||||
|
// Skip non LED panel types
|
||||||
|
switch (panelshapeType)
|
||||||
|
{
|
||||||
|
case SHAPES_CONTROLLER:
|
||||||
|
case LINES_CONECTOR:
|
||||||
|
case CONTROLLER_CAP:
|
||||||
|
case POWER_CONNECTOR:
|
||||||
|
case RHYTM:
|
||||||
|
DebugIf(verbose, _log, "Rhythm/Shape/Lines Controller panel skipped.");
|
||||||
|
hasLED = false;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasLED;
|
||||||
|
}
|
||||||
|
|
||||||
bool LedDeviceNanoleaf::initLedsConfiguration()
|
bool LedDeviceNanoleaf::initLedsConfiguration()
|
||||||
{
|
{
|
||||||
bool isInitOK = true;
|
bool isInitOK = true;
|
||||||
@ -253,15 +247,22 @@ bool LedDeviceNanoleaf::initLedsConfiguration()
|
|||||||
QJsonObject jsonPanelLayout = jsonAllPanelInfo[API_PANELLAYOUT].toObject();
|
QJsonObject jsonPanelLayout = jsonAllPanelInfo[API_PANELLAYOUT].toObject();
|
||||||
|
|
||||||
const QJsonObject globalOrientation = jsonPanelLayout[PANEL_GLOBALORIENTATION].toObject();
|
const QJsonObject globalOrientation = jsonPanelLayout[PANEL_GLOBALORIENTATION].toObject();
|
||||||
int degreesToRotate = globalOrientation[PANEL_GLOBALORIENTATION_VALUE].toInt();
|
int orientation = globalOrientation[PANEL_GLOBALORIENTATION_VALUE].toInt();
|
||||||
|
|
||||||
//Align rotation degree to 15 degree steps
|
int degreesToRotate {orientation};
|
||||||
int degreeRounded = static_cast<int>(((round(degreesToRotate / ROTATION_STEPS_DEGREE) * ROTATION_STEPS_DEGREE) + 360)) % 360;
|
bool isRotated {false};
|
||||||
|
if (degreesToRotate > 0)
|
||||||
|
{
|
||||||
|
isRotated = true;
|
||||||
|
int degreeRounded = static_cast<int>(round(degreesToRotate / ROTATION_STEPS_DEGREE) * ROTATION_STEPS_DEGREE);
|
||||||
|
degreesToRotate = (degreeRounded +360) % 360;
|
||||||
|
}
|
||||||
|
|
||||||
//Nanoleaf orientation is counter-clockwise
|
//Nanoleaf orientation is counter-clockwise
|
||||||
degreeRounded *= -1;
|
degreesToRotate *= -1;
|
||||||
|
|
||||||
double radians = (degreeRounded * std::acos(-1)) / 180;
|
double radians = (degreesToRotate * std::acos(-1)) / 180;
|
||||||
|
DebugIf(verbose, _log, "globalOrientation: %d, degreesToRotate: %d, radians: %0.2f", orientation, degreesToRotate, radians);
|
||||||
|
|
||||||
QJsonObject jsonLayout = jsonPanelLayout[PANEL_LAYOUT].toObject();
|
QJsonObject jsonLayout = jsonPanelLayout[PANEL_LAYOUT].toObject();
|
||||||
|
|
||||||
@ -285,10 +286,10 @@ bool LedDeviceNanoleaf::initLedsConfiguration()
|
|||||||
|
|
||||||
int panelX;
|
int panelX;
|
||||||
int panelY;
|
int panelY;
|
||||||
if (radians != 0)
|
if (isRotated)
|
||||||
{
|
{
|
||||||
panelX = round(posX * cos(radians) - posY * sin(radians));
|
panelX = static_cast<int>(round(posX * cos(radians) - posY * sin(radians)));
|
||||||
panelY = round(posX * sin(radians) + posY * cos(radians));
|
panelY = static_cast<int>(round(posX * sin(radians) + posY * cos(radians)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -296,20 +297,14 @@ bool LedDeviceNanoleaf::initLedsConfiguration()
|
|||||||
panelY = posY;
|
panelY = posY;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (panelshapeType)
|
if (hasLEDs(static_cast<SHAPETYPES>(panelshapeType)))
|
||||||
{
|
{
|
||||||
case SHAPES_CONTROLLER:
|
|
||||||
case LINES_CONECTOR:
|
|
||||||
case CONTROLLER_CAP:
|
|
||||||
case POWER_CONNECTOR:
|
|
||||||
case RHYTM:
|
|
||||||
// Skip non LED panel types
|
|
||||||
DebugIf(verbose, _log, "Skip Panel [%d] (%d,%d) - Type: [%d]", panelId, panelX, panelY, panelshapeType);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
panelMap[panelY][panelX] = panelId;
|
panelMap[panelY][panelX] = panelId;
|
||||||
DebugIf(verbose, _log, "Use Panel [%d] (%d,%d) - Type: [%d] used", panelId, panelX, panelY, panelshapeType);
|
DebugIf(verbose, _log, "Use Panel [%d] (%d,%d) - Type: [%d]", panelId, panelX, panelY, panelshapeType);
|
||||||
break;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DebugIf(verbose, _log, "Skip Panel [%d] (%d,%d) - Type: [%d]", panelId, panelX, panelY, panelshapeType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +161,27 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
// Nanoleaf Panel Shapetypes
|
||||||
|
enum SHAPETYPES {
|
||||||
|
TRIANGLE = 0,
|
||||||
|
RHYTM = 1,
|
||||||
|
SQUARE = 2,
|
||||||
|
CONTROL_SQUARE_PRIMARY = 3,
|
||||||
|
CONTROL_SQUARE_PASSIVE = 4,
|
||||||
|
POWER_SUPPLY = 5,
|
||||||
|
HEXAGON_SHAPES = 7,
|
||||||
|
TRIANGE_SHAPES = 8,
|
||||||
|
MINI_TRIANGE_SHAPES = 9,
|
||||||
|
SHAPES_CONTROLLER = 12,
|
||||||
|
ELEMENTS_HEXAGONS = 14,
|
||||||
|
ELEMENTS_HEXAGONS_CORNER = 15,
|
||||||
|
LINES_CONECTOR = 16,
|
||||||
|
LIGHT_LINES = 17,
|
||||||
|
LIGHT_LINES_SINGLZONE = 18,
|
||||||
|
CONTROLLER_CAP = 19,
|
||||||
|
POWER_CONNECTOR = 20
|
||||||
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
/// @brief Initialise the access to the REST-API wrapper
|
/// @brief Initialise the access to the REST-API wrapper
|
||||||
///
|
///
|
||||||
@ -203,6 +224,13 @@ private:
|
|||||||
///
|
///
|
||||||
int getHwLedCount(const QJsonObject& jsonLayout) const;
|
int getHwLedCount(const QJsonObject& jsonLayout) const;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// @brief Check, if panelshape type has LEDs
|
||||||
|
///
|
||||||
|
/// @return True, if panel shape type has LEDs
|
||||||
|
///
|
||||||
|
bool hasLEDs(const SHAPETYPES& panelshapeType) const;
|
||||||
|
|
||||||
///REST-API wrapper
|
///REST-API wrapper
|
||||||
ProviderRestApi* _restApi;
|
ProviderRestApi* _restApi;
|
||||||
int _apiPort;
|
int _apiPort;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user