@@ -204,6 +204,8 @@ class ScaleManager(QObject):
204204
205205 def __init__ (self , connected_handler :Callable [[str , str ], None ], disconnected_handler :Callable [[str , str ], None ]) -> None :
206206 super ().__init__ ()
207+ self ._logging : bool = False
208+
207209 self .connected_handler = connected_handler
208210 self .disconnected_handler = disconnected_handler
209211 self .scale1 : Scale | None = None
@@ -329,6 +331,7 @@ def scan_scale1_slot(self, model:int) -> None:
329331
330332 @pyqtSlot (bool )
331333 def connect_scale1_slot (self , device_logging :bool ) -> None :
334+ self ._logging = device_logging
332335 if self .scale1 is not None :
333336 self .scale1 .connect_scale (device_logging )
334337
@@ -386,7 +389,8 @@ def scale1_disconnected_slot(self) -> None:
386389 # weight in g
387390 @pyqtSlot (float , bool )
388391 def scale1_weight_changed_slot (self , weight :float , stable :bool ) -> None :
389- ## _log.debug("PRINT scale1_weight_changed_slot(%s,%s)",weight,stable)
392+ if self ._logging :
393+ _log .debug ('scale1_weight_changed_slot(%s,%s)' ,weight ,stable )
390394 toa :float = libtime .time ()
391395 prev_last_weight_sent = self .scale1_last_weight_sent
392396 self .scale1_last_weight_sent = int (round (weight ))
@@ -400,14 +404,17 @@ def scale1_weight_changed_slot(self, weight:float, stable:bool) -> None:
400404 self .scale1_stable_reading_timer .stop () # we stop a pending timer not to have it deliver outdated data as stable
401405 # weights marked as stable by the scale are immediately forwarded as stable weights
402406 self .scale1_stable_weight_changed_signal .emit (self .scale1_last_weight_sent )
403- ## _log.debug("PRINT stable1 emit: %s",self.scale1_last_weight_sent)
407+ if self ._logging :
408+ _log .debug ('stable1 emit: %s' ,self .scale1_last_weight_sent )
404409 else :
405- ## _log.debug("PRINT STABLE->UNSTABLE1 %s, %s", stable and (toa - self.scale1_last_stable_weight_received) > MIN_TIME_BETWEEN_STABLE_WEIGHTS, stable and (prev_last_weight_sent is None or abs(self.scale1_last_weight_sent - prev_last_weight_sent) < MIN_DELTA_BETWEEN_STABLE_WEIGHTS))
410+ if self ._logging :
411+ _log .debug ('STABLE->UNSTABLE1 %s, %s' , stable and (toa - self .scale1_last_stable_weight_received ) > MIN_TIME_BETWEEN_STABLE_WEIGHTS , stable and (prev_last_weight_sent is None or abs (self .scale1_last_weight_sent - prev_last_weight_sent ) < MIN_DELTA_BETWEEN_STABLE_WEIGHTS ))
406412 self .scale1_last_weight = self .scale1_last_weight_sent
407413 # fed into our stable weight timer system to ensure that the "last one" is also emitted as stable weight
408414 self .scale1_stable_reading_timer .start (STABLE_TIMER_PERIOD ) # start/restart stable weight timer
409415 # non-stable weights are immediately forwarded as regular weight updates to keep the display fluid
410- ## _log.debug("PRINT unstable1 emit: %s",self.scale1_last_weight_sent)
416+ if self ._logging :
417+ _log .debug ('unstable1 emit: %s' ,self .scale1_last_weight_sent )
411418 self .scale1_weight_changed_signal .emit (self .scale1_last_weight_sent )
412419
413420 def scale1_tare_pressed_slot (self ) -> None :
@@ -416,7 +423,8 @@ def scale1_tare_pressed_slot(self) -> None:
416423 @pyqtSlot ()
417424 def scale1_stable_reading_timer_slot (self ) -> None :
418425 if self .scale1_last_weight is not None :
419- ## _log.debug("PRINT artificial stable1 emit: %s",self.scale1_last_weight)
426+ if self ._logging :
427+ _log .debug ('artificial stable1 emit: %s' ,self .scale1_last_weight )
420428 self .scale1_stable_weight_changed_signal .emit (self .scale1_last_weight )
421429
422430 def get_scale1_last_weight (self ) -> int | None :
@@ -474,6 +482,7 @@ def scan_scale2_slot(self, model:int) -> None:
474482
475483 @pyqtSlot (bool )
476484 def connect_scale2_slot (self , device_logging :bool ) -> None :
485+ self ._logging = device_logging
477486 if self .scale2 is not None :
478487 self .scale2 .connect_scale (device_logging )
479488
@@ -532,7 +541,8 @@ def scale2_disconnected_slot(self) -> None:
532541 # weight in g
533542 @pyqtSlot (float , bool )
534543 def scale2_weight_changed_slot (self , weight :float , stable :bool ) -> None :
535- ## _log.debug("PRINT scale2_weight_changed_slot(%s,%s)",weight,stable)
544+ if self ._logging :
545+ _log .debug ('scale2_weight_changed_slot(%s,%s)' ,weight ,stable )
536546 toa :float = libtime .time ()
537547 prev_last_weight_sent = self .scale2_last_weight_sent
538548 self .scale2_last_weight_sent = int (round (weight ))
@@ -546,14 +556,17 @@ def scale2_weight_changed_slot(self, weight:float, stable:bool) -> None:
546556 self .scale2_stable_reading_timer .stop () # we stop a pending timer not to have it deliver outdated data as stable
547557 # weights marked as stable by the scale are immediately forwarded as stable weights
548558 self .scale2_stable_weight_changed_signal .emit (self .scale2_last_weight_sent )
549- ## _log.debug("PRINT stable2 emit: %s",self.scale2_last_weight_sent)
559+ if self ._logging :
560+ _log .debug ('PRINT stable2 emit: %s' ,self .scale2_last_weight_sent )
550561 else :
551- ## _log.debug("PRINT STABLE->UNSTABLE2 %s, %s", stable and (toa - self.scale2_last_stable_weight_received) > MIN_TIME_BETWEEN_STABLE_WEIGHTS, stable and (prev_last_weight_sent is None or abs(self.scale2_last_weight_sent - prev_last_weight_sent) < MIN_DELTA_BETWEEN_STABLE_WEIGHTS))
562+ if self ._logging :
563+ _log .debug ('STABLE->UNSTABLE2 %s, %s' , stable and (toa - self .scale2_last_stable_weight_received ) > MIN_TIME_BETWEEN_STABLE_WEIGHTS , stable and (prev_last_weight_sent is None or abs (self .scale2_last_weight_sent - prev_last_weight_sent ) < MIN_DELTA_BETWEEN_STABLE_WEIGHTS ))
552564 self .scale2_last_weight = self .scale2_last_weight_sent
553565 # fed into our stable weight timer system to ensure that the "last one" is also emitted as stable weight
554566 self .scale2_stable_reading_timer .start (STABLE_TIMER_PERIOD ) # start/restart stable weight timer
555567 # non-stable weights are immediately forwarded as regular weight updates to keep the display fluid
556- ## _log.debug("PRINT unstable2 emit: %s",self.scale2_last_weight_sent)
568+ if self ._logging :
569+ _log .debug ('unstable2 emit: %s' ,self .scale2_last_weight_sent )
557570 self .scale2_weight_changed_signal .emit (self .scale2_last_weight_sent )
558571
559572 def scale2_tare_pressed_slot (self ) -> None :
@@ -562,7 +575,8 @@ def scale2_tare_pressed_slot(self) -> None:
562575 @pyqtSlot ()
563576 def scale2_stable_reading_timer_slot (self ) -> None :
564577 if self .scale2_last_weight is not None :
565- ## _log.debug("PRINT artificial stable2 emit: %s",self.scale2_last_weight)
578+ if self ._logging :
579+ _log .debug ('artificial stable2 emit: %s' ,self .scale2_last_weight )
566580 self .scale2_stable_weight_changed_signal .emit (self .scale2_last_weight )
567581
568582 def get_scale2_last_weight (self ) -> int | None :
0 commit comments