annotate py/gpio_rpi.py @ 228:d9e81a563923

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