From bb015818eaf8660bac6bff0cd259b916992a5496 Mon Sep 17 00:00:00 2001 From: Gert Pellin Date: Mon, 1 Oct 2018 14:17:59 +0200 Subject: [PATCH] [imp] hw_scale: Disable Adam if not used Adam scales give a beep if it has no changed value to send. This commit disable the beeping outside the weight screen --- addons/hw_scale/controllers/main.py | 42 ++++++++++++++++++----------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/addons/hw_scale/controllers/main.py b/addons/hw_scale/controllers/main.py index d0425446f83..58cf03ae7a6 100644 --- a/addons/hw_scale/controllers/main.py +++ b/addons/hw_scale/controllers/main.py @@ -81,6 +81,7 @@ Toledo8217Protocol = ScaleProtocol( clearCommand=b'C', emptyAnswerValid=False, autoResetWeight=False, + disable=False ) # The ADAM scales have their own RS232 protocol, usually documented in the scale's manual @@ -110,6 +111,7 @@ ADAMEquipmentProtocol = ScaleProtocol( clearCommand=None, # No clear command -> Tare again emptyAnswerValid=True, # AZExtra does not answer unless a new non-zero weight has been detected autoResetWeight=True, # AZExtra will not return 0 after removing products + disable=True ) @@ -131,6 +133,7 @@ class Scale(Thread): self.device = None self.path_to_scale = '' self.protocol = None + self.disabled = False def lockedstart(self): with self.lock: @@ -258,6 +261,8 @@ class Scale(Thread): return None def get_weight(self): + self.repeats = 5 + self.disabled = False self.lockedstart() return self.weight @@ -338,23 +343,30 @@ class Scale(Thread): self.device = None while True: - if self.device: - old_weight = self.weight - self.read_weight() - if self.weight != old_weight: - _logger.info('New Weight: %s, sleeping %ss', self.weight, self.protocol.newWeightDelay) - time.sleep(self.protocol.newWeightDelay) - if self.weight and self.protocol.autoResetWeight: - self.weight = 0 + if not self.disabled: + if self.device: + old_weight = self.weight + self.read_weight() + if self.weight != old_weight: + _logger.info('New Weight: %s, sleeping %ss', self.weight, self.protocol.newWeightDelay) + time.sleep(self.protocol.newWeightDelay) + if self.weight and self.protocol.autoResetWeight: + self.weight = 0 + else: + _logger.info('Weight: %s, sleeping %ss', self.weight, self.protocol.weightDelay) + time.sleep(self.protocol.weightDelay) + self.disabled = True else: - _logger.info('Weight: %s, sleeping %ss', self.weight, self.protocol.weightDelay) - time.sleep(self.protocol.weightDelay) + with self.scalelock: + self.device = self.get_device() + if not self.device: + # retry later to support "plug and play" + time.sleep(10) + else: + self.disabled = self.protocol.disable else: - with self.scalelock: - self.device = self.get_device() - if not self.device: - # retry later to support "plug and play" - time.sleep(10) + time.sleep(10) + scale_thread = None if serial: