Skip to content

Commit d02132a

Browse files
committed
push code
1 parent 551b876 commit d02132a

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

pymycobot/mybuddyemoticon.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
class Emoticon:
10-
def __init__(self, file_path: list = [], window_size: list = []) -> None:
10+
def __init__(self, file_path: list = [], window_size: list = [], loop=False) -> None:
1111
"""API for playing emoticons
1212
1313
Args:
@@ -19,6 +19,8 @@ def __init__(self, file_path: list = [], window_size: list = []) -> None:
1919
self.__window_size = window_size
2020
self.quit = False
2121
self.stop_play = False
22+
self.start_time = 0
23+
self.loop = loop
2224

2325
@property
2426
def file_path(self):
@@ -73,17 +75,31 @@ def play(self):
7375
if self.quit:
7476
break
7577
while self.stop_play and self.quit == False:
76-
pass
78+
if self.start_time == 0:
79+
self.start_time = time.time() - t
80+
if self.start_time>0:
81+
t = time.time() - self.start_time
82+
self.start_time = 0
7783
ret, frame = cap.read()
78-
# print(frame)
7984
if frame is not None:
8085
cv.imshow(out_win, frame)
81-
if cv.waitKey(1) & 0xFF == ord('q') or ret == False:
82-
if time.time() - t >= self.__file_path[index][1]:
86+
if time.time() - t >= self.__file_path[index][1]:
8387
index += 1
8488
if index >= len(self.__file_path):
8589
index = 0
90+
t = time.time()
91+
if cv.waitKey(1) & 0xFF == ord('q') or ret == False:
8692
cap = cv.VideoCapture(self.__file_path[index][0])
93+
94+
if time.time() - t >= self.__file_path[index][1]:
95+
index += 1
96+
if index >= len(self.__file_path):
97+
if self.loop:
98+
index = 0
99+
else:
100+
break
101+
t = time.time()
102+
cap = cv.VideoCapture(self.__file_path[index][0])
87103
if self.quit:
88104
break
89105
cap.release()
@@ -94,6 +110,6 @@ def start(self):
94110
self.t = threading.Thread(target=self.play, daemon=True)
95111
self.t.start()
96112

97-
def joint(self):
113+
def join(self):
98114
"""Wait for the thread playing the video to finish"""
99-
self.t.joint()
115+
self.t.join()

tests/rasp_mycobot_test_gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def check_mycobot_servos(self):
188188
for idx, command in enumerate(ping_commands, start=1):
189189
self.mycobot._write(command)
190190
time.sleep(0.1)
191-
if not self.mycobot._read():
191+
if not self.mycobot._read(1):
192192
res.append(idx)
193193
time.sleep(0.1)
194194

0 commit comments

Comments
 (0)