Right, so I've implemented some stuff that seems to work quite well.
The commit that will follow on from that it implements the new Units: kWh/100km, km/kWh and mi/kWh.
This is a summary of what I've implemented for scripting - including showing the unit codes I have so far. I've considered a few things:
* Should some of the longer unit codes be shortened (eg mi, mins, m, ft, deg, perc)
* The unit codes could be much more regular and separated by dots eg:
watthours -> w.h
kwhp100km -> kw.h_100km or kw.h/100km
miph -> mi_h or mi/h (or should it be mph).
OVMS# metric units km : km miles : M meters : m feet : ft celcius : °C fahrenheit : °F kpa : kPa pa : Pa psi : psi volts : V amps : A amphours
: Ah kw : kW kwh : kWh watts : W watthours
: Wh seconds : Sec minutes : Min hours : Hour utc : UTC degrees : ° kmph : km/h miph
: Mph kmphps
: km/h/s miphps
: Mph/s mpss : m/s² dbm : dBm sq : sq percent : % whpkm : Wh/km whpmi
: Wh/mi kwhp100km : kWh/100km kmpkwh
: km/kWh mipkwh
: mi/kWh nm : Nm
OVMS# metric unit mi
miles : M
minutes : Min
miph : Mph
miphps : Mph/s
whpmi : Wh/mi
mipkwh : mi/kWhOVMS# metric get xiq.v.trip.consumption
17.0597kWh/100kmOVMS# metric get xiq.v.trip.consumption kpkwh
5.86177km/kWhOVMS# metric get xiq.v.trip.consumption mpkwh
3.64233mi/kWhOVMS# metric set xiq.c.speed 5 miph
Metric setOVMS# metric get xiq.c.speed
8.04673km/hOVMS# metric get xiq.c.speed miph
5MphAnd then in DukTape - there are some questions I have about the implementation:* Names of functions? Better ideas?
* Should ValueUnit output the units?
* In Value() there is the line bool decode = duk_opt_boolean(ctx, 1, true);
* What does 'decode' mean here?
* Do I need it for ValueUnit() ?
(function() {
print( OvmsMetrics.Value("xiq.v.trip.consumption"));
print("\n")
print( OvmsMetrics.ValueUnit("xiq.v.trip.consumption",""));
print("\n")
print( OvmsMetrics.ValueUnit("xiq.v.trip.consumption","mipkwh"));
print("\n")
print( OvmsMetrics.AsFloatUnit("xiq.v.trip.consumption","kmpkwh"));
})();
--- Output ---
17.0597
17.0597kWh/100km
3.64233mi/kWh
5.86177
------
The basic stuff all works - it's just quibbling over the details.. but let's get them right!
//.ichael