本文整理汇总了Python中arduino.Arduino.start方法的典型用法代码示例。如果您正苦于以下问题:Python Arduino.start方法的具体用法?Python Arduino.start怎么用?Python Arduino.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arduino.Arduino
的用法示例。
在下文中一共展示了Arduino.start方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import start [as 别名]
class ArduinoController:
BAUD_RATE = 115200
def __init__(self):
self.parser = Parser()
self.arduino = Arduino(ArduinoController.BAUD_RATE)
self.arduino.register_listener(self)
self.msg_handlers = {
'log_format': self.parser.register_log_format,
'sensor_readings': self.notify_listeners
}
self.log_received_listeners = []
def register_listener(self, listener):
"""Register a listener to the log received event."""
# Make sure the listener has the on_log_received method defined.
m = getattr(listener, 'on_log_received', None)
if callable(m):
self.log_received_listeners.append(listener)
def on_msg_received(self, msg):
"""Attempt to parse & handle the received serial message."""
try:
parsed_msg = self.parser.parse_msg(msg)
handler = self.msg_handlers[parsed_msg['header']]
handler(parsed_msg['data'])
except KeyError:
raise BadSerialMessageError(
'Unknown command: {}'.format(parsed_msg['header']))
except BadSerialMessageError as e:
print 'Ignoring bad msg: {}'.format(e)
def start(self):
self.arduino.start() # For now simply delegate to the Arduino class.
def stop(self):
self.arduino.stop() # For now simply delegate to the Arduino class.
def notify_listeners(self, data):
"""Notify all listeners of the log received event."""
try:
readings = self.parser.parse_sensor_readings(data)
for listener in self.log_received_listeners:
listener.on_log_received(readings)
except BadSerialMessageError as e:
print "Ignoring bad log: {}".format(e)
示例2: main
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import start [as 别名]
def main():
network_clients_sh = path.join(path.dirname(__file__), 'networkClientsInNetwork.sh')
config_path = path.join(path.dirname(__file__), 'config.json')
print config_path
print network_clients_sh
with open(config_path) as config_fh:
config = json.load(config_fh)
args = get_args()
is_live_run = args["productive_system"]
base_url = config["URL"]
security_token = config["KEY"]
port = config["TTY"]
poster = Poster()
if is_live_run:
cprint("Live run!", color="magenta")
delay = 300
else:
cprint("Test run!", color="green")
delay = 3
arduino = Arduino(port=port)
arduino.start()
time.sleep(15)
network_clients_count = None
while True:
is_door_open = arduino.get_is_door_open()
temperature = arduino.get_temperature()
recieved = arduino.get_last_recieved()
nmap = subprocess.Popen(network_clients_sh, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
network_clients_count = int(nmap.stdout.readlines()[0])
poster.post_door_state(base_url, is_door_open, security_token)
poster.post_temperature(base_url, str(temperature), security_token)
poster.post_clients(base_url, str(network_clients_count), security_token)
cprint(str(datetime.datetime.now().strftime('%G-%b-%d-%H:%M:%S')), color="red")
cprint("Nmap " + str(network_clients_count), color="blue")
cprint("Tür offen: " + str(is_door_open), color="yellow")
cprint("Temperatur: " + str(temperature), color="cyan")
print recieved
print ("\n")
time.sleep(delay)
示例3: WebsocketHandler
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import start [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:
#.........这里部分代码省略.........
示例4: Arduino
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import start [as 别名]
return self.my_joystick.get_button(p_button)
return False
FILE = 'index.html'
PORT = 8080
global ard
ard = Arduino()
try:
ard.configure_serial('/dev/tty.usbmodem1451')
except:
print "Serial port configuration failed, moving ahead"
ard.start()
global d
d = 0;
class TestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
"""The test example handler."""
def do_POST(self):
global d
"""Handle a post request by returning the square of the number."""
# poll arduino here
#length = int(self.headers.getheader('content-length'))
#data_string = self.rfile.read(length)