#!/bin/bash

# NOTES:
#  - Variable names must start at the beginning of a line.
#  - There should be nothing after a variable's value, i.e., no comments on the same line.
#  - Values can optionally be quoted with double quotes, NOT single quotes.
#  - If a variable occurs multiple times, only the last value is used.

# Choose between "ZWO" or "RPiHQ".  Note that "auto" is no longer allowed.
CAMERA="RPiHQ"

# Additional parameter - mode mean
#ADD_PARAMS="$ADD_PARAMS -mode 1 -mean-value 0.50 -mean-threshold 0.02 -mean-shuttersteps 6 -mean-fastforward 4.0 -mean-longplay 0 -mean-historySize 3 -mean-maskHorizon 0 -mean-info 1"
ADD_PARAMS="$ADD_PARAMS -mode 1 -mean-info 2"


########## Images
# Set to "true" to upload the current image to your website.
IMG_UPLOAD="false"

# If UPLOAD_IMG is "true", upload images every IMG_UPLOAD_FREQUENCY frames, e.g., every 5 frames.
# 0 uploades every frame.
IMG_UPLOAD_FREQUENCY=0

# The websites look in IMG_DIR for the current image.
# When using the Allsky website from the "allsky-website" packge, "allsky" is an
# alias for "/var/www/html/allsky/"  and   "current" is an alias for "/home/pi/allsky".
# If you use "current" and have the Allsky website, prepend "/current/" to
# the "imageName" in /var/www/html/allsky/config.js, for example:  imageName: "/current/image.jpg",
# Using "current" avoids copying the image to the website.
IMG_DIR="current"

# Set an optional prefix on the image file name, before "$FILENAME.$EXTENSION".
# This must match what the local web site thinks the name is (see /var/www/html/allsky/config.js).
IMG_PREFIX="liveview-"
MEAN_INFO=2

# Resize images before cropping and saving.
# Adjust IMG_WIDTH and IMG_HEIGHT according to your camera's sensor ratio.
IMG_RESIZE="true"
IMG_WIDTH=2028
IMG_HEIGHT=1520

# Crop images, used to improve them when using a fisheye lens.
CROP_IMAGE="false"
CROP_WIDTH=640
CROP_HEIGHT=480
CROP_OFFSET_X=0
CROP_OFFSET_Y=0

# Auto stretch images saved at night.
AUTO_STRETCH="false"
AUTO_STRETCH_AMOUNT=10
AUTO_STRETCH_MID_POINT="10%"

# Resize uploaded images.  Change the size to fit your sensor.
RESIZE_UPLOADS="false"
RESIZE_UPLOADS_SIZE="962x720"

# Remove corrupt images before generating keograms and startrails.
# This can take tens of minutes to run and isn't necessary unless your system produces
# corrupt images which then generate funny colors in the summary images...
REMOVE_BAD_IMAGES="false"

# If REMOVE_BAD_IMAGES is "true", images whose mean brightness is
# less than THRESHOLD_LOW or greater than THRESHOLD_HIGH percent (max: 100) will be removed.
# Set to 0 to disable the brightness checks.
REMOVE_BAD_IMAGES_THRESHOLD_LOW=1
REMOVE_BAD_IMAGES_THRESHOLD_HIGH=90


########## Timelapse
# Set to "true" to generate a timelapse video at the end of each night.
TIMELAPSE="true"

# Set the image width and height for timelapse video (sizes must be divisible by 2).
TIMELAPSEWIDTH=0
TIMELAPSEHEIGHT=0

# Bitrate of the timelapse video.  Higher numbers will produce higher quality but larger files.
TIMELAPSE_BITRATE="15000k"

# Timelapse video Frames Per Second.
FPS=25

# Encoder for timelapse video. May be changed to use a hardware encoder or different codec.
VCODEC="libx264"

# FFLOG determines the amount of log information displayed while creating a timelapse video.
# Set to "info" to see additional information if you are tuning the algorithm.
FFLOG="warning"

# While creating a timelapse video, a sequence of links to the images is created.
# Set to "true" to keep that sequence; set to "false" to have it deleted when done.
KEEP_SEQUENCE="false"

# Any additional timelapse parameters.  Run "ffmpeg -?" to see the options.
TIMELAPSE_PARAMETERS=""

# Set to "true" to upload timelapse video to your website at the end of each night.
UPLOAD_VIDEO="false"


########## Keogram
# Set to "true" to generate a keogram at the end of each night.
KEOGRAM="true"

# Additional Keogram parameters.  Run "keogram --help" to see the options.
# Keograms work best if North is at the top of the image.  If this is not the case you can
# rotate the image; for example, if North is straight down in your image, rotate it 180 degrees.
# Rotation is anticlockwise. 0 disables rotation.
KEOGRAM_EXTRA_PARAMETERS="--rotate 0 --font-size 1.0 --font-line 1 --font-color '255 255 255'"
KEOGRAM_ADD_PARAMS="-fontsize 2.0 -fontline 2 -fontcolor 255 255 255"

# Set to "true" to upload the keogram to your website at the end of each night.
UPLOAD_KEOGRAM="false"


########## Startrails
# Set to "true" to generate a startrails image of each night.
STARTRAILS="true"

# Images with a brightness higher than this threshold will be skipped for
# startrails image generation.  Values are 0.0 to 1.0.
BRIGHTNESS_THRESHOLD=0.3

# Set to "true" to upload the startrails image to your website at the end of each night.
UPLOAD_STARTRAILS="false"


########## Other
# Size of thumbnails.
THUMBNAIL_SIZE_X=100
THUMBNAIL_SIZE_Y=75

# Set to "true" to enable automatic deletion of archived data (images + videos).
AUTO_DELETE="true"

# If AUTO_DELETE="true", set this value to the number of archived nights you want to keep.
NIGHTS_TO_KEEP=30

# Set to "true" to upload data to your server at the end of each night.
POST_END_OF_NIGHT_DATA="false"

# Set to "true" if you want to enable dark frame subtraction on your night-time images.
# You must first create dark frames - see the README.md file for instructions.
DARK_FRAME_SUBTRACTION="false"

# Set to "false" to disable daytime capture.
DAYTIME_CAPTURE="true"

# Night images are always taken and saved to disk.
# Setting DAYTIME_SAVE to "true" also saves daytime images to disk.
# Will only save daytime images if DAYTIME_CAPTURE="true".
DAYTIME_SAVE="false"

# The uhubctl command can reset the USB bus if the camera isn't found and you know it's there.
# Allsky.sh uses this to try and fix "missing" cameras.
# Specify the path to the command and the USB bus number (on a Pi 4, bus 1 is USB 2.0 and
# bus 2 is the USB 3.0 ports).  If you don't have 'uhubctl' installed set UHUBCTL_PATH="".
UHUBCTL_PATH=""
UHUBCTL_PORT=2

# Path to the camera settings (exposure, gain, delay, overlay, etc) files.
# Do not change unless you know what you are doing.
CAMERA_SETTINGS_DIR="/etc/raspap"

if [ "${CAMERA}" = "" ]; then
	echo "${RED}ERROR: Please set CAMERA in config/config.sh${NC}"
	exit 1
elif [ "${CAMERA}" = "auto" ]; then
	echo "${RED}ERROR: 'auto' is no longer a valid CAMERA type.  Please reset CAMERA in config/config.sh${NC}"
	exit 1
fi

# !!! The next few lines are for backwards compatibility and will be removed in the future - do not change !!!
UPLOAD_IMG="${IMG_UPLOAD}"	# UPLOAD_IMG is th eold name for IMG_UPLOAD
if [ "${DAYTIME_CAPTURE}" = "true" ]; then
	DAYTIME=1		# DAYTIME is the old name for DAYTIME_CAPTURE
else
	DAYTIME=0
fi
CAPTURE_24HR=${DAYTIME_SAVE}	# CAPTURE_24HR is the old name for DAYTIME_SAVE

if [[ ${CAMERA} == "auto" ]]; then
	# Restore currently saved autodiscovered camera type, if any.
	source "${ALLSKY_CONFIG}/autocam.sh"	# May reset ${CAMERA}
fi
if [[ ${CAMERA} != "auto" ]]; then
	CAMERA_SETTINGS="${CAMERA_SETTINGS_DIR}/settings_${CAMERA}.json"
 
	# So scripts can conditionally ouput messages; DO NOT CHANGE NEXT LINES.
	ALLSKY_DEBUG_LEVEL=$(jq -r '.debuglevel' "${CAMERA_SETTINGS}")
fi
ALLSKY_DEBUG_LEVEL=${ALLSKY_DEBUG_LEVEL:-0}
