1
0
Fork 0

apps: testapp: Automatically report free memory

Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
This commit is contained in:
Daniel Thompson 2020-12-12 21:35:45 +00:00
parent 338925b4a8
commit 784c9bb36d
6 changed files with 38 additions and 2 deletions

View file

@ -5,9 +5,11 @@
~~~~~~~~~~~~~ ~~~~~~~~~~~~~
""" """
import machine
import wasp import wasp
import gc
import icons import icons
import machine
from apps.pager import PagerApp from apps.pager import PagerApp
@ -23,7 +25,7 @@ class TestApp():
ICON = icons.app ICON = icons.app
def __init__(self): def __init__(self):
self.tests = ('Alarm', 'Button', 'Crash', 'Colours', 'Fill', 'Fill-H', 'Fill-V', 'Line', 'Notifications', 'RLE', 'String', 'Touch', 'Wrap') self.tests = ('Alarm', 'Button', 'Crash', 'Colours', 'Fill', 'Fill-H', 'Fill-V', 'Free Mem', 'Line', 'Notifications', 'RLE', 'String', 'Touch', 'Wrap')
self.test = self.tests[0] self.test = self.tests[0]
self.scroll = wasp.widgets.ScrollIndicator() self.scroll = wasp.widgets.ScrollIndicator()
@ -226,6 +228,15 @@ class TestApp():
for s in self._sliders: for s in self._sliders:
s.draw() s.draw()
self._update_colours() self._update_colours()
elif self.test == 'Free Mem':
if wasp.watch.free:
draw.string("Boot: {}".format(wasp.watch.free), 12, 3*24)
draw.string("Init: {}".format(wasp.free), 12, 4*24)
draw.string("Now: {}".format(gc.mem_free()), 12, 5*24)
gc.collect()
draw.string("GC: {}".format(gc.mem_free()), 12, 6*24)
else:
draw.string("Not supported", 12, 4*24)
elif self.test == 'Notifications': elif self.test == 'Notifications':
draw.string('+', 24, 100) draw.string('+', 24, 100)
draw.string('-', 210, 100) draw.string('-', 210, 100)

View file

@ -13,6 +13,7 @@ from drivers.nrf_rtc import RTC
rtc = RTC(RTCounter(1, mode=RTCounter.PERIODIC, period=1, callback=_callback)) rtc = RTC(RTCounter(1, mode=RTCounter.PERIODIC, period=1, callback=_callback))
rtc.counter.start() rtc.counter.start()
import gc
import os import os
import time import time
@ -135,3 +136,6 @@ try:
except: except:
drawable.string("FAILED", 0, 136, width=240) drawable.string("FAILED", 0, 136, width=240)
backlight.set(2) backlight.set(2)
gc.collect()
free = gc.mem_free()

View file

@ -13,6 +13,7 @@ from drivers.nrf_rtc import RTC
rtc = RTC(RTCounter(1, mode=RTCounter.PERIODIC, period=1, callback=_callback)) rtc = RTC(RTCounter(1, mode=RTCounter.PERIODIC, period=1, callback=_callback))
rtc.counter.start() rtc.counter.start()
import gc
import os import os
import time import time
@ -123,3 +124,6 @@ try:
except: except:
drawable.string("FAILED", 0, 136, width=240) drawable.string("FAILED", 0, 136, width=240)
backlight.set(1) backlight.set(1)
gc.collect()
free = gc.mem_free()

View file

@ -13,6 +13,7 @@ from drivers.nrf_rtc import RTC
rtc = RTC(RTCounter(1, mode=RTCounter.PERIODIC, period=1, callback=_callback)) rtc = RTC(RTCounter(1, mode=RTCounter.PERIODIC, period=1, callback=_callback))
rtc.counter.start() rtc.counter.start()
import gc
import os import os
import time import time
@ -125,3 +126,6 @@ try:
except: except:
drawable.string("FAILED", 0, 136, width=240) drawable.string("FAILED", 0, 136, width=240)
backlight.set(1) backlight.set(1)
gc.collect()
free = gc.mem_free()

View file

@ -188,3 +188,6 @@ vibrator = Vibrator(Pin('MOTOR', Pin.OUT, value=0), active_low=True)
def connected(): def connected():
return not (int(rtc.uptime / 30) & 1) return not (int(rtc.uptime / 30) & 1)
# Free memory cannot be measured on the simulator
free = 0

View file

@ -441,12 +441,17 @@ class Manager():
normal execution context meaning any exceptions and other problems normal execution context meaning any exceptions and other problems
can be observed interactively via the console. can be observed interactively via the console.
""" """
global free
if self._scheduling: if self._scheduling:
print('Watch already running in the background') print('Watch already running in the background')
return return
if not self.app: if not self.app:
self.switch(self.quick_ring[0]) self.switch(self.quick_ring[0])
if watch.free:
gc.collect()
free = gc.mem_free()
# Reminder: wasptool uses this string to confirm the device has # Reminder: wasptool uses this string to confirm the device has
# been set running again. # been set running again.
@ -494,8 +499,13 @@ class Manager():
def schedule(self, enable=True): def schedule(self, enable=True):
"""Run the system manager synchronously.""" """Run the system manager synchronously."""
global free
if not self.app: if not self.app:
self.switch(self.quick_ring[0]) self.switch(self.quick_ring[0])
if watch.free:
gc.collect()
free = gc.mem_free()
if enable: if enable:
watch.schedule = self._schedule watch.schedule = self._schedule