Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
debug restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
andreamah committed Feb 12, 2020
1 parent 15a059c commit 8f36dad
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
2 changes: 0 additions & 2 deletions src/adafruit_circuitplayground/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion src/adafruit_circuitplayground/express.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down
2 changes: 1 addition & 1 deletion src/adafruit_circuitplayground/pixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/common/constants.py
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from unittest import mock
import socketio

from .. import express
from adafruit_circuitplayground import express
from .. import debugger_communication_client


Expand Down
2 changes: 1 addition & 1 deletion src/debug_user_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##
Expand Down

0 comments on commit 8f36dad

Please sign in to comment.