MyMetrics - create a metric but don't initialise a value and set modified
Hi, 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 = (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?
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
participants (2)
-
Michael Balzer -
Steve Davies