本文整理汇总了Python中sensor.Sensor.get_button_states方法的典型用法代码示例。如果您正苦于以下问题:Python Sensor.get_button_states方法的具体用法?Python Sensor.get_button_states怎么用?Python Sensor.get_button_states使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sensor.Sensor
的用法示例。
在下文中一共展示了Sensor.get_button_states方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: int
# 需要导入模块: from sensor import Sensor [as 别名]
# 或者: from sensor.Sensor import get_button_states [as 别名]
#!/usr/bin/python3
"""run.py
Usage:
run.py [--mock]
"""
import socket
import os
import docopt
from sensor import Sensor
args = docopt.docopt(__doc__)
port = int(os.getenv("RGBLAMP_BUTTON_PORT"))
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_socket.bind(('', port))
server_socket.listen(5)
sensor = Sensor(args["--mock"])
while True:
(client_socket, address) = server_socket.accept()
button_states = sensor.get_button_states()
states = map(lambda s: "1" if s else "0", button_states)
states = "".join(states).encode("utf-8")
client_socket.send(bytes(states))