Skip to content

Device Page: support different distance units#2847

Open
ybott-qinetic wants to merge 6 commits intottomkins/unit-refactorfrom
ttomkins/add-ev-distance-conversions
Open

Device Page: support different distance units#2847
ybott-qinetic wants to merge 6 commits intottomkins/unit-refactorfrom
ttomkins/add-ev-distance-conversions

Conversation

@ybott-qinetic
Copy link
Contributor

Contributes to #2846

@ybott-qinetic ybott-qinetic marked this pull request as draft February 25, 2026 22:10
src/units.cpp Outdated
{ DegreesSymbol, Victron::VenusOS::Enums::Units_CardinalDirection, Unit::Default, 0, false },
{ "km", Victron::VenusOS::Enums::Units_Distance_Kilometre, Unit::Default, 0, false },
{ "NM", Victron::VenusOS::Enums::Units_Distance_Nautical_Mile, Unit::Default, 0, false },
{ "m", Victron::VenusOS::Enums::Units_Distance_Metre, Unit::Metre, 0, false },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about the renaming that we discussed yesterday, we can rename Units_Altitude_Metre to Units_Metre, and then that unit can be used regardless of whether we are measuring altitude or land distance. That will make sense for both /Units/Altitude and any potential future /Units/Distance. Same with Units_Altitude_Foot, it should be Units_Foot instead. Can you make this renaming change as a first (separate) commit in this PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When adding Units_Kilometre, update units.cpp to avoid scaling for this unit, so that it's not possible to scale to a number like "1.2 kkm".

Also can you add unit tests for the new units? See tst_units.qml.

I wasn't sure initially about adding Units_Kilometre if we already have Units_Metre - will it cause confusion about which one to use? But I suppose it's convenient to have both if you want to don't want to convert the source VeQuickItem value when displaying a "km" value in a QuantityLabel. And then we could also use it for direct unit conversions with VeQuickItem::sourceUnit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have addressed the above items.

value: dataItem.valid ? dataItem.value * 1000 : NaN // convert raw km -> m
unit: VenusOS.Units_Altitude_Metre
value: dataItem.valid ? root._metresToSystemDistanceUnit(dataItem.value) : NaN // convert raw km -> m
unit: root._systemDistanceUnit()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having _metresToSystemDistanceUnit(), you can do unit conversions directly on the data item, using VeQuickItem::sourceUnit and VeQuickItem::displayUnit. To do this, update the veutil unit conversions:

  • Add Kilometre, Mile and NauticalMile alongside Metre and Foot
  • Update the AltitudeConverter to do those new unit conversions

Then you can do the conversions directly on the data item and it will show the correct value:

ListQuantity {
    //% "Range"
    text: qsTrId("ev_range")
    dataItem.uid: root.bindPrefix + "/RangeToGo"
    dataItem.sourceUnit: Units.unitToVeUnit(VenusOS.Units_Kilometre)
    dataItem.displayUnit: Units.unitToVeUnit(_systemDistanceUnit())
    unit: root._systemDistanceUnit()
}

(See other uses of sourceUnit and displayUnit in gui-v2.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@blammit
Copy link
Contributor

blammit commented Feb 26, 2026

Also, instead of "Device Page", use "EV" for the commit message subject (or "Units" for the unit-only commit) as this change does not generically apply to device pages in general.

Removes altitude from constant names
@ybott-qinetic ybott-qinetic force-pushed the ttomkins/add-ev-distance-conversions branch from f97a23f to 3c73552 Compare February 26, 2026 05:07
Using unit additions of kilometre, mile and nautical mile display
relevant converted distance for range and odometer.

Contributes to #2847
@ybott-qinetic ybott-qinetic force-pushed the ttomkins/add-ev-distance-conversions branch from 3c73552 to beea8cb Compare February 26, 2026 05:20
@ybott-qinetic ybott-qinetic marked this pull request as ready for review February 27, 2026 23:13
@ybott-qinetic ybott-qinetic force-pushed the ttomkins/unit-refactor branch from 9263a7c to 5bf6768 Compare March 2, 2026 06:29
@ybott-qinetic ybott-qinetic force-pushed the ttomkins/unit-refactor branch from 5bf6768 to f1ce8d8 Compare March 10, 2026 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants