Align rotation value to 15 degree steps

This commit is contained in:
Lord-Grey 2023-10-14 17:57:13 +02:00
parent 3257879c22
commit ffd4eb12d0
2 changed files with 27 additions and 8 deletions

View File

@ -2515,10 +2515,18 @@ function nanoleafGeneratelayout(panelLayout, panelOrderTopDown, panelOrderLeftRi
var degreesToRotate = 0; var degreesToRotate = 0;
if (globalOrientation) { if (globalOrientation) {
degreesToRotate = -globalOrientation.value; degreesToRotate = globalOrientation.value;
} }
//Align rotation degree to 15 degree steps
const degreeSteps = 15;
var degreeRounded = ((Math.round(degreesToRotate / degreeSteps) * degreeSteps) + 360) % 360;
//Nanoleaf orientation is counter-clockwise
degreeRounded *= -1;
// Convert degrees to radians // Convert degrees to radians
var radians = (degreesToRotate * Math.PI) / 180; const radians = (degreeRounded * Math.PI) / 180;
//Reduce the capture area //Reduce the capture area
const areaSizeFactor = 0.5; const areaSizeFactor = 0.5;
@ -2536,9 +2544,9 @@ function nanoleafGeneratelayout(panelLayout, panelOrderTopDown, panelOrderLeftRi
panel.areaHeight = shapeTypes[panel.shapeType].sideLengthY * areaSizeFactor; panel.areaHeight = shapeTypes[panel.shapeType].sideLengthY * areaSizeFactor;
if (radians !== 0) { if (radians !== 0) {
var rotatedXY = rotateCoordinates(panel.x, panel.y, radians) var rotatedXY = rotateCoordinates(panel.x, panel.y, radians);
panel.x = rotatedXY.x; panel.x = Math.round(rotatedXY.x);
panel.y = rotatedXY.y; panel.y = Math.round(rotatedXY.y);
} }
panel.maxX = panel.x + panel.areaWidth; panel.maxX = panel.x + panel.areaWidth;

View File

@ -90,6 +90,9 @@ namespace {
const char SSDP_FILTER_HEADER[] = "ST"; const char SSDP_FILTER_HEADER[] = "ST";
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;
} //End of constants } //End of constants
// Nanoleaf Panel Shapetypes // Nanoleaf Panel Shapetypes
@ -250,7 +253,15 @@ 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();
double radians = (-1 * globalOrientation[PANEL_GLOBALORIENTATION_VALUE].toInt() * std::acos(-1)) / 180; int degreesToRotate = globalOrientation[PANEL_GLOBALORIENTATION_VALUE].toInt();
//Align rotation degree to 15 degree steps
int degreeRounded = static_cast<int>(((round(degreesToRotate / ROTATION_STEPS_DEGREE) * ROTATION_STEPS_DEGREE) + 360)) % 360;
//Nanoleaf orientation is counter-clockwise
degreeRounded *= -1;
double radians = (degreeRounded * std::acos(-1)) / 180;
QJsonObject jsonLayout = jsonPanelLayout[PANEL_LAYOUT].toObject(); QJsonObject jsonLayout = jsonPanelLayout[PANEL_LAYOUT].toObject();
@ -276,8 +287,8 @@ bool LedDeviceNanoleaf::initLedsConfiguration()
int panelY; int panelY;
if (radians != 0) if (radians != 0)
{ {
panelX = static_cast<int>(posX * cos(radians) - posY * sin(radians)); panelX = round(posX * cos(radians) - posY * sin(radians));
panelY = static_cast<int>(posX * sin(radians) + posY * cos(radians)); panelY = round(posX * sin(radians) + posY * cos(radians));
} }
else else
{ {