#!/bin/sh
#
# Manage analog channel calibration.
#

. /opt/puzzlefw/lib/functions.sh

# Copy calibration file to the SD card.
cal_save() {

    # Lock to avoid conflicting changes.
    lock_config || exit 1

    echo "Copying changed calibration to SD card ..."

    sync_config calibration.conf || exit 1
}

case "$1" in
  show)
    cat ${CONFIG_DIR}/calibration.conf
    ;;
  save)
    cal_save
    ;;
  *)
    script="${0##*/}"
    cat <<EOF
Usage: $script {show|save}

Manage analog channel calibration.

  $script show
    Display calibration.

  $script save
    Copy a changed calibration file to the SD card.
    Before running this command, the changed calibration must be written to
    ${CONFIG_DIR}/calibration.conf.new.

EOF
    exit 1
    ;;
esac

exit $?