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

Commit

Permalink
Merge branch 'users/t-anmah/frontend-backend-integration' of https://…
Browse files Browse the repository at this point in the history
…github.com/microsoft/vscode-python-devicesimulator into users/t-anmah/frontend-backend-integration
  • Loading branch information
xnkevinnguyen committed Feb 7, 2020
2 parents 78066e8 + 50db730 commit ba328aa
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 124 deletions.
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)

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:
previous_state = copy.deepcopy(state)
print(json.dumps(message) + "\0", end="", file=sys.__stdout__, flush=True)
time.sleep(CONSTANTS.TIME_DELAY)

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

0 comments on commit ba328aa

Please sign in to comment.