Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4fae4db
moved debug_mode reference
andreamah Apr 1, 2020
167a64d
changed debugger to use correct mb instance
andreamah Apr 2, 2020
3a64bd9
Merge branch 'users/t-anmah/microbit-debugger-fix' into users/t-anmah…
andreamah Apr 2, 2020
01fdc33
Merge branch 'dev' into users/t-anmah/clue-debugger
andreamah Apr 2, 2020
ebcb0ca
added debug to existing backend
andreamah Apr 2, 2020
1743190
Merge branch 'dev' into users/t-anmah/clue-debugger
andreamah Apr 2, 2020
c2e0bc3
resolved merge confict
andreamah Apr 2, 2020
1de20b9
merge conflicts
andreamah Apr 2, 2020
026244e
debug update state for backend
andreamah Apr 2, 2020
1774465
Merge branch 'users/t-xunguy/clue-sensors' into users/t-anmah/clue-de…
xnkevinnguyen Apr 3, 2020
f027269
Configure proper flow for keys shortcuts on debug
xnkevinnguyen Apr 3, 2020
f68ca8c
Modify Css to show deactivated state
xnkevinnguyen Apr 3, 2020
f9c06fb
Merge branch 'dev' into users/t-anmah/clue-debugger
xnkevinnguyen Apr 6, 2020
dbae77d
Update branch with latest dev
xnkevinnguyen Apr 7, 2020
8bedb62
Freeze gesture button
xnkevinnguyen Apr 7, 2020
905ba01
python formatting
andreamah Apr 8, 2020
b6e0b99
Merge branch 'dev' into users/t-anmah/clue-debugger
andreamah Apr 8, 2020
b0ecb2d
resolved test fail
andreamah Apr 8, 2020
8d91062
unix fix for ci
andreamah Apr 8, 2020
43db763
Merge branch 'dev' into users/t-anmah/clue-debugger
xnkevinnguyen Apr 8, 2020
96e3792
Run formatter
xnkevinnguyen Apr 8, 2020
4d14fe6
resolved merge
andreamah Apr 8, 2020
1497b33
pull
andreamah Apr 8, 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
5 changes: 2 additions & 3 deletions src/adafruit_circuitplayground/express.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def __init__(self):
"touch": [False] * 7,
"shake": False,
}
self.__debug_mode = False
self.pixels = Pixel(self.__state, self.__debug_mode)
self.pixels = Pixel(self.__state)

@property
def acceleration(self):
Expand Down Expand Up @@ -113,7 +112,7 @@ def light(self):
return self.__state["light"]

def __show(self):
if self.__debug_mode:
if utils.debug_mode:
common.debugger_communication_client.debug_send_to_simulator(
self.__state, CONSTANTS.CPX
)
Expand Down
8 changes: 2 additions & 6 deletions src/adafruit_circuitplayground/pixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@


class Pixel:
def __init__(self, state, debug_mode=False):
def __init__(self, state):
self.__state = state
self.auto_write = True
self.__debug_mode = debug_mode
self.telemetry_state = False

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:
if utils.debug_mode:
common.debugger_communication_client.debug_send_to_simulator(
self.__state, CONSTANTS.CPX
)
Expand All @@ -32,9 +31,6 @@ def __show_if_auto_write(self):
if self.auto_write:
self.show()

def __set_debug_mode(self, debug_mode):
self.__debug_mode = debug_mode

def __getitem__(self, index):
if type(index) is not slice:
if not self.__valid_index(index):
Expand Down
5 changes: 0 additions & 5 deletions src/adafruit_circuitplayground/test/test_pixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ def setup_method(self):
}
)

@pytest.mark.parametrize("debug_mode", [True, False])
def test_set_debug_mode(self, debug_mode):
self.pixel._Pixel__set_debug_mode(debug_mode)
assert debug_mode == self.pixel._Pixel__debug_mode

def test_get_item_out_of_bounds(self):
with pytest.raises(IndexError):
p = self.pixel[3]
Expand Down
20 changes: 19 additions & 1 deletion src/base_circuitpython/displayio/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,22 @@ def __show(self, img):
img_str = str(byte_base64)[2:-1]

sendable_json = {CONSTANTS.BASE_64: img_str}
common.utils.send_to_simulator(sendable_json, CONSTANTS.CLUE)

if common.utils.debug_mode:
common.debugger_communication_client.debug_send_to_simulator(
sendable_json, CONSTANTS.CLUE
)
else:
common.utils.send_to_simulator(sendable_json, CONSTANTS.CLUE)

def __len__(self):
if not self.__contents:
return 0
else:
return len(self.__contents)

def pop(self, i=-1):
item = self.__contents.pop(i)
item.parent = None
self.elem_changed()
return item
9 changes: 7 additions & 2 deletions src/base_circuitpython/neopixel_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys
import os

from common import utils
import common
from adafruit_circuitplayground import cp
import base_cp_constants as CONSTANTS

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

def send_clue(buf):
sendable_json = {CONSTANTS.PIXELS: tuple(buf)}
utils.send_to_simulator(sendable_json, CONSTANTS.CLUE)
if common.utils.debug_mode:
common.debugger_communication_client.debug_send_to_simulator(
sendable_json, CONSTANTS.CLUE
)
else:
common.utils.send_to_simulator(sendable_json, CONSTANTS.CLUE)


def send_cpx(buf):
Expand Down
9 changes: 8 additions & 1 deletion src/clue/adafruit_slideshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import collections
from random import shuffle
from common import utils
from common import debugger_communication_client
from common.telemetry import telemetry_py
from common.telemetry_events import TelemetryEvent
import board
Expand Down Expand Up @@ -380,4 +381,10 @@ def __send(self, img):
img_str = str(byte_base64)[2:-1]

sendable_json = {CONSTANTS.BASE_64: img_str}
utils.send_to_simulator(sendable_json, CONSTANTS.CLUE)

if utils.debug_mode:
debugger_communication_client.debug_send_to_simulator(
sendable_json, CONSTANTS.CLUE
)
else:
utils.send_to_simulator(sendable_json, CONSTANTS.CLUE)
18 changes: 16 additions & 2 deletions src/common/debugger_communication_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,34 @@
import json
import socketio
import copy
import pathlib

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

import os
import python_constants as TOPLEVEL_CONSTANTS

from adafruit_circuitplayground.express import cpx
from adafruit_circuitplayground.constants import CPX

# add ref for micropython and clue
abs_path_to_parent_dir = os.path.dirname(
os.path.join(pathlib.Path(__file__).parent, "..", "..")
)
sys.path.insert(
0, os.path.join(abs_path_to_parent_dir, TOPLEVEL_CONSTANTS.MICROPYTHON_LIBRARY_NAME)
)

sys.path.insert(0, os.path.join(abs_path_to_parent_dir, TOPLEVEL_CONSTANTS.CLUE_DIR))

from microbit.__model.microbit_model import __mb as mb
from microbit.__model.constants import MICROBIT

from base_circuitpython.base_cp_constants import CLUE
from adafruit_clue import clue

device_dict = {CPX: cpx, MICROBIT: mb}
device_dict = {CPX: cpx, MICROBIT: mb, CLUE: clue}
processing_state_event = threading.Event()
previous_state = {}

Expand Down
1 change: 1 addition & 0 deletions src/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
previous_state = {}

abs_path_to_user_file = ""
debug_mode = False


def update_state_with_device_name(state, device_name):
Expand Down
14 changes: 7 additions & 7 deletions src/debug_user_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@
)
sys.path.insert(0, abs_path_to_micropython_lib)

# Insert absolute path to library for CLUE into sys.path
sys.path.insert(0, os.path.join(abs_path_to_parent_dir, CONSTANTS.CLUE))

# Insert absolute path to Circuitpython libraries for CLUE into sys.path
sys.path.insert(0, os.path.join(abs_path_to_parent_dir, CONSTANTS.CIRCUITPYTHON))

Comment on lines +29 to +34

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you run tests, it doesn't run process_user_code.py, which is where this usually happens. This adds src/clue and src/micropython to the sys path so that we can import microbit and clue.

We need to put it in debug_user_code.py rather than its test because some tests import debug_user_code and need these sys.path add-ons in order to import the file.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying!
And why do we need this in process_user_code.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code automatically looks for packages in the out/* directory, but doesn't recursively search. This is so that it can find packages that don't necessarily sit right below out/*. In the case of microbit and clue, they both have their packages defined in sub-folders.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which modules do we want to use? Why can't use the import statement to do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the case of process_user_code.py, we wanted the user to import the packages using a specific way, so we're doing it this way. For all of the imports, we want to keep the method consistent because import micropython.microbit and import microbit imports two different instances of the microbit package.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I am struggling to understand what we are trying to achieve here.
If import micropython.microbit and import microbit import two different instances, why don't we use one or the other? In which case do we want to use one over the other?

# This import must happen after the sys.path is modified
from adafruit_circuitplayground.express import cpx
from microbit.__model.microbit_model import __mb as mb
from common import debugger_communication_client


## Execute User Code ##


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

# Init API variables
utils.abs_path_to_user_file = abs_path_to_code_file
cpx._Express__debug_mode = True
cpx.pixels._Pixel__set_debug_mode(True)
mb._MicrobitModel__set_debug_mode(True)
utils.debug_mode = True

# Execute the user's code file
with open(abs_path_to_code_file, encoding="utf8") as user_code_file:
Expand Down
3 changes: 1 addition & 2 deletions src/micropython/microbit/__model/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def __init__(self):

self.__current_pid = None
self.__lock = threading.Lock()
self.__debug_mode = False

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

if self.__debug_mode:
if common.utils.debug_mode:
common.debugger_communication_client.debug_send_to_simulator(
sendable_json, CONSTANTS.MICROBIT
)
Expand Down
3 changes: 0 additions & 3 deletions src/micropython/microbit/__model/microbit_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,5 @@ def __update_gesture(self, new_state):
new_gesture = new_state.get(CONSTANTS.EXPECTED_INPUT_GESTURE)
self.accelerometer._Accelerometer__update_gesture(new_gesture)

def __set_debug_mode(self, mode):
self.display._Display__debug_mode = mode


__mb = MicrobitModel()
8 changes: 2 additions & 6 deletions src/view/components/clue/ClueImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT license.

import * as React from "react";
import { VIEW_STATE } from "../../constants";
import { BUTTON_CLASSNAME, VIEW_STATE } from "../../constants";
import CONSTANTS, { BUTTON_STYLING_CLASSES } from "../../constants";
import { ViewStateContext } from "../../context";
import { ClueSvg, IRefObject } from "./Clue_svg";
Expand All @@ -19,11 +19,6 @@ interface IProps {
neopixel: number[];
}

const BUTTON_CLASSNAME = {
ACTIVE: "sim-button-outer",
DEACTIVATED: "sim-button-deactivated",
};

export enum BUTTONS_KEYS {
BTN_A = "BTN_A",
BTN_B = "BTN_B",
Expand Down Expand Up @@ -118,6 +113,7 @@ const setupButton = (
eventTriggers: EventTriggers,
key: string
) => {
buttonElement.setAttribute("class", BUTTON_CLASSNAME.ACTIVE);
buttonElement.onmousedown = e => {
buttonElement.focus();
eventTriggers.onMouseDown(e, key);
Expand Down
Loading