Merge pull request #1 from waveform80/cleanup

Minor clean-up
This commit is contained in:
Ben Nuttall
2015-09-15 10:08:05 +01:00
5 changed files with 51 additions and 16 deletions

29
.gitignore vendored
View File

@@ -1 +1,28 @@
*.pyc *.py[cdo]
# Editor detritus
*.vim
*.swp
tags
# Packaging detritus
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
coverage
.coverage
.tox

View File

@@ -126,7 +126,7 @@ from gpio_components import MotionSensor
pir = MotionSensor(5) pir = MotionSensor(5)
while True: while True:
if pir.motion_detected(): if pir.motion_detected:
print("Motion detected") print("Motion detected")
``` ```

View File

@@ -0,0 +1,20 @@
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,
)

View File

@@ -2,10 +2,6 @@ from RPi import GPIO
from w1thermsensor import W1ThermSensor from w1thermsensor import W1ThermSensor
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
class InputDevice(object): class InputDevice(object):
def __init__(self, pin=None): def __init__(self, pin=None):
if pin is None: if pin is None:
@@ -42,8 +38,9 @@ class Button(InputDevice):
class MotionSensor(InputDevice): class MotionSensor(InputDevice):
def _is_active_with_pause(self): def _is_active_with_pause(self):
sleep(0.1) sleep(0.1)
return self.is_active() return self.is_active
@property
def motion_detected(self): def motion_detected(self):
n = 20 n = 20
return sum(self._is_active_with_pause() for i in range(n)) > n/2 return sum(self._is_active_with_pause() for i in range(n)) > n/2
@@ -86,11 +83,6 @@ class LightSensor(object):
average_value = sum(values) / len(values) average_value = sum(values) / len(values)
return average_value return average_value
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): class TemperatureSensor(W1ThermSensor):
@property @property

View File

@@ -1,10 +1,6 @@
from RPi import GPIO from RPi import GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
class OutputDevice(object): class OutputDevice(object):
def __init__(self, pin): def __init__(self, pin):
self.pin = pin self.pin = pin