@@ -17,19 +17,14 @@ void ShotHistoryPlugin::setup(Controller *c, PluginManager *pm) {
17
17
pm->on (" controller:volumetric-measurement:bluetooth:change" , [this ](Event const &event) {
18
18
const float weight = event.getFloat (" value" );
19
19
const unsigned long now = millis ();
20
- // Explicit check: Only process if weight is a valid number (not NaN or Inf)
21
- if (!isnan (weight) && isfinite (weight)) {
22
- if (lastVolumeSample != 0 ) {
23
- const unsigned long timeDiff = now - lastVolumeSample;
24
- const float volumeDiff = weight - currentBluetoothWeight;
25
- currentBluetoothFlow = volumeDiff / static_cast <float >(timeDiff) * 1000 .0f ;
26
- }
27
- lastVolumeSample = now;
28
- currentBluetoothWeight = weight;
29
- } else {
30
- // If weight data is invalid, ignore this update
31
- // This prevents crashes if BLE data is corrupted or connection is unstable
20
+ if (lastVolumeSample != 0 ) {
21
+ const unsigned long timeDiff = now - lastVolumeSample;
22
+ const float volumeDiff = weight - currentBluetoothWeight;
23
+ const float volumeFlow = volumeDiff / static_cast <float >(timeDiff) * 1000 .0f ;
24
+ currentBluetoothFlow = currentBluetoothFlow * 0 .9f + volumeFlow * 0 .1f ;
32
25
}
26
+ lastVolumeSample = now;
27
+ currentBluetoothWeight = weight;
33
28
});
34
29
pm->on (" boiler:currentTemperature:change" , [this ](Event const &event) { currentTemperature = event.getFloat (" value" ); });
35
30
pm->on (" pump:puck-resistance:change" , [this ](Event const &event) { currentPuckResistance = event.getFloat (" value" ); });
0 commit comments