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

Commit 242acdb

Browse files
xnkevinnguyenvandyliuandreamah
authored
Minor update to production (#352)
* Add precision to input slider * Fix inverse switch * Refactor * Switch default is false * Modify precision value for cpx and clue * Table of Contents for README (#349) * Slideshow Backwards/Forwards Bug Fix (#350) * slideshow nav fixed * Fixed print() statements for CLUE display in debug mode (#351) * fixed debug_user_code.py to capture print statements * added starting and ending print statements * new release note apr 21 * added a few fixes Co-authored-by: Vandy Liu <[email protected]> Co-authored-by: Andrea Mah <[email protected]> Co-authored-by: andreamah <[email protected]>
1 parent 1f3023c commit 242acdb

11 files changed

+163
-51
lines changed

README.md

+26-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,32 @@ Make without limit! Device Simulator Express, a Microsoft Garage project, allows
88
result when you plug in your actual microcontroller. Curious about the output of the device, the serial
99
monitor allows you to observe the device output.
1010

11-
## Devices we support:
11+
## Table of Contents
12+
- [Devices we support](#devices-we-support)
13+
- [Prerequisites](#prerequisites)
14+
- [Adafruit Circuit Playground Express (CPX) Simulator](#adafruit-circuit-playground-express-cpx-simulator)
15+
- [Features](#features)
16+
- [Useful Links](#useful-links)
17+
- [Keyboard Shortcuts](#keyboard-shortcuts)
18+
- [BBC micro:bit Simulator](#bbc-microbit-simulator)
19+
- [Features](#features-1)
20+
- [Useful Links](#useful-links-1)
21+
- [Keyboard Shortcuts](#keyboard-shortcuts-1)
22+
- [Adafruit CLUE Simulator](#adafruit-clue-simulator)
23+
- [Features](#features-2)
24+
- [Useful Links](#useful-links-2)
25+
- [Keyboard Shortcuts](#keyboard-shortcuts-2)
26+
- [How to use](#how-to-use)
27+
- [Commands](#commands)
28+
- [Contribute](#contribute)
29+
- [Provide feedback](#provide-feedback)
30+
- [Privacy and Telemetry Notice](#privacy-and-telemetry-notice)
31+
- [Third Party Notice](#third-party-notice)
32+
- [Troubleshooting Tips](#troubleshooting-tips)
33+
- [License](#license)
34+
- [Notes](#notes)
35+
36+
## Devices we support
1237

1338
- [**Adafruit Circuit Playground Express (CPX)**](#adafruit-circuit-playground-express-cpx-simulator)
1439

src/clue/adafruit_slideshow.py

+37-19
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from io import BytesIO
66
from base_circuitpython import base_cp_constants as CONSTANTS
77
import time
8-
import collections
98
from random import shuffle
109
import common
1110
import board
@@ -165,6 +164,7 @@ def __init__(
165164

166165
self._order = order
167166
self._curr_img = ""
167+
self._current_image_index = None
168168

169169
# load images into main queue
170170
self.__load_images()
@@ -219,41 +219,57 @@ def update(self):
219219

220220
def __get_next_img(self):
221221

222-
# handle empty queue
223-
if not len(self.pic_queue):
224-
if self.loop:
225-
self.__load_images()
222+
if self.direction == PlayBackDirection.FORWARD:
223+
if self._current_image_index == None:
224+
self._current_image_index = 0
226225
else:
227-
return ""
226+
self._current_image_index += 1
227+
228+
if self._current_image_index >= len(self.dir_imgs):
229+
230+
if self.loop:
231+
self._current_image_index = 0
232+
self.__load_images()
233+
else:
234+
self._current_image_index = len(self.dir_imgs) - 10
235+
return ""
228236

229-
if self.direction == PlayBackDirection.FORWARD:
230-
return self.pic_queue.popleft()
231237
else:
232-
return self.pic_queue.pop()
238+
if self._current_image_index == None:
239+
self._current_image_index = len(self.dir_imgs) - 1
240+
else:
241+
self._current_image_index -= 1
242+
243+
if self._current_image_index < 0:
244+
if self.loop:
245+
self._current_image_index = len(self.dir_imgs) - 1
246+
self.__load_images()
247+
else:
248+
self._current_image_index = 0
249+
return ""
250+
251+
img = self.dir_imgs[self._current_image_index]
252+
return img
233253

234254
def __load_images(self):
235-
dir_imgs = []
255+
self.dir_imgs = []
236256
for d in self.dirs:
237257
try:
238258
new_path = os.path.join(self.folder, d)
239259

240260
# only add bmp imgs
241-
if os.path.splitext(new_path)[1] == CONSTANTS.BMP_IMG_ENDING:
242-
dir_imgs.append(new_path)
261+
if os.path.splitext(new_path)[-1] == CONSTANTS.BMP_IMG_ENDING:
262+
self.dir_imgs.append(new_path)
243263
except Image.UnidentifiedImageError as e:
244264
continue
245265

246-
if not len(dir_imgs):
266+
if not len(self.dir_imgs):
247267
raise RuntimeError(CONSTANTS.NO_VALID_IMGS_ERR)
248268

249269
if self._order == PlayBackOrder.RANDOM:
250-
shuffle(dir_imgs)
270+
shuffle(self.dir_imgs)
251271
else:
252-
dir_imgs.sort()
253-
254-
# convert list to queue
255-
# (must be list beforehand for potential randomization)
256-
self.pic_queue = collections.deque(dir_imgs)
272+
self.dir_imgs.sort()
257273

258274
def __advance_with_fade(self):
259275
if board.DISPLAY.active_group != self:
@@ -265,6 +281,7 @@ def __advance_with_fade(self):
265281
while not advance_sucessful:
266282
new_path = self.__get_next_img()
267283
if new_path == "":
284+
self._img_start = time.monotonic()
268285
return False
269286

270287
try:
@@ -323,6 +340,7 @@ def __advance_no_fade(self):
323340
while not advance_sucessful:
324341
new_path = self.__get_next_img()
325342
if new_path == "":
343+
self._img_start = time.monotonic()
326344
return False
327345

328346
try:

src/debug_user_code.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,15 @@
3232
# Insert absolute path to Circuitpython libraries for CLUE into sys.path
3333
sys.path.insert(0, os.path.join(abs_path_to_parent_dir, CONSTANTS.CIRCUITPYTHON))
3434

35+
# get board so we can get terminal handle
36+
import board
37+
3538
# This import must happen after the sys.path is modified
3639
from common import debugger_communication_client
3740

41+
# get handle to terminal for clue
42+
curr_terminal = board.DISPLAY.terminal
43+
3844
## Execute User Code ##
3945

4046
# Get user's code path
@@ -56,12 +62,26 @@
5662
utils.abs_path_to_user_file = abs_path_to_code_file
5763
utils.debug_mode = True
5864

65+
# overriding print function so that it shows on clue terminal
66+
def print_decorator(func):
67+
global curr_terminal
68+
69+
def wrapped_func(*args, **kwargs):
70+
curr_terminal.add_str_to_terminal("".join(str(e) for e in args))
71+
return func(*args, **kwargs)
72+
73+
return wrapped_func
74+
75+
76+
print = print_decorator(print)
77+
5978
# Execute the user's code file
6079
with open(abs_path_to_code_file, encoding="utf8") as user_code_file:
80+
curr_terminal.add_str_to_terminal(CONSTANTS.CODE_START_MSG_CLUE)
6181
user_code = user_code_file.read()
6282
try:
6383
codeObj = compile(user_code, abs_path_to_code_file, CONSTANTS.EXEC_COMMAND)
64-
exec(codeObj, {})
84+
exec(codeObj, {"print": print})
6585
sys.stdout.flush()
6686
except Exception as e:
6787
exc_type, exc_value, exc_traceback = sys.exc_info()
@@ -71,3 +91,5 @@
7191
for frameIndex in range(2, len(stackTrace) - 1):
7292
errorMessage += "\t" + str(stackTrace[frameIndex])
7393
print(e, errorMessage, file=sys.stderr, flush=True)
94+
curr_terminal.add_str_to_terminal(CONSTANTS.CODE_FINISHED_MSG_CLUE)
95+
board.DISPLAY.show(None)

src/latest_release_note.ts

+35-22
Large diffs are not rendered by default.

src/view/components/cpx/CpxImage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ export const updateSwitch = (switchState: boolean): void => {
380380
if (switchElement && switchInner) {
381381
svg.addClass(switchInner, "sim-slide-switch-inner");
382382

383-
if (switchState) {
383+
if (!switchState) {
384384
svg.addClass(switchInner, "on");
385385
switchInner.setAttribute("transform", "translate(-5,0)");
386386
} else {

src/view/components/toolbar/GenericSliderComponent.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const GenericSliderComponent: React.FC<IProps> = props => {
2929
value={
3030
props.axisValues[sliderProperties.axisLabel]
3131
}
32+
step={sliderProperties.step}
3233
/>
3334
<br />
3435
</React.Fragment>

src/view/components/toolbar/InputSlider.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class InputSlider extends React.Component<ISliderProps, any, any> {
2121

2222
render() {
2323
const isInputDisabled = this.context === VIEW_STATE.PAUSE;
24+
25+
const nbDecimals =
26+
this.props.step.toString().split(".")[1]?.length || 0;
2427
return (
2528
<div className="input-slider">
2629
<span>{this.props.axisLabel}</span>
@@ -31,8 +34,9 @@ class InputSlider extends React.Component<ISliderProps, any, any> {
3134
onInput={this.handleOnChange}
3235
defaultValue={this.props.minValue.toLocaleString()}
3336
pattern={`^-?[0-9]{0,${
34-
this.props.maxValue.toString().length
35-
}}$`}
37+
(this.props.maxValue / this.props.step).toString()
38+
.length
39+
}}[.]{0,${nbDecimals > 0 ? 1 : 0}}[0-9]{0,${nbDecimals}}$`}
3640
onKeyUp={this.handleOnChange}
3741
aria-label={`${this.props.type} sensor input ${this.props.axisLabel}`}
3842
/>
@@ -56,6 +60,7 @@ class InputSlider extends React.Component<ISliderProps, any, any> {
5660
aria-label={`${this.props.type} sensor`}
5761
defaultValue={this.props.minValue.toLocaleString()}
5862
disabled={isInputDisabled}
63+
step={this.props.step}
5964
/>
6065
<span className="downLabelArea">
6166
<span className="minLabel">{this.props.minLabel}</span>
@@ -100,7 +105,7 @@ class InputSlider extends React.Component<ISliderProps, any, any> {
100105
};
101106

102107
private validateRange = (valueString: string) => {
103-
let valueInt = parseInt(valueString, 10);
108+
let valueInt = parseFloat(valueString);
104109
if (valueInt < this.props.minValue) {
105110
valueInt = this.props.minValue;
106111
this.setState({ value: valueInt });

src/view/components/toolbar/clue/ClueSensorProperties.tsx

+20-3
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,31 @@ import { ISensorProps, ISliderProps } from "../../../viewUtils";
44
const CLUE_SLIDER_R: ISliderProps = {
55
axisLabel: "R",
66
maxLabel: "Max",
7-
maxValue: 255,
7+
maxValue: 65535,
88
minLabel: "Min",
99
minValue: 0,
1010
type: SENSOR_LIST.LIGHT_R,
11+
step: 1,
1112
};
1213

1314
const CLUE_SLIDER_G: ISliderProps = {
1415
axisLabel: "G",
1516
maxLabel: "Max",
16-
maxValue: 255,
17+
maxValue: 65535,
1718
minLabel: "Min",
1819
minValue: 0,
1920
type: SENSOR_LIST.LIGHT_G,
21+
step: 1,
2022
};
2123

2224
const CLUE_SLIDER_B: ISliderProps = {
2325
axisLabel: "B",
2426
maxLabel: "Max",
25-
maxValue: 255,
27+
maxValue: 65535,
2628
minLabel: "Min",
2729
minValue: 0,
2830
type: SENSOR_LIST.LIGHT_B,
31+
step: 1,
2932
};
3033
const CLUE_SLIDER_C: ISliderProps = {
3134
axisLabel: "C",
@@ -34,6 +37,7 @@ const CLUE_SLIDER_C: ISliderProps = {
3437
minLabel: "Min",
3538
minValue: 0,
3639
type: SENSOR_LIST.LIGHT_C,
40+
step: 1,
3741
};
3842

3943
export const CLUE_LIGHT_PROPERTIES: ISensorProps = {
@@ -50,6 +54,7 @@ const CLUE_MAGNET_X: ISliderProps = {
5054
maxValue: 1000,
5155
minValue: -1000,
5256
type: SENSOR_LIST.MAGNET_X,
57+
step: 0.1,
5358
};
5459
const CLUE_MAGNET_Y: ISliderProps = {
5560
axisLabel: "Y",
@@ -58,6 +63,7 @@ const CLUE_MAGNET_Y: ISliderProps = {
5863
maxValue: 1000,
5964
minValue: -1000,
6065
type: SENSOR_LIST.MAGNET_Y,
66+
step: 0.1,
6167
};
6268
const CLUE_MAGNET_Z: ISliderProps = {
6369
axisLabel: "Z",
@@ -66,6 +72,7 @@ const CLUE_MAGNET_Z: ISliderProps = {
6672
maxValue: 1000,
6773
minValue: -1000,
6874
type: SENSOR_LIST.MAGNET_Z,
75+
step: 0.1,
6976
};
7077

7178
export const CLUE_MAGNET_PROPERTIES: ISensorProps = {
@@ -80,6 +87,7 @@ const CLUE_GYRO_X: ISliderProps = {
8087
maxValue: 1000,
8188
minValue: -1000,
8289
type: SENSOR_LIST.GYRO_X,
90+
step: 0.1,
8391
};
8492
const CLUE_GYRO_Y: ISliderProps = {
8593
axisLabel: "Y",
@@ -88,6 +96,7 @@ const CLUE_GYRO_Y: ISliderProps = {
8896
maxValue: 1000,
8997
minValue: -1000,
9098
type: SENSOR_LIST.GYRO_Y,
99+
step: 0.1,
91100
};
92101
const CLUE_GYRO_Z: ISliderProps = {
93102
axisLabel: "Z",
@@ -96,6 +105,7 @@ const CLUE_GYRO_Z: ISliderProps = {
96105
maxValue: 1000,
97106
minValue: -1000,
98107
type: SENSOR_LIST.GYRO_Z,
108+
step: 0.1,
99109
};
100110

101111
export const CLUE_GYRO_PROPERTIES: ISensorProps = {
@@ -114,6 +124,7 @@ export const CLUE_HUMIDITY_PROPERTIES: ISensorProps = {
114124
minLabel: "Min",
115125
minValue: 0,
116126
type: SENSOR_LIST.HUMIDITY,
127+
step: 0.1,
117128
},
118129
],
119130
unitLabel: "%",
@@ -128,6 +139,7 @@ export const CLUE__PROXIMITY_PROPERTIES: ISensorProps = {
128139
minLabel: "Min",
129140
minValue: 0,
130141
type: SENSOR_LIST.PROXIMITY,
142+
step: 1,
131143
},
132144
],
133145
unitLabel: "",
@@ -142,6 +154,7 @@ export const CLUE_PRESSURE_PROPERTIES: ISensorProps = {
142154
minLabel: "Min",
143155
minValue: 800,
144156
type: SENSOR_LIST.PRESSURE,
157+
step: 0.1,
145158
},
146159
],
147160
unitLabel: "hPa",
@@ -153,6 +166,7 @@ const MOTION_SLIDER_PROPS_X: ISliderProps = {
153166
minLabel: "Left",
154167
minValue: -1023,
155168
type: SENSOR_LIST.MOTION_X,
169+
step: 0.1,
156170
};
157171

158172
const MOTION_SLIDER_PROPS_Y: ISliderProps = {
@@ -162,6 +176,7 @@ const MOTION_SLIDER_PROPS_Y: ISliderProps = {
162176
minLabel: "Back",
163177
minValue: -1023,
164178
type: SENSOR_LIST.MOTION_Y,
179+
step: 0.1,
165180
};
166181

167182
const MOTION_SLIDER_PROPS_Z: ISliderProps = {
@@ -171,6 +186,7 @@ const MOTION_SLIDER_PROPS_Z: ISliderProps = {
171186
minLabel: "Up",
172187
minValue: -1023,
173188
type: SENSOR_LIST.MOTION_Z,
189+
step: 0.1,
174190
};
175191

176192
export const MOTION_SENSOR_PROPERTIES: ISensorProps = {
@@ -190,6 +206,7 @@ const TEMPERATURE_SLIDER_PROPS: ISliderProps = {
190206
minLabel: "Cold",
191207
minValue: -55,
192208
type: SENSOR_LIST.TEMPERATURE,
209+
step: 0.1,
193210
};
194211

195212
export const TEMPERATURE_SENSOR_PROPERTIES: ISensorProps = {

0 commit comments

Comments
 (0)