-
Notifications
You must be signed in to change notification settings - Fork 101
SAA1064 and Seven Segment display APIs #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
96ee4f1
8851d1e
e40f746
e3e96ee
b05b9b1
df7bcf4
1c6227e
2607994
90ca30d
8a864d9
a2f69cf
a20f380
2538c95
6c45050
8f39a52
bfa65df
0f35426
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import quick2wire.i2c as i2c | ||
from quick2wire.parts.saa1064 import SAA1064, STATIC_MODE | ||
from time import sleep | ||
|
||
saa1064 = SAA1064(i2c.I2CMaster(), digits=2) | ||
saa1064.brightness=0b01100000 | ||
|
||
for y in range(10): | ||
saa1064.digit(0).value(y) | ||
for x in range(10): | ||
saa1064.digit(1).value(x) | ||
saa1064.write() | ||
sleep(0.1) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
__author__ = 'stuartervine' | ||
|
||
from quick2wire import i2c | ||
from quick2wire.parts.saa1064 import SAA1064 | ||
from quick2wire.parts.seven_segment_display import SevenSegmentDisplay | ||
from time import sleep | ||
|
||
saa1064 = SAA1064(i2c.I2CMaster(), digits=4) | ||
sevenSegmentDisplay=SevenSegmentDisplay(saa1064) | ||
|
||
sevenSegmentDisplay.display('1.5') | ||
sleep(1) | ||
sevenSegmentDisplay.display('100R') | ||
sleep(1) | ||
|
||
for i in range(9999): | ||
sevenSegmentDisplay.display(i) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import subprocess | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about moving PinAPI and PinBankAPI out of the gpio module. To fully implement the Pin and PinBank APIs you'll also need constants defined in gpio module (directions for example). Because in Python you can't define interfaces except by documentation (which I haven't done, I admit), the PinAPI and PinBankAPI are only partial implementations of the interface and things that want to be Pin-like or PinBank-like must implement things that are not defined on PinAPI & PinBankAPI. In fact there's no reason to subclass PinAPI or PinBankAPI if it's easier not to. So, I'd say move them back to gpio. They are modelling digital GPIO pins, and it seems reasonable for them to be in gpio. |
||
from contextlib import contextmanager | ||
from quick2wire.board_revision import revision | ||
from quick2wire.pin import PinAPI, PinBankAPI | ||
from quick2wire.selector import EDGE | ||
|
||
|
||
|
@@ -27,46 +28,6 @@ def gpio_admin(subcommand, pin, pull=None): | |
PullUp = "pullup" | ||
|
||
|
||
|
||
class PinAPI(object): | ||
def __init__(self, bank, index): | ||
self._bank = bank | ||
self._index = index | ||
|
||
@property | ||
def index(self): | ||
return self._index | ||
|
||
@property | ||
def bank(self): | ||
return self._bank | ||
|
||
def __enter__(self): | ||
self.open() | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
self.close() | ||
|
||
value = property(lambda p: p.get(), | ||
lambda p,v: p.set(v), | ||
doc="""The value of the pin: 1 if the pin is high, 0 if the pin is low.""") | ||
|
||
|
||
class PinBankAPI(object): | ||
def __getitem__(self, n): | ||
if 0 < n < len(self): | ||
raise ValueError("no pin index {n} out of range", n=n) | ||
return self.pin(n) | ||
|
||
def write(self): | ||
pass | ||
|
||
def read(self): | ||
pass | ||
|
||
|
||
|
||
class Pin(PinAPI): | ||
"""Controls a GPIO pin.""" | ||
|
||
|
@@ -204,9 +165,6 @@ def __str__(self): | |
index=self.index) | ||
|
||
|
||
|
||
|
||
|
||
class PinBank(PinBankAPI): | ||
def __init__(self, index_to_soc_fn, count=None): | ||
super(PinBank,self).__init__() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
__author__ = 'stuart' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've not been bothering with author statements, as everyone has contributed to almost every file. |
||
|
||
class FakeI2CMaster: | ||
def __init__(self): | ||
self._requests = [] | ||
self._responses = [] | ||
self._next_response = 0 | ||
self.message_precondition = lambda m: True | ||
|
||
def all_messages_must(self, p): | ||
self.message_precondition | ||
|
||
def clear(self): | ||
self.__init__() | ||
|
||
def transaction(self, *messages): | ||
for m in messages: | ||
self.message_precondition(m) | ||
|
||
self._requests.append(messages) | ||
return [] | ||
|
||
def add_response(self, *messages): | ||
self._responses.append(messages) | ||
|
||
|
||
@property | ||
def request_count(self): | ||
return len(self._requests) | ||
|
||
def request(self, n): | ||
return self._requests[n] | ||
|
||
def request_at(self, n): | ||
return I2CRequestWrapper(self._requests[n]) | ||
|
||
def message(self, message_index): | ||
request = self.request(0) | ||
return I2CMessageWrapper(request[message_index]) | ||
|
||
class I2CRequestWrapper: | ||
def __init__(self, i2c_request): | ||
self._i2c_request = i2c_request | ||
|
||
def message(self, index): | ||
return I2CMessageWrapper(self._i2c_request[index]) | ||
|
||
|
||
class I2CMessageWrapper: | ||
def __init__(self, i2_message): | ||
self._i2c_message = i2_message | ||
self.len = i2_message.len | ||
|
||
def byte(self, index): | ||
return self._i2c_message.buf[index][0] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use a consistent naming convention for programs in the examples directory? Hyphens, not underscores, to separate words and no .py suffix (makes working at the command-line more convenient). Also they should be executable and start with the line "#!/usr/bin/env python3"