-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup
executable file
·129 lines (113 loc) · 5.09 KB
/
setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
# adds additional digital inputs and relay outputs to the Raspberry Pi platforms
# the stock RPI Venus distribution includes two relays and two digital inputs
# adding the additional GPIO pins to /etc/venus/gpio_list
# makes additional digital inputs available
# all 5 defined digital inputs are activated by this script
#
# the Raspberry PI default is for the first 8 GPIO pins to have pull UPs
# and the remaining have pull DOWNs. This makes some digital input pins behave differently
# this script also installs a DT overlay that switches to pull UPs for all digital input pins
#
# Only the first relay can be assigned to a function: alarm, genertor start/stop or pump.
# Others are only provided manual on/off control from the menu.
# Six relays are supported. Only the first relay can be assigned to functions
# The remaining relays are manual on/off only.
# run manually initally, then called from reinstallMods
# to uninstall/deactivate, call this script with "uninstall" as first parameter
# original assignments for relays 5 and 6 create conflicts with interrypt pins
# on hat boards such as the Waveshare dual CANbus hats (regular and FD versions)
# An option in this setup script allows selection of different GPIO assignments
# for relays 5 and 6 to avoid these conflicts
#
# Because this conflict will be rare, the option is considered optional.
# That is, an automatic install WILL be permitted even if a manual install has not
# been perfomred.
#
# VeCanSetup will alert the user of conflicts and prevent installing the second
# CANbus interface until this script is rerun to move the relay assignments.
# Note, this script DOES require a system reboot.
gpioListFile="/etc/venus/gpio_list"
rulesFile="/etc/udev/rules.d/wscanrs485.rules"
overlayFile="/u-boot/overlays/sc16is752-spi1.dtbo"
configFile="/u-boot/config.txt"
#### following lines incorporate SetupHelper utilities into this script
# Refer to the SetupHelper ReadMe file for details.
source "/data/SetupHelper/CommonResources"
#### end of lines to include SetupHelper
####### this is duplicate to code in CommonResources -- keep in case SetupHelepr has not been updated
# prevent installing if not a Raspberry Pi
if [ -f /etc/venus/machine ]; then
machine=$(cat /etc/venus/machine)
fi
if [ -z $machine ]; then
if [ -f "$installedFlag" ]; then
logMessage "can't determine Venus device type - uninstalling"
scriptAction='UNINSTALL'
else
logMessage "can't determine Venus device type - exiting"
exit $INCOMPATIBLE_PLATFORM
fi
elif [ $machine != "raspberrypi2" ] && [ $machine != "raspberrypi4" ]; then
if [ -f "$installedFlag" ]; then
logMessage "$packageName not compatible with $machine - uninstalling"
scriptAction='UNINSTALL'
else
logMessage "$packageName not compatible with $machine - exiting"
exit $INCOMPATIBLE_PLATFORM
fi
fi
#### running manually and OK to proceed - prompt for input
if [ $scriptAction == 'NONE' ] ; then
# display innitial message
echo
echo "This package makes the following modifications:"
echo " - modifies the GPIOs for digital inputs and relay output (relay_1 GPIO 21 -> 16)"
echo " - relay_1 Pin 40 / GPIO 21 -> Pin 36 / GPIO 16"
echo " - digital_input_4 Pin 35 / GPIO 19 -> Pin 26 / GPIO 7"
echo " - digital_input_6 (shutdown pin) Pin 36 / GPIO 16"
echo " - installs the overlay file for the SC16IS752 controller (RS485)"
echo " - installs the udev rules to use the RS485 ports in Venus OS"
echo " - activates the overlays in config.txt"
echo
yesNoPrompt "Do you want to continue (y/n)?: "
if $yesResponse ; then
scriptAction='INSTALL'
fi
fi
#### installing
if [ $scriptAction == 'INSTALL' ] ; then
updateActiveFile "$gpioListFile"
updateActiveFile "$rulesFile"
# install overlay only if it doesn't exist
[ -f "$overlayFile" ] || updateActiveFile "$overlayFile"
if [ $(grep -c "CAN+RS485 overlay" "$configFile") == 0 ]; then
logMessage "activating CAN+RS485 DT overlay"
echo "#### begin CAN+RS485 overlay" >> "$configFile"
echo "dtparam=spi=on" >> "$configFile"
echo "dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25,,spimaxfrequency=1000000" >> "$configFile"
echo "dtoverlay=sc16is752-spi1,int_pin=24" >> "$configFile"
echo "gpio=16=ip,pu" >> "$configFile"
echo "#### end CAN+RS485 overlay" >> "$configFile"
filesUpdated=true
fi
fi
# uninstalling - check scriptAction again
# if an install step failed package needs to be removed
if [ $scriptAction == 'UNINSTALL' ] ; then
restoreActiveFile "$gpioListFile"
restoreActiveFile "$rulesFile"
restoreActiveFile "$overlayFile"
# remove mods from configFile - do not use restore in case other mods were made manually
if [ -f "$configFile" ]; then
if [ $(grep -c "#### begin CAN+RS485 overlay" "$configFile") != 0 ]; then
sed -i -e '/#### begin CAN+RS485 overlay/,/#### end CAN+RS485 overlay/d' "$configFile"
filesUpdated=true
fi
fi
fi
if $filesUpdated ; then
rebootNeeded=true
fi
# thats all folks - SCRIPT EXITS INSIDE THE FUNCTION
endScript