commit 172675edb1ce5689b9b9ca4c0aadfcf16db386a5
parent 8d64c8a3d6c734b771d0a56cd56bb2c4e33484a3
Author: rob <rob@tarina.org>
Date: Thu, 24 Aug 2023 14:58:16 +0300
do it!
Diffstat:
M | tarinactrl.py | | | 85 | +++++++++++++++++++++++++++++++++++++++++-------------------------------------- |
1 file changed, 44 insertions(+), 41 deletions(-)
diff --git a/tarinactrl.py b/tarinactrl.py
@@ -25,6 +25,9 @@ for adapter in adapters:
networks.append(ip.ip)
network=networks[0]
+
+##--Cameras---
+
cameras = []
camerasoff =[]
port = config.port
@@ -35,7 +38,7 @@ selected = 1
camselected=0
newselected=0
mastersound=None
-recording=None
+camera_recording=None
sleep=0.2
rectime=None
pingip=0
@@ -47,18 +50,18 @@ def pingtocamera(host, port, data):
print("Sending to "+host+" on port "+str(port)+" DATA:"+data)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(0.1)
+ newcamera=''
try:
while True:
s.connect((host, port))
s.send(str.encode(data))
- if host not in cameras and host not in networks:
- cameras.append(host)
- print("Found camera! "+host)
+ newcamera=host
print("Sent to server..")
break
except:
print('did not connect')
s.close()
+ return newcamera
def sendtocamera(host, port, data):
print("Sending to "+host+" on port "+str(port)+" DATA:"+data)
@@ -98,7 +101,7 @@ def listenforclients(host, port, q):
except:
q.put('')
-def printmenu(recording,selected,cameras,camselected,serverstatus,rectime):
+def printmenu(camera_recording,selected,cameras,camselected,serverstatus,rectime):
print(term.home+term.clear)
print(time.time())
print(rectime)
@@ -112,8 +115,8 @@ def printmenu(recording,selected,cameras,camselected,serverstatus,rectime):
print(serverstatus[1])
except:
print('')
- if recording != None:
- print("Camera "+ str(recording)+" is recording! Shut up. And Action!")
+ if camera_recording != None:
+ print("Camera "+ str(camera_recording)+" is camera_recording! Shut up. And Action!")
a=0
print('-~-')
for i in menu:
@@ -141,8 +144,8 @@ def printmenu(recording,selected,cameras,camselected,serverstatus,rectime):
##----------------------Main loop starts-------------------------
def main(serverstatus):
- global nextstatus, selected, cameras, menu, camselected, recording, sleep, rectime, pingip,searchforcameras
- if recording != None:
+ global nextstatus, selected, cameras, menu, camselected, camera_recording, sleep, rectime, pingip,searchforcameras
+ if camera_recording != None:
menu = ["Quit","New FILM","Sync FILM","New SCENE","Sync SCENE","Stop","Retake","Search","Snapshot"]
else:
menu = ["Quit","New FILM","Sync FILM","New SCENE","Sync SCENE","Record","Retake","Search","Snapshot"]
@@ -186,20 +189,20 @@ def main(serverstatus):
for i in cameras:
if i not in camerasoff:
if a == camselected:
- if recording == camselected:
+ if camera_recording == camselected:
sendtocamera(i,port,'STOPRETAKE')
- recording=None
+ camera_recording=None
else:
sendtocamera(i,port,'RETAKE')
- recording=camselected
+ camera_recording=camselected
else:
- if recording != None:
+ if camera_recording != None:
sendtocamera(i,port,'PLACEHOLDER')
a=a+1
elif event == "KEY_ENTER" and menu[selected] == 'Sync SCENE':
#for p in cameras[1:]:
# if p not in camerasoff:
- # if recording == None:
+ # if camera_recording == None:
# sendtocamera(cameras[0],port,'SYNCIP:'+p)
if camselected != 0:
sendtocamera(cameras[0],port,'SYNCIP:'+cameras[camselected])
@@ -215,43 +218,39 @@ def main(serverstatus):
if i not in camerasoff:
sendtocamera(i,port,'PING')
a=a+1
- elif event == "KEY_PGUP" and recording == None or event=="KEY_ENTER" and menu[selected]=='Record':
+ elif event == "KEY_PGUP" and camera_recording == None or event=="KEY_ENTER" and menu[selected]=='Record':
a=0
for i in cameras:
if i not in camerasoff:
if a == camselected:
- if recording == camselected:
- sendtocamera(i,port,'STOP')
- recording=None
- else:
- sendtocamera(i,port,'REC')
- recording=camselected
- rectime=time.time()
- elif a == mastersound:
- if recording == a:
- sendtocamera(i,port,'STOP')
- else:
- sendtocamera(i,port,'RECSOUND')
- #if recording != mastersound:
- # time.sleep(sleep)
- # sendtocamera(i,port,'RECSOUND')
+ sendtocamera(i,port,'REC')
+ camera_recording=camselected
+ rectime=time.time()
+ #elif a == mastersound:
+ # if camera_recording == a:
+ # sendtocamera(i,port,'STOP')
+ # else:
+ # sendtocamera(i,port,'RECSOUND')
+ # if camera_recording != mastersound:
+ # time.sleep(sleep)
+ # sendtocamera(i,port,'RECSOUND')
else:
sendtocamera(i,port,'PLACEHOLDER')
a=a+1
- elif event == "KEY_PGUP" and recording or event=="KEY_ENTER" and menu[selected]=='Stop':
+ elif event == "KEY_PGUP" and camera_recording or event=="KEY_ENTER" and menu[selected]=='Stop':
a=0
for i in cameras:
if i not in camerasoff:
if a == camselected:
- if recording == camselected:
+ if camera_recording == camselected:
sendtocamera(i,port,'STOP')
- recording=None
+ camera_recording=None
elif a == mastersound:
- if recording == a:
+ if camera_recording == a:
sendtocamera(i,port,'STOP')
else:
sendtocamera(i,port,'RECSOUND')
- #if recording != mastersound:
+ #if camera_recording != mastersound:
# time.sleep(sleep)
# sendtocamera(i,port,'RECSOUND')
#else:
@@ -275,7 +274,7 @@ def main(serverstatus):
if cameras[camselected] in camerasoff:
camerasoff.remove(cameras[camselected])
if camselected != newselected:
- if recording != None:
+ if camera_recording != None:
#change camera
a=0
for c in cameras:
@@ -295,7 +294,7 @@ def main(serverstatus):
sendtocamera(c,port,'STOP')
time.sleep(sleep)
sendtocamera(c,port,'REC')
- recording=newselected
+ camera_recording=newselected
rectime=time.time()
else:
if a == mastersound:
@@ -310,16 +309,20 @@ def main(serverstatus):
a=a+1
camselected=newselected
- # ping ip every 10 sec while not recording to connect cameras
+ # ping ip every 10 sec while not camera_recording to connect cameras
if searchforcameras == True:
- if recording == None:
+ if camera_recording == None:
if pingip < 256:
pingip+=1
else:
pingip=0
searchforcameras=False
- pingtocamera(network[:-3]+str(pingip),port,'PING')
- printmenu(recording,selected,cameras,camselected,serverstatus,rectime)
+ newcamera=pingtocamera(network[:-3]+str(pingip),port,'PING')
+ if newcamera != '':
+ if newcamera not in cameras and newcamera not in networks:
+ cameras.append(newcamera)
+ print("Found camera! "+newcamera)
+ printmenu(camera_recording,selected,cameras,camselected,serverstatus,rectime)
if searchforcameras == True:
print('-~-')
print('pinging ip: '+network[:-3]+str(pingip))