예제 #1
0
파일: xcf.py 프로젝트: ubi-agni/pyhsm
def _xcf_subscribe(state, memory, xpath, handler, actions=xcf.INSERT | xcf.REPLACE):
    # once, define _xcf_events and register enter/exit handlers to actually subscribe/unsubscribe events
    if not hasattr(state, '_xcf_events'):
        # define _xcf_events attribute
        state._xcf_events = []
        # on enter, subscribe to topics
        state.add_handler('enter', lambda event: _subscribe_xcf_events(state, event))
        # on exit, unsubscribe
        state.add_handler('exit', lambda event: _unsubscribe_xcf_events(state, event))

    # a string "handler" is interpreted as an event to be triggered
    if isinstance(handler, string_types):
        name = handler  # need to use another name!
        handler = lambda data: state.root.dispatch(Event(name, msg=data))

    # actually register the event
    state._xcf_events.append(_XCFEvent(memory, xpath, actions, handler))
예제 #2
0
파일: ros.py 프로젝트: ubi-agni/pyhsm
def _ros_subscribe(state, topic, msg_type, handler):
    # once, define _ros_events and register enter/exit handlers to actually subscribe/unsubscribe events
    if not hasattr(state, '_ros_events'):
        # define _ros_events attribute
        state._ros_events = []
        # on enter, subscribe to topics
        state.add_handler('enter',
                          lambda event: _subscribe_ros_events(state, event))
        # on exit, unsubscribe
        state.add_handler('exit',
                          lambda event: _unsubscribe_ros_events(state, event))

    # a string "handler" is interpreted as an event to be triggered
    if isinstance(handler, string_types):
        name = handler  # need to use another name!
        handler = lambda data: state.root.dispatch(Event(name, msg=data))

    # actually register the event
    state._ros_events.append(_ROSEvent(topic, msg_type, handler))
예제 #3
0
파일: oven.py 프로젝트: fpatzelt/hsm
 def on_timeout(self):
     print('Timeout...')
     self.sm.dispatch(Event('timeout', oven=self))
     self.timer = threading.Timer(Oven.TIMEOUT, self.on_timeout)
예제 #4
0
파일: oven.py 프로젝트: fpatzelt/hsm
 def close_door(self):
     self.sm.dispatch(Event('close', oven=self))
예제 #5
0
파일: oven.py 프로젝트: fpatzelt/hsm
 def open_door(self):
     self.sm.dispatch(Event('open', oven=self))
예제 #6
0
파일: oven.py 프로젝트: fpatzelt/hsm
 def toast(self):
     self.sm.dispatch(Event('toast', oven=self))
예제 #7
0
파일: oven.py 프로젝트: fpatzelt/hsm
 def bake(self):
     self.sm.dispatch(Event('bake', oven=self))