Skip to content

Commit

Permalink
Color tests pass, prior to splitting out widgets.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterhinch committed Nov 3, 2020
1 parent 2194524 commit 5ec4948
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 293 deletions.
2 changes: 1 addition & 1 deletion gui/core/nanogui.py
Expand Up @@ -9,7 +9,7 @@
# border: False no border None use bgcolor, int: treat as color

import cmath
from ngui.core.writer import Writer
from gui.core.writer import Writer
import framebuf
import gc

Expand Down
33 changes: 5 additions & 28 deletions gui/demos/aclock.py
Expand Up @@ -2,8 +2,6 @@
# Adafruit 1.5" 128*128 OLED display: https://www.adafruit.com/product/1431
# Adafruit 1.27" 128*96 display https://www.adafruit.com/product/1673

# The MIT License (MIT)

# Released under the MIT License (MIT). See LICENSE.
# Copyright (c) 2018-2020 Peter Hinch

Expand All @@ -17,40 +15,19 @@
# X6 CLK
# X8 DATA

height = 96 # 1.27 inch 96*128 (rows*cols) display
# height = 128 # 1.5 inch 128*128 display

# Demo of initialisation procedure designed to minimise risk of memory fail
# when instantiating the frame buffer. The aim is to do this as early as
# possible before importing other modules.

import machine
import gc
from drivers.ssd1351 import SSD1351 as SSD

# Initialise hardware
pdc = machine.Pin('X1', machine.Pin.OUT_PP, value=0)
pcs = machine.Pin('X2', machine.Pin.OUT_PP, value=1)
prst = machine.Pin('X3', machine.Pin.OUT_PP, value=1)
spi = machine.SPI(1)
gc.collect() # Precaution before instantiating framebuf
ssd = SSD(spi, pcs, pdc, prst, height) # Create a display instance
from nanogui import Dial, Pointer, refresh, Label
from ssd1351_setup import ssd, height # Create a display instance
from gui.core.nanogui import Dial, Pointer, refresh, Label
refresh(ssd) # Initialise and clear display.

# Now import other modules
import cmath
import utime
from ngui.core.writer import CWriter
from gui.core.writer import CWriter

# Font for CWriter
import arial10

GREEN = SSD.rgb(0, 255, 0)
RED = SSD.rgb(255, 0, 0)
BLUE = SSD.rgb(0, 0, 255)
YELLOW = SSD.rgb(255, 255, 0)
BLACK = 0
import gui.fonts.arial10 as arial10
from gui.core.colors import *

def aclock():
uv = lambda phi : cmath.rect(1, phi) # Return a unit vector of phase phi
Expand Down
50 changes: 8 additions & 42 deletions gui/demos/alevel.py
Expand Up @@ -2,27 +2,8 @@
# Adafruit 1.5" 128*128 OLED display: https://www.adafruit.com/product/1431
# Adafruit 1.27" 128*96 display https://www.adafruit.com/product/1673

# The MIT License (MIT)

# Copyright (c) 2018 Peter Hinch

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# Released under the MIT License (MIT). See LICENSE.
# Copyright (c) 2018-2020 Peter Hinch

# WIRING
# Pyb SSD
Expand All @@ -34,40 +15,25 @@
# X6 CLK
# X8 DATA

height = 96 # 1.27 inch 96*128 (rows*cols) display
# height = 128 # 1.5 inch 128*128 display

# Demo of initialisation procedure designed to minimise risk of memory fail
# when instantiating the frame buffer. The aim is to do this as early as
# possible before importing other modules.

import machine
import gc
from ssd1351 import SSD1351 as SSD

# Initialise hardware
pdc = machine.Pin('X1', machine.Pin.OUT_PP, value=0)
pcs = machine.Pin('X2', machine.Pin.OUT_PP, value=1)
prst = machine.Pin('X3', machine.Pin.OUT_PP, value=1)
spi = machine.SPI(1)
gc.collect() # Precaution befor instantiating framebuf
ssd = SSD(spi, pcs, pdc, prst, height) # Create a display instance
from nanogui import Dial, Pointer, refresh
from ssd1351_setup import ssd # Create a display instance

from gui.core.nanogui import Dial, Pointer, refresh
refresh(ssd) # Initialise and clear display.

# Now import other modules

import utime
import pyb
from writer import CWriter
import arial10 # Font

GREEN = SSD.rgb(0, 255, 0)
RED = SSD.rgb(255, 0, 0)
BLUE = SSD.rgb(0, 0, 255)
YELLOW = SSD.rgb(255, 255, 0)
BLACK = 0

from gui.core.writer import CWriter
import gui.fonts.arial10 as arial10
from gui.core.colors import *

def main():
print('alevel test is running.')
Expand Down
40 changes: 6 additions & 34 deletions gui/demos/asnano.py
Expand Up @@ -6,49 +6,21 @@
# Copyright (c) 2020 Peter Hinch
# Released under the MIT License (MIT) - see LICENSE file

# WIRING (Adafruit pin nos and names)
# Pyb SSD
# 3v3 Vin (10)
# Gnd Gnd (11)
# X1 DC (3 DC)
# X2 CS (5 OC OLEDCS)
# X3 Rst (4 R RESET)
# X6 CLK (2 CL SCK)
# X8 DATA (1 SI MOSI)

height = 96 # 1.27 inch 96*128 (rows*cols) display
# height = 128 # 1.5 inch 128*128 display

import machine
import gc
from ssd1351 import SSD1351 as SSD

# Initialise hardware and framebuf before importing modules
#pdc = machine.Pin('X1', machine.Pin.OUT_PP, value=0)
#pcs = machine.Pin('X2', machine.Pin.OUT_PP, value=1)
#prst = machine.Pin('X3', machine.Pin.OUT_PP, value=1)
#spi = machine.SPI(1)
pdc = machine.Pin('Y1', machine.Pin.OUT_PP, value=0)
pcs = machine.Pin('Y2', machine.Pin.OUT_PP, value=1)
prst = machine.Pin('Y3', machine.Pin.OUT_PP, value=1)
spi = machine.SPI(2)
gc.collect() # Precaution befor instantiating framebuf
ssd = SSD(spi, pcs, pdc, prst, height) # Create a display instance
from ssd1351_setup import ssd # Create a display instance

import uasyncio as asyncio
import pyb
import uos
from writer import CWriter
from nanogui import LED, Meter, refresh
from gui.core.writer import CWriter
from gui.core.nanogui import LED, Meter, refresh
refresh(ssd)

# Fonts
import arial10, freesans20
import gui.fonts.arial10 as arial10
import gui.fonts.freesans20 as freesans20

GREEN = SSD.rgb(0, 255, 0)
RED = SSD.rgb(255, 0, 0)
YELLOW = SSD.rgb(255, 255, 0)
BLACK = 0
from gui.core.colors import *

CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it
wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False)
Expand Down
40 changes: 6 additions & 34 deletions gui/demos/asnano_sync.py
Expand Up @@ -6,49 +6,21 @@
# Copyright (c) 2020 Peter Hinch
# Released under the MIT License (MIT) - see LICENSE file

# WIRING (Adafruit pin nos and names)
# Pyb SSD
# 3v3 Vin (10)
# Gnd Gnd (11)
# X1 DC (3 DC)
# X2 CS (5 OC OLEDCS)
# X3 Rst (4 R RESET)
# X6 CLK (2 CL SCK)
# X8 DATA (1 SI MOSI)

height = 96 # 1.27 inch 96*128 (rows*cols) display
# height = 128 # 1.5 inch 128*128 display

import machine
import gc
from ssd1351 import SSD1351 as SSD

# Initialise hardware and framebuf before importing modules
#pdc = machine.Pin('X1', machine.Pin.OUT_PP, value=0)
#pcs = machine.Pin('X2', machine.Pin.OUT_PP, value=1)
#prst = machine.Pin('X3', machine.Pin.OUT_PP, value=1)
#spi = machine.SPI(1)
pdc = machine.Pin('Y1', machine.Pin.OUT_PP, value=0)
pcs = machine.Pin('Y2', machine.Pin.OUT_PP, value=1)
prst = machine.Pin('Y3', machine.Pin.OUT_PP, value=1)
spi = machine.SPI(2)
gc.collect() # Precaution befor instantiating framebuf
ssd = SSD(spi, pcs, pdc, prst, height) # Create a display instance
from ssd1351_setup import ssd # Create a display instance

import uasyncio as asyncio
import pyb
import uos
from writer import CWriter
from nanogui import LED, Meter, refresh
from gui.core.writer import CWriter
from gui.core.nanogui import LED, Meter, refresh
refresh(ssd)

# Fonts
import arial10, freesans20
import gui.fonts.arial10 as arial10
import gui.fonts.freesans20 as freesans20

GREEN = SSD.rgb(0, 255, 0)
RED = SSD.rgb(255, 0, 0)
YELLOW = SSD.rgb(255, 255, 0)
BLACK = 0
from gui.core.colors import *

color = lambda v : RED if v > 0.7 else YELLOW if v > 0.5 else GREEN
txt = lambda v : 'ovr' if v > 0.7 else 'high' if v > 0.5 else 'ok'
Expand Down
52 changes: 9 additions & 43 deletions gui/demos/color15.py
Expand Up @@ -3,57 +3,23 @@
# Adafruit 1.27" 128*96 display https://www.adafruit.com/product/1673
# For wiring details see drivers/ADAFRUIT.md in this repo.

# The MIT License (MIT)
# Released under the MIT License (MIT). See LICENSE.
# Copyright (c) 2018-2020 Peter Hinch

# Copyright (c) 2018 Peter Hinch

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

height = 96 # 1.27 inch 96*128 (rows*cols) display
# height = 128 # 1.5 inch 128*128 display

import machine
import gc
from ssd1351 import SSD1351 as SSD

# Initialise hardware and framebuf before importing modules
pdc = machine.Pin('X1', machine.Pin.OUT_PP, value=0)
pcs = machine.Pin('X2', machine.Pin.OUT_PP, value=1)
prst = machine.Pin('X3', machine.Pin.OUT_PP, value=1)
spi = machine.SPI(1)
gc.collect() # Precaution befor instantiating framebuf
ssd = SSD(spi, pcs, pdc, prst, height) # Create a display instance
from ssd1351_setup import ssd # Create a display instance

import cmath
import utime
import uos
from writer import Writer, CWriter
from nanogui import Label, Meter, LED, Dial, Pointer, refresh
from gui.core.writer import Writer, CWriter
from gui.core.nanogui import Label, Meter, LED, Dial, Pointer, refresh

# Fonts
import arial10, freesans20
import gui.fonts.arial10 as arial10
import gui.fonts.freesans20 as freesans20

from gui.core.colors import *

GREEN = SSD.rgb(0, 255, 0)
RED = SSD.rgb(255, 0, 0)
BLUE = SSD.rgb(0, 0, 255)
YELLOW = SSD.rgb(255, 255, 0)
BLACK = 0
CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it
wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False)
wri.set_clip(True, True, False)
Expand Down
47 changes: 8 additions & 39 deletions gui/demos/color96.py
Expand Up @@ -2,51 +2,20 @@
# https://www.adafruit.com/product/684
# For wiring details see drivers/ADAFRUIT.md in this repo.

# The MIT License (MIT)
# Released under the MIT License (MIT). See LICENSE.
# Copyright (c) 2018-2020 Peter Hinch

# Copyright (c) 2018 Peter Hinch
from ssd1351_setup import ssd # Create a display instance

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import machine
import gc
from ssd1331 import SSD1331 as SSD
pdc = machine.Pin('X1', machine.Pin.OUT_PP, value=0)
pcs = machine.Pin('X2', machine.Pin.OUT_PP, value=1)
prst = machine.Pin('X3', machine.Pin.OUT_PP, value=1)
spi = machine.SPI(1)
gc.collect()
ssd = SSD(spi, pcs, pdc, prst) # Create a display instance

from nanogui import Label, Meter, LED, refresh
from gui.core.nanogui import Label, Meter, LED, refresh
refresh(ssd)
# Fonts
import arial10
from writer import Writer, CWriter
import gui.fonts.arial10 as arial10

from gui.core.writer import Writer, CWriter
import utime
import uos

GREEN = SSD.rgb(0, 255, 0)
RED = SSD.rgb(255, 0, 0)
BLUE = SSD.rgb(0, 0, 255)
YELLOW = SSD.rgb(255, 255, 0)
BLACK = 0
from gui.core.colors import *

CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it
wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False)
Expand Down

0 comments on commit 5ec4948

Please sign in to comment.