Skip to content

Commit

Permalink
add setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kaulketh committed Dec 24, 2023
1 parent b026fd9 commit e97572d
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 7 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### Plan

I would have to switch the fan directly using a small piece of software via a
GPIO pin. The program reads the CPU+GPU temperature and then switches the fan.
GPIO pin. The program reads the CPU+GPU temperature and then switches the fan.
The OS should start the program periodically or automatically.

### Structure
Expand All @@ -21,23 +21,30 @@ and [wiring image](hardware/wiring.png)
### The Python code

* Only required package: [**_RPi.GPIO_**](https://pypi.org/project/RPi.GPIO/)

* **_control.py_** : FanControl class
* In an infinite loop temperature is checked in a certain time interval
* If the temperature is greater than or equal the max value, and the pin is
* If the temperature is greater than or equal the max value, and the
pin is
not already activated, GPIO pin will set to HIGH
* Is the temperature lower than or equal to the minimum value, and the pin
* Is the temperature lower than or equal to the minimum value, and the
pin
is set to HIGH, GPIO pin will set to LOW
* **_config.py_** : Settings:
* GPIO pin of connected fan
* Max temperature at which the fan is switched on
* Min temperature at which the fan is switched off
* Check interval, in seconds

* **_main.py_**: An instance of FanControl will load with passed parameters.

* **_main.py_**: An instance of FanControl will load with passed parameters.

### Auto run at boot up

One possibility is described in **_service_** directory. Refer
to [README](service/README.md)
to [README](service/README.md)

### Installation possibilities and steps

* Clone this repository and configure manually
* Install distribution, service enabled automatically
* Adapt _config.py_
77 changes: 77 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# -----------------------------------------------------------
# setup
# created 24.12.2023
# Thomas Kaulke, kaulketh@gmail.com
# https://github.com/kaulketh
# -----------------------------------------------------------
import platform
import subprocess
import sys

from setuptools import setup, find_packages
from setuptools.command.install import install


class InstallService(install):
FILE_NAME = 'fan_control.service'
FILE_CONTENT = '''
[Unit]
Description=Fan control service
After=multi-user.target
[Service]
Type=idle
ExecStart=/usr/bin/python3 /home/pi/fan_control/main.py
[Install]
WantedBy=multi-user.target
'''

def run(self):
install.run(self) # Call the default install functionality
# Add code here to create the service
with open(f'/etc/systemd/system/{InstallService.FILE_NAME}',
'w') as service_file:
service_file.write(InstallService.FILE_CONTENT)

# Example command to create a service (modify this based on your needs)
if platform.system() == 'Linux':
try:
subprocess.run(['systemctl', 'daemon-reload'])
subprocess.run(
['systemctl', 'enable', InstallService.FILE_NAME],
check=True)
sys.stdout.write(
f'Service "{InstallService.FILE_NAME}" enabled successfully.\n')

except subprocess.CalledProcessError as e:
sys.stderr.write(f'Failed to enable service: {e}\n')


setup(
name='simple-pi-fan-control',
version='1.0',
packages=find_packages(exclude=[]),
author='Thomas Kaulke',
author_email='kaulketh@gmail.com',
description='The program reads the CPU+GPU temperature and switches GPIO channel.',
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
url='https://github.com/kaulketh/simple-pi-fan-control',
license=open('LICENSE.md').read(),
classifiers=[
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
],
install_requires=[
'<RPi.GPIO>',
],
cmdclass={
'install': InstallService,
}
)

if __name__ == '__main__':
setup()

0 comments on commit e97572d

Please sign in to comment.