diff --git a/wasp/apps/testapp.py b/wasp/apps/testapp.py index 66d3fce..2b2e05b 100644 --- a/wasp/apps/testapp.py +++ b/wasp/apps/testapp.py @@ -5,9 +5,11 @@ ~~~~~~~~~~~~~ """ -import machine import wasp + +import gc import icons +import machine from apps.pager import PagerApp @@ -23,7 +25,7 @@ class TestApp(): ICON = icons.app 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.scroll = wasp.widgets.ScrollIndicator() @@ -226,6 +228,15 @@ class TestApp(): for s in self._sliders: s.draw() 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': draw.string('+', 24, 100) draw.string('-', 210, 100) diff --git a/wasp/boards/k9/watch.py.in b/wasp/boards/k9/watch.py.in index b7bfabc..8360451 100644 --- a/wasp/boards/k9/watch.py.in +++ b/wasp/boards/k9/watch.py.in @@ -13,6 +13,7 @@ from drivers.nrf_rtc import RTC rtc = RTC(RTCounter(1, mode=RTCounter.PERIODIC, period=1, callback=_callback)) rtc.counter.start() +import gc import os import time @@ -135,3 +136,6 @@ try: except: drawable.string("FAILED", 0, 136, width=240) backlight.set(2) + +gc.collect() +free = gc.mem_free() diff --git a/wasp/boards/p8/watch.py.in b/wasp/boards/p8/watch.py.in index 9018a66..e133fee 100644 --- a/wasp/boards/p8/watch.py.in +++ b/wasp/boards/p8/watch.py.in @@ -13,6 +13,7 @@ from drivers.nrf_rtc import RTC rtc = RTC(RTCounter(1, mode=RTCounter.PERIODIC, period=1, callback=_callback)) rtc.counter.start() +import gc import os import time @@ -123,3 +124,6 @@ try: except: drawable.string("FAILED", 0, 136, width=240) backlight.set(1) + +gc.collect() +free = gc.mem_free() diff --git a/wasp/boards/pinetime/watch.py.in b/wasp/boards/pinetime/watch.py.in index fbda41e..6db9537 100644 --- a/wasp/boards/pinetime/watch.py.in +++ b/wasp/boards/pinetime/watch.py.in @@ -13,6 +13,7 @@ from drivers.nrf_rtc import RTC rtc = RTC(RTCounter(1, mode=RTCounter.PERIODIC, period=1, callback=_callback)) rtc.counter.start() +import gc import os import time @@ -125,3 +126,6 @@ try: except: drawable.string("FAILED", 0, 136, width=240) backlight.set(1) + +gc.collect() +free = gc.mem_free() diff --git a/wasp/boards/simulator/watch.py b/wasp/boards/simulator/watch.py index 98d9246..5aead3f 100644 --- a/wasp/boards/simulator/watch.py +++ b/wasp/boards/simulator/watch.py @@ -188,3 +188,6 @@ vibrator = Vibrator(Pin('MOTOR', Pin.OUT, value=0), active_low=True) def connected(): return not (int(rtc.uptime / 30) & 1) + +# Free memory cannot be measured on the simulator +free = 0 diff --git a/wasp/wasp.py b/wasp/wasp.py index 7f4d0d4..7cf2883 100644 --- a/wasp/wasp.py +++ b/wasp/wasp.py @@ -441,12 +441,17 @@ class Manager(): normal execution context meaning any exceptions and other problems can be observed interactively via the console. """ + global free + if self._scheduling: print('Watch already running in the background') return if not self.app: 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 # been set running again. @@ -494,8 +499,13 @@ class Manager(): def schedule(self, enable=True): """Run the system manager synchronously.""" + global free + if not self.app: self.switch(self.quick_ring[0]) + if watch.free: + gc.collect() + free = gc.mem_free() if enable: watch.schedule = self._schedule