@@ -15,20 +15,22 @@ void ShotHistoryPlugin::setup(Controller *c, PluginManager *pm) {
15
15
pm->on (" controller:volumetric-measurement:estimation:change" ,
16
16
[this ](Event const &event) { currentEstimatedWeight = event.getFloat (" value" ); });
17
17
pm->on (" controller:volumetric-measurement:bluetooth:change" , [this ](Event const &event) {
18
- try {
19
- const float weight = event.getFloat (" value" );
20
- const unsigned long now = millis ();
21
- if (lastVolumeSample != 0 ) {
22
- const unsigned long timeDiff = now - lastVolumeSample;
23
- const float volumeDiff = weight - currentBluetoothWeight;
24
- currentBluetoothFlow = volumeDiff / static_cast < float >(timeDiff) * 1000 . 0f ;
25
- }
26
- lastVolumeSample = now ;
27
- currentBluetoothWeight = weight;
28
- } catch (...) {
29
- // If there's any exception processing weight data, ignore this update
30
- // This prevents crashes if BLE data is corrupted or connection is unstable
18
+ // Explicit checks instead of try/catch for embedded systems
19
+ const float weight = event.getFloat (" value" );
20
+
21
+ // Validate weight data before processing
22
+ if ( isnan (weight) || weight < 0 ) {
23
+ return ; // Skip invalid weight data
24
+ }
25
+
26
+ const unsigned long now = millis () ;
27
+ if (lastVolumeSample != 0 ) {
28
+ const unsigned long timeDiff = now - lastVolumeSample;
29
+ const float volumeDiff = weight - currentBluetoothWeight;
30
+ currentBluetoothFlow = volumeDiff / static_cast < float >(timeDiff) * 1000 . 0f ;
31
31
}
32
+ lastVolumeSample = now;
33
+ currentBluetoothWeight = weight;
32
34
});
33
35
pm->on (" boiler:currentTemperature:change" , [this ](Event const &event) { currentTemperature = event.getFloat (" value" ); });
34
36
xTaskCreatePinnedToCore (loopTask, " ShotHistoryPlugin::loop" , configMINIMAL_STACK_SIZE * 3 , this , 1 , &taskHandle, 0 );
@@ -71,14 +73,10 @@ void ShotHistoryPlugin::record() {
71
73
if (extendedRecording) {
72
74
const unsigned long now = millis ();
73
75
74
- // Add safety check to prevent crashes if BLE connection is unstable
75
- bool canProcessWeight = true ;
76
- try {
77
- if (!controller || !controller->isVolumetricAvailable ()) {
78
- canProcessWeight = false ;
79
- }
80
- } catch (...) {
81
- canProcessWeight = false ;
76
+ // Explicit safety checks instead of try/catch for embedded systems
77
+ bool canProcessWeight = (controller != nullptr );
78
+ if (canProcessWeight) {
79
+ canProcessWeight = controller->isVolumetricAvailable ();
82
80
}
83
81
84
82
if (!canProcessWeight) {
@@ -152,17 +150,14 @@ void ShotHistoryPlugin::endRecording() {
152
150
recording = false ;
153
151
154
152
// Check if we have active bluetooth weight data (regardless of volumetric mode)
155
- // Add safety check to ensure we have a valid controller and BLE connection
156
153
bool hasActiveWeightData = false ;
157
- try {
158
- hasActiveWeightData = controller &&
159
- controller->isVolumetricAvailable () &&
160
- currentBluetoothWeight > 0 ;
161
- } catch (...) {
162
- // If there's any exception checking BLE status, assume no weight data
163
- hasActiveWeightData = false ;
164
- }
165
154
155
+ if (controller != nullptr ) {
156
+ if (controller->isVolumetricAvailable () && currentBluetoothWeight > 0 ) {
157
+ hasActiveWeightData = true ;
158
+ }
159
+ }
160
+
166
161
if (hasActiveWeightData) {
167
162
// Start extended recording for any shot with active weight data
168
163
extendedRecording = true ;
0 commit comments