-
Notifications
You must be signed in to change notification settings - Fork 1
/
listeners.py
66 lines (58 loc) · 1.95 KB
/
listeners.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
import sys
sys.path.append('/home/pi/MYO/lib/')
# BLUETOOTH'TAN GELEN VERILER IÇIN GEREKEN KÜTÜPHANE
# "lib" dosyasından gelir ve hareketleri yorumlar
from device_listener import DeviceListener
from pose_type import PoseType
from time import sleep
# PrintPose
class PrintPoseListener(DeviceListener):
def on_pose(self, pose):
pose_type = PoseType(pose)
print("# HAREKET : "+pose_type.name+"\n#")
# RS232 Serihaberleşme yapısı
class RS232Listener(DeviceListener):
def __init__(self):
from serial import Serial
self.sonHareket = ""
self.ardu = Serial()
self.ardu.baudrate = 9600
self.baglan()
def on_pose(self, pose):
pose_type = PoseType(pose)
print("# HAREKET : "+pose_type.name+"\n#")
# EL HAREKETLERI BU KISIMDA TANIMLANIR
# VE UART SERI HABERLEŞME PROTOKOLÜ ILE
# MOTORLARIN ÇALIŞMASI SAĞLANIR.
if(pose_type.name == "REST" and self.sonHareket != pose_type.name):
self.sonHareket = pose_type.name
print("# EL ACIK")
self.ardu.write("{}".format(2))
elif(pose_type.name == "FIST" and self.sonHareket != pose_type.name):
self.sonHareket = pose_type.name
print("# EL KAPALI")
self.ardu.write("{}".format(5))
elif(pose_type.name == "WAVE_IN" and self.sonHareket != pose_type.name):
self.sonHareket = pose_type.name
print("# 3 PARMAK TUTMA")
self.ardu.write("{}".format(3))
elif(pose_type.name == "WAVE_OUT" and self.sonHareket != pose_type.name):
self.sonHareket = pose_type.name
print("# ISARET ETME")
self.ardu.write("{}".format(4))
if(pose_type.name == "UNKNOWN"):
self.sonHareket = pose_type.name
return -1
# SERI HABERLEŞME YAPILACAK CIHAZI OTOMATIK BULDURMA
# VE BAĞLANTI YAPMA
def baglan(self):
try: self.ardu.close()
except: pass
sleep(0.5)
import serial.tools.list_ports
comlist = serial.tools.list_ports.comports()
for element in comlist:
if("/dev/ttyUSB" in element.device): self.ardu.port = element.device
try: self.ardu.open()
except: pass