[Ovmsdev] MyMetrics - create a metric but don't initialise a value and set modified

Steve Davies steve at telviva.co.za
Sun Jan 17 22:04:33 HKT 2021


Is there an "official" way to Init my private metrics without setting a
value and having them marked modified?

The problem I am trying to solve is that if I do this, for instance:

  > mt_i3_range_ecoproplus = MyMetrics.InitInt
 ("xi3.v.b.range.ecoproplus",   SM_STALE_HIGH, 0, Kilometers);

Then "0" is officially published as the range.  This is unlikely and messes
up my charts.  I'd rather not publish a value until I get one from the car.

I see that the standard metrics are just created with:

  > ms_v_bat_range_full = new OvmsMetricFloat(MS_V_BAT_RANGE_FULL,
SM_STALE_HIGH, Kilometers);

where V_BAT_RANGE_FULL is "v.b.range.full"

They have no value until they are explicitly set.

So would it be acceptable to rather create my private metrics like that?

I guess then it falls on me to check if the metric already exists - which
is done as part of InitFloat.

So I guess I'd write:

  > mt_i3_range_ecoproplus =
  > if (mt_i3_range_ecoproplus==NULL) mt_i3_range_ecoproplus = new
OvmsMetricInt("xi3.v.b.range.ecoproplus",  SM_STALE_HIGH, Kilometers, 0);

Is this a reasonable approach or am I going about this the wrong way?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20210117/eb088ba1/attachment-0001.htm>

More information about the OvmsDev mailing list