Skip to content
Snippets Groups Projects
Commit 0f92fa83 authored by Tomi Korpipää's avatar Tomi Korpipää
Browse files

Update HomeAutomation to 2.0 API

parent 9786f3aa
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,8 @@ KNX_BOARD {
QT += qml quick
CONFIG += resources_big
target.path = $$[QT_INSTALL_EXAMPLES]/studio3d/$$TARGET
INSTALLS += target
......
......@@ -132,10 +132,10 @@ void HouseModel::generateRooms()
{
removeRows(0, m_rooms.length());
// Position of labels is defined from the center point of window
addRoom(QStringLiteral("Living Room"), QStringLiteral("Livingroom"), 21, 0.8, 120, 200);
addRoom(QStringLiteral("Master Bedroom"), QStringLiteral("Masterbedroom"), 18, 0.8, -380, -290);
addRoom(QStringLiteral("Bedroom"), QStringLiteral("Bedroom"), 15, 0.0, -405, 170);
addRoom(QStringLiteral("Bath Room"), QStringLiteral("Bathroom"), 30, 1.0, -20, -320);
addRoom(QStringLiteral("Living Room"), QStringLiteral("LivingRoom"), 21, 0.8, 120, 200);
addRoom(QStringLiteral("Master Bedroom"), QStringLiteral("MasterBedRoom"), 18, 0.8, -380, -290);
addRoom(QStringLiteral("Bedroom"), QStringLiteral("BedRoom"), 15, 0.0, -405, 170);
addRoom(QStringLiteral("Bath Room"), QStringLiteral("BathRoom"), 30, 1.0, -20, -320);
#if !defined(KNX_BACKEND)
addRoom(QStringLiteral("Entrance"), QStringLiteral("Entrance"), 20, 0.6, -450, -70);
#endif
......
......@@ -60,8 +60,8 @@ Item {
property real green: 0
property real light: 0
property string currentTempAttribute: ""
property string currentLightAttribute: ""
property var currentTempTarget
property var currentLightTarget
Timer {
id: goToHomeTimer
......@@ -69,7 +69,7 @@ Item {
running: false
repeat: false
onTriggered: slideInput.setValue("BackToInitialView")
onTriggered: slideInput.setValue("BackToInitialView");
}
Timer {
......@@ -78,7 +78,7 @@ Item {
running: false
repeat: false
onTriggered: mainMenu.show = true
onTriggered: mainMenu.show = true;
}
signal studio3DPresentationReady()
......@@ -98,11 +98,11 @@ Item {
source: "qrc:/uip/houseStudio.uia"
function switchToRoom(slideName) {
livingRoomHeat.goToTime(slideName === "Livingroom" ? 2 : 0)
masterBedroomHeat.goToTime(slideName === "Masterbedroom" ? 2 : 0)
bedroomHeat.goToTime(slideName === "Bedroom" ? 2 : 0)
bathRoomHeat.goToTime(slideName === "Bathroom" ? 2 : 0)
entranceHeat.goToTime(slideName === "Entrance" ? 2 : 0)
livingRoomLight.setValue(slideName === "LivingRoom" ? 100 : 0);
masterBedRoomLight.setValue(slideName === "MasterBedRoom" ? 100 : 0);
bedRoomLight.setValue(slideName === "BedRoom" ? 100 : 0);
bathRoomLight.setValue(slideName === "BathRoom" ? 100 : 0);
entranceLight.setValue(slideName === "Entrance" ? 100 : 0);
}
// This DataInput item is used to control current slide. The presentation has
......@@ -112,87 +112,116 @@ Item {
name: "slideInput"
}
DataInput {
id: entranceLight
name: "lightEntrance"
}
DataInput {
id: bathRoomLight
name: "lightBathRoom"
}
DataInput {
id: livingRoomLight
name: "lightLivingRoom"
}
DataInput {
id: masterBedRoomLight
name: "lightMasterBedRoom"
}
DataInput {
id: bedRoomLight
name: "lightBedRoom"
}
DataInput {
id: entranceHeat
name: "heatEntrance"
}
DataInput {
id: bathRoomHeat
name: "heatBathRoom"
}
DataInput {
id: livingRoomHeat
name: "heatLivingRoom"
}
DataInput {
id: masterBedRoomHeat
name: "heatMasterBedRoom"
}
DataInput {
id: bedRoomHeat
name: "heatBedRoom"
}
SceneElement {
id: scene
elementPath: "Scene"
onCurrentSlideNameChanged: {
var startTimer = false;
if (currentSlideName === "Livingroom") {
currentTempAttribute = livingRoomHeat.elementPath + ".HeatAreas_Heat_LivingRoom.Heat_LivingRoomSG"
currentLightAttribute = "Scene.3D.RoomLights.LivingroomLightMap.House"
sliderToolbar.show = true
} else if (currentSlideName === "Masterbedroom") {
currentTempAttribute = masterBedroomHeat.elementPath + ".HeatAreas_Heat_MasterBedroom.Heat_MasterBedroomSG"
currentLightAttribute = "Scene.3D.RoomLights.MasterbedroomLightmap.House"
sliderToolbar.show = true
} else if (currentSlideName === "Bedroom") {
currentTempAttribute = bedroomHeat.elementPath + ".HeatAreas_Heat_BedRoom.Heat_BedRoomSG"
currentLightAttribute = "Scene.3D.RoomLights.BedroomLightmap.House"
sliderToolbar.show = true
} else if (currentSlideName === "Bathroom") {
currentTempAttribute = bathRoomHeat.elementPath + ".HeatAreas_Heat_BathRoom.Heat_BathRoomSG"
currentLightAttribute = "Scene.3D.RoomLights.BathroomLightmap.House"
sliderToolbar.show = true
if (currentSlideName === "LivingRoom") {
currentTempTarget = livingRoomHeat;
currentLightTarget = livingRoomLight;
sliderToolbar.show = true;
} else if (currentSlideName === "MasterBedRoom") {
currentTempTarget = masterBedRoomHeat;
currentLightTarget = masterBedRoomLight;
sliderToolbar.show = true;
} else if (currentSlideName === "BedRoom") {
currentTempTarget = bedRoomHeat;
currentLightTarget = bedRoomLight;
sliderToolbar.show = true;
} else if (currentSlideName === "BathRoom") {
currentTempTarget = bathRoomHeat;
currentLightTarget = bathRoomLight;
sliderToolbar.show = true;
} else if (currentSlideName === "Entrance") {
currentTempAttribute = entranceHeat.elementPath + ".Heat_Entrance_HeatAreas.Heat_EntranceSG"
currentLightAttribute = "Scene.3D.RoomLights.EntranceLightmap.House"
sliderToolbar.show = true
currentTempTarget = entranceHeat;
currentLightTarget = entranceLight;
sliderToolbar.show = true;
} else if (currentSlideName === "FloorPlan") {
startTimer = true;
sliderToolbar.show = false
sliderToolbar.show = false;
} else {
sliderToolbar.show = false
sliderToolbar.show = false;
}
presentation.switchToRoom(currentSlideName);
if (currentSlideName === "FloorPlan") {
if (previousSlideName === "InitialView")
mainMenu.show = true
mainMenu.show = true;
else
showMenuTimer.start()
showMenuTimer.start();
} else {
if (showMenuTimer.running)
showMenuTimer.stop()
mainMenu.show = false
showMenuTimer.stop();
mainMenu.show = false;
}
if (startTimer)
goToHomeTimer.start()
goToHomeTimer.start();
else if (goToHomeTimer.running)
goToHomeTimer.stop()
goToHomeTimer.stop();
presentation.setAttribute(currentTempAttribute, "diffuse.r", red)
presentation.setAttribute(currentTempAttribute, "diffuse.g", green)
presentation.setAttribute(currentTempAttribute, "diffuse.b", blue)
presentation.setAttribute(currentLightAttribute, "opacity", light)
if (currentTempTarget) {
currentTempTarget.setValue(Qt.vector3d(red, green, blue));
currentLightTarget.setValue(light);
}
}
}
SceneElement {
id: livingRoomHeat
elementPath: "Scene.3D.HeatAreas.Group_HeatAreas.HeatAreas_Heat_LivingRoom"
}
SceneElement {
id: masterBedroomHeat
elementPath: "Scene.3D.HeatAreas.Group_HeatAreas.HeatAreas_Heat_MasterBedroom"
}
SceneElement {
id: bedroomHeat
elementPath: "Scene.3D.HeatAreas.Group_HeatAreas.HeatAreas_Heat_BedRoom"
}
SceneElement {
id: bathRoomHeat
elementPath: "Scene.3D.HeatAreas.Group_HeatAreas.HeatAreas_Heat_BathRoom"
}
SceneElement {
id: entranceHeat
elementPath: "Scene.3D.HeatAreas.Group_HeatAreas.HeatAreas_Heat_Entrance"
}
}
onPresentationReady: {
home.studio3DPresentationReady()
home.studio3DPresentationReady();
}
}
......@@ -200,9 +229,9 @@ Item {
target: knxBackend
onBoardUpdate: {
if (lightNum > 0 && lightNum < 5) {
var oldValue = houseModel.data(houseModel.index(lightNum - 1, 0), 3)
houseModel.setData(houseModel.index(lightNum - 1, 0), !oldValue, 3)
lightControlLoader.item.value = houseModel.data(houseModel.index(index, 0), 3)
var oldValue = houseModel.data(houseModel.index(lightNum - 1, 0), 3);
houseModel.setData(houseModel.index(lightNum - 1, 0), !oldValue, 3);
lightControlLoader.item.value = houseModel.data(houseModel.index(index, 0), 3);
}
}
}
......@@ -212,21 +241,21 @@ Item {
anchors.fill: parent
onClicked: {
if (scene.currentSlideName === "BackToInitialView") {
slideInput.setValue("InitialView")
disableMouse(2200)
slideInput.setValue("InitialView");
disableMouse(2200);
} else if (scene.currentSlideName === "FloorPlan") {
slideInput.setValue("BackToInitialView")
disableMouse(2100)
slideInput.setValue("BackToInitialView");
disableMouse(2100);
} else if (scene.currentSlideName !== "InitialView") {
slideInput.setValue("FloorPlan")
disableMouse(1000)
slideInput.setValue("FloorPlan");
disableMouse(1000);
}
}
function disableMouse(animationDuration) {
mouseArea.enabled = false
mouseTimer.interval = animationDuration
mouseTimer.start()
mouseArea.enabled = false;
mouseTimer.interval = animationDuration;
mouseTimer.start();
}
Timer {
......@@ -235,7 +264,7 @@ Item {
running: false
repeat: false
onTriggered: mouseArea.enabled = true
onTriggered: mouseArea.enabled = true;
}
}
......@@ -263,13 +292,14 @@ Item {
// Store temperature and light to model before changing the slider value
if (currentIndex != -1) {
houseModel.setData(houseModel.index(currentIndex, 0), tempSlider.currentValue, 2)
houseModel.setData(houseModel.index(currentIndex, 0), lightControlLoader.item.currentValue, 3)
houseModel.setData(houseModel.index(currentIndex, 0), tempSlider.currentValue, 2);
houseModel.setData(houseModel.index(currentIndex, 0),
lightControlLoader.item.currentValue, 3);
}
currentIndex = index
var temp = houseModel.data(houseModel.index(index, 0), 2)
tempSlider.value = (temp - 15) / 15
lightControlLoader.item.value = houseModel.data(houseModel.index(index, 0), 3)
currentIndex = index;
var temp = houseModel.data(houseModel.index(index, 0), 2);
tempSlider.value = (temp - 15) / 15;
lightControlLoader.item.value = houseModel.data(houseModel.index(index, 0), 3);
}
}
......@@ -306,20 +336,21 @@ Item {
Connections {
target: lightControlLoader.item
onLightValueChanged: {
var newLightValue = lightControlLoader.item.lightValue * 100
home.light = newLightValue
presentation.setAttribute(currentLightAttribute, "opacity", newLightValue)
var newLightValue = lightControlLoader.item.lightValue * 100;
home.light = newLightValue;
if (currentLightTarget)
currentLightTarget.setValue(newLightValue);
if (knxBackend) {
var lightNum = 0
if (scene.currentSlideName === "Livingroom")
lightNum = 1
else if (scene.currentSlideName === "Masterbedroom")
lightNum = 2
else if (scene.currentSlideName === "Bedroom")
lightNum = 3
else if (scene.currentSlideName === "Bathroom")
lightNum = 4
knxBackend.toggleLight(lightNum)
var lightNum = 0;
if (scene.currentSlideName === "LivingRoom")
lightNum = 1;
else if (scene.currentSlideName === "MasterBedRoom")
lightNum = 2;
else if (scene.currentSlideName === "BedRoom")
lightNum = 3;
else if (scene.currentSlideName === "BathRoom")
lightNum = 4;
knxBackend.toggleLight(lightNum);
}
}
}
......@@ -332,32 +363,33 @@ Item {
width: mainMenu.width / 3
onRedColorChanged: {
home.red = redColor
presentation.setAttribute(currentTempAttribute, "diffuse.r", redColor)
home.red = redColor;
currentTempTarget.setValue(Qt.vector3d(redColor, home.green, home.blue));
}
onBlueColorChanged: {
home.blue = blueColor
presentation.setAttribute(currentTempAttribute, "diffuse.b", blueColor)
home.blue = blueColor;
currentTempTarget.setValue(Qt.vector3d(home.red, home.green, blueColor));
}
onGreenColorChanged: {
home.green = greenColor
presentation.setAttribute(currentTempAttribute, "diffuse.g", greenColor)
home.green = greenColor;
currentTempTarget.setValue(Qt.vector3d(home.red, greenColor, home.blue));
}
onEconomyChanged: {
if (knxBackend) {
// Toggle red light based on temperature changes
// The initial state of red lights on the board needs to be based on the default temperatures
var lightNum = 0
if (scene.currentSlideName === "Livingroom")
lightNum = 9
else if (scene.currentSlideName === "Masterbedroom")
lightNum = 10
else if (scene.currentSlideName === "Bedroom")
lightNum = 11
else if (scene.currentSlideName === "Bathroom")
lightNum = 12
knxBackend.toggleLight(lightNum)
// The initial state of red lights on the board needs to be based on the default
// temperatures
var lightNum = 0;
if (scene.currentSlideName === "LivingRoom")
lightNum = 9;
else if (scene.currentSlideName === "MasterBedRoom")
lightNum = 10;
else if (scene.currentSlideName === "BedRoom")
lightNum = 11;
else if (scene.currentSlideName === "BathRoom")
lightNum = 12;
knxBackend.toggleLight(lightNum);
}
}
}
......
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://qt.io/qt3dstudio/uia">
<assets initial="houseStudio">
<presentation id="houseStudio" src="houseStudio.uip"/>
<dataInput name="slideInput" type="String"/>
</assets>
<statemachine ref="#logic">
<visual-states>
<state ref="Initial">
<enter>
<goto-slide element="main:Scene" rel="next"/>
</enter>
</state>
</visual-states>
</statemachine>
<?xml version="1.0" encoding="UTF-8" ?>
<application>
<assets initial="houseStudio">
<presentation id="houseStudio" src="houseStudio.uip"/>
<dataInput name="slideInput" type="String"/>
<dataInput name="lightEntrance" type="Ranged Number" min="0" max="100"/>
<dataInput name="lightBathRoom" type="Ranged Number" min="0" max="100"/>
<dataInput name="lightLivingRoom" type="Ranged Number" min="0" max="100"/>
<dataInput name="lightMasterBedRoom" type="Ranged Number" min="0" max="100"/>
<dataInput name="lightBedRoom" type="Ranged Number" min="0" max="100"/>
<dataInput name="heatEntrance" type="Vector3"/>
<dataInput name="heatBathRoom" type="Vector3"/>
<dataInput name="heatLivingRoom" type="Vector3"/>
<dataInput name="heatMasterBedRoom" type="Vector3"/>
<dataInput name="heatBedRoom" type="Vector3"/>
</assets>
<statemachine ref="#logic">
<visual-states>
<state ref="Initial">
<enter>
<goto-slide element="main:Scene" rel="next"/>
</enter>
</state>
</visual-states>
</statemachine>
</application>
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment