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:
|
||||
stopEvent = Event()
|
||||
cameraStopComplete = Event()
|
||||
stopRecording = Event()
|
||||
diskEventQueue: Queue[DiskEvent] = Queue()
|
||||
diskState: DiskState = "disconnected"
|
||||
config = Config()
|
||||
@@ -155,6 +156,8 @@ def ledWorker(state: AppState) -> None:
|
||||
else:
|
||||
blue.off()
|
||||
|
||||
blueCtr += 1
|
||||
|
||||
state.stopEvent.wait(0.25)
|
||||
|
||||
|
||||
@@ -198,6 +201,9 @@ def mountDisk(state: AppState) -> None:
|
||||
|
||||
|
||||
def unmountDisk(state: AppState) -> None:
|
||||
state.cameraState = "armed"
|
||||
state.stopRecording.wait()
|
||||
state.stopRecording.clear()
|
||||
if not state.failedUmount:
|
||||
try:
|
||||
subprocess.run(
|
||||
@@ -362,7 +368,12 @@ def cameraWorker(state: AppState) -> None:
|
||||
state.cameraState = "recording"
|
||||
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()
|
||||
state.cameraState = "armed"
|
||||
recording = False
|
||||
@@ -371,6 +382,9 @@ def cameraWorker(state: AppState) -> None:
|
||||
|
||||
recording_path = None
|
||||
|
||||
if setGlobalFlag:
|
||||
state.stopRecording.set()
|
||||
|
||||
previous_frame = current_frame
|
||||
finally:
|
||||
if recording:
|
||||
|
||||
Reference in New Issue
Block a user