Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions components/BriefCenterDisplay.qml
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,12 @@ Column {
value: Global.system.battery.voltage
}

QuantityLabel {
readonly property bool unitAmps: (Global.systemSettings.electricalQuantity === VenusOS.Units_Amp && !isNaN(Global.system.battery.current))
|| (!isNaN(Global.system.battery.current) && isNaN(Global.system.battery.power))
ElectricalQuantityLabel {
sourceType: VenusOS.ElectricalQuantity_Source_Dc
dataObject: Global.system.battery
valueColor: Theme.color_briefPage_battery_value_text_color
unitColor: Theme.color_briefPage_battery_unit_text_color
font.pixelSize: Theme.font_briefPage_battery_voltage_pixelSize
value: unitAmps ? Global.system.battery.current : Global.system.battery.power
unit: unitAmps ? VenusOS.Units_Amp : VenusOS.Units_Watt
}
}

Expand Down
25 changes: 22 additions & 3 deletions components/ElectricalQuantityLabel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,39 @@
import QtQuick
import Victron.VenusOS

/*
Shows a quantity in Amps or Watts depending on the user-preferred display mode, according to
Global.systemSettings.electricalPowerDisplay:

- PreferWatts: show dataObject.power in Watts.
- PreferAmps: if dataObject.current is valid, show it in Amps, otherwise show dataObject.power
in Watts.
- Mixed: if 'sourceType' is ElectricalQuantity_Source_Dc, and dataObject.current is valid, show
it in Amps. Otherwise, show dataObject.power in Watts.
*/
QuantityLabel {
id: root

property int sourceType: VenusOS.ElectricalQuantity_Source_Any

// An object with 'power' and 'current' values. When showing in Amps, the current is displayed,
// otherwise the power is displayed.
property var dataObject
property bool acInputMode

readonly property bool _dataObjectValid: dataObject !== null && dataObject !== undefined
readonly property bool _unitAmps: Global.systemSettings.electricalQuantity === VenusOS.Units_Amp && _dataObjectValid && !isNaN(dataObject.current)
readonly property bool _unitAmps: (Global.systemSettings.electricalPowerDisplay === VenusOS.ElectricalPowerDisplay_PreferAmps
|| (Global.systemSettings.electricalPowerDisplay === VenusOS.ElectricalPowerDisplay_Mixed
&& sourceType === VenusOS.ElectricalQuantity_Source_Dc))
&& _dataObjectValid
&& !isNaN(dataObject.current)
readonly property real _value: !_dataObjectValid ? NaN
: _unitAmps ? dataObject.current
: dataObject.power

// For AC inputs, the AcInputDirectionIcon should be present to indicate when power is negative,
// so just show the absolute value without a minus sign.
value: acInputMode ? Math.abs(_value) // will return NaN if _value is NaN.
value: sourceType === VenusOS.ElectricalQuantity_Source_AcInputOnly
? Math.abs(_value) // will return NaN if _value is NaN.
: _value

unit: _unitAmps ? VenusOS.Units_Amp : VenusOS.Units_Watt
Expand Down
2 changes: 0 additions & 2 deletions components/ObjectAcConnection.qml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ QtObject {
readonly property bool singlePhaseCurrentValid: _phaseCount.value === 1 && currentL1.valid
// multi-phase systems don't have a total current
readonly property real current: singlePhaseCurrentValid && currentL1.value !== undefined ? currentL1.value : NaN
readonly property int preferredUnit: Global.systemSettings.electricalQuantity === VenusOS.Units_Amp && singlePhaseCurrentValid ? VenusOS.Units_Amp : VenusOS.Units_Watt
readonly property real preferredQuantity: preferredUnit === VenusOS.Units_Amp ? current : power

readonly property PhaseModel phases: PhaseModel {
id: _phases
Expand Down
1 change: 1 addition & 0 deletions components/ThreePhaseDisplay.qml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Flow {
y: root.widgetSize <= VenusOS.OverviewWidget_Size_S
? phaseLabel.height + Theme.geometry_three_phase_column_spacing
: 0
sourceType: VenusOS.ElectricalQuantity_Source_Ac
dataObject: QtObject {
readonly property real power: phaseDelegate.power
readonly property real current: phaseDelegate.current
Expand Down
2 changes: 1 addition & 1 deletion components/widgets/AcInputWidget.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ AcWidget {
title: !!inputInfo ? Global.acInputs.sourceToText(inputInfo.source) : ""
icon.source: !!inputInfo ? Global.acInputs.sourceIcon(inputInfo.source) : ""
rightPadding: sideGaugeLoader.active ? Theme.geometry_overviewPage_widget_sideGauge_margins : 0
quantityLabel.sourceType: VenusOS.ElectricalQuantity_Source_AcInputOnly
quantityLabel.dataObject: inputOperational ? input : null
quantityLabel.leftPadding: acInputDirectionIcon.visible ? (acInputDirectionIcon.width + Theme.geometry_acInputDirectionIcon_rightMargin) : 0
quantityLabel.acInputMode: true
phaseCount: inputOperational ? input.phases.count : 0
enabled: !!inputInfo
extraContentLoader.sourceComponent: ThreePhaseDisplay {
Expand Down
1 change: 1 addition & 0 deletions components/widgets/AcWidget.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ OverviewWidget {
}
}

quantityLabel.sourceType: VenusOS.ElectricalQuantity_Source_Ac
quantityLabel.visible: !!quantityLabel.dataObject
preferredSize: phaseCount > 1 ? VenusOS.OverviewWidget_PreferredSize_PreferLarge : VenusOS.OverviewWidget_PreferredSize_Any

Expand Down
1 change: 1 addition & 0 deletions components/widgets/DcInputWidget.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ OverviewWidget {
: "/pages/settings/devicelist/dc-in/PageDcMeter.qml"

title: VenusOS.dcMeter_typeToText(inputType)
quantityLabel.sourceType: VenusOS.ElectricalQuantity_Source_Dc
quantityLabel.dataObject: QtObject {
readonly property real power: inputDeviceModel.totalPower
readonly property real current: inputDeviceModel.totalCurrent
Expand Down
1 change: 1 addition & 0 deletions components/widgets/DcLoadsWidget.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ OverviewWidget {
type: VenusOS.OverviewWidget_Type_DcLoads
enabled: systemLoadDevices.count > 1 || nonSystemLoadDevices.count > 0

quantityLabel.sourceType: VenusOS.ElectricalQuantity_Source_Dc
quantityLabel.dataObject: Global.system.dc

onClicked: {
Expand Down
3 changes: 2 additions & 1 deletion components/widgets/EvcsWidget.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ OverviewWidget {
type: VenusOS.OverviewWidget_Type_Evcs
preferredSize: VenusOS.OverviewWidget_PreferredSize_LargeOnly
enabled: true
quantityLabel.sourceType: VenusOS.ElectricalQuantity_Source_Ac
quantityLabel.dataObject: Global.evChargers

extraContentChildren: [
Expand Down Expand Up @@ -54,7 +55,7 @@ OverviewWidget {

width: parent.width

ElectricalQuantityLabel {
QuantityLabel {
height: chargingTimeLabel.height // use normal label height, instead of default baseline calculation
value: energyItem.value ?? NaN
valueColor: unitColor
Expand Down
2 changes: 0 additions & 2 deletions data/System.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ QtObject {
readonly property real current: currentValid ? power / voltage : NaN
readonly property real voltage: _dcBatteryVoltage.valid ? _dcBatteryVoltage.value : NaN
readonly property real maximumPower: _maximumDcPower.valid ? _maximumDcPower.value : NaN
readonly property int preferredUnit: Global.systemSettings.electricalQuantity === VenusOS.Units_Amp && currentValid ? VenusOS.Units_Amp : VenusOS.Units_Watt
readonly property real preferredQuantity: preferredUnit === VenusOS.Units_Amp ? current : power

readonly property VeQuickItem _dcSystemPower: VeQuickItem {
uid: root.serviceUid + "/Dc/System/Power"
Expand Down
21 changes: 14 additions & 7 deletions data/SystemSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ QtObject {
// It's hard to skip onboarding without touch, so disable onboarding if touch is disabled.
&& _touchEnabled.valid && _touchEnabled.value !== 0

property int electricalQuantity: VenusOS.Units_None
property int electricalPowerDisplay: VenusOS.ElectricalPowerDisplay_PreferWatts
property int temperatureUnit: VenusOS.Units_None
property string temperatureUnitSuffix
property int volumeUnit: VenusOS.Units_None
Expand Down Expand Up @@ -71,14 +71,17 @@ QtObject {
return accessLevel.valid && accessLevel.value >= level
}

function setElectricalQuantity(value) {
function setElectricalPowerDisplay(value) {
switch (value) {
case VenusOS.Units_Watt:
case VenusOS.ElectricalPowerDisplay_PreferWatts:
_electricalQuantity.setValue(_electricalQuantity.ve_watt)
break
case VenusOS.Units_Amp:
case VenusOS.ElectricalPowerDisplay_PreferAmps:
_electricalQuantity.setValue(_electricalQuantity.ve_amp)
break
case VenusOS.ElectricalPowerDisplay_Mixed:
_electricalQuantity.setValue(_electricalQuantity.ve_mixed)
break
default:
console.warn("setElectricalQuantity() unknown value:", value)
break
Expand Down Expand Up @@ -339,19 +342,23 @@ QtObject {
property VeQuickItem _electricalQuantity: VeQuickItem {
readonly property int ve_watt: 0
readonly property int ve_amp: 1
readonly property int ve_mixed: 2

uid: root.serviceUid + "/Settings/Gui/ElectricalPowerIndicator"
onValueChanged: {
switch (value) {
case ve_watt:
root.electricalQuantity = VenusOS.Units_Watt
root.electricalPowerDisplay = VenusOS.ElectricalPowerDisplay_PreferWatts
break
case ve_amp:
root.electricalQuantity = VenusOS.Units_Amp
root.electricalPowerDisplay = VenusOS.ElectricalPowerDisplay_PreferAmps
break
case ve_mixed:
root.electricalPowerDisplay = VenusOS.ElectricalPowerDisplay_Mixed
break
default:
console.warn("Cannot load electrical quantity,", uid, "has unsupported value:", value, "default to watts")
root.electricalQuantity = VenusOS.Units_Watt
root.electricalPowerDisplay = VenusOS.ElectricalPowerDisplay_PreferWatts
break
}
}
Expand Down
16 changes: 9 additions & 7 deletions data/mock/MockShortcuts.qml
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,12 @@ QtObject {
}

// Change the system unit
Global.systemSettings.setElectricalQuantity(
Global.systemSettings.electricalQuantity === VenusOS.Units_Watt
? VenusOS.Units_Amp
: VenusOS.Units_Watt)
Global.systemSettings.setElectricalPowerDisplay(
Global.systemSettings.electricalPowerDisplay === VenusOS.ElectricalPowerDisplay_PreferWatts
? VenusOS.ElectricalPowerDisplay_PreferAmps
: Global.systemSettings.electricalPowerDisplay === VenusOS.ElectricalPowerDisplay_PreferAmps
? VenusOS.ElectricalPowerDisplay_Mixed
: VenusOS.ElectricalPowerDisplay_PreferWatts)
Global.systemSettings.setTemperatureUnit(
Global.systemSettings.temperatureUnit === VenusOS.Units_Temperature_Celsius
? VenusOS.Units_Temperature_Fahrenheit
Expand All @@ -287,9 +289,9 @@ QtObject {
: VenusOS.Units_Speed_KilometresPerHour)

pageConfigTitle.text = "Units: "
+ (Global.systemSettings.electricalQuantity === VenusOS.Units_Watt
? "Watts"
: "Amps") + " | "
+ (Global.systemSettings.electricalPowerDisplay === VenusOS.ElectricalPowerDisplay_PreferWatts ? "Watts"
: Global.systemSettings.electricalPowerDisplay === VenusOS.ElectricalPowerDisplay_PreferAmps ? "Amps"
: "Mixed") + " | "
+ (Global.systemSettings.temperatureUnit === VenusOS.Units_Temperature_Celsius
? "Celsius"
: "Fahrenheit") + " | "
Expand Down
6 changes: 5 additions & 1 deletion pages/BriefPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ SwipeViewPage {
icon.source: Global.acInputs.sourceIcon(Global.acInputs.highlightedInput?.source ?? Global.acInputs.findValidSource())
leftPadding: root._gaugeLabelMargin - root._gaugeArcMargin
opacity: root._gaugeLabelOpacity
quantityLabel.sourceType: VenusOS.ElectricalQuantity_Source_AcInputOnly
quantityLabel.dataObject: Global.acInputs.highlightedInput
quantityLabel.acInputMode: true
}
}
onStatusChanged: if (status === Loader.Error) console.warn("Unable to load AC input edge")
Expand Down Expand Up @@ -211,6 +211,7 @@ SwipeViewPage {
: VenusOS.dcMeter_iconForMultipleTypes()
leftPadding: root._gaugeLabelMargin - root._gaugeArcMargin
opacity: root._gaugeLabelOpacity
quantityLabel.sourceType: VenusOS.ElectricalQuantity_Source_Dc
quantityLabel.dataObject: Global.dcInputs
}

Expand Down Expand Up @@ -250,6 +251,7 @@ SwipeViewPage {
icon.source: "qrc:/images/solaryield.svg"
leftPadding: root._gaugeLabelMargin - root._gaugeArcMargin
opacity: root._gaugeLabelOpacity
quantityLabel.sourceType: VenusOS.ElectricalQuantity_Source_Any
quantityLabel.dataObject: Global.system.solar
}
}
Expand Down Expand Up @@ -297,6 +299,7 @@ SwipeViewPage {
icon.source: dcLoadGauge.active ? "qrc:/images/acloads.svg" : "qrc:/images/consumption.svg"
rightPadding: root._gaugeLabelMargin - root._gaugeArcMargin
opacity: root._gaugeLabelOpacity
quantityLabel.sourceType: VenusOS.ElectricalQuantity_Source_Ac
quantityLabel.dataObject: Global.system.load.ac
}
}
Expand Down Expand Up @@ -330,6 +333,7 @@ SwipeViewPage {
icon.source: "qrc:/images/dcloads.svg"
rightPadding: root._gaugeLabelMargin - root._gaugeArcMargin
opacity: root._gaugeLabelOpacity
quantityLabel.sourceType: VenusOS.ElectricalQuantity_Source_Dc
quantityLabel.dataObject: Global.system.dc
}

Expand Down
7 changes: 5 additions & 2 deletions pages/BriefSidePanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ ColumnLayout {
icon.source: "qrc:/images/generator.svg"
loadersActive: generatorInput && generatorInput.operational && Global.generators.model.firstObject
visible: loadersActive
quantityLabel.sourceType: VenusOS.ElectricalQuantity_Source_AcInputOnly
quantityLabel.dataObject: generatorInput
quantityLabel.leftPadding: generatorDirectionIcon.visible ? (generatorDirectionIcon.width + Theme.geometry_acInputDirectionIcon_rightMargin) : 0
quantityLabel.acInputMode: true
sideComponent: Item {
width: generatorLabel.width
height: generatorLabel.height
Expand Down Expand Up @@ -83,9 +83,9 @@ ColumnLayout {

title: loadersActive ? Global.acInputs.sourceToText(nonGeneratorInput.source) : ""
icon.source: loadersActive ? Global.acInputs.sourceIcon(nonGeneratorInput.source) : ""
quantityLabel.sourceType: VenusOS.ElectricalQuantity_Source_AcInputOnly
quantityLabel.dataObject: nonGeneratorInput
quantityLabel.leftPadding: acInputDirectionIcon.visible ? (acInputDirectionIcon.width + Theme.geometry_acInputDirectionIcon_rightMargin) : 0
quantityLabel.acInputMode: true
loadersActive: nonGeneratorInput && nonGeneratorInput.operational
visible: loadersActive

Expand Down Expand Up @@ -217,6 +217,7 @@ exported power v 0.4 | /
: VenusOS.dcMeter_iconForMultipleTypes()
loadersActive: Global.dcInputs.model.count > 0
visible: loadersActive
quantityLabel.sourceType: VenusOS.ElectricalQuantity_Source_Dc
quantityLabel.dataObject: Global.dcInputs
sideComponent: LoadGraph {
animationEnabled: root.animationEnabled
Expand Down Expand Up @@ -256,6 +257,7 @@ exported power v 0.4 | /
//% "AC Loads"
title: qsTrId("brief_ac_loads")
icon.source: "qrc:/images/acloads.svg"
quantityLabel.sourceType: VenusOS.ElectricalQuantity_Source_Ac
quantityLabel.dataObject: Global.system.load.ac
loadersActive: true
sideComponent: LoadGraph {
Expand Down Expand Up @@ -285,6 +287,7 @@ exported power v 0.4 | /
icon.source: "qrc:/images/dcloads.svg"
loadersActive: Global.system.dc.hasPower
visible: loadersActive
quantityLabel.sourceType: VenusOS.ElectricalQuantity_Source_Dc
quantityLabel.dataObject: Global.system.dc
sideComponent: LoadGraph {
animationEnabled: root.animationEnabled
Expand Down
14 changes: 7 additions & 7 deletions pages/boat/ConsumptionGauge.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ Column {
QuantityLabelIconRow {
id: motorDriveLoad

sourceType: VenusOS.ElectricalQuantity_Source_Dc
dataObject: root.motorDrive.dcConsumption.scalar
font.pixelSize: root._pixelSize
value: root.motorDrive.dcConsumption.scalar.valid ? root.motorDrive.dcConsumption.scalar.value : NaN
unit: root.motorDrive.dcConsumption.scalarUnit
icon.source: "qrc:/images/icon_propeller.svg"
visible: root.gps.valid && root.motorDrive.dcConsumption.scalar && root.motorDrive.dcConsumption.scalar.valid
visible: root.gps.valid && !isNaN(value)
}

QuantityLabelIconRow {
Expand All @@ -42,8 +42,8 @@ Column {
anchors.right: parent.right
font.pixelSize: root._pixelSize
height: font.pixelSize
value: Global.system.load.ac.preferredQuantity
unit: Global.system.load.ac.preferredUnit
sourceType: VenusOS.ElectricalQuantity_Source_Ac
dataObject: Global.system.load.ac
icon.source: "qrc:/images/acloads.svg"
icon.width: Theme.geometry_widgetHeader_icon_size
visible: !motorDriveLoad.visible // && !isNaN(value) once #2159 is resolved
Expand All @@ -55,8 +55,8 @@ Column {
anchors.right: parent.right
font.pixelSize: root._pixelSize
height: font.pixelSize
value: Global.system.dc.preferredQuantity
unit: Global.system.dc.preferredUnit
sourceType: VenusOS.ElectricalQuantity_Source_Dc
dataObject: Global.system.dc
icon.source: "qrc:/images/dcloads.svg"
icon.width: Theme.geometry_widgetHeader_icon_size
visible: !motorDriveLoad.visible && !isNaN(value)
Expand Down
13 changes: 8 additions & 5 deletions pages/boat/MotorDrive.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ QtObject {
readonly property string serviceUid: _motorDriveServices.firstUid

readonly property QtObject dcConsumption: QtObject {
// we no longer support max current, so any ArcGauges (such as the BoatPage center gauge) always shows power, regardless of Global.systemSettings.electricalQuantity
// we no longer support max current, so any ArcGauges (such as the BoatPage center gauge)
// always shows power, regardless of Global.systemSettings.electricalPowerDisplay
readonly property VeQuickItemsQuotient quotient: root.power

// we can show current in the consumption gauge
readonly property VeQuickItem scalar: Global.systemSettings.electricalQuantity === VenusOS.Units_Amp ? _scalarCurrent : root.power._numerator
readonly property int scalarUnit: Global.systemSettings.electricalQuantity
readonly property QtObject scalar: QtObject {
readonly property real power: root.power._numerator.value ?? NaN
readonly property real current: _scalarCurrent.value ?? NaN

readonly property VeQuickItem _scalarCurrent: VeQuickItem {
uid: root.serviceUid ? BackendConnection.serviceUidForType("system") + "/MotorDrive/Current" : ""
readonly property VeQuickItem _scalarCurrent: VeQuickItem {
uid: root.serviceUid ? BackendConnection.serviceUidForType("system") + "/MotorDrive/Current" : ""
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions pages/boat/QuantityLabelIconRow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import QtQuick.Controls.impl as CP
Row {
id: root

property alias sourceType: label.sourceType
property alias dataObject: label.dataObject
property alias value: label.value
property alias unit: label.unit
property alias icon: icon
property alias font: label.font

spacing: Theme.geometry_boatPage_row_spacing

QuantityLabel {
ElectricalQuantityLabel {
id: label

anchors.verticalCenter: parent.verticalCenter
Expand Down
Loading