forked from DeskPi-Team/deskpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deskpi-config
executable file
·98 lines (95 loc) · 3.92 KB
/
deskpi-config
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
#!/bin/bash
# This is a fan speed control utility tool for user to customize fan speed.
# Priciple: send speed argument to the MCU
# Technical Part
# There are four arguments:
# pwm_025 means sending 25% PWM signal to MCU. The fan will run at 25% speed level.
# pwm_050 means sending 50% PWM signal to MCU. The fan will run at 50% speed level.
# pwm_075 means sending 75% PWM signal to MCU. The fan will run at 75% speed level.
# pwm_100 means sending 100% PWM signal to MCU.The fan will run at 100% speed level.
#
. /lib/lsb/init-functions
# This is the serial port that connect to deskPi mainboard and it will
# communicate with Raspberry Pi and get the signal for fan speed adjusting.
serial_port='/dev/ttyUSB0'
# Stop deskpi.service so that user can define the speed level.
sudo systemctl stop deskpi.service
# Define the function of set_config
function set_config() {
if [ -e /etc/deskpi.conf ]; then
sudo sh -c "rm -f /etc/deskpi.conf"
fi
sudo touch /etc/deskpi.conf
sudo chmod 777 /etc/deskpi.conf
log_action_msg "Under normal circumstances, we recommend four gears. The
following requires you to control the fan's operating status according to
the temperature and speed defined by yourself, and you need to input 4
different temperature thresholds (for example: 42, 50, 60, 70) , And 4 PWM
values of different speeds parameters(for example 25, 50, 75, 100, this is the default
value),you can define the speed level during 0-100."
for i in `seq 1 4`;
do
echo -e "\e[32;40mCurrent CPU Temperature:\e[0m \e[31;40m`vcgencmd measure_temp`\e[0m\n"
read -p "Temperature_threshold_$i:" temp
read -p "Fan_Speed level_$i:" fan_speed_level
sudo sh -c "echo $temp" >> /etc/deskpi.conf
sudo sh -c "echo $fan_speed_level" >> /etc/deskpi.conf
done
log_action_msg "Configuration file has been created on /etc/deskpi.conf"
}
# Greetings and information for user.
log_action_msg "Welcome to Use DeskPi-Team's Product"
log_action_msg "Please select speed level that you want: "
log_action_msg "It will always run at the speed level that you choosed."
log_action_msg "---------------------------------------------------------------"
log_action_msg "1 - set fan speed level to 25%"
log_action_msg "2 - set fan speed level to 50%"
log_action_msg "3 - set fan speed level to 75%"
log_action_msg "4 - set fan speed level to 100%"
log_action_msg "5 - Turn off Fan"
log_action_msg "6 - Adjust the start speed level according to the temperature"
log_action_msg "7 - Cancel manual control and enable automatical fan control"
log_action_msg "---------------------------------------------------------------"
log_action_msg "Just input the number and press enter."
read -p "Your choice:" levelNumber
case $levelNumber in
1)
log_action_msg "You've select 25% speed level"
sudo sh -c "echo pwm_025 > $serial_port"
log_action_msg "Fan speed level has been change to 25%"
;;
2)
log_action_msg "You've select 50% speed level"
sudo sh -c "echo pwm_050 > $serial_port"
log_action_msg "Fan speed level has been change to 50%"
;;
3)
log_action_msg "You've select 75% speed level"
sudo sh -c "echo pwm_075 > $serial_port"
log_action_msg "Fan speed level has been change to 75%"
;;
4)
log_action_msg "You'tve select 100% speed level"
sudo sh -c "echo pwm_100 > $serial_port"
log_action_msg "Fan speed level has been change to 100%"
;;
5)
log_action_msg "Turn off fan"
sudo sh -c "echo pwm_000 > $serial_port"
log_action_msg "Fan speed level has been turned off."
;;
6)
log_action_msg "Customizing the start speed level according the temperature"
sudo systemctl stop deskpi.service &
set_config
sudo systemctl start deskpi.service &
;;
7)
log_action_msg "Cancel manual control and enable automatical fan control"
sudo systemctl start deskpi.service &
;;
*)
log_action_msg "You type the wrong selection, please try again!"
. /usr/bin/deskpi-config
;;
esac