[Ovmsdev] MyMetrics - create a metric but don't initialise a value and set modified
Michael Balzer
dexter at expeedo.de
Sun Jan 17 22:34:27 HKT 2021
Steve,
Am 17.01.21 um 15:04 schrieb Steve Davies:
> Is there an "official" way to Init my private metrics without setting
> a value and having them marked modified?
>
> …
>
> So I guess I'd write:
>
> > mt_i3_range_ecoproplus =
> (OvmsMetricInt*)MyMetrics.Find("xi3.v.b.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?
That's perfectly OK.
The Init…() calls are convenience wrappers.
If you always deregister all your custom metrics in your destructor, you
can skip the Find().
Regards,
Michael
--
Michael Balzer * Helkenberger Weg 9 * D-58256 Ennepetal
Fon 02333 / 833 5735 * Handy 0176 / 206 989 26
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 203 bytes
Desc: OpenPGP digital signature
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20210117/68788ed1/attachment.sig>
More information about the OvmsDev
mailing list