Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Switch Device for support of smartswitch #1840

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ set (VENUS_QML_MODULE_SOURCES
data/PvInverters.qml
data/SolarChargers.qml
data/StartPageConfiguration.qml
data/Switches.qml
data/SwitchesCardModel.qml
data/System.qml
data/SystemLoad.qml
data/SystemSettings.qml
Expand Down Expand Up @@ -426,11 +428,13 @@ set (VENUS_QML_MODULE_SOURCES
data/common/SolarHistory.qml
data/common/SolarHistoryErrorModel.qml
data/common/SolarTrackerDailyHistory.qml
data/common/SwitchDev.qml
data/common/SystemBattery.qml
data/common/Tank.qml
data/common/TankDescription.qml
data/common/TankModel.qml

pages/AuxPage.qml
pages/BriefSidePanel.qml
pages/BriefPage.qml
pages/ControlCardsPage.qml
Expand Down Expand Up @@ -545,6 +549,7 @@ set (VENUS_QML_MODULE_SOURCES
pages/settings/devicelist/PageMeteo.qml
pages/settings/devicelist/PageMeteoSettings.qml
pages/settings/devicelist/PageMotorDrive.qml
pages/settings/devicelist/PageSwitch.qml
pages/settings/devicelist/PageUnsupportedDevice.qml
pages/settings/devicelist/battery/BatteryDetails.qml
pages/settings/devicelist/battery/BatteryHistory.qml
Expand Down Expand Up @@ -597,6 +602,7 @@ set (VENUS_QML_MODULE_SOURCES
pages/settings/devicelist/delegates/DeviceListDelegate_pulsemeter.qml
pages/settings/devicelist/delegates/DeviceListDelegate_pvinverter.qml
pages/settings/devicelist/delegates/DeviceListDelegate_solarcharger.qml
pages/settings/devicelist/delegates/DeviceListDelegate_switch.qml
pages/settings/devicelist/delegates/DeviceListDelegate_tank.qml
pages/settings/devicelist/delegates/DeviceListDelegate_temperature.qml
pages/settings/devicelist/delegates/DeviceListDelegate_unsupported.qml
Expand Down Expand Up @@ -644,6 +650,11 @@ set (VENUS_QML_MODULE_SOURCES
pages/solar/SolarChargerPage.qml
pages/solar/SolarDeviceListPage.qml
pages/solar/SolarHistoryPage.qml
pages/switch/SwitchAuxInsert.qml
pages/switch/SwitchDelegate.qml
pages/switch/SwitchAuxCard.qml
pages/switch/DimmingSlider.qml

pages/vebusdevice/PageAcSensor.qml
pages/vebusdevice/PageAcSensors.qml
pages/vebusdevice/PageVeBusAdvanced.qml
Expand Down Expand Up @@ -803,6 +814,7 @@ set(Dbus_QML_MODULE_SOURCES
data/dbus/NotificationsImpl.qml
data/dbus/PvInvertersImpl.qml
data/dbus/SolarChargersImpl.qml
data/dbus/SwitchesImpl.qml
data/dbus/SystemSettingsImpl.qml
data/dbus/TanksImpl.qml
data/dbus/InverterChargersImpl.qml
Expand Down Expand Up @@ -851,6 +863,7 @@ set(Mock_QML_MODULE_SOURCES
data/mock/PulseMetersImpl.qml
data/mock/PvInvertersImpl.qml
data/mock/SolarChargersImpl.qml
data/mock/SwitchesImpl.qml
data/mock/SystemImpl.qml
data/mock/SystemSettingsImpl.qml
data/mock/TanksImpl.qml
Expand Down Expand Up @@ -922,6 +935,7 @@ set(Mqtt_QML_MODULE_SOURCES
data/mqtt/NotificationsImpl.qml
data/mqtt/PvInvertersImpl.qml
data/mqtt/SolarChargersImpl.qml
data/mqtt/SwitchesImpl.qml
data/mqtt/SystemSettingsImpl.qml
data/mqtt/TanksImpl.qml
data/mqtt/InverterChargersImpl.qml
Expand Down Expand Up @@ -1037,6 +1051,8 @@ qt_add_resources(${PROJECT_NAME} "${PROJECT_NAME}_large_resources"
fonts/Roboto-Regular.ttf
images/acloads.svg
images/alternator.svg
images/icon_auxpage_off_32.svg
images/icon_auxpage_on_32.svg
images/breadcrumb_lhs.svg
images/breadcrumb_rhs.svg
images/icon_battery_24.svg
Expand Down
2 changes: 2 additions & 0 deletions Global.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ QtObject {
property var pvInverters
property var solarChargers
property var system
property var switches
property var systemSettings
property var tanks

property var venusPlatform
property bool auxDevicePresent: !!switches ? Global.switches.model.count > 0 : false
property bool splashScreenVisible: true
property bool dataManagerLoaded
property bool allPagesLoaded
Expand Down
1 change: 1 addition & 0 deletions components/AllDevicesModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ AggregateDeviceModel {
motorDriveDevices,
pulseMeterDevices,
Global.pvInverters.model,
Global.switches.model,
Global.solarChargers.model,
unsupportedDevices,

Expand Down
1 change: 1 addition & 0 deletions components/Page.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ FocusScope {


property int topLeftButton: VenusOS.StatusBar_LeftButton_None
property int topAuxButton: VenusOS.StatusBar_LeftButton_None
property int topRightButton: VenusOS.StatusBar_RightButton_None

property var tryPop // optional function: returns whether the page can be poppped
Expand Down
26 changes: 25 additions & 1 deletion components/StatusBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Rectangle {
property string title

property int leftButton: VenusOS.StatusBar_LeftButton_None
property int auxButton: VenusOS.StatusBar_LeftButton_None
property int rightButton: VenusOS.StatusBar_RightButton_None
readonly property bool notificationButtonsEnabled: Global.mainView.currentPage && !!Global.mainView.currentPage.url && Global.mainView.currentPage.url.endsWith("NotificationsPage.qml")
readonly property bool notificationButtonVisible: alertButton.enabled || alertButton.animating || alarmButton.enabled || alarmButton.animating
Expand All @@ -24,6 +25,7 @@ Rectangle {
signal leftButtonClicked()
signal rightButtonClicked()
signal popToPage(toPage: Page)
signal auxButtonClicked()

width: parent.width
height: Theme.geometry_statusBar_height
Expand Down Expand Up @@ -100,6 +102,29 @@ Rectangle {
onClicked: root.leftButtonClicked()
}

StatusBarButton {
id: auxButton
anchors {
left: leftButton.right
leftMargin: Theme.geometry_statusBar_horizontalMargin
verticalCenter: parent.verticalCenter
}
icon.source: root.auxButton === VenusOS.StatusBar_AuxButton_AuxInactive
? "qrc:/images/icon_auxpage_off_32.svg"
: "qrc:/images/icon_auxpage_on_32.svg"
color: root.auxButton === VenusOS.StatusBar_AuxButton_AuxDisabled
? Theme.color_darkBlue
: root.auxButton === VenusOS.StatusBar_AuxButton_AuxActive
? Theme.color_ok
: Theme.color_button_down

enabled: !!Global.pageManager
&& Global.pageManager.interactivity === VenusOS.PageManager_InteractionMode_Interactive
&& root.auxButton != VenusOS.StatusBar_AuxButton_None

onClicked: root.auxButtonClicked()
}

Breadcrumbs {
id: breadcrumbs

Expand Down Expand Up @@ -138,7 +163,6 @@ Rectangle {
}
}


Label {
id: clockLabel
anchors.centerIn: parent
Expand Down
2 changes: 2 additions & 0 deletions data/DataManager.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Item {
&& !!Global.solarChargers
&& !!Global.system
&& !!Global.systemSettings
&& !!Global.switches
&& !!Global.tanks
&& !!Global.venusPlatform

Expand Down Expand Up @@ -100,6 +101,7 @@ Item {
Notifications {}
PvInverters {}
SolarChargers {}
Switches {}
System {}
SystemSettings {}
Tanks {}
Expand Down
128 changes: 128 additions & 0 deletions data/Switches.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
** Copyright (C) 2023 Victron Energy B.V.
** See LICENSE.txt for license information.
*/

import QtQuick
import Victron.VenusOS

QtObject {
id: root

property DeviceModel model: DeviceModel {
modelId: "switches"
}

function switchStatusToText(val) {
switch (val) {
//channel status
case VenusOS.Switch_Status_Active:
//% "Active"
return qsTrId("switchDev_active")
case VenusOS.Switch_Status_Disabled:
return CommonWords.disabled
case VenusOS.Switch_Status_Input_Active:
return CommonWords.active_status
case VenusOS.Switch_Status_Off:
return CommonWords.off
case VenusOS.Switch_Status_On:
return CommonWords.on
case VenusOS.Switch_Status_Over_Temperature:
//% "Over temperature"
return qsTrId("Switches_Over_temperature")
case VenusOS.Switch_Status_Short_Fault:
//% "Short"
return qsTrId("Switches_short") //move to common
case VenusOS.Switch_Status_Tripped:
//% "Tripped"
return qsTrId("Switches_tripped")//move to common

//module state
case VenusOS.Switch_ModuleState_Channel_Fault:
//% "Channel Fault"
return qsTrId("Switches_Channel_fault")
case VenusOS.Switch_ModuleState_Channel_Tripped:
//% "Channel Tripped"
return qsTrId("Switches_Channel_Trippped")
case VenusOS.Switch_ModuleState_Connected:
return CommonWords.connected
case VenusOS.Switch_ModuleState_Over_Temperature:
//% "Over temperature"
return qsTrId("Switches_Over_temperature")
case VenusOS.Switch_ModuleState_Temperature_Warning:
//% "Temperature Warning"
return qsTrId("Switches_temperature_warning")
case VenusOS.Switch_ModuleState_Under_Voltage:
//% "Under voltage"
return qsTrId("Switches_under_voltage")
default:
return ""
}
}
function switchStatusToColor(val) {
switch (val) {
//channel status


case VenusOS.Switch_Status_Disabled:
case VenusOS.Switch_Status_Off:
return "WHITE"

case VenusOS.Switch_Status_Input_Active:
case VenusOS.Switch_Status_On:
case VenusOS.Switch_Status_Active:
return "GREEN"

case VenusOS.Switch_Status_Over_Temperature:
case VenusOS.Switch_Status_Short_Fault:
case VenusOS.Switch_Status_Tripped:
return "RED"

//module state
case VenusOS.Switch_ModuleState_Channel_Fault:
case VenusOS.Switch_ModuleState_Channel_Tripped:
case VenusOS.Switch_ModuleState_Over_Temperature:
return "RED"

case VenusOS.Switch_ModuleState_Connected:
return "GREEN"

case VenusOS.Switch_ModuleState_Temperature_Warning:
case VenusOS.Switch_ModuleState_Under_Voltage:
return "YELLOW"

default:
return "RED"
}
}

function switchStateToText(val) {
switch (val) {
case 0:
return CommonWords.off
case 1:
return CommonWords.on
default:
return ""
}
}

function switchFunctionToText(val){
switch (val) {
case VenusOS.Switch_Function_Momentary:
//% "Momentary"
return qsTrId("Switches_Momentary")
case VenusOS.Switch_Function_Latching:
//% "Latching"
return qsTrId("Switches_Latching")
case VenusOS.Switch_Function_Dimmable:
//% "Dimmable"
return qsTrId("Switches_Dimmable")
default:
//% "Undefined"
return qsTrId("Switches_Undefined")
}
}

Component.onCompleted: Global.switches = root
}
Loading
Loading