scheme: add few helper functions
This commit is contained in:
parent
3e1e242301
commit
56fdb75831
|
@ -32,8 +32,15 @@ class Controller():
|
|||
print('Setting target', target)
|
||||
self.target = target
|
||||
|
||||
def set_warning_range(self, target):
|
||||
self.target = target
|
||||
def get_target(self):
|
||||
return self.target
|
||||
|
||||
def set_warning_range(self, range):
|
||||
print('Setting range', range)
|
||||
self.range = range
|
||||
|
||||
def get_warning_range(self):
|
||||
return self.range
|
||||
|
||||
def one_cycle(self, time=None):
|
||||
print("ERROR: This function must be implemented by the controller")
|
||||
|
|
27
phasectrl.py
27
phasectrl.py
|
@ -83,9 +83,11 @@ class State():
|
|||
_('seconds', 1, lambda x: x.car,
|
||||
_('manual-intervention', -1, manual_intervention_wrapper(self),
|
||||
_('set-target', 2, self.set_target,
|
||||
_('set-controller', 2, self.set_controller,
|
||||
_('reload-recipes', 0, lambda x: self.reloadRecipes(),
|
||||
MY_GLOBAL_ENV)))))))))))
|
||||
_('get-sensor-target', 1, self.get_sensor_target,
|
||||
_('get-controller-target', 1, self.get_controller_target,
|
||||
_('set-controller', 2, self.set_controller,
|
||||
_('reload-recipes', 0, lambda x: self.reloadRecipes(),
|
||||
MY_GLOBAL_ENV)))))))))))))
|
||||
self.env = self.baseenv
|
||||
self.envdata = {}
|
||||
self.onupdate = onupdate
|
||||
|
@ -226,11 +228,30 @@ class State():
|
|||
|
||||
def set_target(self, args):
|
||||
sensor, target = (stringify(args.car, quote=False), args.cdr.car)
|
||||
# We get the controller, and set it to target
|
||||
value, controller, _ = self.envdata['sensors'][sensor]
|
||||
self.envdata['sensors'][sensor] = (value, controller, target)
|
||||
self.envdata['controllers'][controller].set_target(target)
|
||||
print('setting sensor', sensor, controller, 'to target', target)
|
||||
|
||||
def get_sensor_target(self, args):
|
||||
sensor = stringify(args.car, quote=False)
|
||||
if sensor not in self.envdata['sensors'].keys():
|
||||
print(f'Sensor {sensor} not found')
|
||||
return None
|
||||
_, controller, target = self.envdata['sensors'][sensor]
|
||||
if controller is None:
|
||||
print('Sensor has no associated controller')
|
||||
return None
|
||||
return target
|
||||
|
||||
def get_controller_target(self, args):
|
||||
controller = stringify(args.car, quote=False)
|
||||
if controller not in self.envdata['controllers'].keys():
|
||||
print(f'Controller {controller} not found')
|
||||
return None
|
||||
return self.envdata['controllers'][controller].get_target()
|
||||
|
||||
def set_controller(self, args):
|
||||
controller, sensor = (stringify(args.car, quote=False),
|
||||
stringify(args.cdr.car, quote=False))
|
||||
|
|
Loading…
Reference in New Issue