mirror of
https://github.com/CopterExpress/clever-show.git
synced 2026-05-29 08:29:31 +00:00
87 lines
2.0 KiB
Python
Executable File
87 lines
2.0 KiB
Python
Executable File
import socket
|
|
import play_animation
|
|
sock = socket.socket()
|
|
serv = '192.168.1.10'
|
|
port = 1234
|
|
sock.connect((serv, port))
|
|
sock.send(bytes('left','utf-8'))
|
|
command = ''
|
|
|
|
def receive():
|
|
global command
|
|
|
|
try:
|
|
while True:
|
|
data = str(sock.recv(1024))
|
|
try:
|
|
if b'programm' in data:
|
|
anim = open('anim.csv', 'w')
|
|
data = data[data.index(b'programm') + 8:]
|
|
anim.write(data)
|
|
|
|
while True:
|
|
data = str(sock.recv(1024))
|
|
|
|
if b'stop' in data:
|
|
anim.write(data[:data.index(b'stop')])
|
|
break
|
|
else:
|
|
anim.write(data)
|
|
|
|
else:
|
|
try:
|
|
sq = data.split('$$')
|
|
for i in range(len(sq) - 1):
|
|
print(sq[i])
|
|
command = sq[i]
|
|
|
|
except Exception as e:
|
|
print(e)
|
|
|
|
except:
|
|
print('er')
|
|
sock.close()
|
|
except KeyboardInterrupt:
|
|
print("Shutting down")
|
|
|
|
led.off()
|
|
sock.close()
|
|
|
|
def time_synch():
|
|
c = ntplib.NTPClient()
|
|
response = c.request('ntp1.stratum2.ru')
|
|
return response.tx_time-time.time()
|
|
|
|
|
|
def pl_anim(c_frame):
|
|
global command
|
|
takeoff()
|
|
for frame in c_frame:
|
|
if command != 'pause':
|
|
time.sleep(0.1)
|
|
play_animation.do_next_animation(frame)
|
|
|
|
|
|
if __name__==__main__:
|
|
t_0 = Thread(target=receive)
|
|
t_0.daemon = True
|
|
t_0.start()
|
|
play_animation.read_animation_file()
|
|
dtime=time_synch() - time.time()
|
|
|
|
while True:
|
|
|
|
if 'begin_anim' in command:
|
|
t_st = int(command[command.index('('):])
|
|
if t_st==dtime+time.time:
|
|
break
|
|
if 'synch' in command:
|
|
dtime=time_synch() - time.time()
|
|
print(dtime)
|
|
|
|
pl_anim(play_animation.frame())
|
|
|
|
|
|
|
|
|