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

Basic functionality for microbit Debugging and fixes #216

Merged
merged 28 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
15a059c
some debugger work
andreamah Feb 12, 2020
8f36dad
debug restructure
andreamah Feb 12, 2020
e20d4ad
resolved merge conflicts
andreamah Feb 12, 2020
429ef24
merged listeners
andreamah Feb 12, 2020
8eae513
fixed circular dependency
andreamah Feb 13, 2020
997719d
Remove duplicate emitter
xnkevinnguyen Feb 13, 2020
f657255
Load device into script tag for initial open
xnkevinnguyen Feb 13, 2020
cb0db0c
Merge branch 'users/t-xunguy/debugger-webview' into users/t-anmah/deb…
xnkevinnguyen Feb 13, 2020
f7e5b52
modified debugger listener
andreamah Feb 13, 2020
88bff5e
connected microbit to debugger
andreamah Feb 13, 2020
c5dddb8
handshake for client communication
andreamah Feb 19, 2020
a050aff
updated debugger client
andreamah Feb 19, 2020
b3f6567
modifications to active device microbit
andreamah Feb 19, 2020
7f5bdb2
Emit only when the calls are finished
xnkevinnguyen Feb 19, 2020
297dd87
Reformatting
xnkevinnguyen Feb 19, 2020
ffecbf6
Update branch with dev
xnkevinnguyen Feb 19, 2020
2fb6f9f
fixed backend socket issue
andreamah Feb 19, 2020
5ab2a1b
disconnect works when program is done
andreamah Feb 20, 2020
ca7d7ea
debugger work
andreamah Feb 20, 2020
b645302
backend cleanup
andreamah Feb 20, 2020
12f6458
Merge branch 'dev' into users/t-anmah/debugger
andreamah Feb 20, 2020
25f2d5a
Make messages constant
xnkevinnguyen Feb 21, 2020
e951947
remove temporary console logs
xnkevinnguyen Feb 21, 2020
470282d
src/adafruit_circuitplayground
andreamah Feb 24, 2020
e029bee
removed bad call from debug user code
andreamah Feb 24, 2020
997cf2a
Update with feedback
xnkevinnguyen Feb 24, 2020
79187f4
resolved merge conflicts
andreamah Feb 24, 2020
78821fb
Merge branch 'users/t-anmah/debugger' of https://github.com/microsoft…
andreamah Feb 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/adafruit_circuitplayground/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@

VALID_PIXEL_ASSIGN_ERROR = "The pixel color value should be a tuple with three values between 0 and 255 or a hexadecimal color between 0x000000 and 0xFFFFFF."

TELEMETRY_EVENT_NAMES = {
"TAPPED": "API.TAPPED",
"PLAY_FILE": "API.PLAY.FILE",
"PLAY_TONE": "API.PLAY.TONE",
"START_TONE": "API.START.TONE",
"STOP_TONE": "API.STOP.TONE",
"DETECT_TAPS": "API.DETECT.TAPS",
"ADJUST_THRESHOLD": "API.ADJUST.THRESHOLD",
"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"]
EVENTS_SENSOR_CHANGED = ["temperature", "light", "motion_x", "motion_y", "motion_z"]
Expand Down
69 changes: 0 additions & 69 deletions src/adafruit_circuitplayground/debugger_communication_client.py

This file was deleted.

7 changes: 5 additions & 2 deletions src/adafruit_circuitplayground/express.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from .pixel import Pixel
from . import constants as CONSTANTS
from collections import namedtuple
from . import debugger_communication_client
from applicationinsights import TelemetryClient
import common

Acceleration = namedtuple("acceleration", ["x", "y", "z"])

Expand Down Expand Up @@ -115,7 +116,9 @@ def light(self):

def __show(self):
if self.__debug_mode:
debugger_communication_client.debug_send_to_simulator(self.__state)
common.debugger_communication_client.debug_send_to_simulator(
self.__state, CONSTANTS.CPX
)
else:
utils.send_to_simulator(self.__state, CONSTANTS.CPX)

Expand Down
8 changes: 5 additions & 3 deletions src/adafruit_circuitplayground/pixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

import json
import sys
import common

from common import utils
from common.telemetry import telemetry_py
from common.telemetry_events import TelemetryEvent
from . import constants as CONSTANTS
from . import debugger_communication_client


class Pixel:
Expand All @@ -22,9 +22,11 @@ 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:
debugger_communication_client.debug_send_to_simulator(self.__state)
common.debugger_communication_client.debug_send_to_simulator(
self.__state, CONSTANTS.CPX
)
else:
utils.send_to_simulator(self.__state, CONSTANTS.CPX)
common.utils.send_to_simulator(self.__state, CONSTANTS.CPX)

def __show_if_auto_write(self):
if self.auto_write:
Expand Down

This file was deleted.

7 changes: 7 additions & 0 deletions src/common/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
MAC_OS = "darwin"

ERROR_SENDING_EVENT = "Error trying to send event to the process : "

ACTIVE_DEVICE_FIELD = "active_device"
STATE_FIELD = "state"

CONNECTION_ATTEMPTS = 10
TIME_DELAY = 0.03
DEFAULT_PORT = "5577"
81 changes: 81 additions & 0 deletions src/common/debugger_communication_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import sys
import json
import socketio
import copy

from . import constants as CONSTANTS
from . import utils
import threading


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}
processing_state_event = threading.Event()
previous_state = {}

# similar to utils.send_to_simulator, but for debugging
# (needs handle to device-specific debugger)
def debug_send_to_simulator(state, active_device):
global previous_state
if state != previous_state:
previous_state = copy.deepcopy(state)

updated_state = utils.update_state_with_device_name(state, active_device)
message = utils.create_message(updated_state)

update_state(json.dumps(message))


# Create Socket Client
sio = socketio.Client(reconnection_attempts=CONSTANTS.CONNECTION_ATTEMPTS)

# TODO: Get port from process_user_code.py via childprocess communication


# Initialize connection
def init_connection(port=CONSTANTS.DEFAULT_PORT):
sio.connect("http://localhost:{}".format(port))


# Transfer the user's inputs to the API
def __update_api_state(data):
try:
event_state = json.loads(data)
active_device_string = event_state.get(CONSTANTS.ACTIVE_DEVICE_FIELD)

if active_device_string is not None:
active_device = device_dict.get(active_device_string)
if active_device is not None:
active_device.update_state(event_state.get(CONSTANTS.STATE_FIELD))

except Exception as e:
print(CONSTANTS.ERROR_SENDING_EVENT, e, file=sys.stderr, flush=True)


# Method : Update State
def update_state(state):
processing_state_event.clear()
sio.emit("updateState", state)
processing_state_event.wait()


# Event : Button pressed (A, B, A+B, Switch)
# or Sensor changed (Temperature, light, Motion)
@sio.on("input_changed")
def input_changed(data):
sio.emit("receivedState", data)
__update_api_state(data)


@sio.on("received_state")
def received_state(data):
processing_state_event.set()
Loading