-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathsock.py
63 lines (52 loc) · 2.48 KB
/
sock.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
import socket
class Socket:
"""Socket class for message data transmission"""
def __init__(self):
self.roll = 0.0 # rotate along inner axis
self.pitch = 0.0 # rotate along horizontal axis
self.yaw = 0.0 # rotate along vertical axis
self.eyeOpenLeft = 0.0 # degree of left eye openness
self.eyeOpenRight = 0.0 # degree of right eye openness
self.eyeballX = 0.0 # horizontal position of two eyes (has same ratio)
self.eyeballY = 0.0 # vertical position of two eyes (has same ratio)
self.eyebrowLeft = 0.0 # vertical position of left eyebrow
self.eyebrowRight = 0.0 # vertical position of right eyebrow
self.mouthWidth = 0.0 # mouth width / face width
self.mouthOpen = 0.0 # degree of mouth openness
self.eyeOpenLeftLast = self.eyeOpenLeft # last frame
self.eyeOpenRightLast = self.eyeOpenRight # last frame
self.eyebrowLeftLast = self.eyebrowLeft # last frame
self.eyebrowRightLast = self.eyebrowRight # last frame
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def update_all(self, roll, pitch, yaw, eyeOpenLeft, eyeOpenRight, eyeballX, eyeballY, eyebrowLeft, eyebrowRight, mouthWidth, mouthOpen):
"""Update all parameters"""
self.roll = roll
self.pitch = pitch
self.yaw = yaw
self.eyeOpenLeft = eyeOpenLeft
self.eyeOpenRight = eyeOpenRight
self.eyeballX = eyeballX
self.eyeballY = eyeballY
self.eyebrowLeft = eyebrowLeft
self.eyebrowRight = eyebrowRight
self.mouthWidth = mouthWidth
self.mouthOpen = mouthOpen
# Update some values of last frames
self.eyeOpenLeftLast = self.eyeOpenLeft
self.eyeOpenRightLast = self.eyeOpenRight
self.eyebrowLeftLast = self.eyebrowLeft
self.eyebrowRightLast = self.eyebrowRight
def conv2msg(self):
"""Convert all parameters to message data"""
self.msg = '%.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f' % \
(self.roll, self.pitch, self.yaw, self.eyeOpenLeft, self.eyeOpenRight,
self.eyeballX, self.eyeballY, self.eyebrowLeft, self.eyebrowRight, self.mouthWidth, self.mouthOpen)
def connect(self, addr):
"""Establish connection"""
self.s.connect(addr)
def send(self):
"""Sending message data"""
self.s.send(bytes(self.msg, "utf-8"))
def close(self):
"""Close socket"""
self.s.close()