Skip to content

Commit

Permalink
make fan-control support rock5B
Browse files Browse the repository at this point in the history
  • Loading branch information
pymumu committed Oct 20, 2022
1 parent 5bdd275 commit bfb289a
Show file tree
Hide file tree
Showing 17 changed files with 740 additions and 197 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.o
*.deb
systemd/fan-control.service
src/fan-control
src/*.o
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Nick Peng
Copyright (c) 2022 Nick Peng

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
60 changes: 52 additions & 8 deletions Makefile
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,14 +1,58 @@
# MIT License

.PHONY:all
CFLAGS= -O2 -Wall
# Copyright (c) 2022 Nick Peng

all: fan-control
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

PKG_CONFIG := pkg-config
DESTDIR :=
PREFIX := /usr
SBINDIR := $(PREFIX)/sbin
SYSCONFDIR := /etc
RUNSTATEDIR := /var/run
SYSTEMDSYSTEMUNITDIR := $(shell ${PKG_CONFIG} --variable=systemdsystemunitdir systemd)
FAN_CONTROL_SYSTEMD = systemd/fan-control.service

.PHONY: all clean install FAN_CONTROL_BIN package
all: package

FAN_CONTROL_BIN: $(FAN_CONTROL_SYSTEMD)
$(MAKE) $(MFLAGS) -C src all

$(FAN_CONTROL_SYSTEMD): systemd/fan-control.service.in
cp $< $@
sed -i 's|@SBINDIR@|$(SBINDIR)|' $@
sed -i 's|@SYSCONFDIR@|$(SYSCONFDIR)|' $@
sed -i 's|@RUNSTATEDIR@|$(RUNSTATEDIR)|' $@

package: FAN_CONTROL_BIN
cd package && ./make.sh -o $(shell pwd)

clean:
$(RM) fan-control *.o
$(MAKE) $(MFLAGS) -C src clean
$(RM) $(FAN_CONTROL_SYSTEMD)
$(RM) fan-control*.deb

fan-control: fan-control.o
$(CC) $(CFLAGS) $^ -o $@ -lwiringPi
install: FAN_CONTROL_BIN
install -v -m 0640 -D -t $(DESTDIR)$(SYSCONFDIR)/default etc/default/fan-control
install -v -m 0755 -D -t $(DESTDIR)$(SYSCONFDIR)/init.d etc/init.d/fan-control
install -v -m 0640 -D -t $(DESTDIR)$(SYSCONFDIR)/fan-control etc/fan-control/fan-control.conf
install -v -m 0755 -D -t $(DESTDIR)$(SBINDIR) src/fan-control
install -v -m 0644 -D -t $(DESTDIR)$(SYSTEMDSYSTEMUNITDIR) systemd/fan-control.service

%.o : %.c
$(CC) $(CFLAGS) -c $< -o $@
12 changes: 10 additions & 2 deletions ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
Fan-control
==============

A tool to control fan speed by temperature automatically for Raspberry PI by using PWM pin.
A tool to control fan speed by temperature automatically for ROCK5B.

Features
--------------
1. Control fan speed by temperature.
2. set fan speed manually

Build & install
==============
```shell
make package
dpkg -i fan-control*.deb
```

Usage
==============
```shell
./fan-control -d
systemctl enable fan-control
systemctl start fan-control
```

License
Expand Down
111 changes: 111 additions & 0 deletions etc/init.d/fan-control
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/bin/sh
#
# MIT License

# Copyright (c) 2022 Nick Peng

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

### BEGIN INIT INFO
# Provides: fan-control
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Start fan-control service
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin

FAN_CONTROL=/usr/sbin/fan-control
PIDFILE=/run/fan-control.pid

test -x $FAN_CONTROL || exit 5

case $1 in
start)
$FAN_CONTROL -d -p $PIDFILE
while true; do
if [ -e "$PIDFILE" ]; then
break;
fi
sleep .5
done
PID="$(cat $PIDFILE 2>/dev/null)"
if [ -z "$PID" ]; then
echo "start fan-control service failed."
exit 1
fi
if [ ! -e "/proc/$PID" ]; then
echo "start fan-control service failed."
exit 1
fi
echo "start fan-control service success."
;;
stop)
if [ ! -f "$PIDFILE" ]; then
echo "fan-control service is stopped."
exit 0
fi
PID="$(cat $PIDFILE 2>/dev/null)"
if [ ! -e "/proc/$PID" ] || [ -z "$PID" ]; then
echo "fan-control service is stopped"
exit 0
fi

kill -TERM "$PID"
if [ $? -ne 0 ]; then
echo "Stop fan-control service failed."
exit 1;
fi
LOOP=1
while true; do
if [ ! -d "/proc/$PID" ]; then
break;
fi

if [ $LOOP -gt 12 ]; then
kill -9 "$PID"
break;
fi
LOOP=$((LOOP+1))
sleep .5
done
echo "Stop fan-control service success."
;;
restart)
"$0" stop && "$0" start
;;
status)
PID="$(cat "$PIDFILE" 2>/dev/null)"
if [ ! -e "/proc/$PID" ] || [ -z "$PID" ]; then
echo "fan-control service is not running."
exit 1
fi
echo "fan-control service is running."
status=$?
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 2
;;
esac

exit $status

0 comments on commit bfb289a

Please sign in to comment.