From 6aba239972ae6415177171c26bbe44b0d32b6646 Mon Sep 17 00:00:00 2001 From: Matthew Jaskula Date: Fri, 13 May 2022 14:58:35 -0400 Subject: [PATCH 1/5] add rp2 to the micropython mocks --- software/tests/mocks/rp2.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 software/tests/mocks/rp2.py diff --git a/software/tests/mocks/rp2.py b/software/tests/mocks/rp2.py new file mode 100644 index 000000000..c5be4606d --- /dev/null +++ b/software/tests/mocks/rp2.py @@ -0,0 +1,16 @@ +import functools + +class PIO: + OUT_LOW = 0 + +class StateMachine: + pass + + +def asm_pio(**kwargs): + def decorator(func): + @functools.wraps(func) + def wrapper(*args, **kwargs): + pass + return wrapper + return decorator \ No newline at end of file From 1bee61e0c13fe17710e97bb159417808069bbffc Mon Sep 17 00:00:00 2001 From: Matthew Jaskula Date: Fri, 13 May 2022 15:03:42 -0400 Subject: [PATCH 2/5] add framebuf to the micropython mocks --- software/tests/mocks/framebuf.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 software/tests/mocks/framebuf.py diff --git a/software/tests/mocks/framebuf.py b/software/tests/mocks/framebuf.py new file mode 100644 index 000000000..a25437a71 --- /dev/null +++ b/software/tests/mocks/framebuf.py @@ -0,0 +1,3 @@ + +class FrameBuffer: + pass \ No newline at end of file From 318b1a8b5943ade8904cd7704f54166a592c1986 Mon Sep 17 00:00:00 2001 From: Matthew Jaskula Date: Fri, 13 May 2022 16:29:03 -0400 Subject: [PATCH 3/5] Update micropython detection code Check the sys.implementation.name field for 'micropython' instead of checking for the existence of the micropython module. This will allow scrips to use the micropython module in tests. --- software/firmware/europi.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/software/firmware/europi.py b/software/firmware/europi.py index c38af7127..fe2ff2dae 100644 --- a/software/firmware/europi.py +++ b/software/firmware/europi.py @@ -13,6 +13,7 @@ Will set the CV output 3 to a voltage of 4.5V. """ +import sys import time from machine import ADC @@ -22,10 +23,9 @@ from ssd1306 import SSD1306_I2C -try: - import micropython +if sys.implementation.name == "micropython": TEST_ENV = False # We're in micropython, so we can assume access to real hardware -except ModuleNotFoundError: +else: TEST_ENV = True # This var is set when we don't have any real hardware, for example in a test or doc generation setting try: From 342b54b49302e092a779701cb971b3a54863989e Mon Sep 17 00:00:00 2001 From: Matthew Jaskula Date: Fri, 13 May 2022 16:48:08 -0400 Subject: [PATCH 4/5] add back in the use of micropython into the cvrecorder also add the necessary mock module --- software/contrib/cvecorder.py | 5 +++-- software/tests/mocks/micropython.py | 0 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 software/tests/mocks/micropython.py diff --git a/software/contrib/cvecorder.py b/software/contrib/cvecorder.py index b85afbb7b..9dcfd9268 100644 --- a/software/contrib/cvecorder.py +++ b/software/contrib/cvecorder.py @@ -6,6 +6,7 @@ import json import gc import os +import micropython #import framebuf ''' @@ -86,7 +87,7 @@ def __init__(self): # Test routine, pick a random bank n times and save, then load the state if self.initTest: - #print(micropython.mem_info("level")) + print(micropython.mem_info("level")) for n in range(3000): # Clear vars #self.CvRecording = [] @@ -271,7 +272,7 @@ def saveState(self): print(f'[{attempts}] Error: Memory allocation failed, retrying: {e}') if self.debugLogging: self.writeToDebugLog(f"[saveState] Error: Memory allocation failed, retrying: {e}") - #print(micropython.mem_info("level")) + print(micropython.mem_info("level")) else: pass diff --git a/software/tests/mocks/micropython.py b/software/tests/mocks/micropython.py new file mode 100644 index 000000000..e69de29bb From ba7b072ee6ab06163b52c3b1f69379c5c77c9ed9 Mon Sep 17 00:00:00 2001 From: Matthew Jaskula Date: Fri, 13 May 2022 17:31:31 -0400 Subject: [PATCH 5/5] add framebuf usage back into cvrecorder --- software/contrib/cvecorder.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/software/contrib/cvecorder.py b/software/contrib/cvecorder.py index 9dcfd9268..7f648f844 100644 --- a/software/contrib/cvecorder.py +++ b/software/contrib/cvecorder.py @@ -7,7 +7,7 @@ import gc import os import micropython -#import framebuf +import framebuf ''' CVecorder @@ -431,9 +431,8 @@ def writeToDebugLog(self, msg): def showLoadingScreen(self): # push the bytearray of the Rpi logo into a 32 x 32 framebuffer, then show on the screen - # framebuf stuff commented out until we have framebuf testing built - # buffer = bytearray(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|?\x00\x01\x86@\x80\x01\x01\x80\x80\x01\x11\x88\x80\x01\x05\xa0\x80\x00\x83\xc1\x00\x00C\xe3\x00\x00~\xfc\x00\x00L'\x00\x00\x9c\x11\x00\x00\xbf\xfd\x00\x00\xe1\x87\x00\x01\xc1\x83\x80\x02A\x82@\x02A\x82@\x02\xc1\xc2@\x02\xf6>\xc0\x01\xfc=\x80\x01\x18\x18\x80\x01\x88\x10\x80\x00\x8c!\x00\x00\x87\xf1\x00\x00\x7f\xf6\x00\x008\x1c\x00\x00\x0c \x00\x00\x03\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") - # fb = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB) + buffer = bytearray(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|?\x00\x01\x86@\x80\x01\x01\x80\x80\x01\x11\x88\x80\x01\x05\xa0\x80\x00\x83\xc1\x00\x00C\xe3\x00\x00~\xfc\x00\x00L'\x00\x00\x9c\x11\x00\x00\xbf\xfd\x00\x00\xe1\x87\x00\x01\xc1\x83\x80\x02A\x82@\x02A\x82@\x02\xc1\xc2@\x02\xf6>\xc0\x01\xfc=\x80\x01\x18\x18\x80\x01\x88\x10\x80\x00\x8c!\x00\x00\x87\xf1\x00\x00\x7f\xf6\x00\x008\x1c\x00\x00\x0c \x00\x00\x03\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") + fb = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB) oled.fill(0) #oled.blit(fb, 0,0) oled.text('Loading...', 40, 12, 1)