Remove mqtt

This commit is contained in:
jimmy 2022-07-23 05:27:29 +12:00
parent a58f11ac0e
commit 15e79e67df
2 changed files with 14 additions and 46 deletions

View File

@ -13,12 +13,9 @@ from image import Image
import multiprocessing import multiprocessing
class App: class App:
def __init__(self, client, x, y): def __init__(self, x, y):
self.x = x self.x = x
self.y = y self.y = y
self.client = client
self.video = Video(x, y) self.video = Video(x, y)
self.image = Image(x, y) self.image = Image(x, y)
self.videos = [join("slave/videos", f) for f in listdir("slave/videos") if isfile(join("slave/videos", f))] self.videos = [join("slave/videos", f) for f in listdir("slave/videos") if isfile(join("slave/videos", f))]
@ -27,41 +24,17 @@ class App:
self.lastimage = -1 self.lastimage = -1
print(self.videos) print(self.videos)
print(self.videos[randint(0, len(self.videos)-1)]) print(self.videos[randint(0, len(self.videos)-1)])
def on_connect(self, client, userdata, flags, rc):
print("Connected with result code "+str(rc))
self.client.subscribe("slave")
def on_message(self, client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
if msg.payload == b'idle':
print("Idle")
self.x = multiprocessing.Process(target = self.idle)
self.x.start()
elif msg.payload == b'stop':
print("Stop")
try:
self.x.terminate()
except:
pass
def idle(self): def idle(self):
last = -1 last = -1
while True: while True:
try:
self.x.terminate()
except:
pass
# if i == last: # if i == last:
# continue # continue
if randint(0,5) == 0: if randint(0,5) == 0:
self.showimage() self.showimage()
else: else:
self.playvideo() self.playvideo()
def showimage(self): def showimage(self):
totalimages = len(self.images)-1 totalimages = len(self.images)-1
@ -72,7 +45,7 @@ class App:
i = 0 i = 0
self.lastimage = i self.lastimage = i
self.image.show(self.images[i]) self.image.show(self.images[i])
cv2.waitKey(1000) cv2.waitKey(10000)
def playvideo(self): def playvideo(self):
totalvideos = len(self.videos)-1 totalvideos = len(self.videos)-1
@ -90,15 +63,8 @@ class App:
def main(): def main():
client = mqtt.Client() app = App(int(sys.argv[1]), int(sys.argv[2]))
app = App(client, int(sys.argv[1]), int(sys.argv[2])) app.idle()
client.on_connect = app.on_connect
client.on_message = app.on_message
client.connect("10.1.1.162", 1883, 60)
client.loop_forever()
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -2,6 +2,7 @@ from random import randint
import cv2 import cv2
import multiprocessing import multiprocessing
import time import time
import sys
class Video: class Video:
def __init__(self, x, y): def __init__(self, x, y):
@ -27,7 +28,7 @@ class Video:
delay = 1/fps * 1000 delay = 1/fps * 1000
print(fps, delay) print(fps, delay)
i = 0 i = 0
playframes = randint(50, 200) playframes = randint(300, 500)
while(self.cap.isOpened() ): while(self.cap.isOpened() ):
i += 1 i += 1
if i > playframes: if i > playframes:
@ -45,14 +46,15 @@ class Video:
cv2.imshow("window", frame) cv2.imshow("window", frame)
if cv2.waitKey(int(delay)) == ord('q'): if cv2.waitKey(int(delay)) & 0xFF == ord('q'):
break self.cap.release()
cv2.destroyAllWindows()
sys.exit(0)
# Break the loop # Break the loop
else: else:
break break
#self.cap.release() self.cap.release()
# Closes all the frames # Closes all the frames
#cv2.destroyAllWindows() #cv2.destroyAllWindows()