#!/bin/bash

# printf parameters information
print_info()
{
echo "Usage:sudo ./DSI-1024x600-show"
echo "Usage:sudo ./DSI-1024x600-show i2c0"
echo "Usage:sudo ./DSI-1024x600-show i2c1"
echo "Usage:sudo ./DSI-1024x600-show i2c1 dsi0"
echo "Usage:sudo ./DSI-1024x600-show i2c0 dsi0"
echo "i2c0--Using I2C0 bus"
echo "i2c1--Using I2C1 bus"
echo "dsi0--Using DSI0 interface"
echo "DSI uses DSI1 interface by default"
echo "If there are no parameters, I2C0 bus and DSI1 interface will be used by default"
}

#clean *.o files
if ls *.o > /dev/null 2>&1; then
        sudo make clean
fi

#configue config.txt
sudo sed -i "/vc4-kms-dsi-qdtft-panel/d" /boot/firmware/config.txt

if [ $# -eq 0 ]; then
sudo echo "dtoverlay=vc4-kms-dsi-qdtft-panel" >> /boot/firmware/config.txt
elif [ $# -eq 1 ]; then
if [ "$1" == "i2c0" ] || [ "$1" == "i2c1" ]; then
sudo echo "dtoverlay=vc4-kms-dsi-qdtft-panel,$1" >> /boot/firmware/config.txt
else
echo "Invalid parameter"
print_info
exit
fi
elif [ $# -eq 2 ]; then
if [ "$1" == "i2c0" ] || [ "$1" == "i2c1" ]; then
if [ "$2" == "dsi0" ]; then
sudo echo "dtoverlay=vc4-kms-dsi-qdtft-panel,$1,$2" >> /boot/firmware/config.txt
else
echo "Invalid parameter"
print_info
exit
fi
else
echo "Invalid parameter"
print_info
exit
fi
else
print_info
echo "Too many parameters, Up to two parameters are allowed"
exit
fi


#compile driver
sudo make
sudo make install
sudo reboot
