made changes from klardotsh's review

This commit is contained in:
Cole Smith 2022-04-15 22:15:03 -07:00 committed by xs5871
parent ad43377a5e
commit 7e760a2917
2 changed files with 47 additions and 38 deletions

View File

@ -35,7 +35,7 @@ These are the changes that need to be made / added to your main.py
### Config
no mater how you are going to use the oled you need this part
```python
from kmk.extensions.peg_oledDisplay import oled
from kmk.extensions.peg_oled_Display import Oled,OledDisplayMode,OledReactionType
keyboard = KMKKeyboard()
# ... Other oled code
keyboard.extensions.append(oled_ext)
@ -44,24 +44,23 @@ no mater how you are going to use the oled you need this part
### Photos
So the config for photos is quite simple. Getting the photos maybe not so much. I will explain.
oled takes 3-4 arguments
1. keyboard
* this is where we get the config from
2. array of data
oled takes 2-3 arguments
1. array of data
* this array can have a length of 1 or 4. For images we use a length of 1.
* Every item in the array has 2 fields
* 0: this is the reaction type right now it can be "LAYER" or "STATIC"
* 0: this is the reaction type right now it can be OledReactionType.LAYER or OledReactionType.STATIC
* 1: the items you want to show for the reaction. In this example 4 images to switch on the 4 layers
3. toDisplay this takes a string "TXT" or "IMG".
2. toDisplay this takes a OledDisplayMode TXT or IMG.
* this tells the extension to load images or text.
4. flip Boolean this will simply flip your display.
3. flip Boolean this will simply flip your display.
![code layout](https://i.imgur.com/MrRYzo8.png)
```python
oled_ext = oled(keyboard, [{0:"LAYER",1:["1.bmp","2.bmp","3.bmp","4.bmp"]}],toDisplay='IMG',flip=True)
oled_ext = oled([{0:OledReactionType.LAYER,1:["1.bmp","2.bmp","3.bmp","4.bmp"]}],toDisplay=OledDisplayMode.IMG,flip=True)
```
In this code example we are saying to react to the layer change and load a image filed named "1.bmp" for layer one and "2.bmp" for layer two and so on.
### Preparing the images
So you need to include all the images in your circuitpython drive in the root along side main.py
@ -70,7 +69,7 @@ Your images need to be 128x32px and should only be black and white. After you ha
### Text
Ok now we get into something that looks a lot more complicated but we will get though it.
Almost everything is the same we are still passing in the keyboard for pin config. We swap toDisplay to "TXT" lets get into that array.
Almost everything is the same We swap toDisplay to TXT and there are more things in the array. Lets get into that array.
So each item in the array is a corner of the oled display
@ -78,20 +77,20 @@ So each item in the array is a corner of the oled display
1. top right
2. bottom left
3. bottom right
After that is the same as the previous example. Each one has two fields 0:the reaction type. 1:what to display
In this code we will always display the word "layer" in the top left corner of the screen then the other 3 corners will swap depending on the layer.
![code layout](https://i.imgur.com/wXl8nmZ.png)
```python
oled_ext = oled(keyboard,[
{0:"STATIC",1:["layer"]},
{0:"LAYER",1:["1","2","3","4"]},
{0:"LAYER",1:["base","raise","lower","adjust"]},
{0:"LAYER",1:["qwerty","nums","shifted","leds"]}
],toDisplay='TXT',flip=False)
oled_ext = oled([
{0:OledReactionType.STATIC,1:["layer"]},
{0:OledReactionType.LAYER,1:["1","2","3","4"]},
{0:OledReactionType.LAYER,1:["base","raise","lower","adjust"]},
{0:OledReactionType.LAYER,1:["qwerty","nums","shifted","leds"]}
],toDisplay=OledDisplayMode.TXT,flip=False)
```
![example](https://boardsource.imgix.net/a4f155e0-bc83-11ec-a4ed-79d542ba3127.gif)

View File

@ -9,37 +9,39 @@ from adafruit_display_text import label
from kmk.extensions import Extension
class oled(Extension):
class OledDisplayMode:
TXT = 0
IMG = 1
class OledReactionType:
STATIC = 0
LAYER = 1
class Oled(Extension):
def __init__(
self,
board,
views,
toDisplay: str = 'TXT',
oWidth: int = 128,
oHeight: int = 32,
toDisplay=OledDisplayMode.TXT,
oWidth=128,
oHeight=32,
flip: bool = False,
):
displayio.release_displays()
self.rotation = 180 if flip else 0
self._views = views
self._toDisplay = toDisplay
i2c = busio.I2C(board.SCL, board.SDA)
self.width = (oWidth,)
self.height = (oHeight,)
self.rotation = 180 if flip else 0
self._display = adafruit_displayio_ssd1306.SSD1306(
displayio.I2CDisplay(i2c, device_address=0x3C),
width=oWidth,
height=oHeight,
rotation=self.rotation,
)
self._width = oWidth
self._height = oHeight
self._prevLayers = 0
gc.collect()
def returnCurrectRenderText(self, layer, singleView):
# for now we only have static things and react to layers. But when we react to battery % and wpm we can handle the logic here
if singleView[0] == 'STATIC':
if singleView[0] == OledReactionType.STATIC:
return singleView[1][0]
if singleView[0] == 'LAYER':
if singleView[0] == OledReactionType.LAYER:
return singleView[1][layer]
def renderOledTextLayer(self, layer):
@ -94,9 +96,9 @@ class oled(Extension):
gc.collect()
def updateOLED(self, sandbox):
if self._toDisplay == 'TXT':
if self._toDisplay == OledDisplayMode.TXT:
self.renderOledTextLayer(sandbox.active_layers[0])
if self._toDisplay == 'IMG':
if self._toDisplay == OledDisplayMode.IMG:
self.renderOledImgLayer(sandbox.active_layers[0])
gc.collect()
@ -106,7 +108,15 @@ class oled(Extension):
def on_runtime_disable(self, sandbox):
return
def during_bootup(self, sandbox):
def during_bootup(self, board):
displayio.release_displays()
i2c = busio.I2C(board.SCL, board.SDA)
self._display = adafruit_displayio_ssd1306.SSD1306(
displayio.I2CDisplay(i2c, device_address=0x3C),
width=self._width,
height=self._height,
rotation=self.rotation,
)
self.renderOledImgLayer(0)
return