#!/bin/sh
#
# Load/unload cdc-acm driver for the 5D module USB serial port
#

MODULE=/mnt/UDISK/drivers/cdc-acm.ko
PORT=/dev/ttyACM0

case "$1" in
  start)
	echo "Loading cdc-acm..."
	[ -d /sys/module/cdc_acm ] || insmod "$MODULE"
	# wait for the 5D module port before klipper starts
	for i in 1 2 3 4 5; do
		[ -e "$PORT" ] && break
		sleep 1
	done
	;;
  stop)
	echo "Unloading cdc-acm..."
	[ -d /sys/module/cdc_acm ] && rmmod cdc_acm
	;;
  restart)
	"$0" stop
	sleep 1
	"$0" start
	;;
  *)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
esac
