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


Python Arduino.change_relay_state方法代码示例

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


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

示例1: WebsocketHandler

# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import change_relay_state [as 别名]
class WebsocketHandler(websocket.WebSocketHandler):
    def initialize(self, uni):
        """docstring for __init__"""
        self.arduino = Arduino()
        self.arduino.start()
        self.client = MongoClient('localhost', 27017)
        self.uni = uni
        self.mongo_gestures = self.client.affordance.gestures
        self.mongo_envelopes = self.client.affordance.envelopes
        self.mongo_users = self.client.affordance.users
        self.mongo_tracking = self.client.affordance.tracking
        self.mongo_studies = self.client.affordance.studies
        self.list_obj = []
        self.current_study_participant = None
        self.data_fetcher = DataFetcher(self.client.affordance)
        self.zap_speed = 1500
        self.zap_strength = {"ems1": self.arduino.channels['ems1']['min_max'][0], "ems2": self.arduino.channels['ems2']['min_max'][0]}
        self.zap_gestures = {"squeeze": False, "shake": False, "repel": False, "tap": False, "rotate": False, "ems1": False, "ems2": False, "ems3": False, "ems4": False}
        #self.data_fetcher = DataFetcher(self.mongo_tracking, False) # Recorded data!
        self.hand = Hand(self.data_fetcher, self.client.affordance, self.arduino)

        self.uni.hand = self.hand
        #screw_driver = AffordanceObjects(self.data_fetcher, self.uni, self.arduino, ["screwdriver_trackable"], "screwdriver", "Screwdriver")
        #screw_brick = AffordanceObjects(self.data_fetcher, self.uni, self.arduino, ["screw_brick_trackable"], "screw_brick", "Screw brick")
        #teapot = AffordanceObjects(self.data_fetcher, self.uni, self.arduino, ["teapot_trackable"], "teapot", "Teapot")
        #spray_can = AffordanceObjects(self.data_fetcher, self.uni, self.arduino, ["spray_can_trackable"], "spray_can", "Spray Can")
        #lamp = AffordanceObjects(self.data_fetcher, self.uni, self.arduino, ["hot_cup_trackable"], "hot_cup", "hot_cup")
        #paint_brush = AffordanceObjects(self.data_fetcher, self.uni, self.arduino, ["paint_trackable"], "paint_brush", "Paint brush")
        self.hand.start()
        self.data_fetcher.register_trackers()


    #def ar_callback(self, data):
    #  self.write_message("channel_data" + ";".join(map(lambda x: x[:-1][1:], data.split("#")))[1:])

    def collider_cb(self, list_obj):
        """Callback that sends the list of colliders to the web interface"""
        self.list_obj = list_obj
        self.write_message("colliders_init,True")

    def open(self):
        print("WebSocket opened")
        self.write_message("init," + json.dumps(self.arduino.channels).replace(",", "§") + "," + bson.json_util.dumps(self.mongo_users.find({})).replace(",", "§"))
        self.uni.ask_for_colliders(self.collider_cb)


    def on_message(self, msg):
        message = msg.split(",")
        if message[0] == "run":
            if message[1] == "true":
                self.arduino.stop = False
                self.data_fetcher.stop = False
                self.arduino.open_all_channels()
                print("run")
            else:
                self.data_fetcher.stop = True
                self.arduino.stop = True
                self.arduino.close_all_channels()
                print("stop")
        elif message[0] == "teapot":
            if message[1] == "1":
                self.hand.current_state = "none"
            elif message[1] == "2":
                self.hand.current_state = "hot"
        elif message[0] == "muscle_control":
            if message[2] == "true":
                if message[1] == "ems1":
                    self.arduino.send_ems_strength({"ems1": self.zap_strength["ems1"]})
                    self.arduino.change_relay_state("ems1", True)
                elif message[1] == "ems2":
                    self.arduino.send_ems_strength({"ems2": self.zap_strength["ems2"]})
                    self.arduino.change_relay_state("ems2", True)
                elif message[1] == "ems3":
                    self.arduino.send_ems_strength({"ems3": self.zap_strength["ems1"]})
                    self.arduino.change_relay_state("ems3", True)
                elif message[1] == "ems4":
                    self.arduino.send_value("h")
                elif message[1] == "0":
                    if self.zap_strength["ems1"] > 4:
                        self.zap_strength["ems1"] -= 5
                    self.write_message("ems_strength,ems1," + str(self.zap_strength["ems1"]))
                elif message[1] == "-":
                    self.zap_strength["ems1"] = 0
                    self.write_message("ems_strength,ems1," + str(self.zap_strength["ems1"]))
                elif message[1] == "+":
                    if self.zap_strength["ems1"] < 96:
                        self.zap_strength["ems1"] += 5
                    self.write_message("ems_strength,ems1," + str(self.zap_strength["ems1"]))
                elif message[1] == "p":
                    if self.zap_strength["ems2"] > 4:
                        self.zap_strength["ems2"] -= 5
                    self.write_message("ems_strength,ems2," + str(self.zap_strength["ems2"]))
                elif message[1] == "[":
                    self.zap_strength["ems2"] = 0
                    self.write_message("ems_strength,ems2," + str(self.zap_strength["ems2"]))
                elif message[1] == "]":
                    if self.zap_strength["ems2"] < 96:
                        self.zap_strength["ems2"] += 5
                    self.write_message("ems_strength,ems2," + str(self.zap_strength["ems2"]))
            else:
#.........这里部分代码省略.........
开发者ID:PedroLopes,项目名称:affordance,代码行数:103,代码来源:websocket_handler.py


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