mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 01:30:37 +00:00
Add setup.py and distribution basics
This commit is contained in:
22
CONTRIBUTING.md
Normal file
22
CONTRIBUTING.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# Contributing
|
||||
|
||||
This module was designed for use in education; particularly for young children. It is not intended to replace `RPi.GPIO` and it does not claim to be suitable for all purposes. It is intended to provide a simple interface to everyday components.
|
||||
|
||||
If a proposed change added an advanced feature but made basic usage more complex, it is unlikely to be added.
|
||||
|
||||
## Suggestions
|
||||
|
||||
Please make suggestions by opening an [issue](https://github.com/RPi-Distro/gpio-zero/issues) explaining your reasoning clearly.
|
||||
|
||||
## Bugs
|
||||
|
||||
Please submit bug reports by opening an [issue](https://github.com/RPi-Distro/gpio-zero/issues) explaining the problem clearly using code examples.
|
||||
|
||||
## Documentation
|
||||
|
||||
The documentation source lives in the [docs](https://github.com/RPi-Distro/gpio-zero/tree/master/docs) folder and is rendered from markdown into HTML using [mkdocs](http://www.mkdocs.org/). Contributions to the documentation are welcome but should be easy to read and understand.
|
||||
|
||||
## Python
|
||||
|
||||
- Python 2/3 compatibility
|
||||
- PEP8-compliance (with exceptions)
|
||||
27
LICENCE.txt
Normal file
27
LICENCE.txt
Normal file
@@ -0,0 +1,27 @@
|
||||
Copyright 2015- Raspberry Pi Foundation
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of the copyright holder nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
1
MANIFEST.in
Normal file
1
MANIFEST.in
Normal file
@@ -0,0 +1 @@
|
||||
include README.rst
|
||||
5
README.rst
Normal file
5
README.rst
Normal file
@@ -0,0 +1,5 @@
|
||||
========
|
||||
gpiozero
|
||||
========
|
||||
|
||||
A simple interface to everyday GPIO components used with Raspberry Pi
|
||||
@@ -1,6 +1,6 @@
|
||||
# gpio-components
|
||||
# gpio-zero
|
||||
|
||||
Abstraction for everyday GPIO components, based on Ben Croston's `RPi.GPIO` library.
|
||||
A simple interface to everyday GPIO components used with Raspberry Pi
|
||||
|
||||
## Why?
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
from gpio_components import LED, Buzzer, Button
|
||||
from time import sleep
|
||||
|
||||
|
||||
class MyHat(object):
|
||||
def __init__(self):
|
||||
self.red = LED(9)
|
||||
self.yellow = LED(10)
|
||||
self.green = LED(11)
|
||||
self.buzzer = Buzzer(14)
|
||||
self.button = Button(15)
|
||||
|
||||
self.leds = [self.red, self.yellow, self.green]
|
||||
self.outputs = self.leds + [self.buzzer]
|
||||
|
||||
def all_on(self):
|
||||
for device in self.outputs:
|
||||
device.on()
|
||||
|
||||
def all_off(self):
|
||||
for device in self.outputs:
|
||||
device.off()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
hat = MyHat()
|
||||
|
||||
while True:
|
||||
if hat.button.is_pressed():
|
||||
hat.all_on()
|
||||
else:
|
||||
hat.all_off()
|
||||
@@ -1,20 +0,0 @@
|
||||
from RPi import GPIO
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
|
||||
from .input_devices import (
|
||||
InputDeviceError,
|
||||
InputDevice,
|
||||
Button,
|
||||
MotionSensor,
|
||||
LightSensor,
|
||||
TemperatureSensor,
|
||||
)
|
||||
from .output_devices import (
|
||||
OutputDevice,
|
||||
LED,
|
||||
Buzzer,
|
||||
Motor,
|
||||
)
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
from RPi import GPIO
|
||||
from w1thermsensor import W1ThermSensor
|
||||
|
||||
|
||||
class InputDevice(object):
|
||||
def __init__(self, pin=None):
|
||||
if pin is None:
|
||||
raise InputDeviceError('No GPIO pin number given')
|
||||
|
||||
self.pin = pin
|
||||
self.pull = GPIO.PUD_UP
|
||||
self.edge = GPIO.FALLING
|
||||
self.active = 0
|
||||
self.inactive = 1
|
||||
GPIO.setup(pin, GPIO.IN, self.pull)
|
||||
|
||||
@property
|
||||
def is_active(self):
|
||||
return GPIO.input(self.pin) == self.active
|
||||
|
||||
def wait_for_input(self):
|
||||
GPIO.wait_for_edge(self.pin, self.edge)
|
||||
|
||||
def add_callback(self, callback=None, bouncetime=1000):
|
||||
if callback is None:
|
||||
raise InputDeviceError('No callback function given')
|
||||
|
||||
GPIO.add_event_detect(self.pin, self.edge, callback, bouncetime)
|
||||
|
||||
def remove_callback(self):
|
||||
GPIO.remove_event_detect(self.pin)
|
||||
|
||||
|
||||
class Button(InputDevice):
|
||||
pass
|
||||
|
||||
|
||||
class MotionSensor(InputDevice):
|
||||
def _is_active_with_pause(self):
|
||||
sleep(0.1)
|
||||
return self.is_active
|
||||
|
||||
@property
|
||||
def motion_detected(self):
|
||||
n = 20
|
||||
return sum(self._is_active_with_pause() for i in range(n)) > n/2
|
||||
|
||||
|
||||
class LightSensor(object):
|
||||
def __init__(self, pin=None, darkness_level=0.01):
|
||||
if pin is None:
|
||||
raise InputDeviceError('No GPIO pin number given')
|
||||
|
||||
self.pin = pin
|
||||
self.darkness_level = darkness_level
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
return self._get_average_light_level(5)
|
||||
|
||||
def _get_light_level(self):
|
||||
time_taken = self._time_charging_light_capacitor()
|
||||
value = 100 * time_taken / self.darkness_level
|
||||
return 100 - value
|
||||
|
||||
def _time_charging_light_capacitor(self):
|
||||
GPIO.setup(self.pin, GPIO.OUT)
|
||||
GPIO.output(self.pin, GPIO.LOW)
|
||||
sleep(0.1)
|
||||
GPIO.setup(self.pin, GPIO.IN)
|
||||
start_time = time()
|
||||
end_time = time()
|
||||
while (
|
||||
GPIO.input(self.pin) == GPIO.LOW and
|
||||
time() - start_time < self.darkness_level
|
||||
):
|
||||
end_time = time()
|
||||
time_taken = end_time - start_time
|
||||
return min(time_taken, self.darkness_level)
|
||||
|
||||
def _get_average_light_level(self, num):
|
||||
values = [self._get_light_level() for n in range(num)]
|
||||
average_value = sum(values) / len(values)
|
||||
return average_value
|
||||
|
||||
|
||||
class TemperatureSensor(W1ThermSensor):
|
||||
@property
|
||||
def value(self):
|
||||
return self.get_temperature()
|
||||
|
||||
|
||||
class InputDeviceError(Exception):
|
||||
pass
|
||||
@@ -1,25 +0,0 @@
|
||||
from RPi import GPIO
|
||||
|
||||
|
||||
class OutputDevice(object):
|
||||
def __init__(self, pin):
|
||||
self.pin = pin
|
||||
GPIO.setup(pin, GPIO.OUT)
|
||||
|
||||
def on(self):
|
||||
GPIO.output(self.pin, True)
|
||||
|
||||
def off(self):
|
||||
GPIO.output(self.pin, False)
|
||||
|
||||
|
||||
class LED(OutputDevice):
|
||||
pass
|
||||
|
||||
|
||||
class Buzzer(OutputDevice):
|
||||
pass
|
||||
|
||||
|
||||
class Motor(OutputDevice):
|
||||
pass
|
||||
10
mkdocs.yml
Normal file
10
mkdocs.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
site_name: gpio-zero
|
||||
theme: readthedocs
|
||||
site_url: http://pythonhosted.org/gpiozero
|
||||
repo_url: https://github.com/RPi-Distro/gpio-zero
|
||||
site_description: A simple interface to everyday GPIO components used with Raspberry Pi
|
||||
site_author: Ben Nuttall
|
||||
site_dir: pythonhosted
|
||||
google_analytics: ['UA-46270871-6', 'pythonhosted.org/gpiozero']
|
||||
pages:
|
||||
- 'Home': 'index.md'
|
||||
35
setup.py
Normal file
35
setup.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import os
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
|
||||
def read(fname):
|
||||
return open(os.path.join(os.path.dirname(__file__), fname)).read()
|
||||
|
||||
|
||||
setup(
|
||||
name="gpiozero",
|
||||
version="0.1.0",
|
||||
author="Ben Nuttall",
|
||||
description="A simple interface to everyday GPIO components used with Raspberry Pi",
|
||||
license="BSD",
|
||||
keywords=[
|
||||
"raspberrypi",
|
||||
"gpio",
|
||||
],
|
||||
url="https://github.com/RPi-Distro/gpio-zero",
|
||||
packages=find_packages(),
|
||||
install_requires=[
|
||||
"RPi.GPIO",
|
||||
"w1thermsensor",
|
||||
],
|
||||
long_description=read('README.rst'),
|
||||
classifiers=[
|
||||
"Development Status :: 1 - Planning",
|
||||
"Intended Audience :: Education",
|
||||
"Topic :: Education",
|
||||
"Topic :: System :: Hardware",
|
||||
"License :: OSI Approved :: BSD License",
|
||||
"Programming Language :: Python :: 2",
|
||||
"Programming Language :: Python :: 3",
|
||||
],
|
||||
)
|
||||
Reference in New Issue
Block a user