From 8f36dad7caeffeac09d723c648a59b61ba3a6ec2 Mon Sep 17 00:00:00 2001 From: andreamah Date: Wed, 12 Feb 2020 11:16:54 -0800 Subject: [PATCH] debug restructure --- src/adafruit_circuitplayground/constants.py | 2 -- src/adafruit_circuitplayground/express.py | 2 +- src/adafruit_circuitplayground/pixel.py | 2 +- src/common/constants.py | 3 +++ .../debugger_communication_client.py | 24 +++++++++++++------ .../test_debugger_communication_client.py | 2 +- src/debug_user_code.py | 2 +- 7 files changed, 24 insertions(+), 13 deletions(-) rename src/{adafruit_circuitplayground => common}/debugger_communication_client.py (73%) rename src/{adafruit_circuitplayground => common}/test/test_debugger_communication_client.py (97%) diff --git a/src/adafruit_circuitplayground/constants.py b/src/adafruit_circuitplayground/constants.py index 4e6100d97..d0a4ef6fe 100644 --- a/src/adafruit_circuitplayground/constants.py +++ b/src/adafruit_circuitplayground/constants.py @@ -38,11 +38,9 @@ "RED_LED": "API.RED.LED", "PIXELS": "API.PIXELS", } -ERROR_SENDING_EVENT = "Error trying to send event to the process : " TIME_DELAY = 0.03 -DEFAULT_PORT = "5577" EVENTS_BUTTON_PRESS = ["button_a", "button_b", "switch"] diff --git a/src/adafruit_circuitplayground/express.py b/src/adafruit_circuitplayground/express.py index 9e20af4b2..aafc77555 100644 --- a/src/adafruit_circuitplayground/express.py +++ b/src/adafruit_circuitplayground/express.py @@ -12,7 +12,7 @@ from collections import namedtuple from applicationinsights import TelemetryClient from .telemetry import telemetry_py -from . import debugger_communication_client +from common import debugger_communication_client Acceleration = namedtuple("acceleration", ["x", "y", "z"]) diff --git a/src/adafruit_circuitplayground/pixel.py b/src/adafruit_circuitplayground/pixel.py index 631311ce8..d1c6e22d9 100644 --- a/src/adafruit_circuitplayground/pixel.py +++ b/src/adafruit_circuitplayground/pixel.py @@ -9,7 +9,7 @@ from applicationinsights import TelemetryClient from . import constants as CONSTANTS from .telemetry import telemetry_py -from . import debugger_communication_client +from common import debugger_communication_client class Pixel: diff --git a/src/common/constants.py b/src/common/constants.py index 97ea32386..1e28ff603 100644 --- a/src/common/constants.py +++ b/src/common/constants.py @@ -1,3 +1,6 @@ MAC_OS = "darwin" TIME_DELAY = 0.03 + +ERROR_SENDING_EVENT = "Error trying to send event to the process : " +DEFAULT_PORT = "5577" \ No newline at end of file diff --git a/src/adafruit_circuitplayground/debugger_communication_client.py b/src/common/debugger_communication_client.py similarity index 73% rename from src/adafruit_circuitplayground/debugger_communication_client.py rename to src/common/debugger_communication_client.py index a4743ced5..51a461831 100644 --- a/src/adafruit_circuitplayground/debugger_communication_client.py +++ b/src/common/debugger_communication_client.py @@ -5,22 +5,31 @@ import json import socketio import copy -from . import express +# from adafruit_circuitplayground import cpx +# from microbit import __mb as mb from . import constants as CONSTANTS from common import utils +from adafruit_circuitplayground.express import cpx +from adafruit_circuitplayground.constants import CPX + +from microbit.__model.microbit_model import __mb as mb +from microbit.__model.constants import MICROBIT + + +device_dict = {CPX: cpx, MICROBIT: mb} previous_state = {} # similar to utils.send_to_simulator, but for debugging # (needs handle to device-specific debugger) -def debug_show(state): +def debug_show(state, active_device): global previous_state if state != previous_state: previous_state = copy.deepcopy(state) - updated_state = utils.update_state_with_device_name(state, CONSTANTS.CPX) + updated_state = utils.update_state_with_device_name(state, active_device) message = utils.create_message(updated_state) update_state(json.dumps(message)) @@ -42,10 +51,11 @@ def __update_api_state(data, expected_events): try: event_state = json.loads(data) active_device = event_state.get("active_device") - for event in expected_events: - express.cpx._Express__state[event] = event_state.get( - event, express.cpx._Express__state[event] - ) + + # for event in expected_events: + # express.cpx._Express__state[event] = event_state.get( + # event, express.cpx._Express__state[event] + # ) except Exception as e: print(CONSTANTS.ERROR_SENDING_EVENT, e, file=sys.stderr, flush=True) diff --git a/src/adafruit_circuitplayground/test/test_debugger_communication_client.py b/src/common/test/test_debugger_communication_client.py similarity index 97% rename from src/adafruit_circuitplayground/test/test_debugger_communication_client.py rename to src/common/test/test_debugger_communication_client.py index b25e27eb8..6c1e158d5 100644 --- a/src/adafruit_circuitplayground/test/test_debugger_communication_client.py +++ b/src/common/test/test_debugger_communication_client.py @@ -3,7 +3,7 @@ from unittest import mock import socketio -from .. import express +from adafruit_circuitplayground import express from .. import debugger_communication_client diff --git a/src/debug_user_code.py b/src/debug_user_code.py index 8d5b57873..724a39b63 100644 --- a/src/debug_user_code.py +++ b/src/debug_user_code.py @@ -20,7 +20,7 @@ # This import must happen after the sys.path is modified from adafruit_circuitplayground.express import cpx -from adafruit_circuitplayground import debugger_communication_client +from common import debugger_communication_client ## Execute User Code ##