From b3a507404cb5c0c452a20be76dd2e0bd585736ef Mon Sep 17 00:00:00 2001 From: yoyojacky Date: Thu, 9 May 2024 17:58:28 +0800 Subject: [PATCH 1/8] Update installation script for bookworm 64bit --- installation/README.md | 9 + installation/drivers/README.md | 39 +++++ installation/drivers/c/Makefile | 16 ++ installation/drivers/c/pwmControlFan.c | 205 +++++++++++++++++++++++ installation/drivers/c/pwmControlFan64 | Bin 0 -> 71408 bytes installation/drivers/c/safecutoffpower.c | 79 +++++++++ installation/drivers/c/safecutoffpower64 | Bin 0 -> 70856 bytes installation/install.sh | 163 ++++++++++++++++++ installation/uninstall.sh | 69 ++++++++ 9 files changed, 580 insertions(+) create mode 100644 installation/README.md create mode 100644 installation/drivers/README.md create mode 100644 installation/drivers/c/Makefile create mode 100644 installation/drivers/c/pwmControlFan.c create mode 100755 installation/drivers/c/pwmControlFan64 create mode 100644 installation/drivers/c/safecutoffpower.c create mode 100755 installation/drivers/c/safecutoffpower64 create mode 100755 installation/install.sh create mode 100755 installation/uninstall.sh diff --git a/installation/README.md b/installation/README.md new file mode 100644 index 0000000..7ad2593 --- /dev/null +++ b/installation/README.md @@ -0,0 +1,9 @@ +# Installation script for Raspberry Pi OS 64bit bookworm +## How to install driver by using shell script +```bash +cd ~ +git clone -b feature/bookworm https://github.com/deskpi-team/deskpi +cd deskpi/installation/ +sudo ./install.sh +``` + diff --git a/installation/drivers/README.md b/installation/drivers/README.md new file mode 100644 index 0000000..23a5949 --- /dev/null +++ b/installation/drivers/README.md @@ -0,0 +1,39 @@ +# Control Your Fan througn PWM signal via Serial port(OTG) +## Configure /boot/config.txt to enbale otg function. +```bash +sudo vim.tiny /boot/firmware/config.txt +``` +add: +```bash +dtoverlay=dwc2,dr_mode=host +``` +save it and reboot Raspberry Pi. +## C Language +* 1. At First, get the demo code from github. +```bash +cd ~ +git clone -b feature/bookworm https://github.com/DeskPi-Team/deskpi.git +cd ~/deskpi/installation/drivers/c/ +``` +* 2. How to compile it. +```bash +make +``` +* 3. How to run it. +```bash +sudo ./pwmFanControl64 +``` +* 4. How to stop it. +Press "Ctrl + C" on keyboard. +* 5. How to clean the source code directory. +```bash +make clean +``` +## How to change speed of the fan. +This program is send the pwm signal from Raspberry Pi to the extension board via OTG serial port, which will be recognized by your Raspberry Pi as "/dev/ttyUSB0" device. so if you want to control the fan as your wish, you can modify pwmControlFan.c code and recompile it. +* In the default code, we have set 4 level for you Fan on pwm signal: +* Level 0: 0% speed-> send "pwm_000" to /dev/ttyUSB0", means to turn off the fan +* Level 1: 25% speed-> send "pwm_025" to /dev/ttyUSB0", means to set fan speed to 25% +* Level 2: 50% speed-> send "pwm_050" to /dev/ttyUSB0", means to set fan speed to 50% +* Level 3: 75% speed-> send "pwm_075" to /dev/ttyUSB0", means to set fan speed to 75% +* Level 4:100% speed-> send "pwm_100" to /dev/ttyUSB0", means to set fan speed to 100% diff --git a/installation/drivers/c/Makefile b/installation/drivers/c/Makefile new file mode 100644 index 0000000..7d442b4 --- /dev/null +++ b/installation/drivers/c/Makefile @@ -0,0 +1,16 @@ +DEFAULT: all +.PHONY: install + +all: pwmControlFan64 safecutoffpower64 + +install: + sudo sh -c "sudo chmod 755 pwmControlFan64 safecutoffpower64" + sudo sh -c "sudo cp pwmControlFan64 safecutoffpower64 /usr/bin/" + sudo sh -c "sudo chcon -u system_u -t bin_t /usr/bin/pwmControlFan64 /usr/bin/safecutoffpower64" + +pwmControlFan64: pwmControlFan.c + gcc -o pwmControlFan64 pwmControlFan.c +safecutoffpower64: safecutoffpower.c + gcc -o safecutoffpower64 safecutoffpower.c +clean: + rm -rf safecutoffpower64 pwmControlFan64 diff --git a/installation/drivers/c/pwmControlFan.c b/installation/drivers/c/pwmControlFan.c new file mode 100644 index 0000000..d4f544b --- /dev/null +++ b/installation/drivers/c/pwmControlFan.c @@ -0,0 +1,205 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//#define TEST_MODE +#define PERCENTAGE 10 // switch over percentage range + + +static int serial_port=0; +/* initialized the serial port*/ +int init_serial( char *serial_name) +{ + serial_port = open(serial_name, O_RDWR); + + if (serial_port < 0){ + printf("Can not open /dev/DeskPi_FAN serial port ErrorCode: %s\n", strerror(errno)); + printf("Please check udev file in /etc/udev/rules.d/10-deskpi.rules"); + printf("Please check the /boot/firmware/config.txt file and add dtoverlay=dwc2, dr_mode=host and reboot RPi \n"); + } + + struct termios tty; + + if(tcgetattr(serial_port, &tty) !=0){ + printf("Please check serial port over OTG\n"); + } + + tty.c_cflag &= ~PARENB; + tty.c_cflag |= PARENB; + tty.c_cflag &= ~CSTOPB; + tty.c_cflag |= CSTOPB; + + tty.c_cflag |= CS5; + tty.c_cflag |= CS6; + tty.c_cflag |= CS7; + tty.c_cflag |= CS8; + + tty.c_cflag &= ~CRTSCTS; + tty.c_cflag |= CRTSCTS; + + tty.c_cflag |= CREAD | CLOCAL; + + tty.c_lflag &= ~ICANON; + tty.c_lflag &= ~ECHO; + tty.c_lflag &= ~ECHOE; + tty.c_lflag &= ~ECHONL; + tty.c_lflag &= ~ISIG; + + tty.c_iflag &= ~(IXON | IXOFF | IXANY); + tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL); + + tty.c_oflag &= ~OPOST; + tty.c_oflag &= ~ONLCR; + + tty.c_cc[VTIME] = 10; + tty.c_cc[VMIN] = 0; + + cfsetispeed(&tty, B9600); + cfsetospeed(&tty, B9600); + + if (tcsetattr(serial_port, TCSANOW, &tty) !=0){ + printf("---Serial Port Can not detected---\n"); + } + return 0; +} + +/* send data to serial port function*/ +int send_serial(char *data,size_t data_len) +{ + return write(serial_port, data, data_len); +} + +/* close the serial port function*/ +int __init_serial() +{ + return close(serial_port); +} +/* read cpu temperature function */ +unsigned int read_cpu_tmp() +{ + FILE *fp=NULL; + unsigned int cpu_temp=0; + char buff[255]; + bzero(buff, sizeof(buff)); + fp = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); + if( NULL != fp) + { + if (fgets(buff, 255, (FILE*)fp) != NULL){ + cpu_temp = atoi(buff) /1000 ; + } + fclose(fp); + } + return cpu_temp; +} + +/* main loop */ +int main(void){ + int i=0; + FILE *fp=NULL; + char buffer[100]; + bzero(buffer, sizeof(buffer)); + + char data[8]={0}; + unsigned int conf_info[8]; + unsigned int cpu_temp=0; + unsigned int last_cpu_temp = 0; // last temperature level recorded + unsigned int min_temp = 0; // calculated minimum temperature based on percentage + init_serial("/dev/DeskPi_FAN"); + /* default configuration if /etc/deskpi.conf dose not exist */ + conf_info[0]=40; + conf_info[1]=25; + + conf_info[2]=50; + conf_info[3]=50; + + conf_info[4]=65; + conf_info[5]=75; + + conf_info[6]=75; + conf_info[7]=100; + + while(1) + { + fp = fopen("/etc/deskpi.conf", "r"); + if(fp != NULL) + { + for(i=0;i<8;i++) + { + bzero(buffer, sizeof(buffer)); + if (fgets(buffer, 100, fp) != NULL) + { + conf_info[i] = atoi(buffer); + } + } + fclose(fp); + } + + /* Testing section + for(i=0;i<8;i++) + { + printf("temp:%d\n",conf_info[i]); + i++; + printf("pwm:%d\n",conf_info[i]); + } + */ + cpu_temp = read_cpu_tmp(); + #ifdef TEST_MODE + printf("cpu_temp:%d / last_cpu_temp:%d / fan_speed:", cpu_temp, last_cpu_temp); + #endif + + if (last_cpu_temp == 0 || cpu_temp > last_cpu_temp) { + if(cpu_temp < conf_info[0]) + { + memcpy( (char *) &data, "pwm_000", sizeof("pwm_000")); + last_cpu_temp = 0; + } + else if(cpu_temp >= conf_info[0] && cpu_temp < conf_info[2]) + { + sprintf((char *)&data, "pwm_%03d", conf_info[1]); + last_cpu_temp = conf_info[0]; + } + else if(cpu_temp >= conf_info[2] && cpu_temp < conf_info[4]) + { + sprintf((char *)&data, "pwm_%03d", conf_info[3]); + last_cpu_temp = conf_info[2]; + } + else if(cpu_temp >= conf_info[4] && cpu_temp < conf_info[6]) + { + sprintf((char *)&data, "pwm_%03d", conf_info[5]); + last_cpu_temp = conf_info[4]; + } + else if(cpu_temp >= conf_info[6]) + { + sprintf((char *)&data, "pwm_%03d", conf_info[7]); + last_cpu_temp = conf_info[6]; + } + send_serial((char *) &data, sizeof(data)); + #ifdef TEST_MODE + printf("*"); + #endif + } + + // leave fan speed as is if not within pre defined percentage + min_temp = last_cpu_temp - round(last_cpu_temp * PERCENTAGE / 100); + if (cpu_temp < min_temp) { + last_cpu_temp = 0; // reset level + } + + #ifdef TEST_MODE + printf("%s", data); + printf(" until min_temp:%d", min_temp); + printf("\n"); + #endif + + sleep(1); + } + __init_serial(); + return 0; +} diff --git a/installation/drivers/c/pwmControlFan64 b/installation/drivers/c/pwmControlFan64 new file mode 100755 index 0000000000000000000000000000000000000000..3c1fffc7b557936209da61cab8900b09689aae8e GIT binary patch literal 71408 zcmeHMeQ;dWbw9f+8{6`S`~f!DmY$769D`T>sxbt@>cf@|{;DiGbOL#L+I^C?UhP}n zKH2g|8$oC%2^q#3NaK{TacKT91{$X0X)MyI6{e-0hM9U`l5r;=tOUt0EwqM^6a~cg zocHco-F>@DnQ8y%bk6lWoqK-woO93p-H*5L`pesQ?}$bsz$FIX2VbiXkc4V@VZpRb z0=B_yNWe;10W-0^4j;A)%MX+r%UNhkC58|AZHtmtDVGN@u;kuJ&QNXD#M)~ElqCeC z@&8h;m!^XDOH)BamRD6CA1KLwq>|qi<#$E-u`H;>Sn~L2Z1i-gcwyO&ZB$s2EtUPh z^iov+?qXl9koN~Luw=jAM?cE*)0PHh*s1!f#Y=d8cpjQF>7M3HYJDc19UNM3S#Gj_ z>y~)liEj+Xy#(Xa9Cz%!7q0u~_NShG`A5csmwWGsWbS=^>tEO1M0ryV6pw7Eko`4& zEx@Ub`&00z5;3TUowF-VW3Uv?LTQ41gO&JqQKczdM9ipye;%>bRq(qJs}`rZ2A-{f z_tn6c)xfFGYW>pksfH83)$lLX!24_9KSkWYCtMy!pj!NI*TCo1z=vw!oi*@(MclwA zT<$@jT0Rfgz-hfzvxnY3+si{fW7|2%4Pv#|$=O-3JSPpNiMt_b<~_^x%mFK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8AFJNbh058H?5|99w1{fEcN{!Q4X7qX?IOJ2J{OYrxKvglVA w`}7`Z$A|ObeNEr@oO|FI{7uvcJ)}d8+%MbGe^-P|{HAB<1D@JK4j~o(3&x{WSpWb4 literal 0 HcmV?d00001 diff --git a/installation/drivers/c/safecutoffpower.c b/installation/drivers/c/safecutoffpower.c new file mode 100644 index 0000000..a5e009d --- /dev/null +++ b/installation/drivers/c/safecutoffpower.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define serial_fan "/dev/DeskPi_FAN" + +int main(void){ + while(1){ + int serial_port = open(serial_fan, O_RDWR); + if (serial_port < 0){ + printf("Can not access /dev/DeskPi_FAN which links to /dev/ttyUSB0, please check it out.\n"); + printf("Check /etc/udev/rules.d/10-deskpi.rules file"); + } + + struct termios tty; + + if(tcgetattr(serial_port, &tty) !=0){ + printf("serial port can not be accessed\n"); + } + + tty.c_cflag &= ~PARENB; + tty.c_cflag |= PARENB; + tty.c_cflag &= ~CSTOPB; + tty.c_cflag |= CSTOPB; + + tty.c_cflag |= CS5; + tty.c_cflag |= CS6; + tty.c_cflag |= CS7; + tty.c_cflag |= CS8; + + tty.c_cflag &= ~CRTSCTS; + tty.c_cflag |= CRTSCTS; + + tty.c_cflag |= CREAD | CLOCAL; + + tty.c_lflag &= ~ICANON; + tty.c_lflag &= ~ECHO; + tty.c_lflag &= ~ECHOE; + tty.c_lflag &= ~ECHONL; + tty.c_lflag &= ~ISIG; + + tty.c_iflag &= ~(IXON | IXOFF | IXANY); + tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL); + + tty.c_oflag &= ~OPOST; + tty.c_oflag &= ~ONLCR; + + tty.c_cc[VTIME] = 10; + tty.c_cc[VMIN] = 0; + + cfsetispeed(&tty, B9600); + cfsetospeed(&tty, B9600); + + if (tcsetattr(serial_port, TCSANOW, &tty) !=0){ + printf("Please check out /boot/firmware/config.txt file\n"); + } + + char data[10]; + data[0] = 'p'; + data[1] = 'o'; + data[2] = 'w'; + data[3] = 'e'; + data[4] = 'r'; + data[5] = '_'; + data[6] = 'o'; + data[7] = 'f'; + data[8] = 'f'; + data[9] = '\0'; + write(serial_port, data, sizeof(data)); + close(serial_port); + } + return 0; +} diff --git a/installation/drivers/c/safecutoffpower64 b/installation/drivers/c/safecutoffpower64 new file mode 100755 index 0000000000000000000000000000000000000000..e1de6924b56e235426958eb206ceffaabfb01a73 GIT binary patch literal 70856 zcmeI0e{5S<6~~X`tiO_WN!l%4(=~2ap>ArOv@2V}3Uhw6X<2`*%|_8AUZ3rk_)*99 z?3XodCl&@mzyLMcUCT`-KZ+WP+DzM1ruZ%n-;drob&EI z&h@iB4GI1`FLKU3-+Ruv_kP}e@A>(mtvk2Xg+jnb7=8)lO)gMMOm}>B@mx#{x?my1 z;6_*p^RT}jKO7gd@9H$Rx-5isURND9@Ce#AB?DU?o$NKbubO#ru~ONBzZ&(Q=6Y^c z^`Dzn71^HB^Ejg|=aEZ!mvr7GoyT@cPmC?EkC@PBP}d9Ee(a-zEydEY_cbp`?W>Kx zTVb~-8Q5~(-Iz!7{HRBh4&0~5tHmXFUidt8q}_N&I=Lb3W=6+0*mgdVx@~i`kd1Cs z>t2TS=^PL2z6XAP;==JQPtDu6YU-Bf7yS5#@BCy@_#(}l=0No*h7O9K@3)jreLS9) zKavSU103fhEC_IT6}*E z{imo$@Dn^76spxZR6{48)#C4~p?B5Le}j4iKf&YEC{(KtxlykG*_@LB%fh{runL}? z_pA}y%|K$P;CR_W&T*31n;5gLAva^E-J_1`a#dF%oh>+!%extG2)x9w$JSft@>g`>ajTjklMYw{8Y&$KWn2>ExYZx8OPX!CignY{nV1 z<7o%yFg%jY=owlnv}&MQeI4%7aOp4DRxu&mclTqHue--5zJpsJ49B!~+V|_=D=HlC zQ*@>kM5Z@Q3a+baVb)hEDea zK4ONhZ^eGsc0<>X8eiXQ=u5Z=+5?7ut)U+@^kzeEkA(j;d+c}5&W2&)UVz7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}RTGl6`5?`FG&1GNo~|BFCAzn`=HQ6N7!{v`GD z4BtXZ`TV|r{v+mJ!d$*KX+(ZcxTN!^^aaQJi^t`Ca2azbgy+xi4QKQleJ2$)4$f!$ zI`*0Q{5!){oj-2mQj_!8{u4DbpMQ@?`D*2U77eS!s2;C!iK73tMH_x4O$(~xMMtCVuoX6$ZW^7c; O|5Brh3 '$deskpi_rules_file' + ACTION==\"add\", ATTRS{$idVendor},ATTRS{$idProduct},SYMLINK+="DeskPi_FAN" + EOF" + sudo sh -c "sudo udevadm control --reload-rules" + sudo sh -c "sudo udevadm trigger" +fi + +# Remove old repository. +if [[ -d /tmp/deskpi ]]; then + rm -rf /tmp/deskpi* +fi + +if [[ -f $deskpi_service_file ]]; then + sudo sh -c "sudo systemctl stop deskpi.service" + sudo sh -c "sudo systemctl disable deskpi.service" + sudo sh -c "sudo rm -f $deskpi_service_file" + sudo sh -c "sudo systemctl daemon-reload" +fi + +if [[ -f $deskpi_powermanager_file ]]; then + sudo sh -c "sudo systemctl disable deskpi-cutoffpower.service" + sudo sh -c "sudo rm -f $deskpi_powermanager_file" +fi + +# Install git tool +pkgStatus=`sudo dpkg-query -l git |grep git | awk '{print $1}'` +if [[ $pkgStatus != 'ii' ]]; then + sudo sh -c "sudo apt-get update" + sudo sh -c "sudo apt-get -y install git-core" +fi + +# Check if dwc2 dtoverlay has been enabled. +checkResult=`grep dwc2 /boot/firmware/config.txt` +if [[ $? -ne 0 ]]; then + log_warning_msg "Adding dtoverlay=dwc2,dr_mode=host to /boot/firmware/config.txt file." + sudo sh -c "sudo sed -i '/dtoverlay=dwc2*/d' /boot/firmware/config.txt" + sudo sh -c "sudo sed -i '\$a\dtoverlay=dwc2,dr_mode=host' /boot/firmware/config.txt" + log_action_msg "check dwc2 overlay will be enabled after rebooting." +fi + +# Download deskpi driver +cd /tmp/ +if [[ ! -d /tmp/deskpi ]]; then + while [[ ! -d /tmp/deskpi ]]; + do + log_warning_msg "Could not able to download deskpi repo,will retry again." + sh -c "git clone https://github.com/DeskPi-Team/deskpi.git" + done +fi + + +# copy pre-compiled binary file to /usr/bin/ folder +# +if [[ -d /tmp/deskpi/ ]]; then + sudo sh -c "sudo mkdir -pv /usr/bin/deskpi/" + sudo sh -c "sudo cp -Rvf /tmp/deskpi/installation/drivers/c/pwmFanControl64 /usr/bin/deskpi/pwmFanControl64" + sudo sh -c "sudo cp -Rvf /tmp/deskpi/installation/drivers/c/safecutoffpower64 /usr/bin/deskpi/safecutoffpower64" + sudo sh -c "sudo cp -Rvf /tmp/deskpi/installation/deskpi-config /usr/bin/deskpi-config" + sudo sh -c "sudo chmod +x /usr/bin/deskpi/pwmFanControl64" + sudo sh -c "sudo chmod +x /usr/bin/deskpi/safecutoffpower64" + sudo sh -c "sudo chmod +x /usr/bin/deskpi-config" +fi + +# Genreate systemd service file +if [[ ! -e $deskpi_service_file ]]; then +sudo sh -c "sudo cat < '$deskpi_service_file' +[Unit] +Description=DeskPi Fan Control Service +After=multi-user.target +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/bin/deskpi/pwmFanControl64 +[Install] +WantedBy=multi-user.target + +EOF" + +fi + +# Send signal to MCU before system shutting down. +if [[ ! -e $deskpi_powermanager_file ]]; then + sudo sh -c "sudo cat < '$deskpi_powermanager_file' +[Unit] +Description=DeskPi cutoffpower service +Conflicts=reboot.target +Before=halt.target shutdown.target poweroff.target +DefaultDependencies=no +[Service] +Type=oneshot +ExecStart= /usr/bin/deskpi/safecutoffpower64 +RemainAfterExit=yes +[Install] +WantedBy=halt.target shutdown.target poweroff.target + +EOF" + +fi + +# Grant privilleges to root user. +if [[ -e $deskpi_service_file ]]; then + sudo sh -c "sudo chown root:root $deskpi_service_file" + sudo sh -c "sudo chmod 755 $deskpi_service_file" + log_action_msg "Load DeskPi service and load modules" + sudo sh -c "sudo systemctl enable $deskpi_service_file" + sudo sh -c "sudo systemctl start $deskpi_service_file" +fi + +if [[ -e $deskpi_powermanager_file ]]; then + sudo sh -c "sudo chown root:root $deskpi_powermanager_file" + sudo sh -c "sudo chmod 755 $deskpi_powermanager_file" + sudo sh -c "sudo systemctl enable $deskpi_powermanager_file" +fi + + +# Greetings +if [[ $? -eq 0 ]]; then + log_success_msg "Congratulations! DeskPi Pro driver has been installed successfully, Have Fun!" + log_success_msg "System will be reboot in 5 seconds to take effect." +else + log_success_warning "Could not download deskpi repository, please check the internet connection and try to execute it again!" + log_success_msg "Usage: ./install.sh" +fi + +sudo sh -c "sudo sync && sleep 5 && sudo reboot" diff --git a/installation/uninstall.sh b/installation/uninstall.sh new file mode 100755 index 0000000..b0cd5bc --- /dev/null +++ b/installation/uninstall.sh @@ -0,0 +1,69 @@ +#!/bin/bash +# Function: uninstall driver for DeskPi Pro + +# Define systemd service name +deskpi_service_file="/etc/systemd/system/deskpi.service" +deskpi_powermanager_file="/etc/systemd/system/deskpi-cutoffpower.service" + + +# Initializing message functions +if [[ -e /lib/lsb/init-functions ]]; then + . /lib/lsb/init-functions + log_action_msg "Initializing functions..." +fi + +# Remove udev rules of deskpi +deskpi_rules_file="/etc/udev/rules.d/10-deskpi.rules" + +if [[ -e $deskpi_rules_file ]]; then + sudo sh -c "sudo rm -f $deskpi_rules_file" + sudo sh -c "sudo udevadm control --reload-rules" + sudo sh -c "sudo udevadm trigger" +fi + +# Remove old repository. +if [[ -d /tmp/deskpi ]]; then + rm -rf /tmp/deskpi* +fi + + +if [[ -f $deskpi_service_file ]]; then + sudo sh -c "sudo systemctl stop deskpi.service" + sudo sh -c "sudo systemctl disable deskpi.service" + sudo sh -c "sudo rm -f $deskpi_service_file" + sudo sh -c "sudo systemctl daemon-reload" +fi + +if [[ -f $deskpi_powermanager_file ]]; then + sudo sh -c "sudo systemctl disable deskpi-cutoffpower.service" + sudo sh -c "sudo rm -f $deskpi_powermanager_file" + sudo sh -c "sudo systemctl daemon-reload" +fi + +# Check if dwc2 dtoverlay has been enabled. +checkResult=`grep dwc2 /boot/firmware/config.txt` +if [[ $? -ne 0 ]]; then + log_warning_msg "Adding dtoverlay=dwc2,dr_mode=host to /boot/firmware/config.txt file." +else + sudo sh -c "sudo sed -i '/dtoverlay=dwc2*/d' /boot/firmware/config.txt" + log_action_msg "Remove dtoverlay parameter from /boot/firmware/config.txt file." +fi + +# Remove /usr/bin/deskpi folder and /usr/bin/deskpi-config file +if [[ -d /usr/bin/deskpi/ ]]; then + sudo sh -c "sudo rm -rf /usr/bin/deskpi" + sudo sh -c "sudo rm -f /usr/bin/deskpi-config" + log_success_msg "/usr/bin/deskpi folder has been removed!" + log_success_msg "/usr/bin/deskpi-config file has been removed!" +fi + +# Greetings +if [[ $? -eq 0 ]]; then + log_success_msg "Farewell! DeskPi Pro driver has been removed successfully!" + log_success_msg "System will be reboot in 5 seconds to take effect." +else + log_warning_msg "Could not remove deskpi driver, please re-execute uninstall.sh again with root permission or remove it manually" + log_success_msg "Usage: ./uninstall.sh" +fi + +sudo sh -c "sudo sync && sleep 5 && sudo reboot" From 9c2c33803a3db2b9b8f89a01beef3b984e7568a3 Mon Sep 17 00:00:00 2001 From: yoyojacky Date: Thu, 9 May 2024 18:49:31 +0800 Subject: [PATCH 2/8] Fixed file name bug Signed-off-by: yoyojacky --- installation/drivers/c/Makefile | 14 ++++---- .../{safecutoffpower.c => safeCutOffPower.c} | 0 .../{safecutoffpower64 => safeCutOffPower64} | Bin 70856 -> 70856 bytes installation/install.sh | 28 ++++++++++------ installation/uninstall.sh | 30 ++++++++++++++---- 5 files changed, 48 insertions(+), 24 deletions(-) rename installation/drivers/c/{safecutoffpower.c => safeCutOffPower.c} (100%) rename installation/drivers/c/{safecutoffpower64 => safeCutOffPower64} (99%) diff --git a/installation/drivers/c/Makefile b/installation/drivers/c/Makefile index 7d442b4..b5cfe64 100644 --- a/installation/drivers/c/Makefile +++ b/installation/drivers/c/Makefile @@ -1,16 +1,16 @@ DEFAULT: all .PHONY: install -all: pwmControlFan64 safecutoffpower64 +all: pwmControlFan64 safeCutOffPower64 install: - sudo sh -c "sudo chmod 755 pwmControlFan64 safecutoffpower64" - sudo sh -c "sudo cp pwmControlFan64 safecutoffpower64 /usr/bin/" - sudo sh -c "sudo chcon -u system_u -t bin_t /usr/bin/pwmControlFan64 /usr/bin/safecutoffpower64" + sudo sh -c "sudo chmod 755 pwmControlFan64 safeCutOffPower64" + sudo sh -c "sudo cp pwmControlFan64 safeCutOffPower64 /usr/bin/" + sudo sh -c "sudo chcon -u system_u -t bin_t /usr/bin/pwmControlFan64 /usr/bin/safeCutOffPower64" pwmControlFan64: pwmControlFan.c gcc -o pwmControlFan64 pwmControlFan.c -safecutoffpower64: safecutoffpower.c - gcc -o safecutoffpower64 safecutoffpower.c +safeCutOffPower64: safeCutOffPower.c + gcc -o safeCutOffPower64 safeCutOffPower.c clean: - rm -rf safecutoffpower64 pwmControlFan64 + rm -rf safeCutOffPower64 pwmControlFan64 diff --git a/installation/drivers/c/safecutoffpower.c b/installation/drivers/c/safeCutOffPower.c similarity index 100% rename from installation/drivers/c/safecutoffpower.c rename to installation/drivers/c/safeCutOffPower.c diff --git a/installation/drivers/c/safecutoffpower64 b/installation/drivers/c/safeCutOffPower64 similarity index 99% rename from installation/drivers/c/safecutoffpower64 rename to installation/drivers/c/safeCutOffPower64 index e1de6924b56e235426958eb206ceffaabfb01a73..b31f8ccea9a890289e7cd8cd61b7bbc10f5051ba 100755 GIT binary patch delta 25 gcmX@HlI6romWC~iHC*h@r6vApX#v}txfor!0E4Co*Z=?k delta 25 gcmX@HlI6romWC~iHC*h;r6u`kX$9Mxxfor!0EcD?H~;_u diff --git a/installation/install.sh b/installation/install.sh index d0b98de..bd12875 100755 --- a/installation/install.sh +++ b/installation/install.sh @@ -23,6 +23,13 @@ if [[ -e /lib/lsb/init-functions ]]; then log_action_msg "Initializing functions..." fi +# Install figlet display information +sudo sh -c "sudo apt update" +sudo sh -c "sudo apt -y install figlet" +sudo sh -c "echo 'DESKPI PRO INSTALLATION' | figlet -c" +sleep 3 +sudo sh -c "echo 'STARTING...' | figlet -c" + # OS information detection OS_version=`lsb_release -a|grep -i codename |awk '{print $2}'` if [[ $OS_version != 'bookworm' ]]; then @@ -65,12 +72,13 @@ pkgStatus=`sudo dpkg-query -l git |grep git | awk '{print $1}'` if [[ $pkgStatus != 'ii' ]]; then sudo sh -c "sudo apt-get update" sudo sh -c "sudo apt-get -y install git-core" + fi # Check if dwc2 dtoverlay has been enabled. checkResult=`grep dwc2 /boot/firmware/config.txt` if [[ $? -ne 0 ]]; then - log_warning_msg "Adding dtoverlay=dwc2,dr_mode=host to /boot/firmware/config.txt file." + log_action_msg "Adding dtoverlay=dwc2,dr_mode=host to /boot/firmware/config.txt file." sudo sh -c "sudo sed -i '/dtoverlay=dwc2*/d' /boot/firmware/config.txt" sudo sh -c "sudo sed -i '\$a\dtoverlay=dwc2,dr_mode=host' /boot/firmware/config.txt" log_action_msg "check dwc2 overlay will be enabled after rebooting." @@ -82,20 +90,20 @@ if [[ ! -d /tmp/deskpi ]]; then while [[ ! -d /tmp/deskpi ]]; do log_warning_msg "Could not able to download deskpi repo,will retry again." - sh -c "git clone https://github.com/DeskPi-Team/deskpi.git" + sh -c "git clone -b feature/bookworm https://github.com/DeskPi-Team/deskpi.git" done fi # copy pre-compiled binary file to /usr/bin/ folder # -if [[ -d /tmp/deskpi/ ]]; then +if [[ -d /tmp/deskpi ]]; then sudo sh -c "sudo mkdir -pv /usr/bin/deskpi/" - sudo sh -c "sudo cp -Rvf /tmp/deskpi/installation/drivers/c/pwmFanControl64 /usr/bin/deskpi/pwmFanControl64" - sudo sh -c "sudo cp -Rvf /tmp/deskpi/installation/drivers/c/safecutoffpower64 /usr/bin/deskpi/safecutoffpower64" + sudo sh -c "sudo cp -Rvf /tmp/deskpi/installation/drivers/c/pwmControlFan64 /usr/bin/deskpi/pwmControlFan64 && echo 'Copy ok'" + sudo sh -c "sudo cp -Rvf /tmp/deskpi/installation/drivers/c/safeCutOffPower64 /usr/bin/deskpi/safeCutOffPower64 && echo 'Copy ok'" sudo sh -c "sudo cp -Rvf /tmp/deskpi/installation/deskpi-config /usr/bin/deskpi-config" - sudo sh -c "sudo chmod +x /usr/bin/deskpi/pwmFanControl64" - sudo sh -c "sudo chmod +x /usr/bin/deskpi/safecutoffpower64" + sudo sh -c "sudo chmod +x /usr/bin/deskpi/pwmControlFan64" + sudo sh -c "sudo chmod +x /usr/bin/deskpi/safeCutOffPower64" sudo sh -c "sudo chmod +x /usr/bin/deskpi-config" fi @@ -108,7 +116,7 @@ After=multi-user.target [Service] Type=oneshot RemainAfterExit=true -ExecStart=/usr/bin/deskpi/pwmFanControl64 +ExecStart=/usr/bin/deskpi/pwmControlFan64 [Install] WantedBy=multi-user.target @@ -126,7 +134,7 @@ Before=halt.target shutdown.target poweroff.target DefaultDependencies=no [Service] Type=oneshot -ExecStart= /usr/bin/deskpi/safecutoffpower64 +ExecStart=/usr/bin/deskpi/safeCutOffPower64 RemainAfterExit=yes [Install] WantedBy=halt.target shutdown.target poweroff.target @@ -160,4 +168,4 @@ else log_success_msg "Usage: ./install.sh" fi -sudo sh -c "sudo sync && sleep 5 && sudo reboot" +# sudo sh -c "sudo sync && sleep 5 && sudo reboot" diff --git a/installation/uninstall.sh b/installation/uninstall.sh index b0cd5bc..b9b41e5 100755 --- a/installation/uninstall.sh +++ b/installation/uninstall.sh @@ -12,6 +12,17 @@ if [[ -e /lib/lsb/init-functions ]]; then log_action_msg "Initializing functions..." fi +# warning message +echo "DESKPI PRO UNINSTALLATION" | figlet -c +echo "BEGIN IN 3 seconds" | figlet -c +sleep 1 +for i in `seq 1 3|sort -rn` +do + echo "$i " | figlet -c + sleep 1 +done + + # Remove udev rules of deskpi deskpi_rules_file="/etc/udev/rules.d/10-deskpi.rules" @@ -43,8 +54,7 @@ fi # Check if dwc2 dtoverlay has been enabled. checkResult=`grep dwc2 /boot/firmware/config.txt` if [[ $? -ne 0 ]]; then - log_warning_msg "Adding dtoverlay=dwc2,dr_mode=host to /boot/firmware/config.txt file." -else + log_warning_msg "Find dtoverlay=dwc2,dr_mode=host in /boot/firmware/config.txt file." sudo sh -c "sudo sed -i '/dtoverlay=dwc2*/d' /boot/firmware/config.txt" log_action_msg "Remove dtoverlay parameter from /boot/firmware/config.txt file." fi @@ -59,11 +69,17 @@ fi # Greetings if [[ $? -eq 0 ]]; then - log_success_msg "Farewell! DeskPi Pro driver has been removed successfully!" log_success_msg "System will be reboot in 5 seconds to take effect." -else - log_warning_msg "Could not remove deskpi driver, please re-execute uninstall.sh again with root permission or remove it manually" - log_success_msg "Usage: ./uninstall.sh" fi +echo "COUNTING DOWN TO REBOOT" | figlet -c +sleep 1 +for i in `seq 1 5|sort -rn` +do + echo "$i" | figlet -c + sleep 1 + clear +done +echo "DeskPi Pro!" | figlet -c +echo "FAREWELL!" | figlet -c -sudo sh -c "sudo sync && sleep 5 && sudo reboot" +# sudo sh -c "sudo sync && sleep 5 && sudo reboot" From 86896a4af569884017b22dce7bfa3f89ee854e46 Mon Sep 17 00:00:00 2001 From: yoyojacky Date: Thu, 9 May 2024 18:53:17 +0800 Subject: [PATCH 3/8] Update figlet infor --- installation/install.sh | 6 ++++-- installation/uninstall.sh | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/installation/install.sh b/installation/install.sh index bd12875..3027da4 100755 --- a/installation/install.sh +++ b/installation/install.sh @@ -167,5 +167,7 @@ else log_success_warning "Could not download deskpi repository, please check the internet connection and try to execute it again!" log_success_msg "Usage: ./install.sh" fi - -# sudo sh -c "sudo sync && sleep 5 && sudo reboot" +echo "DESKPI PRO" |figlet -c +echo "INSTALLATION SUCCESSFULL!" | figlet -c +echo "REBOOT IN 5 SECONDS" | figlet -c +sudo sh -c "sudo sync && sleep 5 && sudo reboot" diff --git a/installation/uninstall.sh b/installation/uninstall.sh index b9b41e5..992cd00 100755 --- a/installation/uninstall.sh +++ b/installation/uninstall.sh @@ -81,5 +81,4 @@ do done echo "DeskPi Pro!" | figlet -c echo "FAREWELL!" | figlet -c - -# sudo sh -c "sudo sync && sleep 5 && sudo reboot" +sudo sh -c "sudo sync && sleep 1 && sudo reboot" From ea1dafa878912e3fd89c7de6f797d5fdf2e9a904 Mon Sep 17 00:00:00 2001 From: yoyojacky Date: Thu, 9 May 2024 19:02:57 +0800 Subject: [PATCH 4/8] update deskpi-config file Signed-off-by: yoyojacky --- installation/deskpi-config | 98 ++++++++++++++++++++++++++++++++++++++ installation/install.sh | 3 ++ 2 files changed, 101 insertions(+) create mode 100755 installation/deskpi-config diff --git a/installation/deskpi-config b/installation/deskpi-config new file mode 100755 index 0000000..5ec0ae1 --- /dev/null +++ b/installation/deskpi-config @@ -0,0 +1,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/DeskPi_FAN' + +# 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 sh -c "sudo touch /etc/deskpi.conf" + sudo sh -c "sudo chmod 777 /etc/deskpi.conf" + echo "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 + echo "Configuration file has been created on /etc/deskpi.conf" +} + +# Greetings and information for user. +echo "Welcome to Use DeskPi-Team's Product" +echo "Please select speed level that you want: " +echo "It will always run at the speed level that you choosed." +echo "---------------------------------------------------------------" +echo "1 - set fan speed level to 25%" +echo "2 - set fan speed level to 50%" +echo "3 - set fan speed level to 75%" +echo "4 - set fan speed level to 100%" +echo "5 - Turn off Fan" +echo "6 - Adjust the start speed level according to the temperature" +echo "7 - Cancel manual control and enable automatical fan control" +echo "---------------------------------------------------------------" +echo "Just input the number and press enter." +read -p "Your choice:" levelNumber +case $levelNumber in + 1) + echo "You've select 25% speed level" + sudo sh -c "echo pwm_025 > $serial_port" + echo "Fan speed level has been change to 25%" + ;; + 2) + echo "You've select 50% speed level" + sudo sh -c "echo pwm_050 > $serial_port" + echo "Fan speed level has been change to 50%" + ;; + 3) + echo "You've select 75% speed level" + sudo sh -c "echo pwm_075 > $serial_port" + echo "Fan speed level has been change to 75%" + ;; + 4) + echo "You'tve select 100% speed level" + sudo sh -c "echo pwm_100 > $serial_port" + echo "Fan speed level has been change to 100%" + ;; + 5) + echo "Turn off fan" + sudo sh -c "echo pwm_000 > $serial_port" + echo "Fan speed level has been turned off." + ;; + 6) + echo "Customizing the start speed level according the temperature" + sudo systemctl stop deskpi.service & + set_config + sudo systemctl start deskpi.service & + ;; + 7) + echo "Cancel manual control and enable automatical fan control" + sudo systemctl start deskpi.service & + ;; + *) + echo "You type the wrong selection, please try again!" + . /usr/bin/deskpi-config + ;; +esac diff --git a/installation/install.sh b/installation/install.sh index 3027da4..b1cca8f 100755 --- a/installation/install.sh +++ b/installation/install.sh @@ -99,8 +99,11 @@ fi # if [[ -d /tmp/deskpi ]]; then sudo sh -c "sudo mkdir -pv /usr/bin/deskpi/" + if [[ -e /tmp/deskpi/installation/drivers/c/pwmControlFan64 ]]; then sudo sh -c "sudo cp -Rvf /tmp/deskpi/installation/drivers/c/pwmControlFan64 /usr/bin/deskpi/pwmControlFan64 && echo 'Copy ok'" sudo sh -c "sudo cp -Rvf /tmp/deskpi/installation/drivers/c/safeCutOffPower64 /usr/bin/deskpi/safeCutOffPower64 && echo 'Copy ok'" + fi + sudo sh -c "sudo cp -Rvf /tmp/deskpi/installation/deskpi-config /usr/bin/deskpi-config" sudo sh -c "sudo chmod +x /usr/bin/deskpi/pwmControlFan64" sudo sh -c "sudo chmod +x /usr/bin/deskpi/safeCutOffPower64" From 3c7039c53bfb915d155367d356fa3613016710e1 Mon Sep 17 00:00:00 2001 From: yoyojacky Date: Thu, 9 May 2024 19:06:28 +0800 Subject: [PATCH 5/8] update README.md Signed-off-by: yoyojacky --- installation/drivers/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/installation/drivers/README.md b/installation/drivers/README.md index 23a5949..31e0c4e 100644 --- a/installation/drivers/README.md +++ b/installation/drivers/README.md @@ -21,7 +21,7 @@ make ``` * 3. How to run it. ```bash -sudo ./pwmFanControl64 +sudo ./pwmControlFan64 ``` * 4. How to stop it. Press "Ctrl + C" on keyboard. @@ -30,10 +30,10 @@ Press "Ctrl + C" on keyboard. make clean ``` ## How to change speed of the fan. -This program is send the pwm signal from Raspberry Pi to the extension board via OTG serial port, which will be recognized by your Raspberry Pi as "/dev/ttyUSB0" device. so if you want to control the fan as your wish, you can modify pwmControlFan.c code and recompile it. +This program is send the pwm signal from Raspberry Pi to the extension board via OTG serial port, which will be recognized by your Raspberry Pi as "/dev/DeskPi_FAN" device which is symboliclink to /dev/ttyUSB0. so if you want to control the fan as your wish, you can modify pwmControlFan.c code and recompile it. * In the default code, we have set 4 level for you Fan on pwm signal: -* Level 0: 0% speed-> send "pwm_000" to /dev/ttyUSB0", means to turn off the fan -* Level 1: 25% speed-> send "pwm_025" to /dev/ttyUSB0", means to set fan speed to 25% -* Level 2: 50% speed-> send "pwm_050" to /dev/ttyUSB0", means to set fan speed to 50% -* Level 3: 75% speed-> send "pwm_075" to /dev/ttyUSB0", means to set fan speed to 75% -* Level 4:100% speed-> send "pwm_100" to /dev/ttyUSB0", means to set fan speed to 100% +* Level 0: 0% speed-> send "pwm_000" to /dev/DeskPi_FAN", means to turn off the fan +* Level 1: 25% speed-> send "pwm_025" to /dev/DeskPi_FAN", means to set fan speed to 25% +* Level 2: 50% speed-> send "pwm_050" to /dev/DeskPi_FAN", means to set fan speed to 50% +* Level 3: 75% speed-> send "pwm_075" to /dev/DeskPi_FAN", means to set fan speed to 75% +* Level 4:100% speed-> send "pwm_100" to /dev/DeskPi_FAN", means to set fan speed to 100% From 34513ddfb218c12df0062052d88baa13cde488c2 Mon Sep 17 00:00:00 2001 From: yoyojacky Date: Thu, 9 May 2024 19:11:52 +0800 Subject: [PATCH 6/8] update udev rules part Signed-off-by: yoyojacky --- installation/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation/install.sh b/installation/install.sh index b1cca8f..af6e0f9 100755 --- a/installation/install.sh +++ b/installation/install.sh @@ -44,7 +44,7 @@ deskpi_rules_file="/etc/udev/rules.d/10-deskpi.rules" if [[ ! -e $deskpi_rules_file ]]; then sudo sh -c "sudo cat < '$deskpi_rules_file' - ACTION==\"add\", ATTRS{$idVendor},ATTRS{$idProduct},SYMLINK+="DeskPi_FAN" + ACTION==\"add\", ATTRS{\"$idVendor\"},ATTRS{\"$idProduct\"},SYMLINK+=\"DeskPi_FAN\" EOF" sudo sh -c "sudo udevadm control --reload-rules" sudo sh -c "sudo udevadm trigger" From 59abb59408dc0883a2891111be2b65be20aee646 Mon Sep 17 00:00:00 2001 From: yoyojacky Date: Thu, 9 May 2024 19:23:41 +0800 Subject: [PATCH 7/8] adding service check Signed-off-by: yoyojacky --- installation/install.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/installation/install.sh b/installation/install.sh index af6e0f9..0e05673 100755 --- a/installation/install.sh +++ b/installation/install.sh @@ -117,9 +117,9 @@ sudo sh -c "sudo cat < '$deskpi_service_file' Description=DeskPi Fan Control Service After=multi-user.target [Service] -Type=oneshot +Type=simple RemainAfterExit=true -ExecStart=/usr/bin/deskpi/pwmControlFan64 +ExecStart=/usr/bin/sudo /usr/bin/deskpi/pwmControlFan64 [Install] WantedBy=multi-user.target @@ -137,7 +137,7 @@ Before=halt.target shutdown.target poweroff.target DefaultDependencies=no [Service] Type=oneshot -ExecStart=/usr/bin/deskpi/safeCutOffPower64 +ExecStart=/usr/bin/sudo /usr/bin/deskpi/safeCutOffPower64 RemainAfterExit=yes [Install] WantedBy=halt.target shutdown.target poweroff.target @@ -151,14 +151,16 @@ if [[ -e $deskpi_service_file ]]; then sudo sh -c "sudo chown root:root $deskpi_service_file" sudo sh -c "sudo chmod 755 $deskpi_service_file" log_action_msg "Load DeskPi service and load modules" - sudo sh -c "sudo systemctl enable $deskpi_service_file" - sudo sh -c "sudo systemctl start $deskpi_service_file" + sudo sh -c "sudo systemctl daemon-reload" + sudo sh -c "sudo systemctl enable deskpi.service" + sudo sh -c "sudo systemctl start deskpi.service" fi if [[ -e $deskpi_powermanager_file ]]; then sudo sh -c "sudo chown root:root $deskpi_powermanager_file" sudo sh -c "sudo chmod 755 $deskpi_powermanager_file" - sudo sh -c "sudo systemctl enable $deskpi_powermanager_file" + sudo sh -c "sudo systemctl daemon-reload" + sudo sh -c "sudo systemctl enable deskpi-cutoffpower.service" fi From 2dee8a6c5697f3a52441dc2a29f5d5288c07823d Mon Sep 17 00:00:00 2001 From: yoyojacky Date: Thu, 9 May 2024 19:44:02 +0800 Subject: [PATCH 8/8] modify rules file and adding /etc/deskpi.conf Signed-off-by: yoyojacky --- installation/deskpi-config | 15 ++++++++++----- installation/install.sh | 18 +++++++++++++++++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/installation/deskpi-config b/installation/deskpi-config index 5ec0ae1..4d1ee2f 100755 --- a/installation/deskpi-config +++ b/installation/deskpi-config @@ -11,10 +11,11 @@ . /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/DeskPi_FAN' +serial_port='/dev/ttyUSB0' # Stop deskpi.service so that user can define the speed level. sudo systemctl stop deskpi.service +sudo systemctl daemon-reload # Define the function of set_config function set_config() { @@ -41,7 +42,8 @@ function set_config() { } # Greetings and information for user. -echo "Welcome to Use DeskPi-Team's Product" +# +echo "DESKPI PRO FAN CONTROL" | figlet -c echo "Please select speed level that you want: " echo "It will always run at the speed level that you choosed." echo "---------------------------------------------------------------" @@ -83,13 +85,16 @@ case $levelNumber in ;; 6) echo "Customizing the start speed level according the temperature" - sudo systemctl stop deskpi.service & + sudo systemctl stop deskpi.service + sudo systemctl daemon-reload set_config - sudo systemctl start deskpi.service & + sudo systemctl daemon-reload + sudo systemctl start deskpi.service ;; 7) echo "Cancel manual control and enable automatical fan control" - sudo systemctl start deskpi.service & + sudo systemctl daemon-reload + sudo systemctl restart deskpi.service ;; *) echo "You type the wrong selection, please try again!" diff --git a/installation/install.sh b/installation/install.sh index 0e05673..8cf3853 100755 --- a/installation/install.sh +++ b/installation/install.sh @@ -44,12 +44,28 @@ deskpi_rules_file="/etc/udev/rules.d/10-deskpi.rules" if [[ ! -e $deskpi_rules_file ]]; then sudo sh -c "sudo cat < '$deskpi_rules_file' - ACTION==\"add\", ATTRS{\"$idVendor\"},ATTRS{\"$idProduct\"},SYMLINK+=\"DeskPi_FAN\" + ACTION==\"add\",SUBSYSTEM==\"tty\",ATTRS{\"$idVendor\"},ATTRS{\"$idProduct\"},SYMLINK+=\"DeskPi_FAN\" EOF" + sudo sh -c "sudo chmod 0666 $deskpi_rules_file" sudo sh -c "sudo udevadm control --reload-rules" sudo sh -c "sudo udevadm trigger" fi +# Adding /etc/deskpi.conf file +deskpi_config="/etc/deskpi.conf" +if [[ ! -e $deskpi_config ]]; then + sh -c "cat < '$deskpi_config' + 40 + 100 + 50 + 100 + 55 + 100 + 60 + 100 + EOF" +fi + # Remove old repository. if [[ -d /tmp/deskpi ]]; then rm -rf /tmp/deskpi*