annotate py/gpio_rpi.py @ 534:0cc7f2dda0e8

missing sensor.py
author Matt Johnston <matt@ucc.asn.au>
date Tue, 05 May 2015 21:29:19 +0800
parents dd8895652485
children d9b819dcac53
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
527
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 import os
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 import RPi.GPIO as GPIO
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 from utils import L,D,EX,W
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 __all__ = ["Gpio"]
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 class Gpio(object):
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 def __init__(self, pin, name):
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 self.pin = pin
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 self.name = name
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 GPIO.setmode(GPIO.BOARD)
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 GPIO.setup(self.pin, GPIO.OUT)
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 def turn(self, value):
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 self.state = bool(value)
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 GPIO.output(self.pin, self.state)
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 def get_state(self):
dd8895652485 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 return GPIO.input(self.pin)