Added safe unmount and fixed blue counter bug
This commit is contained in:
16
main.py
16
main.py
@@ -43,6 +43,7 @@ class Config:
|
|||||||
class AppState:
|
class AppState:
|
||||||
stopEvent = Event()
|
stopEvent = Event()
|
||||||
cameraStopComplete = Event()
|
cameraStopComplete = Event()
|
||||||
|
stopRecording = Event()
|
||||||
diskEventQueue: Queue[DiskEvent] = Queue()
|
diskEventQueue: Queue[DiskEvent] = Queue()
|
||||||
diskState: DiskState = "disconnected"
|
diskState: DiskState = "disconnected"
|
||||||
config = Config()
|
config = Config()
|
||||||
@@ -155,6 +156,8 @@ def ledWorker(state: AppState) -> None:
|
|||||||
else:
|
else:
|
||||||
blue.off()
|
blue.off()
|
||||||
|
|
||||||
|
blueCtr += 1
|
||||||
|
|
||||||
state.stopEvent.wait(0.25)
|
state.stopEvent.wait(0.25)
|
||||||
|
|
||||||
|
|
||||||
@@ -198,6 +201,9 @@ def mountDisk(state: AppState) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def unmountDisk(state: AppState) -> None:
|
def unmountDisk(state: AppState) -> None:
|
||||||
|
state.cameraState = "armed"
|
||||||
|
state.stopRecording.wait()
|
||||||
|
state.stopRecording.clear()
|
||||||
if not state.failedUmount:
|
if not state.failedUmount:
|
||||||
try:
|
try:
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
@@ -362,7 +368,12 @@ def cameraWorker(state: AppState) -> None:
|
|||||||
state.cameraState = "recording"
|
state.cameraState = "recording"
|
||||||
recording_trigger_time = now
|
recording_trigger_time = now
|
||||||
|
|
||||||
elif recording and now - last_motion_time >= QUIET_SECONDS:
|
elif (recording and now - last_motion_time >= QUIET_SECONDS) or (
|
||||||
|
recording and state.cameraState == "armed"
|
||||||
|
):
|
||||||
|
setGlobalFlag = False
|
||||||
|
if recording and state.cameraState == "armed":
|
||||||
|
setGlobalFlag = True
|
||||||
circular_output.stop()
|
circular_output.stop()
|
||||||
state.cameraState = "armed"
|
state.cameraState = "armed"
|
||||||
recording = False
|
recording = False
|
||||||
@@ -371,6 +382,9 @@ def cameraWorker(state: AppState) -> None:
|
|||||||
|
|
||||||
recording_path = None
|
recording_path = None
|
||||||
|
|
||||||
|
if setGlobalFlag:
|
||||||
|
state.stopRecording.set()
|
||||||
|
|
||||||
previous_frame = current_frame
|
previous_frame = current_frame
|
||||||
finally:
|
finally:
|
||||||
if recording:
|
if recording:
|
||||||
|
|||||||
Reference in New Issue
Block a user