kopia lustrzana https://github.com/peterhinch/micropython-micro-gui
Add free RAM print and quiet() function.
rodzic
01b00c5e2c
commit
e289692be1
|
@ -311,7 +311,8 @@ gc.collect() # Precaution before instantiating framebuf
|
|||
# Instantiate display and assign to ssd. For args see display drivers doc.
|
||||
ssd = SSD(spi, pcs, pdc, prst, usd=True)
|
||||
|
||||
from gui.core.ugui import Display, setup
|
||||
from gui.core.ugui import Display, quiet
|
||||
# quiet()
|
||||
# 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
|
||||
|
@ -330,6 +331,9 @@ The final arg specifies the sensitivity of the attached encoder, the higher the
|
|||
value the more the knob has to be turned for a desired effect. A value of 1
|
||||
provides the highest sensitivity, being the native rate of the encoder.
|
||||
|
||||
The commented-out `quiet()` line provides a means of suppressing diagnostic
|
||||
messages.
|
||||
|
||||
Instantiation of `SSD` and `Display` classes is detailed in
|
||||
[section 3](./README.md#3-the-ssd-and-display-objects).
|
||||
|
||||
|
@ -390,6 +394,9 @@ Once again, directory structure must be maintained. An example directory
|
|||
structure, pruned to contain a minimum of files, may be seen
|
||||
[here](https://github.com/peterhinch/micropython-nano-gui#4-esp8266).
|
||||
|
||||
For reasons that are unclear, freezing the display driver can lead to
|
||||
instability. For this reason it is recommended to freeze the gui tree only.
|
||||
|
||||
###### [Contents](./README.md#0-contents)
|
||||
|
||||
## 1.8 Performance and hardware notes
|
||||
|
|
|
@ -17,6 +17,7 @@ from gui.primitives import Pushbutton
|
|||
# Globally available singleton objects
|
||||
display = None # Singleton instance
|
||||
ssd = None
|
||||
_vb = True
|
||||
|
||||
gc.collect()
|
||||
__version__ = (0, 1, 5)
|
||||
|
@ -34,12 +35,15 @@ _NEXT = const(1)
|
|||
_PREV = const(2)
|
||||
_LAST = const(3)
|
||||
|
||||
def quiet():
|
||||
global _vb
|
||||
_vb = False
|
||||
|
||||
# Input abstracts input from 2-5 pushbuttons or 3 buttons + encoder. Handles
|
||||
# transitions between modes (normal, precision, adjustment)
|
||||
class Input:
|
||||
|
||||
def __init__(self, nxt, sel, prev, incr, decr, encoder):
|
||||
verbose = True
|
||||
self._encoder = encoder # Encoder in use
|
||||
self._precision = False # Precision mode
|
||||
self._adj = False # Adjustment mode
|
||||
|
@ -60,13 +64,13 @@ class Input:
|
|||
self._prev = Pushbutton(prev)
|
||||
self._prev.press_func(Screen.ctrl_move, (_PREV,))
|
||||
if encoder:
|
||||
verbose and print('Using encoder.')
|
||||
_vb and print('Using encoder.')
|
||||
if incr is None or decr is None:
|
||||
raise ValueError('Must specify pins for encoder.')
|
||||
from gui.primitives.encoder import Encoder
|
||||
self._enc = Encoder(incr, decr, div=encoder, callback=Screen.adjust)
|
||||
else:
|
||||
verbose and print('Using {:d} switches.'.format(self._nb))
|
||||
_vb and print('Using {:d} switches.'.format(self._nb))
|
||||
# incr and decr methods get the button as an arg.
|
||||
if incr is not None:
|
||||
sup = Pushbutton(incr)
|
||||
|
@ -499,11 +503,14 @@ class Screen:
|
|||
self.tasks.append((task, on_change))
|
||||
|
||||
async def _garbage_collect(self):
|
||||
n = 0
|
||||
while True:
|
||||
await asyncio.sleep_ms(500)
|
||||
gc.collect()
|
||||
gc.threshold(gc.mem_free() // 4 + gc.mem_alloc())
|
||||
# print(gc.mem_free())
|
||||
n += 1
|
||||
n &= 0x1f
|
||||
_vb and (not n) and print("Free RAM", gc.mem_free())
|
||||
|
||||
# Very basic window class. Cuts a rectangular hole in a screen on which
|
||||
# content may be drawn.
|
||||
|
|
|
@ -43,7 +43,8 @@ spi = SPI(0, baudrate=30_000_000)
|
|||
gc.collect() # Precaution before instantiating framebuf
|
||||
ssd = SSD(spi, pcs, pdc, prst, usd=True)
|
||||
|
||||
from gui.core.ugui import Display
|
||||
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
|
||||
|
@ -51,5 +52,5 @@ 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) # Encoder mode
|
||||
# display = Display(ssd, nxt, sel, prev) # 3-button mode
|
||||
display = Display(ssd, nxt, sel, prev, increase, decrease, 5) # Encoder mode
|
||||
|
|
Ładowanie…
Reference in New Issue