Skip to content

Commit

Permalink
Merge branch 'main' of Predator
Browse files Browse the repository at this point in the history
  • Loading branch information
connervieira committed Nov 12, 2024
2 parents 65e0b42 + bdcb9e2 commit 06a2322
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 66 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,3 +556,13 @@ November 11th, 2024

- Updated dash-cam mode.
- Added more options for physical controls via GPIO buttons.
- Updated audio output.
- Added support for multiple audio player back-ends.
- In addition to supporting the original `mpg321` back-end, Predator now also supports `mplayer`.
- Moved configuration values.
- The `sounds` configuration section has been renamed, moved, and re-organized.
- Added more sounds.
- `gps_connected` is played when the GPS gains a location fix.
- `gps_disconnected` is played when the GPS loses the location fix.
- `gps_fault` is played when the GPS encounters a problem.
- `dashcam_saved` is played when a dash-cam video segment is saved.
80 changes: 63 additions & 17 deletions assets/support/configdefault.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,69 @@
"alpr_detection": "[U]&R=255&G=128&B=0",
"dashcam_save": "[U]&R=0&G=0&B=255"
}
},
"audio": {
"enabled": false,
"player": {
"backend": "mplayer",
"mpg321": {
},
"mplayer": {
"device": "alsa:device=hw=0.0"
}
},
"sounds": {
"startup": {
"path": "./assets/sounds/startup.mp3",
"repeat": 0,
"delay": 0.3
},
"alpr_notification": {
"path": "./assets/sounds/platedetected.mp3",
"repeat": 1,
"delay": 0.3
},
"alpr_alert": {
"path": "./assets/sounds/alerthit.mp3",
"repeat": 1,
"delay": 2.5
},
"gps_connected": {
"path": "./assets/sounds/voice/gps_connected.mp3",
"repeat": 1,
"delay": 1
},
"gps_disconnected": {
"path": "./assets/sounds/voice/gps_disconnected.mp3",
"repeat": 1,
"delay": 1
},
"gps_fault": {
"path": "./assets/sounds/voice/gps_fault.mp3",
"repeat": 1,
"delay": 1
},
"dashcam_saved": {
"path": "./assets/sounds/voice/video_saved.mp3",
"repeat": 1,
"delay": 1
},
"message_notice": {
"path": "./assets/sounds/voice/notice.mp3",
"repeat": 1,
"delay": 1
},
"message_warning": {
"path": "./assets/sounds/voice/warning.mp3",
"repeat": 1,
"delay": 1
},
"message_error": {
"path": "./assets/sounds/voice/error.mp3",
"repeat": 1,
"delay": 1
}
}
}
},
"management": {
Expand Down Expand Up @@ -107,23 +170,6 @@
}
}
},
"sounds": {
"startup_sound": {
"path": "./assets/sounds/startup.mp3",
"repeat": 0,
"delay": 0.3
},
"notification_sound": {
"path": "./assets/sounds/platedetected.mp3",
"repeat": 1,
"delay": 0.3
},
"alert_sound": {
"path": "./assets/sounds/alerthit.mp3",
"repeat": 1,
"delay": 2.5
}
},
"saving": {
"remote_alert_sources": {
"enabled": true,
Expand Down
80 changes: 63 additions & 17 deletions assets/support/configoutline.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,69 @@
"alpr_detection": "str",
"dashcam_save": "str"
}
},
"audio": {
"enabled": "bool",
"player": {
"backend": ["mpg321", "mplayer"],
"mpg321": {
},
"mplayer": {
"device": "str"
}
},
"sounds": {
"startup": {
"path": "file",
"repeat": "+int",
"delay": "+float"
},
"alpr_notification": {
"path": "file",
"repeat": "+int",
"delay": "+float"
},
"alpr_alert": {
"path": "file",
"repeat": "+int",
"delay": "+float"
},
"gps_connected": {
"path": "file",
"repeat": "+int",
"delay": "+float"
},
"gps_disconnected": {
"path": "file",
"repeat": "+int",
"delay": "+float"
},
"gps_fault": {
"path": "file",
"repeat": "+int",
"delay": "+float"
},
"dashcam_saved": {
"path": "file",
"repeat": "+int",
"delay": "+float"
},
"message_notice": {
"path": "file",
"repeat": "+int",
"delay": "+float"
},
"message_warning": {
"path": "file",
"repeat": "+int",
"delay": "+float"
},
"message_error": {
"path": "file",
"repeat": "+int",
"delay": "+float"
}
}
}
},
"management": {
Expand Down Expand Up @@ -101,23 +164,6 @@
"devices": "dict"
}
},
"sounds": {
"startup_sound": {
"path": "file",
"repeat": "+int",
"delay": "+float"
},
"notification_sound": {
"path": "file",
"repeat": "+int",
"delay": "+float"
},
"alert_sound": {
"path": "file",
"repeat": "+int",
"delay": "+float"
}
},
"saving": {
"remote_alert_sources": {
"enabled": "bool",
Expand Down
50 changes: 32 additions & 18 deletions docs/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,35 @@ This document describes the configuration values found `config.json`.
- The `alpr_detection` status is relevant in real-time mode, and used when Predator detects any valid license plate.
- The `dashcam_save` status is relevant to dash-cam mode, and is triggered when a dashcam video file is saved using the dashcam lock trigger file.
- The lighting will remain in the "dashcam_save" status until the segment has ended, and Predator returns to normal, unlocked recording.
- `audio` contains settings that control audio play-back.
- `enabled` is a boolean value that determines whether audio playback is enabled.
- `player` contains settings for controlling how sounds are played.
- `backend` sets the audio player back-end Predator will use.
- This value can only be set to one of these values: "mpg321", "mplayer"
- `mpg321` contains settings for the MPG321 player back-end (if it is selected).
- `mplayer` contains settings for the MPlayer player back-end (if it is selected).
- `device` is a string that specifies the audio device that will be used for audio playback.
- Leaving this value blank will use the default audio playback device.
- `sounds` contains the sound effects that Predator can play when certain events occur.
- Each entry in this section has 3 attributes.
- The `path` value should be set to the file path of the audio file you want to play.
- The `repeat` value should be set to how many times you want the sound effect to be repeated.
- To disable a sound from playing, set this to 0.
- Under normal circumstances, this value should just be "1", but there might be some cases in which you want to play a particular sound repeatedly.
- The `delay` value determines how long Predator will wait, in seconds, between repetitions, if `reptition` is set to more than 1.
- Note that this delay includes the time it takes for the previous instances of the sound effect to play.
- For example, if the audio clip you're repeating takes 2 seconds to play, and you want a 1 second delay between audio clips, this setting should be 3 seconds.
- If the delay is set to zero, then all of the repetitions will play over top of each-other.
- Each entry in this section corresponds to a sound effect.
- `startup` is the sound played just after Predator finishes loading.
- `alpr_notification` is the sound played when a valid plate is detected in real-time mode, and the plate is not in an alert database.
- `alpr_alert` is the sound played when a valid plate is detected, and the plate is in an alert database.
- `gps_connected` is played when the GPS finds a 2D or 3D location fix.
- `gps_disconnected` is played when the GPS loses the fix.
- `gps_fault` is played when the GPS encounters an error.
- `message_notice` is played when a "notice" level message is displayed.
- `message_warning` is played when a "warning" level message is displayed.
- `message_error` is played when a "error" level message is displayed.
- `management` contains configuration values related to management mode.
- `disk_statistics` is a boolean that enables and disables the disk statistics feature of management mode.
- Setting this to `false` disables disk statistics, and eliminates the need for the 'psutil' Python package to be installed.
Expand Down Expand Up @@ -146,23 +175,6 @@ This document describes the configuration values found `config.json`.
- `camera` contains settings related to image capture.
- `device` specifies the camera device that will be used to capture images.
- Example: `"/dev/video0"`
- `sounds` contains the sound effects that Predator can play when certain events occur.
- Each entry in this section has 3 attributes.
- The `path` value should be set to the file path of the audio file you want to play.
- The `repeat` value should be set to how many times you want the sound effect to be repeated.
- To disable a sound from playing, set this to 0.
- Under normal circumstances, this value should just be "1", but there might be some cases in which you want to play a particular sound repeatedly.
- The `device` determines the name of the device that Predator will use to record audio.
- You can get a list of the names of the available sound inputs by running the `arecord -L` command.
- Leaving this value as a blank string will cause Predator to use the default audio input determined by `arecord`.
- The `delay` value determines how long Predator will wait, in seconds, between repetitions, if `reptition` is set to more than 1.
- Note that this delay includes the time it takes for the previous instances of the sound effect to play.
- For example, if the audio clip you're repeating takes 2 seconds to play, and you want a 1 second delay between audio clips, this setting should be 3 seconds.
- If the delay is set to zero, then all of the repetitions will play over top of each-other.
- Each entry in this section corresponds to a sound effect.
- `startup_sound` is the sound played just after Predator finishes loading.
- `notification_sound` is the sound played when a valid plate is detected in real-time mode, and the plate is not in an alert database.
- `alert_sound` is the sound played when a valid plate is detected, and the plate is in an alert database.
- `saving` contains settings related to information logging while operating in real-time mode.
- `license_plates` contains settings related to saving detected license plates.
- `enabled` is a boolean value that determines whether license plate saving is enabled.
Expand Down Expand Up @@ -242,7 +254,9 @@ This document describes the configuration values found `config.json`.
- `audio` contains settings for configuring Predator's audio recording behavior.
- `enabled` is a boolean that determines whether or not audio will be recorded during dash-cam operation.
- `extension` sets the file extension that audio will be saved with.
- `device` specifies the device ID (as determined by `arecord --list-pcms`) that will be used to capture audio.
- `device` determines the name of the device that Predator will use to record audio.
- You can get a list of the names of the available sound inputs by running the `arecord -L` command.
- Leaving this value as a blank string will cause Predator to use the default audio input determined by `arecord`.
- `format` specifies the format that will be used by the `arecord` process.
- `merge` is a boolean that determines whether or not Predator will merge the separate audio and video files when each segment is done recording.
- `record_as_user` specifies the user on the system that the audio recording process will be run as.
Expand Down
13 changes: 6 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
clear = utils.clear # Load the screen clearing function from the utils script.
prompt = utils.prompt # Load the user input prompt function from the utils script.
is_json = utils.is_json # Load the function used to determine if a given string is valid JSON.
play_sound = utils.play_sound # Load the function used to play sounds from the utils script.
display_message = utils.display_message # Load the message display function from the utils script.
process_gpx = utils.process_gpx # Load the GPX processing function from the utils script.
save_to_file = utils.save_to_file # Load the file saving function from the utils script.
Expand Down Expand Up @@ -204,7 +203,7 @@
if (config["general"]["display"]["startup_message"]!= ""): # Only display the line for the custom message if the user has defined one.
print(config["general"]["display"]["startup_message"]) # Show the user's custom defined start-up message.

play_sound("startup")
utils.play_sound("startup")

if (config["realtime"]["push_notifications"]["enabled"] == True): # Check to see if the user has push notifications enabled.
debug_message("Issuing start-up push notification")
Expand Down Expand Up @@ -239,9 +238,6 @@
config["prerecorded"]["image"]["processing"]["cropping"]["bottom_margin"] = 0
config["prerecorded"]["image"]["processing"]["cropping"]["top_margin"] = 0

for device in config["realtime"]["image"]["camera"]["devices"]: # Iterate through each video device specified in the configuration.
if (os.path.exists(config["realtime"]["image"]["camera"]["devices"][device]) == False): # Check to make sure that a camera device points to a valid file.
display_message("The 'realtime>image>camera>devices>" + device + "' configuration value does not point to a valid file.", 3)



Expand Down Expand Up @@ -1281,6 +1277,9 @@

elif (mode_selection == "2" and config["general"]["modes"]["enabled"]["realtime"] == True): # The user has set Predator to boot into real-time mode.
debug_message("Started real-time mode")
for device in config["realtime"]["image"]["camera"]["devices"]: # Iterate through each video device specified in the configuration.
if (os.path.exists(config["realtime"]["image"]["camera"]["devices"][device]) == False): # Check to make sure that a camera device points to a valid file.
display_message("The 'realtime>image>camera>devices>" + device + "' configuration value does not point to a valid file.", 3)


# Load the license plate history file.
Expand Down Expand Up @@ -1450,7 +1449,7 @@
print("Displaying detected license plates...")

for plate in new_plates_detected:
play_sound("notification")
utils.play_sound("alpr_notification")
if (config["realtime"]["interface"]["display"]["output_level"] >= 2): # Only display this status message if the output level indicates to do so.
print("Plates detected: " + str(len(new_plates_detected))) # Display the number of license plates detected this round.
for plate in new_plates_detected:
Expand Down Expand Up @@ -1553,7 +1552,7 @@
if (config["realtime"]["interface"]["display"]["shape_alerts"] == True): # Check to see if the user has enabled shape notifications.
display_shape("triangle") # Display an ASCII triangle in the output.

play_sound("alert") # Play the alert sound, if configured to do so.
utils.play_sound("alpr_alert") # Play the alert sound, if configured to do so.

if (config["realtime"]["interface"]["display"]["output_level"] >= 3): # Only display this status message if the output level indicates to do so.
print("Done.\n----------")
Expand Down
Loading

0 comments on commit 06a2322

Please sign in to comment.