Skip to content

Commit 599c42f

Browse files
authored
Merge pull request #64 from FoamyGuy/keyboard_featherwing
adding a helper class for keyboard featherwing
2 parents 0c2c6db + d2a42af commit 599c42f

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2020 Foamyguy for Adafruit Industries LLC
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
"""
23+
`adafruit_featherwing.keyboard_featherwing`
24+
====================================================
25+
26+
Helper for using the `Keyboard Featherwing`
27+
<https://www.tindie.com/products/arturo182/keyboard-featherwing-qwerty-keyboard-26-lcd/>`_.
28+
29+
* Author(s): Foamyguy
30+
31+
Requires:
32+
* adafruit_ili9341
33+
* adafruit_stmpe610
34+
"""
35+
36+
__version__ = "0.0.0-auto.0"
37+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"
38+
39+
import board
40+
import digitalio
41+
import displayio
42+
import adafruit_ili9341
43+
from adafruit_stmpe610 import Adafruit_STMPE610_SPI
44+
import sdcardio
45+
import storage
46+
from bbq10keyboard import BBQ10Keyboard
47+
import neopixel
48+
49+
50+
# pylint: disable-msg=too-few-public-methods
51+
class KeyboardFeatherwing:
52+
"""Class representing a `Keyboard Featherwing`
53+
<https://www.tindie.com/products/arturo182/keyboard-featherwing-qwerty-keyboard-26-lcd/>`_.
54+
55+
"""
56+
57+
def __init__(self, spi=None, cs=None, dc=None, i2c=None):
58+
displayio.release_displays()
59+
if spi is None:
60+
spi = board.SPI()
61+
if cs is None:
62+
cs = board.D9
63+
if dc is None:
64+
dc = board.D10
65+
if i2c is None:
66+
i2c = board.I2C()
67+
68+
ts_cs = digitalio.DigitalInOut(board.D6)
69+
self.touchscreen = Adafruit_STMPE610_SPI(spi, ts_cs)
70+
71+
display_bus = displayio.FourWire(spi, command=dc, chip_select=cs)
72+
self.display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240)
73+
self.neopixel = neopixel.NeoPixel(board.D11, 1)
74+
self.keyboard = BBQ10Keyboard(i2c)
75+
sd_cs = board.D5
76+
self._sdcard = None
77+
try:
78+
self._sdcard = sdcardio.SDCard(spi, sd_cs)
79+
vfs = storage.VfsFat(self._sdcard)
80+
storage.mount(vfs, "/sd")
81+
except OSError as error:
82+
print("No SD card found:", error)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
This example will display a CircuitPython console and
3+
print the coordinates of touchscreen presses, as well
4+
as keyboard events from the BBQ10 keyboard.
5+
It will also try to write and then read a file on the
6+
SD Card.
7+
It will also set the color of the neopixel on the featherwing.
8+
9+
"""
10+
from bbq10keyboard import STATE_RELEASE, STATE_LONG_PRESS
11+
from adafruit_featherwing import keyboard_featherwing
12+
13+
kbd_featherwing = keyboard_featherwing.KeyboardFeatherwing()
14+
15+
# set the neopixel on the kbd featherwing
16+
kbd_featherwing.neopixel.brightness = 0.1
17+
kbd_featherwing.neopixel[0] = 0x002244
18+
19+
try:
20+
f = open("/sd/tft_featherwing.txt", "w")
21+
f.write("Blinka\nBlackberry Q10 Keyboard")
22+
f.close()
23+
24+
f = open("/sd/tft_featherwing.txt", "r")
25+
print(f.read())
26+
f.close()
27+
except OSError as error:
28+
print("Unable to write to SD Card.")
29+
30+
while True:
31+
# print touch info
32+
if not kbd_featherwing.touchscreen.buffer_empty:
33+
print(kbd_featherwing.touchscreen.read_data())
34+
35+
# print keyboard events
36+
key_count = kbd_featherwing.keyboard.key_count
37+
if key_count > 0:
38+
key = kbd_featherwing.keyboard.key
39+
STATE = "pressed"
40+
if key[0] == STATE_LONG_PRESS:
41+
STATE = "held down"
42+
elif key[0] == STATE_RELEASE:
43+
STATE = "released"
44+
print(
45+
"key: '%s' (dec %d, hex %02x) %s"
46+
% (key[1], ord(key[1]), ord(key[1]), STATE)
47+
)

0 commit comments

Comments
 (0)