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


Python Arduino.perform_gesture方法代码示例

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


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

示例1: WebsocketHandler

# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import perform_gesture [as 别名]

#.........这里部分代码省略.........
                self.hand.door_mode = "enter"
            elif message[1] == "k":
                self.hand.door_mode = "knock"

        elif message[0] == "load_user":
            self.hand.user = message[2]
            gestures = list(self.mongo_gestures.find({"user_id": ObjectId(message[2])}, {"name": True}))
            if not message[1] == message[2]:
                user_gestures = list(self.mongo_gestures.find({"user_id": ObjectId(message[1])}, {"name": True}))
                new_gestures = []
                for gesture in gestures:
                    for gest in user_gestures:
                        if gest['name'] == gesture['name']:
                            gest['name'] = gest['name'] + " (modified)"
                            gesture = gest
                    new_gestures.append(gesture)
                gestures = new_gestures


            the_user = self.mongo_users.find_one({"_id": ObjectId(message[1])})
            if the_user is not None:
                for channel, val in the_user['channels'].items():
                    if channel in self.arduino.channels.keys():
                        self.arduino.channels[channel]['min_max'] = [int(val['min']), int(val['max'])]
                users = bson.json_util.dumps(the_user).replace(",", "§")
                gestures = bson.json_util.dumps(gestures).replace(",", "§")

                self.write_message("user_info," + users + "," + gestures)
        elif message[0] == "add_user":
            user_id = self.mongo_users.insert({
                "name": message[1],
                "channels": {}
            })
            self.write_message("newly_added_user_id," + bson.json_util.dumps(self.mongo_users.find_one({"_id": ObjectId(user_id)})).replace(",", "§"))

        elif message[0] == "envelope":
            if message[1] == "save":
                already_exists = 0
                if message[8] == "true":
                    already_exists = self.mongo_envelopes.find({"_id": ObjectId(message[3]), "user_id": ObjectId(message[2])}).limit(1).count()
                if already_exists == 1:
                    self.mongo_envelopes.update({"_id": ObjectId(message[3])}, {"$set": {
                        "gesture": ObjectId(message[4]),
                        "gesture duration": message[5],
                        "allpoints": json.loads(message[6].replace("§", ",")),
                        "individual_points": json.loads(message[7].replace("§", ",")),
                    }})
                else:
                    if message[8] == "true":
                        name = self.mongo_envelopes.find({"_id": ObjectId(message[3])}).limit(0)[0]['name']
                    else:
                        name = message[3]

                    self.mongo_envelopes.insert({
                        "name": name,
                        "gesture": ObjectId(message[4]),
                        "gesture duration": message[5],
                        "allpoints": json.loads(message[6].replace("§", ",")),
                        "individual_points": json.loads(message[7].replace("§", ",")),
                        "user_id": ObjectId(message[2])
                    })
        elif message[0] == "gesture":
            if message[1] == "save":
                already_exists = self.mongo_gestures.find({"_id": ObjectId(message[3]), "user_id": ObjectId(message[2])}).limit(1).count()
                if already_exists == 1:
                    self.mongo_gestures.update({"_id": ObjectId(message[3])}, {"$set": {
                        "allpoints": json.loads(message[4].replace("§", ", ")),
                        "line_segments":  json.loads(message[5].replace("§", ", "))
                    }})
                else:
                    old_thing = self.mongo_gestures.find({"_id": ObjectId(message[3])}).limit(0)[0]
                    self.mongo_gestures.insert({
                        "name": old_thing['name'],
                        "allpoints": json.loads(message[4].replace("§", ", ")),
                        "line_segments":  json.loads(message[5].replace("§", ", ")),
                        "user_id": ObjectId(message[2])
                    })
                gestures = list(self.mongo_gestures.find({"user_id": ObjectId(message[2])}, {"name": True}))
                self.write_message("reload_gestures," + bson.json_util.dumps(gestures).replace(",", "§"))

            elif message[1] == "save_new":
                self.mongo_gestures.insert({
                    "name": message[3],
                    "allpoints": json.loads(message[4].replace("§", ", ")),
                    "line_segments":  json.loads(message[5].replace("§", ", ")),
                    "user_id": ObjectId(message[2])
                })
                gestures = list(self.mongo_gestures.find({"user_id": ObjectId(message[2])}, {"name": True}))
                self.write_message("reload_gestures," + bson.json_util.dumps(gestures).replace(",", "§"))
            elif message[1] == "get":
                gesture = bson.json_util.dumps(list(self.mongo_gestures.find({"_id": ObjectId(message[2])}))[0]).replace(",", "§")
                self.write_message("gesture_info," + gesture)
            elif message[1] == "test":
                duration = 1000
                if message[3] and message[3].isdigit():
                    duration = int(message[3])
                self.arduino.perform_gesture(json.loads(message[2].replace("§", ", ")), duration)

    def on_close(self):
        print("WebSocket closed")
开发者ID:PedroLopes,项目名称:affordance,代码行数:104,代码来源:websocket_handler.py


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