This repository was archived by the owner on Dec 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
Basic functionality for microbit Debugging and fixes #216
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
15a059c
some debugger work
andreamah 8f36dad
debug restructure
andreamah e20d4ad
resolved merge conflicts
andreamah 429ef24
merged listeners
andreamah 8eae513
fixed circular dependency
andreamah 997719d
Remove duplicate emitter
xnkevinnguyen f657255
Load device into script tag for initial open
xnkevinnguyen cb0db0c
Merge branch 'users/t-xunguy/debugger-webview' into users/t-anmah/deb…
xnkevinnguyen f7e5b52
modified debugger listener
andreamah 88bff5e
connected microbit to debugger
andreamah c5dddb8
handshake for client communication
andreamah a050aff
updated debugger client
andreamah b3f6567
modifications to active device microbit
andreamah 7f5bdb2
Emit only when the calls are finished
xnkevinnguyen 297dd87
Reformatting
xnkevinnguyen ffecbf6
Update branch with dev
xnkevinnguyen 2fb6f9f
fixed backend socket issue
andreamah 5ab2a1b
disconnect works when program is done
andreamah ca7d7ea
debugger work
andreamah b645302
backend cleanup
andreamah 12f6458
Merge branch 'dev' into users/t-anmah/debugger
andreamah 25f2d5a
Make messages constant
xnkevinnguyen e951947
remove temporary console logs
xnkevinnguyen 470282d
src/adafruit_circuitplayground
andreamah e029bee
removed bad call from debug user code
andreamah 997cf2a
Update with feedback
xnkevinnguyen 79187f4
resolved merge conflicts
andreamah 78821fb
Merge branch 'users/t-anmah/debugger' of https://github.com/microsoft…
andreamah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 0 additions & 69 deletions
69
src/adafruit_circuitplayground/debugger_communication_client.py
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 0 additions & 63 deletions
63
src/adafruit_circuitplayground/test/test_debugger_communication_client.py
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.