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 18 commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
806576b
shim design example
andreamah Jan 25, 2020
deceeb7
some effort on image object design
andreamah Jan 28, 2020
8ed9e5b
initial look at image class
andreamah Jan 28, 2020
32060ce
fixes to image
andreamah Jan 28, 2020
ef6498c
finished first draft of most image methods
andreamah Jan 28, 2020
d2a7672
width and height modifications
andreamah Jan 29, 2020
16beee3
more additions to image
andreamah Jan 29, 2020
52ba07e
display microbit library
Jan 29, 2020
91352a0
resolve merge conflicts
Jan 29, 2020
cc0ac13
update dusplay
Jan 29, 2020
c761e8b
integrated image into display class
andreamah Jan 29, 2020
4cbda2b
fixed LED array reference issue
andreamah Jan 29, 2020
3557047
changes to display
Jan 29, 2020
0717e6b
fixed merge conflicts
Jan 29, 2020
ecd96e0
added bytearray compatability
andreamah Jan 29, 2020
9652a23
Before merge
Jan 29, 2020
ddcf389
reserve merge conflicts
Jan 29, 2020
20690b2
display show working, still need to add tests
Jan 30, 2020
b627989
updated display tests and refactored some code
Jan 30, 2020
e13db4c
functions and structure implemented for Image class
andreamah Jan 31, 2020
5ee0a0a
merged with dev and resolved merge conflicts
andreamah Jan 31, 2020
3643afb
changed dir structure and removed unused imports
andreamah Jan 31, 2020
aafbf63
more cleanup
andreamah Jan 31, 2020
2a6553e
started scroll method for display
Jan 31, 2020
90bd1d0
fixed small mistake in gulpfile
andreamah Jan 31, 2020
d325d4a
formatting tweaks
andreamah Jan 31, 2020
2edea8f
moved and added tests for repr and str
andreamah Jan 31, 2020
1c9d190
formatted files
andreamah Jan 31, 2020
268b168
resovled merge conflicts
andreamah Jan 31, 2020
f178c97
Update micro:bit displayed word to match branding
xnkevinnguyen Jan 29, 2020
b24e214
Refactor cpx image to a class component to have proper rerendering
xnkevinnguyen Jan 30, 2020
2d84074
Update snapshot tests
xnkevinnguyen Jan 30, 2020
44794a1
Add styling for microbit image
xnkevinnguyen Jan 30, 2020
c67d610
Microbit registers button clicks
xnkevinnguyen Jan 30, 2020
4d368a5
Add listeners for button clicks
xnkevinnguyen Jan 31, 2020
1762d97
incorporated PR feedback
andreamah Jan 31, 2020
18ce589
more PR feedback
andreamah Feb 1, 2020
b2cde9b
Update tests snapshots for ui changes
xnkevinnguyen Jan 30, 2020
4d106ed
Implement feedback from reviews
xnkevinnguyen Feb 3, 2020
4011d50
Creating the skeleton of the microbit library and adding a button obj…
vandyliu Jan 31, 2020
1e0e059
Creating the skeleton of the microbit library and adding a button obj…
xnkevinnguyen Feb 3, 2020
a3b4de8
Update test snapshot
xnkevinnguyen Feb 3, 2020
7593b04
before merge
Feb 4, 2020
f9f9ee5
Update leds on prop change from microbitsimulator
xnkevinnguyen Feb 4, 2020
72069b8
created common lib
andreamah Feb 4, 2020
ccc752c
fixed merge conflicts
Feb 4, 2020
5a11e1c
Changed comment
Feb 4, 2020
39643f4
new test
Feb 4, 2020
7c2640a
Add event listener for microbit
xnkevinnguyen Feb 4, 2020
6f0cbe9
test
Feb 4, 2020
ce63229
temp work on leds
andreamah Feb 4, 2020
77dcd03
merged display
andreamah Feb 4, 2020
88a1226
Done unit tests
Feb 4, 2020
8a76684
Removed unused file
Feb 4, 2020
a6d24b9
Deleted comments
Feb 4, 2020
7c3b53f
more changes for display integration
andreamah Feb 4, 2020
b694739
merge conflicts resolved
andreamah Feb 4, 2020
02d4e25
Receive file from python side
xnkevinnguyen Feb 4, 2020
68420f0
Add microbit svg and style
xnkevinnguyen Jan 29, 2020
3952361
connected display to communciation
andreamah Feb 4, 2020
25a2f72
Update snapshot tests
xnkevinnguyen Jan 30, 2020
f978503
Add styling for microbit image
xnkevinnguyen Jan 30, 2020
9d1c0bf
Microbit registers button clicks
xnkevinnguyen Jan 30, 2020
80ebeb2
Add listeners for button clicks
xnkevinnguyen Jan 31, 2020
b4a8ad8
Creating the skeleton of the microbit library and adding a button obj…
xnkevinnguyen Feb 3, 2020
e00ac69
resolved merge conflicts
andreamah Feb 4, 2020
20969a4
fixes
andreamah Feb 4, 2020
6d175b2
resolved merge conflicts
andreamah Feb 4, 2020
7d04635
shim adjustement
andreamah Feb 4, 2020
a5ce294
Merge branch 'users/t-xunguy/leds' into users/t-anmah/frontend-backen…
andreamah Feb 4, 2020
4a0a84b
worksgit add *!
andreamah Feb 4, 2020
01f52e3
Remove children declaration from cpx simulator
xnkevinnguyen Feb 4, 2020
579985f
Fix merge conflicts
xnkevinnguyen Feb 4, 2020
e4ae67e
Merge branch 'dev' into users/t-xunguy/buttons
xnkevinnguyen Feb 4, 2020
7214d37
Use NodeRef instead of getelementbyid
xnkevinnguyen Feb 4, 2020
a8c12db
Merge branch 'users/t-xunguy/buttons' of https://github.com/microsoft…
xnkevinnguyen Feb 4, 2020
dc8470c
Add active device to play message
xnkevinnguyen Feb 4, 2020
61ec635
some experimentation with recieving device type
andreamah Feb 4, 2020
f5f0132
Merge branch 'users/t-anmah/frontend-backend-integration' of https://…
andreamah Feb 4, 2020
b62b076
Add proper typing to ref
xnkevinnguyen Feb 4, 2020
de38218
Stop button will reset correctly
xnkevinnguyen Feb 4, 2020
e27a428
Functionality for refresh button on microbit
xnkevinnguyen Feb 4, 2020
5231b03
Format files
xnkevinnguyen Feb 4, 2020
8596f0c
resolved merge con
andreamah Feb 4, 2020
bac6cc2
Fix merge conflicts
xnkevinnguyen Feb 5, 2020
09e5370
Update test snapshots
xnkevinnguyen Feb 5, 2020
2fccfce
Add refs to buttons
xnkevinnguyen Feb 5, 2020
4ea844d
Add state management for devices inside extension api
xnkevinnguyen Feb 5, 2020
8f73070
refactoring
andreamah Feb 5, 2020
b4e7b6a
Merge branch 'users/t-anmah/frontend-backend-integration' of https://…
xnkevinnguyen Feb 5, 2020
7dbfa8d
small adjustment
andreamah Feb 5, 2020
5067bab
Merge branch 'users/t-anmah/frontend-backend-integration' of https://…
xnkevinnguyen Feb 5, 2020
7b6d2ca
Only send current device messages to webview
xnkevinnguyen Feb 5, 2020
42be28a
Kill process on tab change
xnkevinnguyen Feb 5, 2020
ec606b2
Remove unecessary logs
xnkevinnguyen Feb 5, 2020
13b9852
Update with latest changes
xnkevinnguyen Feb 6, 2020
059b9f5
Use reference for buttons
xnkevinnguyen Feb 6, 2020
a8a4ea5
Use device list key for keeping state of current active device
xnkevinnguyen Feb 6, 2020
e5593dc
Linting ts
xnkevinnguyen Feb 6, 2020
6ed027d
formatted python black
andreamah Feb 6, 2020
c96a4e3
Update UI test for selector
xnkevinnguyen Feb 6, 2020
55b7250
Remove unecessary spread operations of the state for microbit
xnkevinnguyen Feb 6, 2020
05f9bca
abstracted debugger away
andreamah Feb 6, 2020
ca1ed69
Merge branch 'users/t-anmah/frontend-backend-integration' of https://…
andreamah Feb 6, 2020
35a945a
merged in display
andreamah Feb 6, 2020
eeb025d
fixed deadlock issues
andreamah Feb 6, 2020
7363419
reformat w black
andreamah Feb 6, 2020
50db730
fixed utils test
andreamah Feb 6, 2020
78066e8
Logic for set state only in extension.tsx
xnkevinnguyen Feb 7, 2020
ba328aa
Merge branch 'users/t-anmah/frontend-backend-integration' of https://…
xnkevinnguyen Feb 7, 2020
7551e5c
Microbit svg to a class with getters to get svg element
xnkevinnguyen Feb 7, 2020
4437284
Use refs for leds
xnkevinnguyen Feb 7, 2020
a109abc
Export messaging utils in a separate file
xnkevinnguyen Feb 7, 2020
dc73efb
Remove unused imports
xnkevinnguyen Feb 7, 2020
d859420
Messages from webview are made constant
xnkevinnguyen Feb 7, 2020
26358b0
Update snapshots
xnkevinnguyen Feb 7, 2020
84fd761
Change function name to onselectfile
xnkevinnguyen Feb 7, 2020
4e8e95e
Update typing for sending message
xnkevinnguyen Feb 10, 2020
6cbdf5b
updated create_message to use state copy
andreamah Feb 10, 2020
ee50718
fixed state updating for emitter
andreamah Feb 10, 2020
6b4f9f1
fixed state modification issue
andreamah Feb 10, 2020
afc1a5a
fixed small state issue
andreamah Feb 10, 2020
3611b56
changed var name from state_copy to updated_state
andreamah Feb 10, 2020
2318a06
Merge branch 'dev' into users/t-anmah/frontend-backend-integration
andreamah Feb 10, 2020
f962c0e
Add safety on set state for cpx and microbit
xnkevinnguyen Feb 10, 2020
c510ba3
Merge branch 'users/t-anmah/frontend-backend-integration' of https://…
xnkevinnguyen Feb 10, 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
15 changes: 15 additions & 0 deletions src/adafruit_circuitplayground/debugger_communication_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,23 @@
import sys
import json
import socketio
import copy
from . import express
from . import constants as CONSTANTS
from common import utils


previous_state = {}

# similar to utils.send_to_simulator, but for debugging
# (needs handle to device-specific debugger)
def debug_show(state):
global previous_state

if state != previous_state:
previous_state = copy.deepcopy(state)
message = utils.create_message(state, CONSTANTS.CPX)
update_state(json.dumps(message))


# Create Socket Client
Expand Down
6 changes: 5 additions & 1 deletion src/adafruit_circuitplayground/express.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from collections import namedtuple
from applicationinsights import TelemetryClient
from .telemetry import telemetry_py
from . import debugger_communication_client

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

Expand Down Expand Up @@ -106,7 +107,10 @@ def light(self):
return self.__state["light"]

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

def __touch(self, i):
return self.__state["touch"][i - 1]
Expand Down
7 changes: 6 additions & 1 deletion src/adafruit_circuitplayground/pixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from applicationinsights import TelemetryClient
from . import constants as CONSTANTS
from .telemetry import telemetry_py
from . import debugger_communication_client


class Pixel:
Expand All @@ -20,7 +21,11 @@ def __init__(self, state, debug_mode=False):

def show(self):
# Send the state to the extension so that React re-renders the Webview
utils.show(self.__state, CONSTANTS.CPX, self.__debug_mode)
# or send the state to the debugger (within this library)
if self.__debug_mode:
debugger_communication_client.debug_send_to_simulator(self.__state)
else:
utils.send_to_simulator(self.__state, CONSTANTS.CPX)

def __show_if_auto_write(self):
if self.auto_write:
Expand Down
2 changes: 1 addition & 1 deletion src/adafruit_circuitplayground/test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from unittest import mock

from .. import constants as CONSTANTS
from .. import utils
from common import utils


class TestUtils(object):
Expand Down
1 change: 1 addition & 0 deletions src/common/constants.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
MAC_OS = "darwin"

TIME_DELAY = 0.03
22 changes: 14 additions & 8 deletions src/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@
previous_state = {}


def show(state, device_name, debug_mode=False):
def create_message(state, device_name):
state_ext = {
"device_name": device_name,
}
state.update(state_ext)
Comment thread
andreamah marked this conversation as resolved.
Outdated

message = {"type": "state", "data": json.dumps(state)}
return message


def send_to_simulator(state, device_name):
global previous_state

if not device_name in previous_state or state != previous_state[device_name]:
message = create_message(state, device_name)

previous_state[device_name] = copy.deepcopy(state)
state_ext = {
"device_name": device_name,
}
state.update(state_ext)
message = {"type": "state", "data": json.dumps(state)}
if state != previous_state:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for addressing the comment!
But now this part might not work as expected, right?
I would take the state updating logic and put it in this method (or in a function and call that function here).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! I just abstracted out the state updating and made the process two function calls :).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Awesome!
One more thing, now send_to_simulator and debug_show mutate the input parameters. It would be easier for a developer if they can use these functions without worrying about any unintended consequences.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ok, tried to fix it in the last commit :)

Copy link
Copy Markdown

@nasadigital nasadigital Feb 10, 2020

Choose a reason for hiding this comment

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

Almost perfect!
Now this check will always return true if state != previous_state:. Perhaps use state_copy instead of state?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oops! fixed

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

*nit*
I would change the name to updated_state from state_copy. Up to you!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fixed!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM!
Thanks for your patience :D
giphy

previous_state = copy.deepcopy(state)
print(json.dumps(message) + "\0", end="", file=sys.__stdout__, flush=True)
time.sleep(CONSTANTS.TIME_DELAY)

Expand Down
9 changes: 0 additions & 9 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,6 @@ export enum TelemetryEventName {
}
export const DEFAULT_DEVICE = CONSTANTS.DEVICE_NAME.CPX;

export enum WebviewMessages {
BUTTON_PRESS = "button-press",
PLAY_SIMULATOR = "play-simulator",
SENSOR_CHANGED = "sensor-changed",
REFRESH_SIMULATOR = "refresh-simulator",
SLIDER_TELEMETRY = "slider-telemetry",
SWITCH_DEVICE = "switch-device",
}

// tslint:disable-next-line: no-namespace
export namespace DialogResponses {
export const ACCEPT_AND_RUN: MessageItem = {
Expand Down
15 changes: 7 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
DialogResponses,
SERVER_INFO,
TelemetryEventName,
WebviewMessages,
} from "./constants";
import { CPXWorkspace } from "./cpxWorkspace";
import { DebuggerCommunicationServer } from "./debuggerCommunicationServer";
Expand All @@ -23,6 +22,7 @@ import { SerialMonitor } from "./serialMonitor";
import { SimulatorDebugConfigurationProvider } from "./simulatorDebugConfigurationProvider";
import TelemetryAI from "./telemetry/telemetryAI";
import { UsbDetector } from "./usbDetector";
import { WEBVIEW_MESSAGES } from "./view/constants";

let currentFileAbsPath: string = "";
let currentTextDocument: vscode.TextDocument;
Expand Down Expand Up @@ -156,7 +156,7 @@ export async function activate(context: vscode.ExtensionContext) {
message => {
const messageJson = JSON.stringify(message.text);
switch (message.command) {
case WebviewMessages.BUTTON_PRESS:
case WEBVIEW_MESSAGES.BUTTON_PRESS:
// Send input to the Python process
handleButtonPressTelemetry(message.text);
console.log(`About to write ${messageJson} \n`);
Expand All @@ -173,7 +173,7 @@ export async function activate(context: vscode.ExtensionContext) {
);
}
break;
case WebviewMessages.PLAY_SIMULATOR:
case WEBVIEW_MESSAGES.TOGGLE_PLAY_STOP:
console.log(`Play button ${messageJson} \n`);
if (message.text.state as boolean) {
setPathAndSendMessage(
Expand Down Expand Up @@ -204,7 +204,7 @@ export async function activate(context: vscode.ExtensionContext) {

break;

case WebviewMessages.SENSOR_CHANGED:
case WEBVIEW_MESSAGES.SENSOR_CHANGED:
checkForTelemetry(message.text);
console.log(`Sensor changed ${messageJson} \n`);
if (
Expand All @@ -220,14 +220,14 @@ export async function activate(context: vscode.ExtensionContext) {
);
}
break;
case WebviewMessages.REFRESH_SIMULATOR:
case WEBVIEW_MESSAGES.REFRESH_SIMULATOR:
console.log("Refresh button");
runSimulatorCommand();
break;
case WebviewMessages.SLIDER_TELEMETRY:
case WEBVIEW_MESSAGES.SLIDER_TELEMETRY:
handleSensorTelemetry(message.text);
break;
case WebviewMessages.SWITCH_DEVICE:
case WEBVIEW_MESSAGES.SWITCH_DEVICE:
switchDevice(message.text.active_device);
killProcessIfRunning();
break;
Expand Down Expand Up @@ -1089,7 +1089,6 @@ function getWebviewContent(context: vscode.ExtensionContext) {
</html>`;
}
function switchDevice(deviceName: string) {
console.log("Switched Devices");
currentActiveDevice = deviceName;
}

Expand Down
3 changes: 3 additions & 0 deletions src/microbit/model/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@
# 5x5 Alphabet
# Taken from https://raw.githubusercontent.com/micropython/micropython/264d80c84e034541bd6e4b461bfece4443ffd0ac/ports/nrf/boards/microbit/modules/microbitfont.h
ALPHABET = b"\x00\x00\x00\x00\x00\x08\x08\x08\x00\x08\x0a\x4a\x40\x00\x00\x0a\x5f\xea\x5f\xea\x0e\xd9\x2e\xd3\x6e\x19\x32\x44\x89\x33\x0c\x92\x4c\x92\x4d\x08\x08\x00\x00\x00\x04\x88\x08\x08\x04\x08\x04\x84\x84\x88\x00\x0a\x44\x8a\x40\x00\x04\x8e\xc4\x80\x00\x00\x00\x04\x88\x00\x00\x0e\xc0\x00\x00\x00\x00\x08\x00\x01\x22\x44\x88\x10\x0c\x92\x52\x52\x4c\x04\x8c\x84\x84\x8e\x1c\x82\x4c\x90\x1e\x1e\xc2\x44\x92\x4c\x06\xca\x52\x5f\xe2\x1f\xf0\x1e\xc1\x3e\x02\x44\x8e\xd1\x2e\x1f\xe2\x44\x88\x10\x0e\xd1\x2e\xd1\x2e\x0e\xd1\x2e\xc4\x88\x00\x08\x00\x08\x00\x00\x04\x80\x04\x88\x02\x44\x88\x04\x82\x00\x0e\xc0\x0e\xc0\x08\x04\x82\x44\x88\x0e\xd1\x26\xc0\x04\x0e\xd1\x35\xb3\x6c\x0c\x92\x5e\xd2\x52\x1c\x92\x5c\x92\x5c\x0e\xd0\x10\x10\x0e\x1c\x92\x52\x52\x5c\x1e\xd0\x1c\x90\x1e\x1e\xd0\x1c\x90\x10\x0e\xd0\x13\x71\x2e\x12\x52\x5e\xd2\x52\x1c\x88\x08\x08\x1c\x1f\xe2\x42\x52\x4c\x12\x54\x98\x14\x92\x10\x10\x10\x10\x1e\x11\x3b\x75\xb1\x31\x11\x39\x35\xb3\x71\x0c\x92\x52\x52\x4c\x1c\x92\x5c\x90\x10\x0c\x92\x52\x4c\x86\x1c\x92\x5c\x92\x51\x0e\xd0\x0c\x82\x5c\x1f\xe4\x84\x84\x84\x12\x52\x52\x52\x4c\x11\x31\x31\x2a\x44\x11\x31\x35\xbb\x71\x12\x52\x4c\x92\x52\x11\x2a\x44\x84\x84\x1e\xc4\x88\x10\x1e\x0e\xc8\x08\x08\x0e\x10\x08\x04\x82\x41\x0e\xc2\x42\x42\x4e\x04\x8a\x40\x00\x00\x00\x00\x00\x00\x1f\x08\x04\x80\x00\x00\x00\x0e\xd2\x52\x4f\x10\x10\x1c\x92\x5c\x00\x0e\xd0\x10\x0e\x02\x42\x4e\xd2\x4e\x0c\x92\x5c\x90\x0e\x06\xc8\x1c\x88\x08\x0e\xd2\x4e\xc2\x4c\x10\x10\x1c\x92\x52\x08\x00\x08\x08\x08\x02\x40\x02\x42\x4c\x10\x14\x98\x14\x92\x08\x08\x08\x08\x06\x00\x1b\x75\xb1\x31\x00\x1c\x92\x52\x52\x00\x0c\x92\x52\x4c\x00\x1c\x92\x5c\x90\x00\x0e\xd2\x4e\xc2\x00\x0e\xd0\x10\x10\x00\x06\xc8\x04\x98\x08\x08\x0e\xc8\x07\x00\x12\x52\x52\x4f\x00\x11\x31\x2a\x44\x00\x11\x31\x35\xbb\x00\x12\x4c\x8c\x92\x00\x11\x2a\x44\x98\x00\x1e\xc4\x88\x1e\x06\xc4\x8c\x84\x86\x08\x08\x08\x08\x08\x18\x08\x0c\x88\x18\x00\x00\x0c\x83\x60"
# We support ASCII characters between these indexes on the microbit
ASCII_START = 32
ASCII_END = 126
SPACE_BETWEEN_LETTERS_WIDTH = 1
WHITESPACE_WIDTH = 3

# numerical LED values
LED_HEIGHT = 5
Expand Down
Loading