menu: new fast step rate feature
Signed-off-by: Janar Sööt <janar.soot@gmail.com>
This commit is contained in:
parent
1379a59085
commit
5144c5f01e
|
@ -116,6 +116,11 @@
|
||||||
# This is mandatory attribute for input.
|
# This is mandatory attribute for input.
|
||||||
# It accepts positive integer or float value. Will determine increment
|
# It accepts positive integer or float value. Will determine increment
|
||||||
# and decrement steps for edit value.
|
# and decrement steps for edit value.
|
||||||
|
#input_step2:
|
||||||
|
# This is optional attribute for input.
|
||||||
|
# It accepts positive integer or float value. Will determine fast rate
|
||||||
|
# increment and decrement steps for edit value.
|
||||||
|
# The default is 0 (input_step will be used instead)
|
||||||
|
|
||||||
#[menu list1]
|
#[menu list1]
|
||||||
#type:list or vsdcard
|
#type:list or vsdcard
|
||||||
|
|
|
@ -379,6 +379,7 @@ parameter: extruder0.target
|
||||||
input_min: 0
|
input_min: 0
|
||||||
input_max: 250
|
input_max: 250
|
||||||
input_step: 1
|
input_step: 1
|
||||||
|
input_step2: 10
|
||||||
gcode: M104 T0 S{0:.0f}
|
gcode: M104 T0 S{0:.0f}
|
||||||
|
|
||||||
[menu __temp __hotend1_current]
|
[menu __temp __hotend1_current]
|
||||||
|
@ -395,6 +396,7 @@ parameter: extruder1.target
|
||||||
input_min: 0
|
input_min: 0
|
||||||
input_max: 250
|
input_max: 250
|
||||||
input_step: 1
|
input_step: 1
|
||||||
|
input_step2: 10
|
||||||
gcode: M104 T1 S{0:.0f}
|
gcode: M104 T1 S{0:.0f}
|
||||||
|
|
||||||
[menu __temp __hotbed_current]
|
[menu __temp __hotbed_current]
|
||||||
|
@ -411,6 +413,7 @@ parameter: heater_bed.target
|
||||||
input_min: 0
|
input_min: 0
|
||||||
input_max: 130
|
input_max: 130
|
||||||
input_step: 1
|
input_step: 1
|
||||||
|
input_step2: 10
|
||||||
gcode: M140 S{0:.0f}
|
gcode: M140 S{0:.0f}
|
||||||
|
|
||||||
[menu __temp __preheat_pla]
|
[menu __temp __preheat_pla]
|
||||||
|
|
|
@ -495,6 +495,7 @@ class MenuInput(MenuCommand):
|
||||||
self._input_min = config.getfloat('input_min', sys.float_info.min)
|
self._input_min = config.getfloat('input_min', sys.float_info.min)
|
||||||
self._input_max = config.getfloat('input_max', sys.float_info.max)
|
self._input_max = config.getfloat('input_max', sys.float_info.max)
|
||||||
self._input_step = config.getfloat('input_step', above=0.)
|
self._input_step = config.getfloat('input_step', above=0.)
|
||||||
|
self._input_step2 = config.getfloat('input_step2', 0, minval=0.)
|
||||||
|
|
||||||
def is_scrollable(self):
|
def is_scrollable(self):
|
||||||
return False
|
return False
|
||||||
|
@ -529,30 +530,34 @@ class MenuInput(MenuCommand):
|
||||||
def reset_value(self):
|
def reset_value(self):
|
||||||
self._input_value = None
|
self._input_value = None
|
||||||
|
|
||||||
def inc_value(self):
|
def inc_value(self, fast_rate=False):
|
||||||
last_value = self._input_value
|
last_value = self._input_value
|
||||||
|
input_step = (self._input_step2 if fast_rate and self._input_step2 > 0
|
||||||
|
else self._input_step)
|
||||||
if self._input_value is None:
|
if self._input_value is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
if(self._reverse is True):
|
if(self._reverse is True):
|
||||||
self._input_value -= abs(self._input_step)
|
self._input_value -= abs(input_step)
|
||||||
else:
|
else:
|
||||||
self._input_value += abs(self._input_step)
|
self._input_value += abs(input_step)
|
||||||
self._input_value = min(self._input_max, max(
|
self._input_value = min(self._input_max, max(
|
||||||
self._input_min, self._input_value))
|
self._input_min, self._input_value))
|
||||||
|
|
||||||
if self._realtime and last_value != self._input_value:
|
if self._realtime and last_value != self._input_value:
|
||||||
self._onchange()
|
self._onchange()
|
||||||
|
|
||||||
def dec_value(self):
|
def dec_value(self, fast_rate=False):
|
||||||
last_value = self._input_value
|
last_value = self._input_value
|
||||||
|
input_step = (self._input_step2 if fast_rate and self._input_step2 > 0
|
||||||
|
else self._input_step)
|
||||||
if self._input_value is None:
|
if self._input_value is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
if(self._reverse is True):
|
if(self._reverse is True):
|
||||||
self._input_value += abs(self._input_step)
|
self._input_value += abs(input_step)
|
||||||
else:
|
else:
|
||||||
self._input_value -= abs(self._input_step)
|
self._input_value -= abs(input_step)
|
||||||
self._input_value = min(self._input_max, max(
|
self._input_value = min(self._input_max, max(
|
||||||
self._input_min, self._input_value))
|
self._input_min, self._input_value))
|
||||||
|
|
||||||
|
@ -607,14 +612,14 @@ class MenuGroup(MenuContainer):
|
||||||
s += self._render_item(item, (i == self.selected), True)
|
s += self._render_item(item, (i == self.selected), True)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def _call_selected(self, method=None):
|
def _call_selected(self, method=None, *args):
|
||||||
res = None
|
res = None
|
||||||
if self.selected is not None:
|
if self.selected is not None:
|
||||||
try:
|
try:
|
||||||
if method is None:
|
if method is None:
|
||||||
res = self[self.selected]
|
res = self[self.selected]
|
||||||
else:
|
else:
|
||||||
res = getattr(self[self.selected], method)()
|
res = getattr(self[self.selected], method)(*args)
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.exception("Call selected error")
|
logging.exception("Call selected error")
|
||||||
return res
|
return res
|
||||||
|
@ -622,11 +627,11 @@ class MenuGroup(MenuContainer):
|
||||||
def is_editing(self):
|
def is_editing(self):
|
||||||
return self._call_selected('is_editing')
|
return self._call_selected('is_editing')
|
||||||
|
|
||||||
def inc_value(self):
|
def inc_value(self, fast_rate=False):
|
||||||
self._call_selected('inc_value')
|
self._call_selected('inc_value', fast_rate)
|
||||||
|
|
||||||
def dec_value(self):
|
def dec_value(self, fast_rate=False):
|
||||||
self._call_selected('dec_value')
|
self._call_selected('dec_value', fast_rate)
|
||||||
|
|
||||||
def selected_item(self):
|
def selected_item(self):
|
||||||
return self._call_selected()
|
return self._call_selected()
|
||||||
|
@ -918,7 +923,11 @@ class MenuManager:
|
||||||
self.up_pin = config.get('up_pin', None)
|
self.up_pin = config.get('up_pin', None)
|
||||||
self.down_pin = config.get('down_pin', None)
|
self.down_pin = config.get('down_pin', None)
|
||||||
self.kill_pin = config.get('kill_pin', None)
|
self.kill_pin = config.get('kill_pin', None)
|
||||||
self._last_click_press = 0
|
self._last_press = 0
|
||||||
|
self._encoder_fast_rate = config.getfloat(
|
||||||
|
'encoder_fast_rate', .03, above=0.)
|
||||||
|
self._last_encoder_cw_eventtime = 0
|
||||||
|
self._last_encoder_ccw_eventtime = 0
|
||||||
# printer objects
|
# printer objects
|
||||||
self.buttons = self.printer.try_load_module(config, "buttons")
|
self.buttons = self.printer.try_load_module(config, "buttons")
|
||||||
# register itself for a printer_state callback
|
# register itself for a printer_state callback
|
||||||
|
@ -1215,14 +1224,14 @@ class MenuManager:
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def up(self):
|
def up(self, fast_rate=False):
|
||||||
container = self.stack_peek()
|
container = self.stack_peek()
|
||||||
if self.running and isinstance(container, MenuContainer):
|
if self.running and isinstance(container, MenuContainer):
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
current = container[self.selected]
|
current = container[self.selected]
|
||||||
if (isinstance(current, (MenuInput, MenuGroup))
|
if (isinstance(current, (MenuInput, MenuGroup))
|
||||||
and current.is_editing()):
|
and current.is_editing()):
|
||||||
current.dec_value()
|
current.dec_value(fast_rate)
|
||||||
elif (isinstance(current, MenuGroup)
|
elif (isinstance(current, MenuGroup)
|
||||||
and current.find_prev_item() is not None):
|
and current.find_prev_item() is not None):
|
||||||
pass
|
pass
|
||||||
|
@ -1241,14 +1250,14 @@ class MenuManager:
|
||||||
if isinstance(container[self.selected], MenuGroup):
|
if isinstance(container[self.selected], MenuGroup):
|
||||||
container[self.selected].find_prev_item()
|
container[self.selected].find_prev_item()
|
||||||
|
|
||||||
def down(self):
|
def down(self, fast_rate=False):
|
||||||
container = self.stack_peek()
|
container = self.stack_peek()
|
||||||
if self.running and isinstance(container, MenuContainer):
|
if self.running and isinstance(container, MenuContainer):
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
current = container[self.selected]
|
current = container[self.selected]
|
||||||
if (isinstance(current, (MenuInput, MenuGroup))
|
if (isinstance(current, (MenuInput, MenuGroup))
|
||||||
and current.is_editing()):
|
and current.is_editing()):
|
||||||
current.inc_value()
|
current.inc_value(fast_rate)
|
||||||
elif (isinstance(current, MenuGroup)
|
elif (isinstance(current, MenuGroup)
|
||||||
and current.find_next_item() is not None):
|
and current.find_next_item() is not None):
|
||||||
pass
|
pass
|
||||||
|
@ -1347,6 +1356,7 @@ class MenuManager:
|
||||||
reactor = self.printer.get_reactor()
|
reactor = self.printer.get_reactor()
|
||||||
reactor.register_callback(self.dispatch_gcode)
|
reactor.register_callback(self.dispatch_gcode)
|
||||||
self.gcode_queue.append(script)
|
self.gcode_queue.append(script)
|
||||||
|
|
||||||
def dispatch_gcode(self, eventtime):
|
def dispatch_gcode(self, eventtime):
|
||||||
while self.gcode_queue:
|
while self.gcode_queue:
|
||||||
script = self.gcode_queue[0]
|
script = self.gcode_queue[0]
|
||||||
|
@ -1396,10 +1406,16 @@ class MenuManager:
|
||||||
|
|
||||||
# buttons & encoder callbacks
|
# buttons & encoder callbacks
|
||||||
def encoder_cw_callback(self, eventtime):
|
def encoder_cw_callback(self, eventtime):
|
||||||
self.up()
|
fast_rate = ((eventtime - self._last_encoder_cw_eventtime)
|
||||||
|
<= self._encoder_fast_rate)
|
||||||
|
self._last_encoder_cw_eventtime = eventtime
|
||||||
|
self.up(fast_rate)
|
||||||
|
|
||||||
def encoder_ccw_callback(self, eventtime):
|
def encoder_ccw_callback(self, eventtime):
|
||||||
self.down()
|
fast_rate = ((eventtime - self._last_encoder_ccw_eventtime)
|
||||||
|
<= self._encoder_fast_rate)
|
||||||
|
self._last_encoder_ccw_eventtime = eventtime
|
||||||
|
self.down(fast_rate)
|
||||||
|
|
||||||
def click_callback(self, eventtime, state):
|
def click_callback(self, eventtime, state):
|
||||||
if self.click_pin:
|
if self.click_pin:
|
||||||
|
|
Loading…
Reference in New Issue