aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/buttons.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-05-26 00:18:48 -0400
committerKevin O'Connor <kevin@koconnor.net>2019-05-26 00:18:48 -0400
commit8cd8cb492e44d1661add19b2c77b699a82f5eb49 (patch)
treeacd40ab6aab34d952a558a82c0eaa42abf4338f1 /klippy/extras/buttons.py
parent9e1d79500aaf8c4002da58cf88d267e6a991cfde (diff)
downloadkutter-8cd8cb492e44d1661add19b2c77b699a82f5eb49.tar.gz
kutter-8cd8cb492e44d1661add19b2c77b699a82f5eb49.tar.xz
kutter-8cd8cb492e44d1661add19b2c77b699a82f5eb49.zip
buttons: Minor code movement
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/buttons.py')
-rw-r--r--klippy/extras/buttons.py80
1 files changed, 43 insertions, 37 deletions
diff --git a/klippy/extras/buttons.py b/klippy/extras/buttons.py
index b06f1f83..dfb552b5 100644
--- a/klippy/extras/buttons.py
+++ b/klippy/extras/buttons.py
@@ -5,48 +5,14 @@
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
-QUERY_TIME = .002
-RETRANSMIT_COUNT = 50
-ADC_REPORT_TIME = 0.015
-ADC_DEBOUNCE_TIME = 0.025
-ADC_SAMPLE_TIME = 0.001
-ADC_SAMPLE_COUNT = 6
-
-# Rotary encoder handler https://github.com/brianlow/Rotary
-# Copyright 2011 Ben Buxton (bb@cactii.net).
-# Licenced under the GNU GPL Version 3.
-R_START = 0x0
-R_CW_FINAL = 0x1
-R_CW_BEGIN = 0x2
-R_CW_NEXT = 0x3
-R_CCW_BEGIN = 0x4
-R_CCW_FINAL = 0x5
-R_CCW_NEXT = 0x6
-R_DIR_CW = 0x10
-R_DIR_CCW = 0x20
-R_DIR_MSK = 0x30
-# Use the full-step state table (emits a code at 00 only)
-ENCODER_STATES = (
- # R_START
- (R_START, R_CW_BEGIN, R_CCW_BEGIN, R_START),
- # R_CW_FINAL
- (R_CW_NEXT, R_START, R_CW_FINAL, R_START | R_DIR_CW),
- # R_CW_BEGIN
- (R_CW_NEXT, R_CW_BEGIN, R_START, R_START),
- # R_CW_NEXT
- (R_CW_NEXT, R_CW_BEGIN, R_CW_FINAL, R_START),
- # R_CCW_BEGIN
- (R_CCW_NEXT, R_START, R_CCW_BEGIN, R_START),
- # R_CCW_FINAL
- (R_CCW_NEXT, R_CCW_FINAL, R_START, R_START | R_DIR_CCW),
- # R_CCW_NEXT
- (R_CCW_NEXT, R_CCW_FINAL, R_CCW_BEGIN, R_START)
-)
######################################################################
# Button state tracking
######################################################################
+QUERY_TIME = .002
+RETRANSMIT_COUNT = 50
+
class MCU_buttons:
def __init__(self, printer, mcu):
self.reactor = printer.get_reactor()
@@ -116,6 +82,15 @@ class MCU_buttons:
self.last_button = button
+######################################################################
+# ADC button tracking
+######################################################################
+
+ADC_REPORT_TIME = 0.015
+ADC_DEBOUNCE_TIME = 0.025
+ADC_SAMPLE_TIME = 0.001
+ADC_SAMPLE_COUNT = 6
+
class MCU_ADC_buttons:
def __init__(self, printer, pin, pullup, debug=False):
self.reactor = printer.get_reactor()
@@ -193,6 +168,37 @@ class MCU_ADC_buttons:
# Rotary Encoders
######################################################################
+# Rotary encoder handler https://github.com/brianlow/Rotary
+# Copyright 2011 Ben Buxton (bb@cactii.net).
+# Licenced under the GNU GPL Version 3.
+R_START = 0x0
+R_CW_FINAL = 0x1
+R_CW_BEGIN = 0x2
+R_CW_NEXT = 0x3
+R_CCW_BEGIN = 0x4
+R_CCW_FINAL = 0x5
+R_CCW_NEXT = 0x6
+R_DIR_CW = 0x10
+R_DIR_CCW = 0x20
+R_DIR_MSK = 0x30
+# Use the full-step state table (emits a code at 00 only)
+ENCODER_STATES = (
+ # R_START
+ (R_START, R_CW_BEGIN, R_CCW_BEGIN, R_START),
+ # R_CW_FINAL
+ (R_CW_NEXT, R_START, R_CW_FINAL, R_START | R_DIR_CW),
+ # R_CW_BEGIN
+ (R_CW_NEXT, R_CW_BEGIN, R_START, R_START),
+ # R_CW_NEXT
+ (R_CW_NEXT, R_CW_BEGIN, R_CW_FINAL, R_START),
+ # R_CCW_BEGIN
+ (R_CCW_NEXT, R_START, R_CCW_BEGIN, R_START),
+ # R_CCW_FINAL
+ (R_CCW_NEXT, R_CCW_FINAL, R_START, R_START | R_DIR_CCW),
+ # R_CCW_NEXT
+ (R_CCW_NEXT, R_CCW_FINAL, R_CCW_BEGIN, R_START)
+)
+
class RotaryEncoder:
def __init__(self, cw_callback, ccw_callback):
self.cw_callback = cw_callback