made changes from klardotsh's review
This commit is contained in:
parent
ad43377a5e
commit
7e760a2917
@ -35,7 +35,7 @@ These are the changes that need to be made / added to your main.py
|
|||||||
### Config
|
### Config
|
||||||
no mater how you are going to use the oled you need this part
|
no mater how you are going to use the oled you need this part
|
||||||
```python
|
```python
|
||||||
from kmk.extensions.peg_oledDisplay import oled
|
from kmk.extensions.peg_oled_Display import Oled,OledDisplayMode,OledReactionType
|
||||||
keyboard = KMKKeyboard()
|
keyboard = KMKKeyboard()
|
||||||
# ... Other oled code
|
# ... Other oled code
|
||||||
keyboard.extensions.append(oled_ext)
|
keyboard.extensions.append(oled_ext)
|
||||||
@ -44,24 +44,23 @@ no mater how you are going to use the oled you need this part
|
|||||||
### Photos
|
### Photos
|
||||||
So the config for photos is quite simple. Getting the photos maybe not so much. I will explain.
|
So the config for photos is quite simple. Getting the photos maybe not so much. I will explain.
|
||||||
|
|
||||||
oled takes 3-4 arguments
|
oled takes 2-3 arguments
|
||||||
1. keyboard
|
|
||||||
* this is where we get the config from
|
1. array of data
|
||||||
2. array of data
|
|
||||||
* this array can have a length of 1 or 4. For images we use a length of 1.
|
* 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
|
* 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
|
* 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.
|
* 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.
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
```python
|
```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.
|
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
|
### Preparing the images
|
||||||
So you need to include all the images in your circuitpython drive in the root along side main.py
|
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
|
### Text
|
||||||
Ok now we get into something that looks a lot more complicated but we will get though it.
|
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
|
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
|
1. top right
|
||||||
2. bottom left
|
2. bottom left
|
||||||
3. bottom right
|
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
|
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.
|
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.
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
oled_ext = oled(keyboard,[
|
oled_ext = oled([
|
||||||
{0:"STATIC",1:["layer"]},
|
{0:OledReactionType.STATIC,1:["layer"]},
|
||||||
{0:"LAYER",1:["1","2","3","4"]},
|
{0:OledReactionType.LAYER,1:["1","2","3","4"]},
|
||||||
{0:"LAYER",1:["base","raise","lower","adjust"]},
|
{0:OledReactionType.LAYER,1:["base","raise","lower","adjust"]},
|
||||||
{0:"LAYER",1:["qwerty","nums","shifted","leds"]}
|
{0:OledReactionType.LAYER,1:["qwerty","nums","shifted","leds"]}
|
||||||
],toDisplay='TXT',flip=False)
|
],toDisplay=OledDisplayMode.TXT,flip=False)
|
||||||
```
|
```
|
||||||

|

|
||||||
|
|
||||||
|
@ -9,37 +9,39 @@ from adafruit_display_text import label
|
|||||||
from kmk.extensions import Extension
|
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__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
board,
|
|
||||||
views,
|
views,
|
||||||
toDisplay: str = 'TXT',
|
toDisplay=OledDisplayMode.TXT,
|
||||||
oWidth: int = 128,
|
oWidth=128,
|
||||||
oHeight: int = 32,
|
oHeight=32,
|
||||||
flip: bool = False,
|
flip: bool = False,
|
||||||
):
|
):
|
||||||
displayio.release_displays()
|
displayio.release_displays()
|
||||||
|
self.rotation = 180 if flip else 0
|
||||||
self._views = views
|
self._views = views
|
||||||
self._toDisplay = toDisplay
|
self._toDisplay = toDisplay
|
||||||
i2c = busio.I2C(board.SCL, board.SDA)
|
self._width = oWidth
|
||||||
self.width = (oWidth,)
|
self._height = oHeight
|
||||||
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._prevLayers = 0
|
self._prevLayers = 0
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
def returnCurrectRenderText(self, layer, singleView):
|
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
|
# 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]
|
return singleView[1][0]
|
||||||
if singleView[0] == 'LAYER':
|
if singleView[0] == OledReactionType.LAYER:
|
||||||
return singleView[1][layer]
|
return singleView[1][layer]
|
||||||
|
|
||||||
def renderOledTextLayer(self, layer):
|
def renderOledTextLayer(self, layer):
|
||||||
@ -94,9 +96,9 @@ class oled(Extension):
|
|||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
def updateOLED(self, sandbox):
|
def updateOLED(self, sandbox):
|
||||||
if self._toDisplay == 'TXT':
|
if self._toDisplay == OledDisplayMode.TXT:
|
||||||
self.renderOledTextLayer(sandbox.active_layers[0])
|
self.renderOledTextLayer(sandbox.active_layers[0])
|
||||||
if self._toDisplay == 'IMG':
|
if self._toDisplay == OledDisplayMode.IMG:
|
||||||
self.renderOledImgLayer(sandbox.active_layers[0])
|
self.renderOledImgLayer(sandbox.active_layers[0])
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
@ -106,7 +108,15 @@ class oled(Extension):
|
|||||||
def on_runtime_disable(self, sandbox):
|
def on_runtime_disable(self, sandbox):
|
||||||
return
|
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)
|
self.renderOledImgLayer(0)
|
||||||
return
|
return
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user