Simplify use of mpremote mount to run demos.

pull/55/head
Peter Hinch 2024-12-24 12:05:39 +00:00
rodzic 7cb2277363
commit 7edc54e54a
9 zmienionych plików z 1318 dodań i 70 usunięć

Wyświetl plik

@ -281,8 +281,6 @@ is required `-f` is also required. Supplied examples are:
* `font10.py` FreeSans 17 high. * `font10.py` FreeSans 17 high.
* `freesans20.py` FreeSans 20 high. * `freesans20.py` FreeSans 20 high.
The directory `gui/fonts/bitmaps` is only required for the `bitmap.py` demo.
###### [Contents](./README.md#0-contents) ###### [Contents](./README.md#0-contents)
## 1.4 Navigation ## 1.4 Navigation
@ -638,6 +636,16 @@ gui.demos.simple.test()
``` ```
Before running a different demo the host should be reset (ctrl-d) to clear RAM. Before running a different demo the host should be reset (ctrl-d) to clear RAM.
It is possible to run the demos without installing. Copy the directory tree to
the PC with
```bash
$ git clone https://github.com/peterhinch/micropython-micro-gui
```
Ensure your hardware_setup.py is in the GUI root and the hardware is connected.
Then issue (e.g.)
```bash
$ mpremote mount . exec "import gui.demos.simple"
```
These will run on screens of 128x128 pixels or above. The initial ones are These will run on screens of 128x128 pixels or above. The initial ones are
minimal and aim to demonstrate a single technique. minimal and aim to demonstrate a single technique.
* `simple.py` Minimal demo discussed below. `Button` presses print to REPL. * `simple.py` Minimal demo discussed below. `Button` presses print to REPL.
@ -663,7 +671,7 @@ minimal and aim to demonstrate a single technique.
* `adjust_vec.py` A pair of `Adjuster`s vary a vector. * `adjust_vec.py` A pair of `Adjuster`s vary a vector.
* `bitmap.py` Demo of the `BitMap` widget showing a changing image. (See widget * `bitmap.py` Demo of the `BitMap` widget showing a changing image. (See widget
docs). docs).
* `qrcode.py` Display a QR code. Requires the uQR module. * `qrcode.py` Display a QR code. Requires the uQR module: see widget docs.
* `calendar.py` Demo of grid widget. * `calendar.py` Demo of grid widget.
* `epaper.py` Warts-and-all demo for an ePaper display. Currently the only * `epaper.py` Warts-and-all demo for an ePaper display. Currently the only
supported display is the supported display is the
@ -2829,8 +2837,9 @@ Because of the use of file storage when an update occurs there will be a brief
is displayed when a screen initialises, or if it changes in response to a user is displayed when a screen initialises, or if it changes in response to a user
action. Use in animations is questionable. action. Use in animations is questionable.
See `gui/demos/bitmap.py` for a usage example. Files must be copied from See `gui/demos/bitmap.py` for a usage example. Example bitmaps are in
`gui/fonts/bitmaps/` to the root directory of the device. `optional_extras/bitmaps/`. This directory structure should be copied to the
device.
###### [Contents](./README.md#0-contents) ###### [Contents](./README.md#0-contents)
@ -2884,7 +2893,7 @@ If memory errors are encountered try cross-compiling or the use of frozen byte
code. code.
See `gui/demos/qrcode.py` for a usage example. The demo expects `uQR.py` to be See `gui/demos/qrcode.py` for a usage example. The demo expects `uQR.py` to be
located in the root directory of the target. located in 'optional_extras/py/' on the target.
###### [Contents](./README.md#0-contents) ###### [Contents](./README.md#0-contents)

Wyświetl plik

@ -23,12 +23,15 @@ class BaseScreen(Screen):
row = 25 row = 25
self.graphic = BitMap(wri, row, col, 99, 99, fgcolor=WHITE, bgcolor=BLACK) self.graphic = BitMap(wri, row, col, 99, 99, fgcolor=WHITE, bgcolor=BLACK)
col = 120 col = 120
Button(wri, row, col, text="Next", callback=self.cb) Button(wri, row, col, text="Next", litcolor=WHITE, callback=self.cb)
CloseButton(wri) # Quit the application CloseButton(wri) # Quit the application
self.image = 0 self.image = 0
def cb(self, _): def cb(self, _):
self.graphic.value(f"/m{self.image:02d}") try:
self.graphic.value(path := f"optional_extras/bitmaps/m{self.image:02d}")
except OSError:
print(f"File {path} not found.")
self.image += 1 self.image += 1
self.image %= 4 self.image %= 4
if self.image == 3: if self.image == 3:

Wyświetl plik

@ -6,10 +6,10 @@ from framebuf import FrameBuffer, MONO_HLSB
from gui.core.ugui import Widget from gui.core.ugui import Widget
from gui.core.colors import * from gui.core.colors import *
from gui.core.ugui import ssd from gui.core.ugui import ssd
from uQR import QRCode from optional_extras.py.uQR import QRCode
from utime import ticks_diff, ticks_ms from utime import ticks_diff, ticks_ms
class QRMap(Widget): class QRMap(Widget):
@staticmethod @staticmethod
def len_side(version): def len_side(version):
@ -20,7 +20,7 @@ class QRMap(Widget):
side = QRMap.len_side(version) * scale side = QRMap.len_side(version) * scale
width = (side >> 3) + int(side & 7 > 0) # Width in bytes width = (side >> 3) + int(side & 7 > 0) # Width in bytes
return bytearray(side * width) return bytearray(side * width)
def __init__(self, writer, row, col, version=4, scale=1, *, bdcolor=RED, buf=None): def __init__(self, writer, row, col, version=4, scale=1, *, bdcolor=RED, buf=None):
self._version = version self._version = version
self._scale = scale self._scale = scale

Wyświetl plik

@ -1,59 +0,0 @@
# pico_epaper_42.py on my PCB (non-standard connection)
# Released under the MIT License (MIT). See LICENSE.
# Copyright (c) 2023 Peter Hinch
# This Hardware_setup.py is for # https://www.waveshare.com/pico-epaper-4.2.htm
# wired to the Pico using the ribbon cable rather than the default socket.
# This was to enable testing using my ILI9341 PCB and its pushbuttons.
# Use commented-out code below if using the built-in Pico socket.
# WIRING
# Pico Display
# GPIO Pin
# 3v3 36 Vin
# IO6 9 CLK Hardware SPI0
# IO7 10 DATA (AKA SI MOSI)
# IO8 11 DC
# IO9 12 Rst
# Gnd 13 Gnd
# IO10 14 CS
# Pushbuttons are wired between the pin and Gnd
# Pico pin Meaning
# 16 Operate current control
# 17 Decrease value of current control
# 18 Select previous control
# 19 Select next control
# 20 Increase value of current control
from machine import Pin, SPI, freq
import gc
from drivers.epaper.pico_epaper_42 import EPD as SSD
freq(250_000_000) # RP2 overclock
# Create and export an SSD instance
prst = Pin(9, Pin.OUT, value=1)
pcs = Pin(10, Pin.OUT, value=1)
pdc = Pin(8, Pin.OUT, value=0) # Arbitrary pins
busy = Pin(15, Pin.IN)
# Datasheet allows 10MHz
spi = SPI(0, sck=Pin(6), mosi=Pin(7), miso=Pin(4), baudrate=10_000_000)
gc.collect() # Precaution before instantiating framebuf
# Using normal socket connection default args apply
# ssd = SSD()
ssd = SSD(spi, pcs, pdc, prst, busy)
gc.collect()
from gui.core.ugui import Display, quiet
# quiet()
# Create and export a Display instance
# Define control buttons
nxt = Pin(19, Pin.IN, Pin.PULL_UP) # Move to next control
sel = Pin(16, Pin.IN, Pin.PULL_UP) # Operate current control
prev = Pin(18, Pin.IN, Pin.PULL_UP) # Move to previous control
increase = Pin(20, Pin.IN, Pin.PULL_UP) # Increase control's value
decrease = Pin(17, Pin.IN, Pin.PULL_UP) # Decrease control's value
# display = Display(ssd, nxt, sel, prev) # 3-button mode
display = Display(ssd, nxt, sel, prev, increase, decrease) # 5-button mode
ssd.wait_until_ready() # Blocking wait
ssd.set_partial() # Subsequent refreshes are partial

Plik diff jest za duży Load Diff