This repository has been archived by the owner on Dec 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'users/t-vali/microbit-template' of https://github.com/m…
…icrosoft/vscode-python-devicesimulator into users/t-vali/microbit-template
- Loading branch information
Showing
30 changed files
with
2,110 additions
and
3,013 deletions.
There are no files selected for viewing
This file contains 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,16 +1,17 @@ | ||
{ | ||
"deviceSimulatorExpressExtension.commands.changeBaudRate": "Change Baud Rate", | ||
"deviceSimulatorExpressExtension.commands.closeSerialMonitor": "Close Serial Monitor", | ||
"deviceSimulatorExpressExtension.commands.label": "Device Simulator Express", | ||
"deviceSimulatorExpressExtension.commands.openSerialMonitor": "Open Serial Monitor", | ||
"deviceSimulatorExpressExtension.commands.openSimulator": "Open Simulator", | ||
"deviceSimulatorExpressExtension.commands.runSimulator": "Run Simulator", | ||
"deviceSimulatorExpressExtension.commands.newFile": "New File", | ||
"deviceSimulatorExpressExtension.commands.runDevice": "Deploy to Device", | ||
"deviceSimulatorExpressExtension.commands.selectSerialPort": "Select Serial Port", | ||
"deviceSimulatorExpressExtension.configuration.title": "Device Simulator Express configuration", | ||
"deviceSimulatorExpressExtension.configuration.properties.open": "Whether to show 'Open Simulator' icon in editor title menu.", | ||
"deviceSimulatorExpressExtension.configuration.properties.device": "Whether to show 'Run Device' icon in editor title menu.", | ||
"deviceSimulatorExpressExtension.configuration.properties.simulator": "Whether to show 'Run Simulator' icon in editor title menu.", | ||
"deviceSimulatorExpressExtension.configuration.properties.debuggerPort": "The port the Server will listen on for communication with the debugger." | ||
} | ||
{ | ||
"deviceSimulatorExpressExtension.commands.changeBaudRate": "Change Baud Rate", | ||
"deviceSimulatorExpressExtension.commands.closeSerialMonitor": "Close Serial Monitor", | ||
"deviceSimulatorExpressExtension.commands.installDependencies": "Install Extension Dependencies", | ||
"deviceSimulatorExpressExtension.commands.label": "Device Simulator Express", | ||
"deviceSimulatorExpressExtension.commands.openSerialMonitor": "Open Serial Monitor", | ||
"deviceSimulatorExpressExtension.commands.openSimulator": "Open Simulator", | ||
"deviceSimulatorExpressExtension.commands.runSimulator": "Run Simulator", | ||
"deviceSimulatorExpressExtension.commands.newFile": "New File", | ||
"deviceSimulatorExpressExtension.commands.runDevice": "Deploy to Device", | ||
"deviceSimulatorExpressExtension.commands.selectSerialPort": "Select Serial Port", | ||
"deviceSimulatorExpressExtension.configuration.title": "Device Simulator Express configuration", | ||
"deviceSimulatorExpressExtension.configuration.properties.open": "Whether to show 'Open Simulator' icon in editor title menu.", | ||
"deviceSimulatorExpressExtension.configuration.properties.device": "Whether to show 'Run Device' icon in editor title menu.", | ||
"deviceSimulatorExpressExtension.configuration.properties.simulator": "Whether to show 'Run Simulator' icon in editor title menu.", | ||
"deviceSimulatorExpressExtension.configuration.properties.debuggerPort": "The port the Server will listen on for communication with the debugger." | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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 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,120 @@ | ||
from . import constants as CONSTANTS | ||
|
||
|
||
class Accelerometer: | ||
# The implementation is based off of https://microbit-micropython.readthedocs.io/en/v1.0.1/accelerometer.html. | ||
def __init__(self): | ||
self.__x = 0 | ||
self.__y = 0 | ||
self.__z = 0 | ||
self.__current_gesture = "" | ||
self.__prev_gestures = set() | ||
self.__gestures = [] | ||
|
||
def get_x(self): | ||
""" | ||
Get the acceleration measurement in the ``x`` axis, as a positive or | ||
negative integer, depending on the direction. The measurement is given in | ||
milli-g. | ||
""" | ||
return self.__x | ||
|
||
def get_y(self): | ||
""" | ||
Get the acceleration measurement in the ``y`` axis, as a positive or | ||
negative integer, depending on the direction. The measurement is given in | ||
milli-g. | ||
""" | ||
return self.__y | ||
|
||
def get_z(self): | ||
""" | ||
Get the acceleration measurement in the ``z`` axis, as a positive or | ||
negative integer, depending on the direction. The measurement is given in | ||
milli-g. | ||
""" | ||
return self.__z | ||
|
||
def get_values(self): | ||
""" | ||
Get the acceleration measurements in all axes at once, as a three-element | ||
tuple of integers ordered as X, Y, Z. | ||
""" | ||
return (self.__x, self.__y, self.__z) | ||
|
||
def current_gesture(self): | ||
""" | ||
Return the name of the current gesture. | ||
""" | ||
self.__add_current_gesture_to_gesture_lists() | ||
return self.__current_gesture | ||
|
||
def is_gesture(self, name): | ||
""" | ||
Return True or False to indicate if the named gesture is currently active. | ||
""" | ||
self.__add_current_gesture_to_gesture_lists() | ||
if name not in CONSTANTS.GESTURES: | ||
raise ValueError(CONSTANTS.INVALID_GESTURE_ERR) | ||
return name == self.__current_gesture | ||
|
||
def was_gesture(self, name): | ||
""" | ||
Return True or False to indicate if the named gesture was active since the | ||
last [was_gesture] call. | ||
""" | ||
self.__add_current_gesture_to_gesture_lists() | ||
if name not in CONSTANTS.GESTURES: | ||
raise ValueError(CONSTANTS.INVALID_GESTURE_ERR) | ||
was_gesture = name in self.__prev_gestures | ||
self.__prev_gestures.clear() | ||
return was_gesture | ||
|
||
def get_gestures(self): | ||
""" | ||
Return a tuple of the gesture history. The most recent is listed last. | ||
Also clears the gesture history before returning. | ||
""" | ||
self.__add_current_gesture_to_gesture_lists() | ||
gestures = tuple(self.__gestures) | ||
self.__gestures.clear() | ||
return gestures | ||
|
||
# Helpers and Hidden Functions | ||
|
||
def __get_accel(self, axis): | ||
if axis == "x": | ||
return self.get_x() | ||
elif axis == "y": | ||
return self.get_y() | ||
elif axis == "z": | ||
return self.get_z() | ||
|
||
def __set_accel(self, axis, accel): | ||
if accel < CONSTANTS.MIN_ACCELERATION or accel > CONSTANTS.MAX_ACCELERATION: | ||
raise ValueError(CONSTANTS.INVALID_ACCEL_ERR) | ||
if axis == "x": | ||
self.__x = accel | ||
elif axis == "y": | ||
self.__y = accel | ||
elif axis == "z": | ||
self.__z = accel | ||
|
||
def __set_gesture(self, gesture): | ||
if gesture in CONSTANTS.GESTURES: | ||
self.__current_gesture = gesture | ||
elif gesture == "": | ||
self.__current_gesture = "" | ||
else: | ||
raise ValueError(CONSTANTS.INVALID_GESTURE_ERR) | ||
|
||
def __add_current_gesture_to_gesture_lists(self): | ||
if self.__current_gesture in CONSTANTS.GESTURES: | ||
self.__gestures.append(self.__current_gesture) | ||
self.__prev_gestures.add(self.__current_gesture) | ||
|
||
def __update(self, axis, accel): | ||
if accel is not None: | ||
previous_accel = self.__get_accel(axis) | ||
if accel != previous_accel: | ||
self.__set_accel(axis, accel) |
This file contains 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
Oops, something went wrong.