buttons: No need to check for None on min_value/max_value

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-11-07 18:42:55 -05:00
parent d40f951d6f
commit 196a69c613
1 changed files with 13 additions and 21 deletions

View File

@ -101,23 +101,16 @@ class MCU_ADC_buttons:
self.last_debouncetime = 0
self.pullup = pullup
self.pin = pin
self.min_value = self.max_value = None
self.min_value = 999999999999.9
self.max_value = 0.
ppins = printer.lookup_object('pins')
self.mcu_adc = ppins.setup_pin('adc', self.pin)
self.mcu_adc.setup_minmax(ADC_SAMPLE_TIME, ADC_SAMPLE_COUNT)
self.mcu_adc.setup_adc_callback(ADC_REPORT_TIME, self.adc_callback)
def setup_button(self, min_value, max_value, callback):
if self.min_value is None:
self.min_value = min_value
else:
self.min_value = min(self.min_value, min_value)
if self.max_value is None:
self.max_value = max_value
else:
self.max_value = max(self.max_value, max_value)
self.buttons.append((min_value, max_value, callback))
def adc_callback(self, read_time, read_value):
@ -127,8 +120,7 @@ class MCU_ADC_buttons:
(lambda e, s=self, v=r: s.handle_button(e, v)))
def get_button(self, value):
if (self.min_value is not None and self.max_value is not None
and self.min_value <= value <= self.max_value):
if self.min_value <= value <= self.max_value:
for i, (min_value, max_value, cb) in enumerate(self.buttons):
if min_value < value < max_value:
return i