From 4fae4db6501bac54bd7678c3a74617aa620e0191 Mon Sep 17 00:00:00 2001 From: andreamah Date: Wed, 1 Apr 2020 16:35:55 -0700 Subject: [PATCH] moved debug_mode reference --- src/adafruit_circuitplayground/express.py | 5 ++--- src/adafruit_circuitplayground/pixel.py | 8 ++------ src/adafruit_circuitplayground/test/test_pixel.py | 5 ----- src/common/debugger_communication_client.py | 1 + src/common/utils.py | 2 +- src/debug_user_code.py | 4 +--- src/micropython/microbit/__model/display.py | 3 +-- src/micropython/microbit/__model/microbit_model.py | 4 ---- 8 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index cc6f16dae..12c45c876 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -47,8 +47,7 @@ def __init__(self): "touch": [False] * 7, "shake": False, } - self.__debug_mode = False - self.pixels = Pixel(self.__state, self.__debug_mode) + self.pixels = Pixel(self.__state) @property def acceleration(self): @@ -114,7 +113,7 @@ def light(self): return self.__state["light"] def __show(self): - if self.__debug_mode: + if utils.debug_mode: common.debugger_communication_client.debug_send_to_simulator( self.__state, CONSTANTS.CPX ) diff --git a/src/adafruit_circuitplayground/pixel.py b/src/adafruit_circuitplayground/pixel.py index 18e0028fc..758084f59 100644 --- a/src/adafruit_circuitplayground/pixel.py +++ b/src/adafruit_circuitplayground/pixel.py @@ -12,16 +12,15 @@ class Pixel: - def __init__(self, state, debug_mode=False): + def __init__(self, state): self.__state = state self.auto_write = True - self.__debug_mode = debug_mode self.telemetry_state = False def show(self): # Send the state to the extension so that React re-renders the Webview # or send the state to the debugger (within this library) - if self.__debug_mode: + if utils.debug_mode: common.debugger_communication_client.debug_send_to_simulator( self.__state, CONSTANTS.CPX ) @@ -32,9 +31,6 @@ def __show_if_auto_write(self): if self.auto_write: self.show() - def __set_debug_mode(self, debug_mode): - self.__debug_mode = debug_mode - def __getitem__(self, index): if type(index) is not slice: if not self.__valid_index(index): diff --git a/src/adafruit_circuitplayground/test/test_pixel.py b/src/adafruit_circuitplayground/test/test_pixel.py index 2532611db..521958552 100644 --- a/src/adafruit_circuitplayground/test/test_pixel.py +++ b/src/adafruit_circuitplayground/test/test_pixel.py @@ -16,11 +16,6 @@ def setup_method(self): } ) - @pytest.mark.parametrize("debug_mode", [True, False]) - def test_set_debug_mode(self, debug_mode): - self.pixel._Pixel__set_debug_mode(debug_mode) - assert debug_mode == self.pixel._Pixel__debug_mode - def test_get_item_out_of_bounds(self): with pytest.raises(IndexError): p = self.pixel[3] diff --git a/src/common/debugger_communication_client.py b/src/common/debugger_communication_client.py index 49f2381b7..fcf2caa39 100644 --- a/src/common/debugger_communication_client.py +++ b/src/common/debugger_communication_client.py @@ -27,6 +27,7 @@ def debug_send_to_simulator(state, active_device): global previous_state if state != previous_state: + print("here!") previous_state = copy.deepcopy(state) updated_state = utils.update_state_with_device_name(state, active_device) diff --git a/src/common/utils.py b/src/common/utils.py index f78dda44d..88d457228 100644 --- a/src/common/utils.py +++ b/src/common/utils.py @@ -10,7 +10,7 @@ previous_state = {} abs_path_to_user_file = "" - +debug_mode=False def update_state_with_device_name(state, device_name): updated_state = dict(state) diff --git a/src/debug_user_code.py b/src/debug_user_code.py index 93b6ba50f..d8ecbfa50 100644 --- a/src/debug_user_code.py +++ b/src/debug_user_code.py @@ -52,9 +52,7 @@ # Init API variables utils.abs_path_to_user_file = abs_path_to_code_file -cpx._Express__debug_mode = True -cpx.pixels._Pixel__set_debug_mode(True) -mb._MicrobitModel__set_debug_mode(True) +utils.debug_mode = True # Execute the user's code file with open(abs_path_to_code_file, encoding="utf8") as user_code_file: diff --git a/src/micropython/microbit/__model/display.py b/src/micropython/microbit/__model/display.py index 1075f2c56..523811db0 100644 --- a/src/micropython/microbit/__model/display.py +++ b/src/micropython/microbit/__model/display.py @@ -21,7 +21,6 @@ def __init__(self): self.__current_pid = None self.__lock = threading.Lock() - self.__debug_mode = False def scroll(self, value, delay=150, wait=True, loop=False, monospace=False): """ @@ -352,7 +351,7 @@ def __create_scroll_image(images): def __update_client(self): sendable_json = {"leds": self.__get_array()} - if self.__debug_mode: + if common.utils.debug_mode: common.debugger_communication_client.debug_send_to_simulator( sendable_json, CONSTANTS.MICROBIT ) diff --git a/src/micropython/microbit/__model/microbit_model.py b/src/micropython/microbit/__model/microbit_model.py index bed74d9cd..f2e78eba9 100644 --- a/src/micropython/microbit/__model/microbit_model.py +++ b/src/micropython/microbit/__model/microbit_model.py @@ -98,8 +98,4 @@ def __update_gesture(self, new_state): new_gesture = new_state.get(CONSTANTS.EXPECTED_INPUT_GESTURE) self.accelerometer._Accelerometer__update_gesture(new_gesture) - def __set_debug_mode(self, mode): - self.display._Display__debug_mode = mode - - __mb = MicrobitModel()