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

Commit 0df6274

Browse files
Merge pull request #294 from microsoft/users/t-anmah/clue-debugger
Clue Debugger
2 parents 42edd93 + 1497b33 commit 0df6274

File tree

20 files changed

+385
-332
lines changed

20 files changed

+385
-332
lines changed

src/adafruit_circuitplayground/express.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ def __init__(self):
4646
"touch": [False] * 7,
4747
"shake": False,
4848
}
49-
self.__debug_mode = False
50-
self.pixels = Pixel(self.__state, self.__debug_mode)
49+
self.pixels = Pixel(self.__state)
5150

5251
@property
5352
def acceleration(self):
@@ -113,7 +112,7 @@ def light(self):
113112
return self.__state["light"]
114113

115114
def __show(self):
116-
if self.__debug_mode:
115+
if utils.debug_mode:
117116
common.debugger_communication_client.debug_send_to_simulator(
118117
self.__state, CONSTANTS.CPX
119118
)

src/adafruit_circuitplayground/pixel.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@
1212

1313

1414
class Pixel:
15-
def __init__(self, state, debug_mode=False):
15+
def __init__(self, state):
1616
self.__state = state
1717
self.auto_write = True
18-
self.__debug_mode = debug_mode
1918
self.telemetry_state = False
2019

2120
def show(self):
2221
# Send the state to the extension so that React re-renders the Webview
2322
# or send the state to the debugger (within this library)
24-
if self.__debug_mode:
23+
if utils.debug_mode:
2524
common.debugger_communication_client.debug_send_to_simulator(
2625
self.__state, CONSTANTS.CPX
2726
)
@@ -32,9 +31,6 @@ def __show_if_auto_write(self):
3231
if self.auto_write:
3332
self.show()
3433

35-
def __set_debug_mode(self, debug_mode):
36-
self.__debug_mode = debug_mode
37-
3834
def __getitem__(self, index):
3935
if type(index) is not slice:
4036
if not self.__valid_index(index):

src/adafruit_circuitplayground/test/test_pixel.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ def setup_method(self):
1616
}
1717
)
1818

19-
@pytest.mark.parametrize("debug_mode", [True, False])
20-
def test_set_debug_mode(self, debug_mode):
21-
self.pixel._Pixel__set_debug_mode(debug_mode)
22-
assert debug_mode == self.pixel._Pixel__debug_mode
23-
2419
def test_get_item_out_of_bounds(self):
2520
with pytest.raises(IndexError):
2621
p = self.pixel[3]

src/base_circuitpython/displayio/group.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,22 @@ def __show(self, img):
288288
img_str = str(byte_base64)[2:-1]
289289

290290
sendable_json = {CONSTANTS.BASE_64: img_str}
291-
common.utils.send_to_simulator(sendable_json, CONSTANTS.CLUE)
291+
292+
if common.utils.debug_mode:
293+
common.debugger_communication_client.debug_send_to_simulator(
294+
sendable_json, CONSTANTS.CLUE
295+
)
296+
else:
297+
common.utils.send_to_simulator(sendable_json, CONSTANTS.CLUE)
298+
299+
def __len__(self):
300+
if not self.__contents:
301+
return 0
302+
else:
303+
return len(self.__contents)
304+
305+
def pop(self, i=-1):
306+
item = self.__contents.pop(i)
307+
item.parent = None
308+
self.elem_changed()
309+
return item

src/base_circuitpython/neopixel_write.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import sys
99
import os
1010

11-
from common import utils
11+
import common
1212
from adafruit_circuitplayground import cp
1313
import base_cp_constants as CONSTANTS
1414

@@ -30,7 +30,12 @@ def neopixel_write(gpio, buf):
3030

3131
def send_clue(buf):
3232
sendable_json = {CONSTANTS.PIXELS: tuple(buf)}
33-
utils.send_to_simulator(sendable_json, CONSTANTS.CLUE)
33+
if common.utils.debug_mode:
34+
common.debugger_communication_client.debug_send_to_simulator(
35+
sendable_json, CONSTANTS.CLUE
36+
)
37+
else:
38+
common.utils.send_to_simulator(sendable_json, CONSTANTS.CLUE)
3439

3540

3641
def send_cpx(buf):

src/clue/adafruit_slideshow.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import collections
99
from random import shuffle
1010
from common import utils
11+
from common import debugger_communication_client
1112
from common.telemetry import telemetry_py
1213
from common.telemetry_events import TelemetryEvent
1314
import board
@@ -380,4 +381,10 @@ def __send(self, img):
380381
img_str = str(byte_base64)[2:-1]
381382

382383
sendable_json = {CONSTANTS.BASE_64: img_str}
383-
utils.send_to_simulator(sendable_json, CONSTANTS.CLUE)
384+
385+
if utils.debug_mode:
386+
debugger_communication_client.debug_send_to_simulator(
387+
sendable_json, CONSTANTS.CLUE
388+
)
389+
else:
390+
utils.send_to_simulator(sendable_json, CONSTANTS.CLUE)

src/common/debugger_communication_client.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,34 @@
55
import json
66
import socketio
77
import copy
8+
import pathlib
89

910
from . import constants as CONSTANTS
1011
from . import utils
1112
import threading
12-
13+
import os
14+
import python_constants as TOPLEVEL_CONSTANTS
1315

1416
from adafruit_circuitplayground.express import cpx
1517
from adafruit_circuitplayground.constants import CPX
1618

19+
# add ref for micropython and clue
20+
abs_path_to_parent_dir = os.path.dirname(
21+
os.path.join(pathlib.Path(__file__).parent, "..", "..")
22+
)
23+
sys.path.insert(
24+
0, os.path.join(abs_path_to_parent_dir, TOPLEVEL_CONSTANTS.MICROPYTHON_LIBRARY_NAME)
25+
)
26+
27+
sys.path.insert(0, os.path.join(abs_path_to_parent_dir, TOPLEVEL_CONSTANTS.CLUE_DIR))
28+
1729
from microbit.__model.microbit_model import __mb as mb
1830
from microbit.__model.constants import MICROBIT
1931

32+
from base_circuitpython.base_cp_constants import CLUE
33+
from adafruit_clue import clue
2034

21-
device_dict = {CPX: cpx, MICROBIT: mb}
35+
device_dict = {CPX: cpx, MICROBIT: mb, CLUE: clue}
2236
processing_state_event = threading.Event()
2337
previous_state = {}
2438

src/common/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
previous_state = {}
1111

1212
abs_path_to_user_file = ""
13+
debug_mode = False
1314

1415

1516
def update_state_with_device_name(state, device_name):

src/debug_user_code.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@
2626
)
2727
sys.path.insert(0, abs_path_to_micropython_lib)
2828

29+
# Insert absolute path to library for CLUE into sys.path
30+
sys.path.insert(0, os.path.join(abs_path_to_parent_dir, CONSTANTS.CLUE))
31+
32+
# Insert absolute path to Circuitpython libraries for CLUE into sys.path
33+
sys.path.insert(0, os.path.join(abs_path_to_parent_dir, CONSTANTS.CIRCUITPYTHON))
34+
2935
# This import must happen after the sys.path is modified
30-
from adafruit_circuitplayground.express import cpx
31-
from microbit.__model.microbit_model import __mb as mb
3236
from common import debugger_communication_client
3337

34-
3538
## Execute User Code ##
3639

37-
3840
# Get user's code path
3941
abs_path_to_code_file = ""
4042
if len(sys.argv) > 1 and sys.argv[1]:
@@ -52,9 +54,7 @@
5254

5355
# Init API variables
5456
utils.abs_path_to_user_file = abs_path_to_code_file
55-
cpx._Express__debug_mode = True
56-
cpx.pixels._Pixel__set_debug_mode(True)
57-
mb._MicrobitModel__set_debug_mode(True)
57+
utils.debug_mode = True
5858

5959
# Execute the user's code file
6060
with open(abs_path_to_code_file, encoding="utf8") as user_code_file:

src/micropython/microbit/__model/display.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def __init__(self):
2121

2222
self.__current_pid = None
2323
self.__lock = threading.Lock()
24-
self.__debug_mode = False
2524

2625
def scroll(self, value, delay=150, wait=True, loop=False, monospace=False):
2726
"""
@@ -352,7 +351,7 @@ def __create_scroll_image(images):
352351
def __update_client(self):
353352
sendable_json = {"leds": self.__get_array()}
354353

355-
if self.__debug_mode:
354+
if common.utils.debug_mode:
356355
common.debugger_communication_client.debug_send_to_simulator(
357356
sendable_json, CONSTANTS.MICROBIT
358357
)

src/micropython/microbit/__model/microbit_model.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,5 @@ def __update_gesture(self, new_state):
9898
new_gesture = new_state.get(CONSTANTS.EXPECTED_INPUT_GESTURE)
9999
self.accelerometer._Accelerometer__update_gesture(new_gesture)
100100

101-
def __set_debug_mode(self, mode):
102-
self.display._Display__debug_mode = mode
103-
104101

105102
__mb = MicrobitModel()

src/view/components/clue/ClueImage.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT license.
33

44
import * as React from "react";
5-
import { VIEW_STATE } from "../../constants";
5+
import { BUTTON_CLASSNAME, VIEW_STATE } from "../../constants";
66
import CONSTANTS, { BUTTON_STYLING_CLASSES } from "../../constants";
77
import { ViewStateContext } from "../../context";
88
import { ClueSvg, IRefObject } from "./Clue_svg";
@@ -19,11 +19,6 @@ interface IProps {
1919
neopixel: number[];
2020
}
2121

22-
const BUTTON_CLASSNAME = {
23-
ACTIVE: "sim-button-outer",
24-
DEACTIVATED: "sim-button-deactivated",
25-
};
26-
2722
export enum BUTTONS_KEYS {
2823
BTN_A = "BTN_A",
2924
BTN_B = "BTN_B",
@@ -118,6 +113,7 @@ const setupButton = (
118113
eventTriggers: EventTriggers,
119114
key: string
120115
) => {
116+
buttonElement.setAttribute("class", BUTTON_CLASSNAME.ACTIVE);
121117
buttonElement.onmousedown = e => {
122118
buttonElement.focus();
123119
eventTriggers.onMouseDown(e, key);

0 commit comments

Comments
 (0)