diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..be205ef --- /dev/null +++ b/CONTRIBUTING.md @@ -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) diff --git a/LICENCE.txt b/LICENCE.txt new file mode 100644 index 0000000..cdf573d --- /dev/null +++ b/LICENCE.txt @@ -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. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..9561fb1 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include README.rst diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..c9835f8 --- /dev/null +++ b/README.rst @@ -0,0 +1,5 @@ +======== +gpiozero +======== + +A simple interface to everyday GPIO components used with Raspberry Pi diff --git a/README.md b/docs/index.md similarity index 96% rename from README.md rename to docs/index.md index 1ae6537..12743ce 100644 --- a/README.md +++ b/docs/index.md @@ -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? diff --git a/examples/my_hat.py b/examples/my_hat.py deleted file mode 100644 index b80fcdb..0000000 --- a/examples/my_hat.py +++ /dev/null @@ -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() diff --git a/gpio_components/__init__.py b/gpio_components/__init__.py deleted file mode 100644 index 2e26e74..0000000 --- a/gpio_components/__init__.py +++ /dev/null @@ -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, - ) - diff --git a/gpio_components/input_devices.py b/gpio_components/input_devices.py deleted file mode 100644 index bbc188a..0000000 --- a/gpio_components/input_devices.py +++ /dev/null @@ -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 diff --git a/gpio_components/output_devices.py b/gpio_components/output_devices.py deleted file mode 100644 index 6129423..0000000 --- a/gpio_components/output_devices.py +++ /dev/null @@ -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 diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..e0e135b --- /dev/null +++ b/mkdocs.yml @@ -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' diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..3514d4c --- /dev/null +++ b/setup.py @@ -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", + ], +)