Skip to content

Commit

Permalink
Add inverter / charger drilldowns
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMcInnes committed Oct 25, 2023
1 parent 89fe98b commit 478dae7
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 9 deletions.
3 changes: 3 additions & 0 deletions components/CommonWords.qml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ QtObject {
//% "%1 Hour(s)"
readonly property string x_hours: qsTrId("common_words_x_hours")

//% "Inverter / Charger"
readonly property string inverter_charger: qsTrId("common_words_inverter_charger")

//% "Inverter overload"
readonly property string inverter_overload: qsTrId("common_words_inverter_overload")

Expand Down
8 changes: 7 additions & 1 deletion components/Units.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ function defaultUnitPrecision(unit) {
The number is scaled if the absolute value is >= 10,000 (e.g. 10000 W = 10kW).
*/
function getDisplayText(unit, value, precision, unitMatchValue = undefined) {
function getDisplayText(unit, value, precision = undefined, unitMatchValue = undefined) {
if (precision === undefined) {
precision = defaultUnitPrecision(unit)
}

switch (unit) {
case V.VenusOS.Units_Watt:
return _scaledQuantity(value, unitMatchValue, precision, "W", "kW")
Expand All @@ -45,6 +49,8 @@ function getDisplayText(unit, value, precision, unitMatchValue = undefined) {
case V.VenusOS.Units_Volume_GallonUS:
case V.VenusOS.Units_Volume_GallonImperial:
return _scaledQuantity(value, unitMatchValue, precision, "gal")
case V.VenusOS.Units_Hz:
return _scaledQuantity(value, unitMatchValue, precision, "Hz", "kHz")
default:
console.warn("getDisplayText(): unknown unit", unit, "with value", value)
return { number: "--", unit: "" }
Expand Down
11 changes: 9 additions & 2 deletions components/widgets/VeBusDeviceWidget.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ OverviewWidget {
title: qsTrId("overview_widget_inverter_title")
icon.source: "qrc:/images/inverter_charger.svg"
type: VenusOS.OverviewWidget_Type_VeBusDevice

enabled: true
quantityLabel.visible: false

extraContent.children: [
Label {
anchors {
Expand All @@ -28,4 +27,12 @@ OverviewWidget {
wrapMode: Text.Wrap
}
]
MouseArea {
anchors.fill: parent
onClicked: {
console.log("onClicked")
Global.pageManager.pushPage("/pages/vebusdevice/VeBusDevicePage.qml",
{ "veBusDevice": Global.veBusDevices.model.firstObject })
}
}
}
10 changes: 7 additions & 3 deletions data/AcInputs.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@
import QtQuick
import Victron.VenusOS
import "common"
import "/components/Units.js" as Units

QtObject {
id: root

property var connectedInput // Only one AC input can be connected and active at any time.
property var generatorInput

property real power: connectedInput != null ? connectedInput.power : NaN
property real current: connectedInput != null ? connectedInput.current : NaN
property real currentLimit: connectedInput != null ? connectedInput.currentLimit : NaN
readonly property real power: connectedInput != null ? connectedInput.power : NaN
readonly property real voltage: connectedInput != null ? connectedInput.voltage : NaN
readonly property real current: connectedInput != null ? connectedInput.current : NaN
readonly property real currentLimit: connectedInput != null ? connectedInput.currentLimit : NaN
readonly property real frequency: connectedInput != null ? connectedInput.frequency : NaN

property DeviceModel model: DeviceModel {
objectProperty: "input"
}

function addInput(input) {
console.log("AcInputs: addInput")
model.addObject(input)
}

Expand Down
5 changes: 5 additions & 0 deletions data/VeBusDevices.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ QtObject {
}

property real totalNominalInverterPower: NaN
readonly property int numberOfPhases: model.firstObject && model.firstObject.numberOfPhases ? model.firstObject.numberOfPhases : NaN

function addVeBusDevice(veBusDevice) {
for (var key in veBusDevice) {
console.log("VeBusDevices: veBusDevice[", key, "]:", veBusDevice[key])

}
if (model.addObject(veBusDevice)) {
refreshNominalInverterPower()
}
Expand Down
12 changes: 10 additions & 2 deletions data/common/AcInputServiceLoader.qml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ Loader {

readonly property VeQuickItem _frequency: VeQuickItem {
uid: !!phase.phasePath ? phase.phasePath + "/F" : ""
onValueChanged: root._updateValue(acInputs, model.index, "frequency", value)
onValueChanged: {
console.log(uid, value)
root._updateValue(acInputs, model.index, "frequency", value)
}

}
readonly property VeQuickItem _current: VeQuickItem {
uid: !!phase.phasePath ? phase.phasePath + "/I" : ""
Expand Down Expand Up @@ -189,7 +193,11 @@ Loader {

readonly property VeQuickItem _frequency: VeQuickItem {
uid: phase.phasePath + "/Frequency"
onValueChanged: root._updateValue(acInputs, model.index, "frequency", value)
onValueChanged: {
console.log("AcInputServiceLoader:", uid, value)
root._updateValue(acInputs, model.index, "frequency", value)
}
Component.onCompleted: console.log("AcInputServiceLoader: onCompleted:", uid, value)
}
readonly property VeQuickItem _current: VeQuickItem {
uid: phase.phasePath + "/Current"
Expand Down
25 changes: 25 additions & 0 deletions data/common/AcOutput.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
** Copyright (C) 2023 Victron Energy B.V.
*/

import QtQuick
import Victron.VenusOS
import Victron.Veutil
import "/components/Utils.js" as Utils

QtObject {
id: root

property string serviceUid

readonly property AcOutputPhase phase1: AcOutputPhase {
serviceUid: root.serviceUid + "/Ac/Out/L1"
}
readonly property AcOutputPhase phase2: AcOutputPhase {
serviceUid: root.serviceUid + "/Ac/Out/L2"
}
readonly property AcOutputPhase phase3: AcOutputPhase {
serviceUid: root.serviceUid + "/Ac/Out/L3"
}
readonly property bool is3Phase: phase1.valid && phase2.valid &&phase3.valid
}
38 changes: 38 additions & 0 deletions data/common/AcOutputPhase.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
** Copyright (C) 2023 Victron Energy B.V.
*/

import QtQuick
import Victron.VenusOS
import Victron.Veutil
import "/components/Utils.js" as Utils

QtObject {
id: root

property string serviceUid
readonly property real frequency: _frequency.value === undefined ? NaN : _frequency.value
readonly property real current: _current.value === undefined ? NaN : _current.value
readonly property real voltage: _voltage.value === undefined ? NaN : _voltage.value
readonly property real power: _power.value === undefined ? NaN : _power.value
readonly property bool valid: !Number.isNaN(frequency) &&
!Number.isNaN(current) &&
!Number.isNaN(voltage) &&
!Number.isNaN(power)

readonly property VeQuickItem _frequency: VeQuickItem {
uid: serviceUid + "/F"
}

readonly property VeQuickItem _current: VeQuickItem {
uid: serviceUid + "/I"
}

readonly property VeQuickItem _voltage: VeQuickItem {
uid: serviceUid + "/F"
}

readonly property VeQuickItem _power: VeQuickItem {
uid: serviceUid + "/P"
}
}
31 changes: 31 additions & 0 deletions data/common/VeBusDevice.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ Device {

readonly property int state: _state.value === undefined ? -1 : _state.value
readonly property int mode: _mode.value === undefined ? -1 : _mode.value
readonly property int numberOfPhases: _numberOfPhases.value === undefined ? NaN : _numberOfPhases.value
readonly property bool modeAdjustable: _modeAdjustable.value !== undefined && _modeAdjustable.value > 0
readonly property real nominalInverterPower: _nominalInverterPower.value === undefined ? NaN : _nominalInverterPower.value

readonly property int dcPower: _dcPower.value === undefined ? NaN : _dcPower.value
readonly property int dcVoltage: _dcVoltage.value === undefined ? NaN : _dcVoltage.value
readonly property real dcCurrent: _dcCurrent.value === undefined ? NaN : _dcCurrent.value

readonly property real stateOfCharge: _stateOfCharge.value === undefined ? NaN : _stateOfCharge.value

property ListModel inputSettings: ListModel {}

readonly property int productId: _productId.value === undefined ? -1 : _productId.value
Expand All @@ -25,6 +32,11 @@ Device {
? _euAmpOptions
: (productType === VenusOS.VeBusDevice_ProductType_UsProduct ? _usAmpOptions : [])

readonly property AcOutput acOutput: AcOutput {
serviceUid: inverter.serviceUid
Component.onCompleted: console.log("VeBusDevice: acOutput: onCompleted:", serviceUid)
}

/* - Mask the Product id with `0xFF00`
* - If the result is `0x1900` or `0x2600` it is an EU model (230VAC)
* - If the result is `0x2000` or `0x2700` it is an US model (120VAC)
Expand Down Expand Up @@ -58,6 +70,25 @@ Device {
uid: inverter.serviceUid + "/Ac/NumberOfAcInputs"
}

readonly property VeQuickItem _numberOfPhases: VeQuickItem {
uid: inverter.serviceUid + "/Ac/NumberOfPhases"
}

readonly property VeQuickItem _dcCurrent: VeQuickItem {
uid: inverter.serviceUid + "/Dc/0/Current"
}
readonly property VeQuickItem _dcPower: VeQuickItem {
uid: inverter.serviceUid + "/Dc/0/Power"
}
readonly property VeQuickItem _dcVoltage: VeQuickItem {
uid: inverter.serviceUid + "/Dc/0/Current"
}

readonly property VeQuickItem _stateOfCharge: VeQuickItem {
uid: inverter.serviceUid + "/Soc"
}


property bool _valid: deviceInstance.value !== undefined
on_ValidChanged: {
if (!!Global.veBusDevices) {
Expand Down
12 changes: 12 additions & 0 deletions data/mock/VeBusDevicesImpl.qml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,25 @@ QtObject {
property int state
property int mode: -1
property bool modeAdjustable
property int numberOfPhases: 1

property ListModel inputSettings: ListModel {}

property int productId
property int productType
property var ampOptions

property var acOutput: {
"phase1" : {
"frequency" : 50.1,
"current" : 20,
"voltage" : 235,
"power" : 4700
},
"phase2" : {},
"phase3" : {}
}

function setMode(newMode) {
mode = newMode
}
Expand Down
Loading

0 comments on commit 478dae7

Please sign in to comment.