当前位置: 首页>>代码示例>>Python>>正文


Python Fysom.arm方法代码示例

本文整理汇总了Python中fysom.Fysom.arm方法的典型用法代码示例。如果您正苦于以下问题:Python Fysom.arm方法的具体用法?Python Fysom.arm怎么用?Python Fysom.arm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fysom.Fysom的用法示例。


在下文中一共展示了Fysom.arm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MainThread

# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import arm [as 别名]
class MainThread(threading.Thread):

    def __init__(self, group=None, target=None, name=None, args=(), kwargs=None, verbose=None):
        super(MainThread, self).__init__(group, target, name, args, kwargs, verbose)
        # load settings file
        self.cfg = get_settings()
        # this is used to stop the arming thread
        self.pill2kill = None
        # keep a buzzer object to stop it from every function. same for the receiver433
        self.buzzer = None

        # prepare a queue to share data between this threads and other thread
        self.shared_queue_keyborad = Queue.Queue()
        self.shared_queue_rfid_reader = Queue.Queue()
        self.shared_queue_433_receiver = Queue.Queue()
        self.shared_queue_message_from_api = Queue.Queue()

        # create an object to manage the screen
        try:
            self.screen_manager = AdafruitScreenManager()
        except IOError:
            raise Exception("No connection with the screen")

        # create an object to manage the arduino
        self.arduino = ArduinoManager()
        try:
            self.arduino.ping()
        except IOError:
            self.screen_manager.set_arduino_connection_missing()
            sys.exit(0)

        # run the keypad thread
        self.keypad_thread = MatrixKeypadManager(self.shared_queue_keyborad)
        self.keypad_thread.start()

        # run the thread that handle RFID
        rfid = RFIDrc522Manager(self.shared_queue_rfid_reader)
        rfid.start()

        # keep 433 receiver thread object in mind
        self.receiver443 = None

        # create the flask rest api
        app = Flask(__name__)
        flask_api = FlaskAPI(app, self.shared_queue_message_from_api, self)
        flask_api.start()

        # Save a buffer where we put each typed number
        self.code_buffer = ""
        self.last_state = "disabled"

        # create the state machine
        self.fsm = Fysom({'initial': self._get_initial_state(),
                          'events': [
                              {'name': 'arm', 'src': 'disabled', 'dst': 'arming'},
                              {'name': 'enable', 'src': 'arming', 'dst': 'enabled'},
                              {'name': 'intrusion', 'src': 'enabled', 'dst': 'waiting_code'},
                              {'name': 'alarm', 'src': 'waiting_code', 'dst': 'alarming'},
                              {'name': 'disable', 'src': ['arming', 'enabled', 'waiting_code', 'alarming'],
                               'dst': 'disabled'}],
                          'callbacks': {
                              'ondisabled': self.ondisabled,
                              'onarming': self.onarming,
                              'onenabled': self.onenabled,
                              'onwaiting_code': self.onwaiting_code,
                              'onalarming': self.onalarming}
                          })

    def run(self):
        print "Run main thread"
        while True:
            if not self.shared_queue_keyborad.empty():
                val = self.shared_queue_keyborad.get()
                print "Key received from keypad: ", val
                if val == "D":
                    self.screen_manager.switch_light()
                elif val == "C":
                    # cancel only if we were in arming status
                    if self.fsm.current == "arming":
                        self.fsm.disable()

                else:
                    # we add a star to the screen
                    self.screen_manager.add_star()
                    # add the value to the buffer
                    self.code_buffer += str(val)
                    # if we have 4 number we can test the code
                    if len(self.code_buffer) == 4:
                        self._test_pin_code()
                        self.code_buffer = ""
            if not self.shared_queue_rfid_reader.empty():
                val = self.shared_queue_rfid_reader.get()
                print "Received UID from RFID ", val
                self._test_rfid_uid(val)
            if not self.shared_queue_433_receiver.empty():
                val = self.shared_queue_433_receiver.get()
                print "Received UID from 433 receiver ", val
                self._test_433_uid(val)

            time.sleep(0.1)
#.........这里部分代码省略.........
开发者ID:Sispheor,项目名称:alarmpi,代码行数:103,代码来源:MainThread.py


注:本文中的fysom.Fysom.arm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。