From 4fa9340fc981c7b520116c87a8a99527b01dc6fd Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Mon, 30 Mar 2020 17:48:39 -0700 Subject: [PATCH 01/48] Connect first sensor for temperature --- src/view/components/clue/Clue.tsx | 7 +- src/view/components/microbit/Microbit.tsx | 18 +-- .../components/toolbar/SensorModalUtils.tsx | 35 ++++- src/view/components/toolbar/Toolbar.spec.tsx | 6 +- .../toolbar/modalContent/ClueModalContent.tsx | 147 ++++++++++++++++++ 5 files changed, 192 insertions(+), 21 deletions(-) create mode 100644 src/view/components/toolbar/modalContent/ClueModalContent.tsx diff --git a/src/view/components/clue/Clue.tsx b/src/view/components/clue/Clue.tsx index ca9818098..ca2e279e0 100644 --- a/src/view/components/clue/Clue.tsx +++ b/src/view/components/clue/Clue.tsx @@ -6,6 +6,8 @@ import { SENSOR_LIST, VSCODE_MESSAGES_TO_WEBVIEW } from "../../constants"; import "../../styles/Simulator.css"; import ToolBar from "../toolbar/ToolBar"; import { ClueSimulator } from "./ClueSimulator"; +import { CLUE_TOOLBAR_ICON_ID } from "../toolbar/SensorModalUtils"; +import * as TOOLBAR_SVG from "../../svgs/toolbar_svg"; // Component grouping the functionality for micro:bit functionalities interface IState { @@ -59,5 +61,8 @@ export class Clue extends React.Component<{}, IState> { } const CLUE_TOOLBAR_BUTTONS: Array<{ label: string; image: JSX.Element }> = [ - // TODO: CLUE TOOLBAR + { + label: CLUE_TOOLBAR_ICON_ID.TEMPERATURE, + image: TOOLBAR_SVG.TEMPERATURE_SVG, + }, ]; diff --git a/src/view/components/microbit/Microbit.tsx b/src/view/components/microbit/Microbit.tsx index b1f0e6dbc..792f72e9e 100644 --- a/src/view/components/microbit/Microbit.tsx +++ b/src/view/components/microbit/Microbit.tsx @@ -2,7 +2,7 @@ // Licensed under the MIT license. import * as React from "react"; -import { MICROBIT_TOOLBAR_ID } from "../../components/toolbar/SensorModalUtils"; +import { MICROBIT_TOOLBAR_ICON_ID } from "../../components/toolbar/SensorModalUtils"; import { GESTURES, SENSOR_LIST, @@ -89,34 +89,34 @@ export class Microbit extends React.Component<{}, IState> { const MICROBIT_TOOLBAR_BUTTONS: Array<{ label: string; image: JSX.Element }> = [ { image: TOOLBAR_SVG.PUSH_BUTTON_SVG, - label: MICROBIT_TOOLBAR_ID.PUSH_BUTTON, + label: MICROBIT_TOOLBAR_ICON_ID.PUSH_BUTTON, }, { image: TOOLBAR_SVG.RED_LED_SVG, - label: MICROBIT_TOOLBAR_ID.LEDS, + label: MICROBIT_TOOLBAR_ICON_ID.LEDS, }, { image: TOOLBAR_SVG.TEMPERATURE_SVG, - label: MICROBIT_TOOLBAR_ID.TEMPERATURE, + label: MICROBIT_TOOLBAR_ICON_ID.TEMPERATURE, }, { image: TOOLBAR_SVG.LIGHT_SVG, - label: MICROBIT_TOOLBAR_ID.LIGHT, + label: MICROBIT_TOOLBAR_ICON_ID.LIGHT, }, { image: TOOLBAR_SVG.MOTION_SVG, - label: MICROBIT_TOOLBAR_ID.ACCELEROMETER, + label: MICROBIT_TOOLBAR_ICON_ID.ACCELEROMETER, }, { image: TOOLBAR_SVG.GPIO_SVG, - label: MICROBIT_TOOLBAR_ID.GPIO, + label: MICROBIT_TOOLBAR_ICON_ID.GPIO, }, { image: TOOLBAR_SVG.SPEAKER_SVG, - label: MICROBIT_TOOLBAR_ID.SOUND, + label: MICROBIT_TOOLBAR_ICON_ID.SOUND, }, { image: TOOLBAR_SVG.WIRELESS_SVG, - label: MICROBIT_TOOLBAR_ID.WIRELESS, + label: MICROBIT_TOOLBAR_ICON_ID.WIRELESS, }, ]; diff --git a/src/view/components/toolbar/SensorModalUtils.tsx b/src/view/components/toolbar/SensorModalUtils.tsx index b4120b6de..690124026 100644 --- a/src/view/components/toolbar/SensorModalUtils.tsx +++ b/src/view/components/toolbar/SensorModalUtils.tsx @@ -9,6 +9,7 @@ import LightSensorBar from "./LightSensorBar"; import { Accelerometer } from "./motion/Accelerometer"; import MotionSensorBar from "./motion/MotionSensorBar"; import TemperatureSensorBar from "./TemperatureSensorBar"; +import { CLUE_TEMPERATURE_MODAL_CONTENT } from "./modalContent/ClueModalContent"; export const TRY_IT_MAKE_CODE = (
@@ -63,7 +64,7 @@ export const CPX_TOOLBAR_ICON_ID = { TEMPERATURE: "toolbar-temperature-sensor", }; -export const MICROBIT_TOOLBAR_ID = { +export const MICROBIT_TOOLBAR_ICON_ID = { TEMPERATURE: "toolbar-temperature-sensor", LIGHT: "toolbar-light-sensor", ACCELEROMETER: "toolbar-accelerometer-sensor", @@ -74,6 +75,23 @@ export const MICROBIT_TOOLBAR_ID = { WIRELESS: "toolbar-microbit-wireless", }; +export const CLUE_TOOLBAR_ICON_ID = { + TEMPERATURE: "toolbar-temperature-sensor", + LIGHT: "toolbar-light-sensor", + ACCELEROMETER: "toolbar-accelerometer-sensor", + LEDS: "toolbar-microbit-led", + PUSH_BUTTON: "toolbar-microbit-a-b-push", + GPIO: "toolbar-gpio", + SPEAKER: "toolbar-speaker", + SOUND: "toolbar-sound-sensor", + PRESSURE: "toolbar-pressure-sensor", + HUMIDITY: "toolbar-humidity-sensor", + GESTURE: "toolbar-gesture-sensor", + PROXIMITY: "toolbar-proximity-sensor", + ALTITUDE: "toolbar-altitude-sensor", + BLUETOOTH: "toolbar-microbit-bluetooth", +}; + export interface IModalContent { components: any; descriptionText: string; @@ -384,12 +402,13 @@ export const LABEL_TO_MODAL_CONTENT_CONSTRUCTOR = new Map([ [CPX_TOOLBAR_ICON_ID.SPEAKER, SPEAKER_MODAL_CONTENT], [CPX_TOOLBAR_ICON_ID.SWITCH, SWITCH_MODAL_CONTENT], [CPX_TOOLBAR_ICON_ID.TEMPERATURE, TEMPERATURE_MODAL_CONTENT], - [MICROBIT_TOOLBAR_ID.ACCELEROMETER, ACCELEROMETER_MODAL_CONTENT], - [MICROBIT_TOOLBAR_ID.LEDS, MICROBIT_LED_CONTENT], - [MICROBIT_TOOLBAR_ID.PUSH_BUTTON, MICROBIT_BUTTON_CONTENT], - [MICROBIT_TOOLBAR_ID.GPIO, MICROBIT_GPIO_MODAL_CONTENT], - [MICROBIT_TOOLBAR_ID.SOUND, MICROBIT_SOUND_MODAL_CONTENT], - [MICROBIT_TOOLBAR_ID.WIRELESS, MICROBIT_WIRELESS_MODAL_CONTENT], + [MICROBIT_TOOLBAR_ICON_ID.ACCELEROMETER, ACCELEROMETER_MODAL_CONTENT], + [MICROBIT_TOOLBAR_ICON_ID.LEDS, MICROBIT_LED_CONTENT], + [MICROBIT_TOOLBAR_ICON_ID.PUSH_BUTTON, MICROBIT_BUTTON_CONTENT], + [MICROBIT_TOOLBAR_ICON_ID.GPIO, MICROBIT_GPIO_MODAL_CONTENT], + [MICROBIT_TOOLBAR_ICON_ID.SOUND, MICROBIT_SOUND_MODAL_CONTENT], + [MICROBIT_TOOLBAR_ICON_ID.WIRELESS, MICROBIT_WIRELESS_MODAL_CONTENT], + [CLUE_TOOLBAR_ICON_ID.TEMPERATURE, CLUE_TEMPERATURE_MODAL_CONTENT], ]); export const getModalContent = ( @@ -403,7 +422,7 @@ export const getModalContent = ( label ); if (modalContentConstructor) { - if (label === MICROBIT_TOOLBAR_ID.ACCELEROMETER) { + if (label === MICROBIT_TOOLBAR_ICON_ID.ACCELEROMETER) { return ACCELEROMETER_MODAL_CONTENT( onUpdateValue, sensorValues, diff --git a/src/view/components/toolbar/Toolbar.spec.tsx b/src/view/components/toolbar/Toolbar.spec.tsx index 897ca722e..bd122082e 100644 --- a/src/view/components/toolbar/Toolbar.spec.tsx +++ b/src/view/components/toolbar/Toolbar.spec.tsx @@ -4,17 +4,17 @@ import { IntlProvider } from "react-intl"; import * as testRenderer from "react-test-renderer"; import { SENSOR_LIST } from "../../constants"; import * as TOOLBAR_SVG from "../../svgs/toolbar_svg"; -import { MICROBIT_TOOLBAR_ID } from "./SensorModalUtils"; +import { MICROBIT_TOOLBAR_ICON_ID } from "./SensorModalUtils"; import Toolbar from "./ToolBar"; const MOCK_TOOLBAR_BUTTONS: Array<{ label: string; image: JSX.Element }> = [ { image: TOOLBAR_SVG.LIGHT_SVG, - label: MICROBIT_TOOLBAR_ID.LIGHT, + label: MICROBIT_TOOLBAR_ICON_ID.LIGHT, }, { image: TOOLBAR_SVG.MOTION_SVG, - label: MICROBIT_TOOLBAR_ID.ACCELEROMETER, + label: MICROBIT_TOOLBAR_ICON_ID.ACCELEROMETER, }, ]; const mockUpdateSensors = () => { diff --git a/src/view/components/toolbar/modalContent/ClueModalContent.tsx b/src/view/components/toolbar/modalContent/ClueModalContent.tsx new file mode 100644 index 000000000..d85b2166a --- /dev/null +++ b/src/view/components/toolbar/modalContent/ClueModalContent.tsx @@ -0,0 +1,147 @@ +import * as React from "react"; +import { IModalContent, FEATURE_REQUEST_ON_GITHUB } from "../SensorModalUtils"; +import { SENSOR_LIST } from "../../../constants"; +import { TAG_INPUT_SVG } from "../../../svgs/tag_input_svg"; +import TemperatureSensorBar from "../TemperatureSensorBar"; +import { TAG_OUTPUT_SVG } from "../../../svgs/tag_output_svg"; +import { Accelerometer } from "../motion/Accelerometer"; +import LightSensorBar from "../LightSensorBar"; + +export const CLUE_TEMPERATURE_MODAL_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + return { + components: [ + , + ], + descriptionText: "toolbar-clue-temperature-sensor.description", + descriptionTitle: "toolbar-temperature-sensor.title", + id: "temperature", + tagInput: TAG_INPUT_SVG, + tagOutput: undefined, + tryItDescription: "toolbar-temperature-sensor.tryItDescription", + }; +}; + +export const CLUE_GPIO_MODAL_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + return { + descriptionTitle: "toolbar-gpio.title", + tagInput: TAG_INPUT_SVG, + tagOutput: TAG_OUTPUT_SVG, + descriptionText: "toolbar-gpio.description", + tryItDescription: "toolbar-gpio.tryItDescription", + components: undefined, + id: "GPIO", + }; +}; +export const ACCELEROMETER_MODAL_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number }, + onSelectGestures?: (event: React.ChangeEvent) => void, + sendGesture?: (isActive: boolean) => void +): IModalContent => { + const accelerometerSensorValues = { + X_AXIS: sensorValues[SENSOR_LIST.MOTION_X], + Y_AXIS: sensorValues[SENSOR_LIST.MOTION_Y], + Z_AXIS: sensorValues[SENSOR_LIST.MOTION_Z], + }; + return { + components: ( + + ), + descriptionText: "toolbar-accelerometer-sensor.description", + descriptionTitle: "toolbar-accelerometer-sensor.title", + id: "accelerometer", + tagInput: TAG_INPUT_SVG, + tagOutput: undefined, + tryItDescription: "toolbar-accelerometer-sensor.tryItDescription", + }; +}; + +export const LIGHT_MODAL_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + return { + descriptionTitle: "toolbar-light-sensor.title", + tagInput: TAG_INPUT_SVG, + tagOutput: undefined, + descriptionText: "toolbar-light-sensor.description", + tryItDescription: "toolbar-light-sensor.tryItDescription", + components: [ + , + ], + id: "light_sensor", + }; +}; +export const MICROBIT_BUTTON_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + return { + descriptionTitle: "toolbar-microbit-a-b-push.title", + tagInput: undefined, + tagOutput: TAG_INPUT_SVG, + descriptionText: "toolbar-microbit-a-b-push.description", + tryItDescription: "toolbar-microbit-a-b-push.tryItDescription", + components: undefined, + id: "microbit_button", + }; +}; +export const MICROBIT_SOUND_MODAL_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + return { + descriptionTitle: "toolbar-microbit-sound.title", + tagInput: undefined, + tagOutput: TAG_OUTPUT_SVG, + descriptionText: "toolbar-microbit-sound.description", + tryItDescription: "toolbar-microbit-sound.tryItDescription", + components: [FEATURE_REQUEST_ON_GITHUB], + id: "microbit_sound", + }; +}; +export const SPEAKER_MODAL_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + return { + descriptionTitle: "toolbar-speaker.title", + tagInput: undefined, + tagOutput: TAG_OUTPUT_SVG, + descriptionText: "toolbar-speaker.description", + tryItDescription: "toolbar-speaker.tryItDescription", + components: [FEATURE_REQUEST_ON_GITHUB], + id: "speaker", + }; +}; +export const MICROBIT_LED_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + return { + descriptionTitle: "toolbar-microbit-led.title", + tagInput: undefined, + tagOutput: TAG_OUTPUT_SVG, + descriptionText: "toolbar-microbit-led.description", + tryItDescription: "toolbar-microbit-led.tryItDescription", + components: undefined, + id: "microbit_LED", + }; +}; From 4c32700f10c4bff57400a449db7f072ccb175995 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Wed, 1 Apr 2020 11:43:37 -0700 Subject: [PATCH 02/48] Separate accelerometer from gestures --- src/view/components/clue/Clue.tsx | 44 ++++++++++++ .../components/toolbar/SensorModalUtils.tsx | 29 ++++---- .../toolbar/modalContent/ClueModalContent.tsx | 6 +- .../toolbar/motion/Accelerometer.tsx | 68 +----------------- .../components/toolbar/motion/Gesture.tsx | 70 +++++++++++++++++++ 5 files changed, 135 insertions(+), 82 deletions(-) create mode 100644 src/view/components/toolbar/motion/Gesture.tsx diff --git a/src/view/components/clue/Clue.tsx b/src/view/components/clue/Clue.tsx index ca2e279e0..d5b4e3846 100644 --- a/src/view/components/clue/Clue.tsx +++ b/src/view/components/clue/Clue.tsx @@ -61,8 +61,52 @@ export class Clue extends React.Component<{}, IState> { } const CLUE_TOOLBAR_BUTTONS: Array<{ label: string; image: JSX.Element }> = [ + { + label: CLUE_TOOLBAR_ICON_ID.PUSH_BUTTON, + image: TOOLBAR_SVG.PUSH_BUTTON_SVG, + }, + { + label: CLUE_TOOLBAR_ICON_ID.LEDS, + image: TOOLBAR_SVG.NEO_PIXEL_SVG, + }, { label: CLUE_TOOLBAR_ICON_ID.TEMPERATURE, image: TOOLBAR_SVG.TEMPERATURE_SVG, }, + { + label: CLUE_TOOLBAR_ICON_ID.LIGHT, + image: TOOLBAR_SVG.LIGHT_SVG, + }, + { + label: CLUE_TOOLBAR_ICON_ID.ACCELEROMETER, + image: TOOLBAR_SVG.TEMPERATURE_SVG, + }, + { + label: CLUE_TOOLBAR_ICON_ID.HUMIDITY, + image: TOOLBAR_SVG.TEMPERATURE_SVG, + }, + { + label: CLUE_TOOLBAR_ICON_ID.PRESSURE, + image: TOOLBAR_SVG.TEMPERATURE_SVG, + }, + { + label: CLUE_TOOLBAR_ICON_ID.PROXIMITY, + image: TOOLBAR_SVG.TEMPERATURE_SVG, + }, + { + label: CLUE_TOOLBAR_ICON_ID.GESTURE, + image: TOOLBAR_SVG.TEMPERATURE_SVG, + }, + { + label: CLUE_TOOLBAR_ICON_ID.GPIO, + image: TOOLBAR_SVG.GPIO_SVG, + }, + { + label: CLUE_TOOLBAR_ICON_ID.SOUND, + image: TOOLBAR_SVG.SOUND_SVG, + }, + { + label: CLUE_TOOLBAR_ICON_ID.SPEAKER, + image: TOOLBAR_SVG.SPEAKER_SVG, + }, ]; diff --git a/src/view/components/toolbar/SensorModalUtils.tsx b/src/view/components/toolbar/SensorModalUtils.tsx index 690124026..7b2b3bd45 100644 --- a/src/view/components/toolbar/SensorModalUtils.tsx +++ b/src/view/components/toolbar/SensorModalUtils.tsx @@ -9,7 +9,10 @@ import LightSensorBar from "./LightSensorBar"; import { Accelerometer } from "./motion/Accelerometer"; import MotionSensorBar from "./motion/MotionSensorBar"; import TemperatureSensorBar from "./TemperatureSensorBar"; -import { CLUE_TEMPERATURE_MODAL_CONTENT } from "./modalContent/ClueModalContent"; +import { + CLUE_TEMPERATURE_MODAL_CONTENT, + CLUE_ACCELEROMETER_MODAL_CONTENT, +} from "./modalContent/ClueModalContent"; export const TRY_IT_MAKE_CODE = (
@@ -77,19 +80,18 @@ export const MICROBIT_TOOLBAR_ICON_ID = { export const CLUE_TOOLBAR_ICON_ID = { TEMPERATURE: "toolbar-temperature-sensor", - LIGHT: "toolbar-light-sensor", - ACCELEROMETER: "toolbar-accelerometer-sensor", - LEDS: "toolbar-microbit-led", - PUSH_BUTTON: "toolbar-microbit-a-b-push", - GPIO: "toolbar-gpio", + LIGHT: "toolbar-clue-light-sensor", + ACCELEROMETER: "toolbar-clue-accelerometer-sensor", + LEDS: "toolbar-clue-led", + PUSH_BUTTON: "toolbar-clue-a-b-push", + GPIO: "toolbar-clue-gpio", SPEAKER: "toolbar-speaker", - SOUND: "toolbar-sound-sensor", - PRESSURE: "toolbar-pressure-sensor", - HUMIDITY: "toolbar-humidity-sensor", - GESTURE: "toolbar-gesture-sensor", - PROXIMITY: "toolbar-proximity-sensor", - ALTITUDE: "toolbar-altitude-sensor", - BLUETOOTH: "toolbar-microbit-bluetooth", + SOUND: "toolbar-clue-sound-sensor", + PRESSURE: "toolbar-clue-pressure-sensor", + HUMIDITY: "toolbar-clue-humidity-sensor", + GESTURE: "toolbar-clue-gesture-sensor", + PROXIMITY: "toolbar--clue-proximity-sensor", + BLUETOOTH: "toolbar-clue-bluetooth", }; export interface IModalContent { @@ -409,6 +411,7 @@ export const LABEL_TO_MODAL_CONTENT_CONSTRUCTOR = new Map([ [MICROBIT_TOOLBAR_ICON_ID.SOUND, MICROBIT_SOUND_MODAL_CONTENT], [MICROBIT_TOOLBAR_ICON_ID.WIRELESS, MICROBIT_WIRELESS_MODAL_CONTENT], [CLUE_TOOLBAR_ICON_ID.TEMPERATURE, CLUE_TEMPERATURE_MODAL_CONTENT], + [CLUE_TOOLBAR_ICON_ID.ACCELEROMETER, CLUE_ACCELEROMETER_MODAL_CONTENT], ]); export const getModalContent = ( diff --git a/src/view/components/toolbar/modalContent/ClueModalContent.tsx b/src/view/components/toolbar/modalContent/ClueModalContent.tsx index d85b2166a..e6f374a2e 100644 --- a/src/view/components/toolbar/modalContent/ClueModalContent.tsx +++ b/src/view/components/toolbar/modalContent/ClueModalContent.tsx @@ -41,7 +41,7 @@ export const CLUE_GPIO_MODAL_CONTENT = ( id: "GPIO", }; }; -export const ACCELEROMETER_MODAL_CONTENT = ( +export const CLUE_ACCELEROMETER_MODAL_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number }, onSelectGestures?: (event: React.ChangeEvent) => void, @@ -70,7 +70,7 @@ export const ACCELEROMETER_MODAL_CONTENT = ( }; }; -export const LIGHT_MODAL_CONTENT = ( +export const CLUE_LIGHT_MODAL_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { @@ -89,7 +89,7 @@ export const LIGHT_MODAL_CONTENT = ( id: "light_sensor", }; }; -export const MICROBIT_BUTTON_CONTENT = ( +export const CLUE_BUTTON_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { diff --git a/src/view/components/toolbar/motion/Accelerometer.tsx b/src/view/components/toolbar/motion/Accelerometer.tsx index b02e96234..d93a6887d 100644 --- a/src/view/components/toolbar/motion/Accelerometer.tsx +++ b/src/view/components/toolbar/motion/Accelerometer.tsx @@ -1,8 +1,7 @@ import * as React from "react"; -import { CONSTANTS, GESTURES, SENSOR_LIST } from "../../../constants"; +import { SENSOR_LIST } from "../../../constants"; import { ISensorProps, ISliderProps } from "../../../viewUtils"; -import { Dropdown } from "../../Dropdown"; -import SensorButton from "../SensorButton"; + import { ThreeDimensionSlider } from "./threeDimensionSlider/ThreeDimensionSlider"; const MOTION_SLIDER_PROPS_X: ISliderProps = { @@ -53,52 +52,10 @@ interface IProps { onSendGesture?: (isActive: boolean) => void; } -const GESTURE_BUTTON_MESSAGE = "Send Gesture"; -const MANUAL_ACCELERATION_MESSAGE = "Set the acceleration manually here"; - export class Accelerometer extends React.Component { - private sensorButtonRef: React.RefObject = React.createRef(); render() { return (
-
-
- - { - if (this.props.onSendGesture) { - this.props.onSendGesture(true); - } - }} - onMouseUp={() => { - if (this.props.onSendGesture) { - this.props.onSendGesture(false); - } - }} - onKeyDown={this.handleOnKeyDown} - onKeyUp={this.handleOnKeyUp} - type="gesture" - /> -
-
-
-

{MANUAL_ACCELERATION_MESSAGE}

-
- {
); } - private handleOnKeyDown = (e: React.KeyboardEvent) => { - if (e.key === CONSTANTS.KEYBOARD_KEYS.ENTER) { - this.sensorButtonRef!.current!.setButtonClass(true); - if (this.props.onSendGesture) { - this.props.onSendGesture(true); - } - } - }; - - private handleOnKeyUp = ( - e: React.KeyboardEvent, - onSendGesture?: (isActive: boolean) => void - ) => { - if (e.key === CONSTANTS.KEYBOARD_KEYS.ENTER) { - this.sensorButtonRef!.current!.setButtonClass(false); - - if (this.props.onSendGesture) { - this.props.onSendGesture(false); - } - } - }; } diff --git a/src/view/components/toolbar/motion/Gesture.tsx b/src/view/components/toolbar/motion/Gesture.tsx new file mode 100644 index 000000000..b039833d1 --- /dev/null +++ b/src/view/components/toolbar/motion/Gesture.tsx @@ -0,0 +1,70 @@ +import * as React from "react"; +import SensorButton from "../SensorButton"; +import { Dropdown } from "../../Dropdown"; +import CONSTANTS, { GESTURES } from "../../../constants"; + +const GESTURE_BUTTON_MESSAGE = "Send Gesture"; +interface IProps { + onSelectGestures?: (event: React.ChangeEvent) => void; + onSendGesture?: (isActive: boolean) => void; +} +export class Gesture extends React.Component { + private sensorButtonRef: React.RefObject = React.createRef(); + render() { + return ( +
+ + { + if (this.props.onSendGesture) { + this.props.onSendGesture(true); + } + }} + onMouseUp={() => { + if (this.props.onSendGesture) { + this.props.onSendGesture(false); + } + }} + onKeyDown={this.handleOnKeyDown} + onKeyUp={this.handleOnKeyUp} + type="gesture" + /> +
+ ); + } + private handleOnKeyDown = (e: React.KeyboardEvent) => { + if (e.key === CONSTANTS.KEYBOARD_KEYS.ENTER) { + this.sensorButtonRef!.current!.setButtonClass(true); + if (this.props.onSendGesture) { + this.props.onSendGesture(true); + } + } + }; + + private handleOnKeyUp = ( + e: React.KeyboardEvent, + onSendGesture?: (isActive: boolean) => void + ) => { + if (e.key === CONSTANTS.KEYBOARD_KEYS.ENTER) { + this.sensorButtonRef!.current!.setButtonClass(false); + + if (this.props.onSendGesture) { + this.props.onSendGesture(false); + } + } + }; +} From a4fbab120adaa6235915fc506cd29cbbf3e6f00f Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Wed, 1 Apr 2020 12:35:27 -0700 Subject: [PATCH 03/48] Place holder for each clue sensors --- .../components/toolbar/SensorModalUtils.tsx | 29 ++++-- .../ClueModalContent.tsx | 96 +++++++++++++++++-- 2 files changed, 110 insertions(+), 15 deletions(-) rename src/view/components/toolbar/{modalContent => clue}/ClueModalContent.tsx (60%) diff --git a/src/view/components/toolbar/SensorModalUtils.tsx b/src/view/components/toolbar/SensorModalUtils.tsx index 7b2b3bd45..09476850d 100644 --- a/src/view/components/toolbar/SensorModalUtils.tsx +++ b/src/view/components/toolbar/SensorModalUtils.tsx @@ -9,10 +9,7 @@ import LightSensorBar from "./LightSensorBar"; import { Accelerometer } from "./motion/Accelerometer"; import MotionSensorBar from "./motion/MotionSensorBar"; import TemperatureSensorBar from "./TemperatureSensorBar"; -import { - CLUE_TEMPERATURE_MODAL_CONTENT, - CLUE_ACCELEROMETER_MODAL_CONTENT, -} from "./modalContent/ClueModalContent"; +import * as CLUE_MODAL from "./clue/ClueModalContent"; export const TRY_IT_MAKE_CODE = (
@@ -410,8 +407,28 @@ export const LABEL_TO_MODAL_CONTENT_CONSTRUCTOR = new Map([ [MICROBIT_TOOLBAR_ICON_ID.GPIO, MICROBIT_GPIO_MODAL_CONTENT], [MICROBIT_TOOLBAR_ICON_ID.SOUND, MICROBIT_SOUND_MODAL_CONTENT], [MICROBIT_TOOLBAR_ICON_ID.WIRELESS, MICROBIT_WIRELESS_MODAL_CONTENT], - [CLUE_TOOLBAR_ICON_ID.TEMPERATURE, CLUE_TEMPERATURE_MODAL_CONTENT], - [CLUE_TOOLBAR_ICON_ID.ACCELEROMETER, CLUE_ACCELEROMETER_MODAL_CONTENT], + [ + CLUE_TOOLBAR_ICON_ID.TEMPERATURE, + CLUE_MODAL.CLUE_TEMPERATURE_MODAL_CONTENT, + ], + [ + CLUE_TOOLBAR_ICON_ID.ACCELEROMETER, + CLUE_MODAL.CLUE_ACCELEROMETER_MODAL_CONTENT, + ], + [CLUE_TOOLBAR_ICON_ID.PUSH_BUTTON, CLUE_MODAL.CLUE_BUTTON_CONTENT], + [CLUE_TOOLBAR_ICON_ID.GPIO, CLUE_MODAL.CLUE_GPIO_MODAL_CONTENT], + [CLUE_TOOLBAR_ICON_ID.LIGHT, CLUE_MODAL.CLUE_LIGHT_MODAL_CONTENT], + [CLUE_TOOLBAR_ICON_ID.LEDS, CLUE_MODAL.CLUE_LED_CONTENT], + [CLUE_TOOLBAR_ICON_ID.SOUND, CLUE_MODAL.CLUE_SOUND_MODAL_CONTENT], + [CLUE_TOOLBAR_ICON_ID.PRESSURE, CLUE_MODAL.CLUE_PRESSURE_MODAL_CONTENT], + [CLUE_TOOLBAR_ICON_ID.HUMIDITY, CLUE_MODAL.CLUE_HUMIDITY_MODAL_CONTENT], + [CLUE_TOOLBAR_ICON_ID.GESTURE, CLUE_MODAL.CLUE_GESTURE_MODAL_CONTENT], + [CLUE_TOOLBAR_ICON_ID.PROXIMITY, CLUE_MODAL.CLUE_PROXIMITY_MODAL_CONTENT], + [CLUE_TOOLBAR_ICON_ID.BLUETOOTH, CLUE_MODAL.CLUE_BLUETOOTH_CONTENT], + [ + CLUE_TOOLBAR_ICON_ID.ACCELEROMETER, + CLUE_MODAL.CLUE_ACCELEROMETER_MODAL_CONTENT, + ], ]); export const getModalContent = ( diff --git a/src/view/components/toolbar/modalContent/ClueModalContent.tsx b/src/view/components/toolbar/clue/ClueModalContent.tsx similarity index 60% rename from src/view/components/toolbar/modalContent/ClueModalContent.tsx rename to src/view/components/toolbar/clue/ClueModalContent.tsx index e6f374a2e..b1ead58c0 100644 --- a/src/view/components/toolbar/modalContent/ClueModalContent.tsx +++ b/src/view/components/toolbar/clue/ClueModalContent.tsx @@ -89,6 +89,82 @@ export const CLUE_LIGHT_MODAL_CONTENT = ( id: "light_sensor", }; }; +export const CLUE_HUMIDITY_MODAL_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + return { + descriptionTitle: "toolbar-light-sensor.title", + tagInput: TAG_INPUT_SVG, + tagOutput: undefined, + descriptionText: "toolbar-light-sensor.description", + tryItDescription: "toolbar-light-sensor.tryItDescription", + components: [ + , + ], + id: "light_sensor", + }; +}; +export const CLUE_GESTURE_MODAL_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + return { + descriptionTitle: "toolbar-light-sensor.title", + tagInput: TAG_INPUT_SVG, + tagOutput: undefined, + descriptionText: "toolbar-light-sensor.description", + tryItDescription: "toolbar-light-sensor.tryItDescription", + components: [ + , + ], + id: "light_sensor", + }; +}; +export const CLUE_PROXIMITY_MODAL_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + return { + descriptionTitle: "toolbar-light-sensor.title", + tagInput: TAG_INPUT_SVG, + tagOutput: undefined, + descriptionText: "toolbar-light-sensor.description", + tryItDescription: "toolbar-light-sensor.tryItDescription", + components: [ + , + ], + id: "light_sensor", + }; +}; +export const CLUE_PRESSURE_MODAL_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + return { + descriptionTitle: "toolbar-light-sensor.title", + tagInput: TAG_INPUT_SVG, + tagOutput: undefined, + descriptionText: "toolbar-light-sensor.description", + tryItDescription: "toolbar-light-sensor.tryItDescription", + components: [ + , + ], + id: "light_sensor", + }; +}; export const CLUE_BUTTON_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } @@ -103,21 +179,23 @@ export const CLUE_BUTTON_CONTENT = ( id: "microbit_button", }; }; -export const MICROBIT_SOUND_MODAL_CONTENT = ( + +export const CLUE_BLUETOOTH_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { return { - descriptionTitle: "toolbar-microbit-sound.title", + descriptionTitle: "toolbar-microbit-a-b-push.title", tagInput: undefined, - tagOutput: TAG_OUTPUT_SVG, - descriptionText: "toolbar-microbit-sound.description", - tryItDescription: "toolbar-microbit-sound.tryItDescription", - components: [FEATURE_REQUEST_ON_GITHUB], - id: "microbit_sound", + tagOutput: TAG_INPUT_SVG, + descriptionText: "toolbar-microbit-a-b-push.description", + tryItDescription: "toolbar-microbit-a-b-push.tryItDescription", + components: undefined, + id: "microbit_button", }; }; -export const SPEAKER_MODAL_CONTENT = ( + +export const CLUE_SOUND_MODAL_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { @@ -131,7 +209,7 @@ export const SPEAKER_MODAL_CONTENT = ( id: "speaker", }; }; -export const MICROBIT_LED_CONTENT = ( +export const CLUE_LED_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { From 662e3ed87eb8e4136fd805caa180f7616aed7d95 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Wed, 1 Apr 2020 13:23:50 -0700 Subject: [PATCH 04/48] Refactor accelerometer component --- .../components/toolbar/SensorModalUtils.tsx | 12 +-- .../toolbar/clue/ClueModalContent.tsx | 6 +- .../toolbar/motion/Accelerometer.tsx | 6 +- .../toolbar/motion/MotionSensorBar.tsx | 6 +- .../ThreeDimensionSlider.tsx | 92 ++++++------------- 5 files changed, 42 insertions(+), 80 deletions(-) diff --git a/src/view/components/toolbar/SensorModalUtils.tsx b/src/view/components/toolbar/SensorModalUtils.tsx index 09476850d..20c8405b3 100644 --- a/src/view/components/toolbar/SensorModalUtils.tsx +++ b/src/view/components/toolbar/SensorModalUtils.tsx @@ -164,9 +164,9 @@ export const MOTION_MODAL_CONTENT = ( sensorValues: { [key: string]: number } ): IModalContent => { const motionSensorValues = { - X_AXIS: sensorValues[SENSOR_LIST.MOTION_X], - Y_AXIS: sensorValues[SENSOR_LIST.MOTION_Y], - Z_AXIS: sensorValues[SENSOR_LIST.MOTION_Z], + X: sensorValues[SENSOR_LIST.MOTION_X], + Y: sensorValues[SENSOR_LIST.MOTION_Y], + Z: sensorValues[SENSOR_LIST.MOTION_Z], }; return { descriptionTitle: "toolbar-motion-sensor.title", @@ -296,9 +296,9 @@ export const ACCELEROMETER_MODAL_CONTENT = ( sendGesture?: (isActive: boolean) => void ): IModalContent => { const accelerometerSensorValues = { - X_AXIS: sensorValues[SENSOR_LIST.MOTION_X], - Y_AXIS: sensorValues[SENSOR_LIST.MOTION_Y], - Z_AXIS: sensorValues[SENSOR_LIST.MOTION_Z], + X: sensorValues[SENSOR_LIST.MOTION_X], + Y: sensorValues[SENSOR_LIST.MOTION_Y], + Z: sensorValues[SENSOR_LIST.MOTION_Z], }; return { components: ( diff --git a/src/view/components/toolbar/clue/ClueModalContent.tsx b/src/view/components/toolbar/clue/ClueModalContent.tsx index b1ead58c0..066b19aa8 100644 --- a/src/view/components/toolbar/clue/ClueModalContent.tsx +++ b/src/view/components/toolbar/clue/ClueModalContent.tsx @@ -48,9 +48,9 @@ export const CLUE_ACCELEROMETER_MODAL_CONTENT = ( sendGesture?: (isActive: boolean) => void ): IModalContent => { const accelerometerSensorValues = { - X_AXIS: sensorValues[SENSOR_LIST.MOTION_X], - Y_AXIS: sensorValues[SENSOR_LIST.MOTION_Y], - Z_AXIS: sensorValues[SENSOR_LIST.MOTION_Z], + X: sensorValues[SENSOR_LIST.MOTION_X], + Y: sensorValues[SENSOR_LIST.MOTION_Y], + Z: sensorValues[SENSOR_LIST.MOTION_Z], }; return { components: ( diff --git a/src/view/components/toolbar/motion/Accelerometer.tsx b/src/view/components/toolbar/motion/Accelerometer.tsx index d93a6887d..85c4fb6ad 100644 --- a/src/view/components/toolbar/motion/Accelerometer.tsx +++ b/src/view/components/toolbar/motion/Accelerometer.tsx @@ -43,9 +43,9 @@ const MOTION_SENSOR_PROPERTIES: ISensorProps = { interface IProps { axisValues: { - X_AXIS: number; - Y_AXIS: number; - Z_AXIS: number; + X: number; + Y: number; + Z: number; }; onUpdateValue: (sensor: SENSOR_LIST, value: number) => void; onSelectGestures?: (event: React.ChangeEvent) => void; diff --git a/src/view/components/toolbar/motion/MotionSensorBar.tsx b/src/view/components/toolbar/motion/MotionSensorBar.tsx index 7ebc8aa94..4b746c1d8 100644 --- a/src/view/components/toolbar/motion/MotionSensorBar.tsx +++ b/src/view/components/toolbar/motion/MotionSensorBar.tsx @@ -46,9 +46,9 @@ const MOTION_SENSOR_PROPERTIES: ISensorProps = { }; interface IProps { axisValues: { - X_AXIS: number; - Y_AXIS: number; - Z_AXIS: number; + X: number; + Y: number; + Z: number; }; onUpdateValue: (sensor: SENSOR_LIST, value: number) => void; } diff --git a/src/view/components/toolbar/motion/threeDimensionSlider/ThreeDimensionSlider.tsx b/src/view/components/toolbar/motion/threeDimensionSlider/ThreeDimensionSlider.tsx index 9de3c0041..9ca466600 100644 --- a/src/view/components/toolbar/motion/threeDimensionSlider/ThreeDimensionSlider.tsx +++ b/src/view/components/toolbar/motion/threeDimensionSlider/ThreeDimensionSlider.tsx @@ -5,83 +5,45 @@ import { X_SLIDER_INDEX, Y_SLIDER_INDEX, Z_SLIDER_INDEX, + ISliderProps, } from "../../../../viewUtils"; import InputSlider from "../../InputSlider"; interface IProps { axisProperties: ISensorProps; axisValues: { - X_AXIS: number; - Y_AXIS: number; - Z_AXIS: number; + X: number; + Y: number; + Z: number; }; onUpdateValue: (sensor: SENSOR_LIST, value: number) => void; } export const ThreeDimensionSlider: React.FC = props => { return (
- -
- -
- + {props.axisProperties.sliderProps.map( + (sliderProperties: ISliderProps, index: number) => { + return ( + + +
+
+ ); + } + )}
); }; From f228a1612aac3c081488036d2f5e70616b9bac41 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Wed, 1 Apr 2020 13:52:10 -0700 Subject: [PATCH 05/48] Update type for generic slider toolbar --- src/view/components/clue/Clue.tsx | 2 +- .../components/toolbar/SensorModalUtils.tsx | 1 + .../components/toolbar/clue/LightSensor.tsx | 46 +++++++++++++++++++ .../ThreeDimensionSlider.tsx | 9 ++-- 4 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 src/view/components/toolbar/clue/LightSensor.tsx diff --git a/src/view/components/clue/Clue.tsx b/src/view/components/clue/Clue.tsx index d5b4e3846..6c8422338 100644 --- a/src/view/components/clue/Clue.tsx +++ b/src/view/components/clue/Clue.tsx @@ -79,7 +79,7 @@ const CLUE_TOOLBAR_BUTTONS: Array<{ label: string; image: JSX.Element }> = [ }, { label: CLUE_TOOLBAR_ICON_ID.ACCELEROMETER, - image: TOOLBAR_SVG.TEMPERATURE_SVG, + image: TOOLBAR_SVG.MOTION_SVG, }, { label: CLUE_TOOLBAR_ICON_ID.HUMIDITY, diff --git a/src/view/components/toolbar/SensorModalUtils.tsx b/src/view/components/toolbar/SensorModalUtils.tsx index 20c8405b3..eef7bba94 100644 --- a/src/view/components/toolbar/SensorModalUtils.tsx +++ b/src/view/components/toolbar/SensorModalUtils.tsx @@ -295,6 +295,7 @@ export const ACCELEROMETER_MODAL_CONTENT = ( onSelectGestures?: (event: React.ChangeEvent) => void, sendGesture?: (isActive: boolean) => void ): IModalContent => { + // this object will be accessed with the axis label const accelerometerSensorValues = { X: sensorValues[SENSOR_LIST.MOTION_X], Y: sensorValues[SENSOR_LIST.MOTION_Y], diff --git a/src/view/components/toolbar/clue/LightSensor.tsx b/src/view/components/toolbar/clue/LightSensor.tsx new file mode 100644 index 000000000..fd8c8cbca --- /dev/null +++ b/src/view/components/toolbar/clue/LightSensor.tsx @@ -0,0 +1,46 @@ +import * as React from "react"; +import { SENSOR_LIST } from "../../../../constants"; +import { + ISensorProps, + X_SLIDER_INDEX, + Y_SLIDER_INDEX, + Z_SLIDER_INDEX, +} from "../../../../viewUtils"; +import InputSlider from "../../InputSlider"; + +interface IProps { + axisProperties: ISensorProps; + axisValues: { + X_AXIS: number; + Y_AXIS: number; + Z_AXIS: number; + }; + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void; +} +export const LightColorSensor: React.FC = props => { + return ( +
+ +
+
+ ); +}; diff --git a/src/view/components/toolbar/motion/threeDimensionSlider/ThreeDimensionSlider.tsx b/src/view/components/toolbar/motion/threeDimensionSlider/ThreeDimensionSlider.tsx index 9ca466600..04ea4ec7b 100644 --- a/src/view/components/toolbar/motion/threeDimensionSlider/ThreeDimensionSlider.tsx +++ b/src/view/components/toolbar/motion/threeDimensionSlider/ThreeDimensionSlider.tsx @@ -12,9 +12,8 @@ import InputSlider from "../../InputSlider"; interface IProps { axisProperties: ISensorProps; axisValues: { - X: number; - Y: number; - Z: number; + // key is accessed with axisLabel + [key: string]: number; }; onUpdateValue: (sensor: SENSOR_LIST, value: number) => void; } @@ -34,9 +33,7 @@ export const ThreeDimensionSlider: React.FC = props => { axisLabel={sliderProperties.axisLabel} onUpdateValue={props.onUpdateValue} value={ - props.axisValues[ - sliderProperties.axisLabel as keyof IProps["axisValues"] - ] + props.axisValues[sliderProperties.axisLabel] } />
From 7eb30b6d45b3627215e9320a39e642face252383 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Wed, 1 Apr 2020 14:11:21 -0700 Subject: [PATCH 06/48] Add light sensor clue --- src/view/components/clue/Clue.tsx | 5 +- .../toolbar/clue/ClueModalContent.tsx | 30 +++++++----- .../toolbar/clue/ClueSensorProperties.tsx | 42 +++++++++++++++++ .../components/toolbar/clue/LightSensor.tsx | 46 ------------------- src/view/constants.ts | 4 ++ 5 files changed, 69 insertions(+), 58 deletions(-) create mode 100644 src/view/components/toolbar/clue/ClueSensorProperties.tsx delete mode 100644 src/view/components/toolbar/clue/LightSensor.tsx diff --git a/src/view/components/clue/Clue.tsx b/src/view/components/clue/Clue.tsx index 6c8422338..992d63bac 100644 --- a/src/view/components/clue/Clue.tsx +++ b/src/view/components/clue/Clue.tsx @@ -16,7 +16,10 @@ interface IState { const DEFAULT_STATE = { sensors: { [SENSOR_LIST.TEMPERATURE]: 0, - [SENSOR_LIST.LIGHT]: 0, + [SENSOR_LIST.LIGHT_R]: 0, + [SENSOR_LIST.LIGHT_G]: 0, + [SENSOR_LIST.LIGHT_B]: 0, + [SENSOR_LIST.LIGHT_C]: 0, [SENSOR_LIST.MOTION_X]: 0, [SENSOR_LIST.MOTION_Y]: 0, [SENSOR_LIST.MOTION_Z]: 0, diff --git a/src/view/components/toolbar/clue/ClueModalContent.tsx b/src/view/components/toolbar/clue/ClueModalContent.tsx index 066b19aa8..d72920dcf 100644 --- a/src/view/components/toolbar/clue/ClueModalContent.tsx +++ b/src/view/components/toolbar/clue/ClueModalContent.tsx @@ -6,7 +6,8 @@ import TemperatureSensorBar from "../TemperatureSensorBar"; import { TAG_OUTPUT_SVG } from "../../../svgs/tag_output_svg"; import { Accelerometer } from "../motion/Accelerometer"; import LightSensorBar from "../LightSensorBar"; - +import { ThreeDimensionSlider } from "../motion/threeDimensionSlider/ThreeDimensionSlider"; +import * as SENSOR_PROPERTIES from "./ClueSensorProperties"; export const CLUE_TEMPERATURE_MODAL_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } @@ -74,19 +75,26 @@ export const CLUE_LIGHT_MODAL_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { + const accelerometerSensorValues = { + R: sensorValues[SENSOR_LIST.LIGHT_R], + G: sensorValues[SENSOR_LIST.LIGHT_G], + B: sensorValues[SENSOR_LIST.LIGHT_B], + C: sensorValues[SENSOR_LIST.LIGHT_C], + }; return { - descriptionTitle: "toolbar-light-sensor.title", + components: ( + + ), + descriptionText: "toolbar-accelerometer-sensor.description", + descriptionTitle: "toolbar-accelerometer-sensor.title", + id: "accelerometer", tagInput: TAG_INPUT_SVG, tagOutput: undefined, - descriptionText: "toolbar-light-sensor.description", - tryItDescription: "toolbar-light-sensor.tryItDescription", - components: [ - , - ], - id: "light_sensor", + tryItDescription: "toolbar-accelerometer-sensor.tryItDescription", }; }; export const CLUE_HUMIDITY_MODAL_CONTENT = ( diff --git a/src/view/components/toolbar/clue/ClueSensorProperties.tsx b/src/view/components/toolbar/clue/ClueSensorProperties.tsx new file mode 100644 index 000000000..57cc76675 --- /dev/null +++ b/src/view/components/toolbar/clue/ClueSensorProperties.tsx @@ -0,0 +1,42 @@ +import { ISliderProps, ISensorProps } from "../../../viewUtils"; +import { SENSOR_LIST } from "../../../constants"; +const CLUE_SLIDER_R: ISliderProps = { + axisLabel: "R", + maxLabel: "Max", + maxValue: 255, + minLabel: "Min", + minValue: 0, + type: SENSOR_LIST.LIGHT_R, +}; + +const CLUE_SLIDER_G: ISliderProps = { + axisLabel: "G", + maxLabel: "Max", + maxValue: 255, + minLabel: "Min", + minValue: 0, + type: SENSOR_LIST.LIGHT_G, +}; + +const CLUE_SLIDER_B: ISliderProps = { + axisLabel: "B", + maxLabel: "Max", + maxValue: 255, + minLabel: "Min", + minValue: 0, + type: SENSOR_LIST.LIGHT_B, +}; +const CLUE_SLIDER_C: ISliderProps = { + axisLabel: "C", + maxLabel: "Max", + maxValue: 255, + minLabel: "Min", + minValue: 0, + type: SENSOR_LIST.LIGHT_C, +}; + +export const CLUE_LIGHT_PROPERTIES: ISensorProps = { + LABEL: "Light Sensor", + sliderProps: [CLUE_SLIDER_R, CLUE_SLIDER_G, CLUE_SLIDER_B, CLUE_SLIDER_C], + unitLabel: "Lux", +}; diff --git a/src/view/components/toolbar/clue/LightSensor.tsx b/src/view/components/toolbar/clue/LightSensor.tsx deleted file mode 100644 index fd8c8cbca..000000000 --- a/src/view/components/toolbar/clue/LightSensor.tsx +++ /dev/null @@ -1,46 +0,0 @@ -import * as React from "react"; -import { SENSOR_LIST } from "../../../../constants"; -import { - ISensorProps, - X_SLIDER_INDEX, - Y_SLIDER_INDEX, - Z_SLIDER_INDEX, -} from "../../../../viewUtils"; -import InputSlider from "../../InputSlider"; - -interface IProps { - axisProperties: ISensorProps; - axisValues: { - X_AXIS: number; - Y_AXIS: number; - Z_AXIS: number; - }; - onUpdateValue: (sensor: SENSOR_LIST, value: number) => void; -} -export const LightColorSensor: React.FC = props => { - return ( -
- -
-
- ); -}; diff --git a/src/view/constants.ts b/src/view/constants.ts index 933253e2b..fc8826ff2 100644 --- a/src/view/constants.ts +++ b/src/view/constants.ts @@ -99,6 +99,10 @@ export enum SENSOR_LIST { MOTION_X = "motion_x", MOTION_Y = "motion_y", MOTION_Z = "motion_z", + LIGHT_R = "light_r", + LIGHT_G = "light_g", + LIGHT_B = "light_b", + LIGHT_C = "light_c", } export const GESTURES = [ From fab9d9d1e392b8e66d0cc2df3cbfa0608efce147 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 Apr 2020 14:40:07 -0700 Subject: [PATCH 07/48] first commit --- src/base_circuitpython/base_cp_constants.py | 4 +- src/clue/adafruit_clue.py | 200 +++++++++++++++++--- src/clue/test/test_adafruit_clue.py | 111 +++++++++++ 3 files changed, 288 insertions(+), 27 deletions(-) diff --git a/src/base_circuitpython/base_cp_constants.py b/src/base_circuitpython/base_cp_constants.py index 67cea36e0..5d2c1c094 100644 --- a/src/base_circuitpython/base_cp_constants.py +++ b/src/base_circuitpython/base_cp_constants.py @@ -7,4 +7,6 @@ IMG_DIR_NAME = "img" SCREEN_HEIGHT_WIDTH = 240 -EXPECTED_INPUT_BUTTONS = ["button_a", "button_b"] +EXPECTED_INPUT_BUTTONS = set(["button_a", "button_b"]) + +ALL_EXPECTED_INPUT_EVENTS = set([]) \ No newline at end of file diff --git a/src/clue/adafruit_clue.py b/src/clue/adafruit_clue.py index 1a2f8cd72..542df619f 100644 --- a/src/clue/adafruit_clue.py +++ b/src/clue/adafruit_clue.py @@ -199,12 +199,23 @@ class Clue: # pylint: disable=too-many-instance-attributes, too-many-public-met RAINBOW = (RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE) def __init__(self): - self._a = False - self._b = False - self.__pressed_buttons = set() - self._pixel = neopixel.NeoPixel( - pin=CONSTANTS.CLUE_PIN, n=1, pixel_order=neopixel.RGB - ) + self.__state = { + "button_a": False, + "button_b": False, + "pressed_buttons": set(), + "accelerometer": {'x': 0, 'y': 0, 'z': 0}, + "color_sensor": {'r': 0, 'g': 0, 'b': 0, 'c': 0}, + "magnetometer": {'x': 0, 'y': 0, 'z': 0}, + "gyro": {'x': 0, 'y': 0, 'z': 0}, + "sea_level_pressure": 1013.25, + "temperature": 0, + "proximity": 0, + "gesture": 0, # Can only be 0, 1, 2, 3, 4 + "humidity": 0, + "pressure": 0, + "pixel": neopixel.NeoPixel( + pin=CONSTANTS.CLUE_PIN, n=1, pixel_order=neopixel.RGB) + } @property def button_a(self): @@ -217,7 +228,7 @@ def button_a(self): if clue.button_a: print("Button A pressed") """ - return self._a + return self.__state["button_a"] @property def button_b(self): @@ -230,17 +241,7 @@ def button_b(self): if clue.button_b: print("Button B pressed") """ - return self._b - - def __update_button(self, button, value): - if button == "button_a": - if value: - self.__pressed_buttons.add("A") - self._a = value - elif button == "button_b": - if value: - self.__pressed_buttons.add("B") - self._b = value + return self.__state["button_b"] @property def were_pressed(self): @@ -251,10 +252,146 @@ def were_pressed(self): while True: print(clue.were_pressed) """ - ret = self.__pressed_buttons.copy() - self.__pressed_buttons.clear() + ret = self.__state["pressed_buttons"].copy() + self.__state["pressed_buttons"].clear() return ret + @property + def acceleration(self): + """Obtain acceleration data from the x, y and z axes. + This example prints the values. Try moving the board to see how the printed values change. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + while True: + print("Accel: {:.2f} {:.2f} {:.2f}".format(*clue.acceleration)) + """ + return (self.__state["accelerometer"]['x'], self.__state["accelerometer"]['y'], self.__state["accelerometer"]['z']) + + @property + def color(self): + """The red, green, blue, and clear light values. (r, g, b, c) + This example prints the values. Try holding something up to the sensor to see the values + change. Works best with white LEDs enabled. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + while True: + print("Color: R: {} G: {} B: {} C: {}".format(*clue.color)) + """ + return (self.__state["color_sensor"]['r'], self.__state["color_sensor"]['g'], self.__state["color_sensor"]['b'], self.__state["color_sensor"]['c']) + + @property + def temperature(self): + """The temperature in degrees Celsius. + This example prints the value. Try touching the sensor to see the value change. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + print("Temperature: {:.1f}C".format(clue.temperature)) + """ + return self.__state["temperature"] + + @property + def magnetic(self): + """Obtain x, y, z magnetic values in microteslas. + This example prints the values. Try moving the board to see how the printed values change. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + while True: + print("Magnetic: {:.3f} {:.3f} {:.3f}".format(*clue.magnetic)) + """ + return (self.__state["magnetometer"]['x'], self.__state["magnetometer"]['y'], self.__state["magnetometer"]['z']) + + @property + def proximity(self): + """A relative proximity to the sensor in values from 0 - 255. + This example prints the value. Try moving your hand towards and away from the front of the + board to see how the printed values change. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + while True: + print("Proximity: {}".format(clue.proximity)) + """ + return self.__state["proximity"] + + @property + def gyro(self): + """Obtain x, y, z angular velocity values in degrees/second. + This example prints the values. Try moving the board to see how the printed values change. + print("Gyro: {:.2f} {:.2f} {:.2f}".format(*clue.gyro)) + """ + return (self.__state["gyro"]['x'], self.__state["gyro"]['y'], self.__state["gyro"]['z']) + + @property + def gesture(self): + """A gesture code if gesture is detected. Shows ``0`` if no gesture detected. + ``1`` if an UP gesture is detected, ``2`` if DOWN, ``3`` if LEFT, and ``4`` if RIGHT. + This example prints the gesture values. Try moving your hand up, down, left or right over + the sensor to see the value change. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + while True: + print("Gesture: {}".format(clue.gesture)) + """ + return self.__state["gesture"] + + @property + def humidity(self): + """The measured relative humidity in percent. + This example prints the value. Try breathing on the sensor to see the values change. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + while True: + print("Humidity: {:.1f}%".format(clue.humidity)) + """ + return self.__state["humidity"] + + @property + def pressure(self): + """The barometric pressure in hectoPascals. + This example prints the value. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + print("Pressure: {:.3f}hPa".format(clue.pressure)) + """ + return self.__state["pressure"] + + @property + def altitude(self): + """The altitude in meters based on the sea level pressure at your location. You must set + ``sea_level_pressure`` to receive an accurate reading. + This example prints the value. Try moving the board vertically to see the value change. + .. code-block:: python + from adafruit_clue import clue + clue.sea_level_pressure = 1015 + print("Altitude: {:.1f}m".format(clue.altitude)) + """ + altitude = 44330 * (1.0 - math.pow(self.__state["pressure"] / self.__state["sea_level_pressure"], 0.1903)) + return altitude + + @property + def sea_level_pressure(self): + """Set to the pressure at sea level at your location, before reading altitude for + the most accurate altitude measurement. + This example prints the value. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + clue.sea_level_pressure = 1015 + print("Pressure: {:.3f}hPa".format(clue.pressure)) + """ + return self.__state["sea_level_pressure"] + + @sea_level_pressure.setter + def sea_level_pressure(self, value): + self.__state["sea_level_pressure"] = value + @property def pixel(self): """The NeoPixel RGB LED. @@ -265,7 +402,7 @@ def pixel(self): while True: clue.pixel.fill((255, 0, 255)) """ - return self._pixel + return self.__state["pixel"] @staticmethod def simple_text_display( @@ -335,13 +472,24 @@ def simple_text_display( ) def update_state(self, new_state): - self.__update_buttons(new_state) + for event in new_state.keys(): + if event in CONSTANTS.EXPECTED_INPUT_BUTTONS: + self.__update_button(event, new_state.get(event)) + elif event in CONSTANTS.ALL_EXPECTED_INPUT_EVENTS: + if self.__state[event] != new_state[event]: + self.__state[event] = new_state.get(event) # helpers - def __update_buttons(self, new_state): - # get button pushes - for button_name in CONSTANTS.EXPECTED_INPUT_BUTTONS: - self.__update_button(button_name, new_state.get(button_name)) + def __update_button(self, button, value): + if button == "button_a": + if value: + self.__state["pressed_buttons"].add("A") + self.__state["button_a"] = value + elif button == "button_b": + if value: + self.__state["pressed_buttons"].add("B") + self.__state["button_b"] = value + clue = Clue() # pylint: disable=invalid-name diff --git a/src/clue/test/test_adafruit_clue.py b/src/clue/test/test_adafruit_clue.py index f634e5ae3..2c158e7d7 100644 --- a/src/clue/test/test_adafruit_clue.py +++ b/src/clue/test/test_adafruit_clue.py @@ -70,3 +70,114 @@ def test_buttons(self): assert set(["A", "B"]) == clue.were_pressed assert set() == clue.were_pressed + + def test_acceleration(self): + MOCK_MOTION_X_A = 1 + MOCK_MOTION_Y = 2 + MOCK_MOTION_Z = 3 + MOCK_MOTION_X_B = 4 + + clue._Clue__state["acceleration"] = {"x": MOCK_MOTION_X_A, "y": MOCK_MOTION_Y, "z": MOCK_MOTION_Z} + assert clue.acceleration == (MOCK_MOTION_X_A, MOCK_MOTION_Y, MOCK_MOTION_Z) + clue._Clue__state["acceleration"]["x"] = MOCK_MOTION_X_B + assert clue.acceleration == (MOCK_MOTION_X_B, MOCK_MOTION_Y, MOCK_MOTION_Z) + + def test_color(self): + MOCK_COLOR_R_A = 1 + MOCK_COLOR_G = 2 + MOCK_COLOR_B = 3 + MOCK_COLOR_C = 4 + MOCK_COLOR_R_B = 5 + + clue._Clue__state["color"] = {"r": MOCK_COLOR_R_A, "g": MOCK_COLOR_G, "b": MOCK_COLOR_B, "c": MOCK_COLOR_C} + assert clue.color == (MOCK_COLOR_R_A, MOCK_COLOR_G, MOCK_COLOR_B, MOCK_COLOR_C) + assert clue._Clue__state["color"]["r"] = MOCK_COLOR_R_B + assert clue.color == (MOCK_COLOR_R_B, MOCK_COLOR_G, MOCK_COLOR_B, MOCK_COLOR_C) + + def test_temperature(self): + MOCK_TEMP_A = 10 + MOCK_TEMP_B = -10 + clue._Clue__state["temperature"] = MOCK_TEMP_A + assert MOCK_TEMP_A == clue.temperature + clue._Clue__state["temperature"] = MOCK_TEMP_B + assert MOCK_TEMP_B == clue.temperature + + def test_magnetic(self): + MOCK_MAGNETIC_X_A = 1 + MOCK_MAGNETIC_Y = 2 + MOCK_MAGNETIC_Z = 3 + MOCK_MAGNETIC_X_B = 4 + + clue._Clue__state["magnetometer"] = {"x": MOCK_MAGNETIC_X_A, "y": MOCK_MAGNETIC_Y, "z": MOCK_MAGNETIC_Z} + assert clue.acceleration == (MOCK_MAGNETIC_X_A, MOCK_MAGNETIC_Y, MOCK_MAGNETIC_Z) + clue._Clue__state["magnetometer"]["x"] = MOCK_MAGNETIC_X_B + assert clue.acceleration == (MOCK_MAGNETIC_X_B, MOCK_MAGNETIC_Y, MOCK_MAGNETIC_Z) + + def test_proximity(self): + MOCK_DISTANCE_A = 10 + MOCK_DISTANCE_B = 250 + clue._Clue__state["proximity"] = MOCK_DISTANCE_A + assert MOCK_DISTANCE_A == clue.proximity + clue._Clue__state["proximity"] = MOCK_DISTANCE_B + assert MOCK_DISTANCE_B == clue.proximity + + def test_gyro(self): + MOCK_GYRO_X_A = 1 + MOCK_GYRO_Y = 2 + MOCK_GYRO_Z = 3 + MOCK_GYRO_X_B = 4 + + clue._Clue__state["gyro"] = {"x": MOCK_GYRO_X_A, "y": MOCK_GYRO_Y, "z": MOCK_GYRO_Z} + assert clue.gyro == (MOCK_GYRO_X_A, MOCK_GYRO_Y, MOCK_GYRO_Z) + clue._Clue__state["gyro"]["x"] = MOCK_GYRO_X_B + assert clue.gyro == (MOCK_GYRO_X_B, MOCK_GYRO_Y, MOCK_GYRO_Z) + + def test_gesture(self): + NONE = 0 + UP = 1 + clue._Clue__state["gesture"] = NONE + assert NONE == clue.gesture + clue._Clue__state["gesture"] = UP + assert UP == clue.gesture + + def test_humidity(self): + MOCK_HUMIDITY_A = 10 + MOCK_HUMIDITY_B = 50 + clue._Clue__state["humidity"] = MOCK_HUMIDITY_A + assert MOCK_HUMIDITY_A == clue.humidity + clue._Clue__state["humidity"] = MOCK_HUMIDITY_B + assert MOCK_HUMIDITY_B == clue.humidity + + def test_pressure(self): + MOCK_PRESSURE_A = 10 + MOCK_PRESSURE_B = 50 + clue._Clue__state["pressure"] = MOCK_PRESSURE_A + assert MOCK_PRESSURE_A == clue.pressure + clue._Clue__state["pressure"] = MOCK_PRESSURE_B + assert MOCK_PRESSURE_B == clue.pressure + + def test_altitude(self): + MOCK_PRESSURE_A = 1000 + MOCK_PRESSURE_B = 1030 + MOCK_ALTITUDE_A = 125.42 + MOCK_ALTITUDE_B = -123.93 + SEA_LEVEL_PRESSURE = 1015 + clue.sea_level_pressure = SEA_LEVEL_PRESSURE + clue._Clue__state["pressure"] = MOCK_PRESSURE_A + assert MOCK_ALTITUDE_A == pytest.approx(clue.altitude) + clue._Clue__state["pressure"] = MOCK_PRESSURE_B + assert MOCK_ALTITUDE_B == pytest.approx(clue.altitude) + + def test_sea_level_pressure(self): + MOCK_PRESSURE = 1040 + clue.sea_level_pressure = MOCK_PRESSURE + assert MOCK_PRESSURE == clue.sea_level_pressure + + def test_pixel(self): + MOCK_RED = (255, 0, 0) + MOCK_WHITE = (255, 255, 255) + clue.pixel.fill(MOCK_RED) + assert MOCK_RED == clue.pixel + clue.pixel.fill(MOCK_WHITE) + assert MOCK_WHITE == clue.pixel + \ No newline at end of file From 03ba91cd300a63c777f9e07d7336d2101abfc463 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 Apr 2020 14:48:18 -0700 Subject: [PATCH 08/48] formatted --- src/base_circuitpython/base_cp_constants.py | 2 +- src/clue/adafruit_clue.py | 46 +++++++++++++++------ src/clue/test/test_adafruit_clue.py | 42 +++++++++++++++---- 3 files changed, 68 insertions(+), 22 deletions(-) diff --git a/src/base_circuitpython/base_cp_constants.py b/src/base_circuitpython/base_cp_constants.py index 5d2c1c094..e58d8cd21 100644 --- a/src/base_circuitpython/base_cp_constants.py +++ b/src/base_circuitpython/base_cp_constants.py @@ -9,4 +9,4 @@ EXPECTED_INPUT_BUTTONS = set(["button_a", "button_b"]) -ALL_EXPECTED_INPUT_EVENTS = set([]) \ No newline at end of file +ALL_EXPECTED_INPUT_EVENTS = set([]) diff --git a/src/clue/adafruit_clue.py b/src/clue/adafruit_clue.py index 542df619f..1277d079c 100644 --- a/src/clue/adafruit_clue.py +++ b/src/clue/adafruit_clue.py @@ -203,18 +203,19 @@ def __init__(self): "button_a": False, "button_b": False, "pressed_buttons": set(), - "accelerometer": {'x': 0, 'y': 0, 'z': 0}, - "color_sensor": {'r': 0, 'g': 0, 'b': 0, 'c': 0}, - "magnetometer": {'x': 0, 'y': 0, 'z': 0}, - "gyro": {'x': 0, 'y': 0, 'z': 0}, + "accelerometer": {"x": 0, "y": 0, "z": 0}, + "color_sensor": {"r": 0, "g": 0, "b": 0, "c": 0}, + "magnetometer": {"x": 0, "y": 0, "z": 0}, + "gyro": {"x": 0, "y": 0, "z": 0}, "sea_level_pressure": 1013.25, "temperature": 0, "proximity": 0, - "gesture": 0, # Can only be 0, 1, 2, 3, 4 + "gesture": 0, # Can only be 0, 1, 2, 3, 4 "humidity": 0, "pressure": 0, "pixel": neopixel.NeoPixel( - pin=CONSTANTS.CLUE_PIN, n=1, pixel_order=neopixel.RGB) + pin=CONSTANTS.CLUE_PIN, n=1, pixel_order=neopixel.RGB + ), } @property @@ -266,7 +267,11 @@ def acceleration(self): while True: print("Accel: {:.2f} {:.2f} {:.2f}".format(*clue.acceleration)) """ - return (self.__state["accelerometer"]['x'], self.__state["accelerometer"]['y'], self.__state["accelerometer"]['z']) + return ( + self.__state["accelerometer"]["x"], + self.__state["accelerometer"]["y"], + self.__state["accelerometer"]["z"], + ) @property def color(self): @@ -279,7 +284,12 @@ def color(self): while True: print("Color: R: {} G: {} B: {} C: {}".format(*clue.color)) """ - return (self.__state["color_sensor"]['r'], self.__state["color_sensor"]['g'], self.__state["color_sensor"]['b'], self.__state["color_sensor"]['c']) + return ( + self.__state["color_sensor"]["r"], + self.__state["color_sensor"]["g"], + self.__state["color_sensor"]["b"], + self.__state["color_sensor"]["c"], + ) @property def temperature(self): @@ -302,7 +312,11 @@ def magnetic(self): while True: print("Magnetic: {:.3f} {:.3f} {:.3f}".format(*clue.magnetic)) """ - return (self.__state["magnetometer"]['x'], self.__state["magnetometer"]['y'], self.__state["magnetometer"]['z']) + return ( + self.__state["magnetometer"]["x"], + self.__state["magnetometer"]["y"], + self.__state["magnetometer"]["z"], + ) @property def proximity(self): @@ -323,7 +337,11 @@ def gyro(self): This example prints the values. Try moving the board to see how the printed values change. print("Gyro: {:.2f} {:.2f} {:.2f}".format(*clue.gyro)) """ - return (self.__state["gyro"]['x'], self.__state["gyro"]['y'], self.__state["gyro"]['z']) + return ( + self.__state["gyro"]["x"], + self.__state["gyro"]["y"], + self.__state["gyro"]["z"], + ) @property def gesture(self): @@ -372,7 +390,12 @@ def altitude(self): clue.sea_level_pressure = 1015 print("Altitude: {:.1f}m".format(clue.altitude)) """ - altitude = 44330 * (1.0 - math.pow(self.__state["pressure"] / self.__state["sea_level_pressure"], 0.1903)) + altitude = 44330 * ( + 1.0 + - math.pow( + self.__state["pressure"] / self.__state["sea_level_pressure"], 0.1903 + ) + ) return altitude @property @@ -489,7 +512,6 @@ def __update_button(self, button, value): if value: self.__state["pressed_buttons"].add("B") self.__state["button_b"] = value - clue = Clue() # pylint: disable=invalid-name diff --git a/src/clue/test/test_adafruit_clue.py b/src/clue/test/test_adafruit_clue.py index 2c158e7d7..3f2e694ad 100644 --- a/src/clue/test/test_adafruit_clue.py +++ b/src/clue/test/test_adafruit_clue.py @@ -77,7 +77,11 @@ def test_acceleration(self): MOCK_MOTION_Z = 3 MOCK_MOTION_X_B = 4 - clue._Clue__state["acceleration"] = {"x": MOCK_MOTION_X_A, "y": MOCK_MOTION_Y, "z": MOCK_MOTION_Z} + clue._Clue__state["acceleration"] = { + "x": MOCK_MOTION_X_A, + "y": MOCK_MOTION_Y, + "z": MOCK_MOTION_Z, + } assert clue.acceleration == (MOCK_MOTION_X_A, MOCK_MOTION_Y, MOCK_MOTION_Z) clue._Clue__state["acceleration"]["x"] = MOCK_MOTION_X_B assert clue.acceleration == (MOCK_MOTION_X_B, MOCK_MOTION_Y, MOCK_MOTION_Z) @@ -89,9 +93,14 @@ def test_color(self): MOCK_COLOR_C = 4 MOCK_COLOR_R_B = 5 - clue._Clue__state["color"] = {"r": MOCK_COLOR_R_A, "g": MOCK_COLOR_G, "b": MOCK_COLOR_B, "c": MOCK_COLOR_C} + clue._Clue__state["color"] = { + "r": MOCK_COLOR_R_A, + "g": MOCK_COLOR_G, + "b": MOCK_COLOR_B, + "c": MOCK_COLOR_C, + } assert clue.color == (MOCK_COLOR_R_A, MOCK_COLOR_G, MOCK_COLOR_B, MOCK_COLOR_C) - assert clue._Clue__state["color"]["r"] = MOCK_COLOR_R_B + assert clue._Clue__state["color"]["r"] == MOCK_COLOR_R_B assert clue.color == (MOCK_COLOR_R_B, MOCK_COLOR_G, MOCK_COLOR_B, MOCK_COLOR_C) def test_temperature(self): @@ -101,17 +110,29 @@ def test_temperature(self): assert MOCK_TEMP_A == clue.temperature clue._Clue__state["temperature"] = MOCK_TEMP_B assert MOCK_TEMP_B == clue.temperature - + def test_magnetic(self): MOCK_MAGNETIC_X_A = 1 MOCK_MAGNETIC_Y = 2 MOCK_MAGNETIC_Z = 3 MOCK_MAGNETIC_X_B = 4 - clue._Clue__state["magnetometer"] = {"x": MOCK_MAGNETIC_X_A, "y": MOCK_MAGNETIC_Y, "z": MOCK_MAGNETIC_Z} - assert clue.acceleration == (MOCK_MAGNETIC_X_A, MOCK_MAGNETIC_Y, MOCK_MAGNETIC_Z) + clue._Clue__state["magnetometer"] = { + "x": MOCK_MAGNETIC_X_A, + "y": MOCK_MAGNETIC_Y, + "z": MOCK_MAGNETIC_Z, + } + assert clue.acceleration == ( + MOCK_MAGNETIC_X_A, + MOCK_MAGNETIC_Y, + MOCK_MAGNETIC_Z, + ) clue._Clue__state["magnetometer"]["x"] = MOCK_MAGNETIC_X_B - assert clue.acceleration == (MOCK_MAGNETIC_X_B, MOCK_MAGNETIC_Y, MOCK_MAGNETIC_Z) + assert clue.acceleration == ( + MOCK_MAGNETIC_X_B, + MOCK_MAGNETIC_Y, + MOCK_MAGNETIC_Z, + ) def test_proximity(self): MOCK_DISTANCE_A = 10 @@ -127,7 +148,11 @@ def test_gyro(self): MOCK_GYRO_Z = 3 MOCK_GYRO_X_B = 4 - clue._Clue__state["gyro"] = {"x": MOCK_GYRO_X_A, "y": MOCK_GYRO_Y, "z": MOCK_GYRO_Z} + clue._Clue__state["gyro"] = { + "x": MOCK_GYRO_X_A, + "y": MOCK_GYRO_Y, + "z": MOCK_GYRO_Z, + } assert clue.gyro == (MOCK_GYRO_X_A, MOCK_GYRO_Y, MOCK_GYRO_Z) clue._Clue__state["gyro"]["x"] = MOCK_GYRO_X_B assert clue.gyro == (MOCK_GYRO_X_B, MOCK_GYRO_Y, MOCK_GYRO_Z) @@ -180,4 +205,3 @@ def test_pixel(self): assert MOCK_RED == clue.pixel clue.pixel.fill(MOCK_WHITE) assert MOCK_WHITE == clue.pixel - \ No newline at end of file From 4d735733bf3ef8046a6ef199468ca61defb38b3b Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 Apr 2020 15:04:36 -0700 Subject: [PATCH 09/48] changed how dicts are updated in __state --- src/clue/test/test_adafruit_clue.py | 46 +++++++++++++---------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/clue/test/test_adafruit_clue.py b/src/clue/test/test_adafruit_clue.py index 3f2e694ad..3f970763c 100644 --- a/src/clue/test/test_adafruit_clue.py +++ b/src/clue/test/test_adafruit_clue.py @@ -77,11 +77,9 @@ def test_acceleration(self): MOCK_MOTION_Z = 3 MOCK_MOTION_X_B = 4 - clue._Clue__state["acceleration"] = { - "x": MOCK_MOTION_X_A, - "y": MOCK_MOTION_Y, - "z": MOCK_MOTION_Z, - } + clue._Clue__state["acceleration"].update( + {"x": MOCK_MOTION_X_A, "y": MOCK_MOTION_Y, "z": MOCK_MOTION_Z,} + ) assert clue.acceleration == (MOCK_MOTION_X_A, MOCK_MOTION_Y, MOCK_MOTION_Z) clue._Clue__state["acceleration"]["x"] = MOCK_MOTION_X_B assert clue.acceleration == (MOCK_MOTION_X_B, MOCK_MOTION_Y, MOCK_MOTION_Z) @@ -93,12 +91,14 @@ def test_color(self): MOCK_COLOR_C = 4 MOCK_COLOR_R_B = 5 - clue._Clue__state["color"] = { - "r": MOCK_COLOR_R_A, - "g": MOCK_COLOR_G, - "b": MOCK_COLOR_B, - "c": MOCK_COLOR_C, - } + clue._Clue__state["color"].update( + { + "r": MOCK_COLOR_R_A, + "g": MOCK_COLOR_G, + "b": MOCK_COLOR_B, + "c": MOCK_COLOR_C, + } + ) assert clue.color == (MOCK_COLOR_R_A, MOCK_COLOR_G, MOCK_COLOR_B, MOCK_COLOR_C) assert clue._Clue__state["color"]["r"] == MOCK_COLOR_R_B assert clue.color == (MOCK_COLOR_R_B, MOCK_COLOR_G, MOCK_COLOR_B, MOCK_COLOR_C) @@ -117,11 +117,9 @@ def test_magnetic(self): MOCK_MAGNETIC_Z = 3 MOCK_MAGNETIC_X_B = 4 - clue._Clue__state["magnetometer"] = { - "x": MOCK_MAGNETIC_X_A, - "y": MOCK_MAGNETIC_Y, - "z": MOCK_MAGNETIC_Z, - } + clue._Clue__state["magnetometer"].update( + {"x": MOCK_MAGNETIC_X_A, "y": MOCK_MAGNETIC_Y, "z": MOCK_MAGNETIC_Z,} + ) assert clue.acceleration == ( MOCK_MAGNETIC_X_A, MOCK_MAGNETIC_Y, @@ -148,11 +146,9 @@ def test_gyro(self): MOCK_GYRO_Z = 3 MOCK_GYRO_X_B = 4 - clue._Clue__state["gyro"] = { - "x": MOCK_GYRO_X_A, - "y": MOCK_GYRO_Y, - "z": MOCK_GYRO_Z, - } + clue._Clue__state["gyro"].update( + {"x": MOCK_GYRO_X_A, "y": MOCK_GYRO_Y, "z": MOCK_GYRO_Z,} + ) assert clue.gyro == (MOCK_GYRO_X_A, MOCK_GYRO_Y, MOCK_GYRO_Z) clue._Clue__state["gyro"]["x"] = MOCK_GYRO_X_B assert clue.gyro == (MOCK_GYRO_X_B, MOCK_GYRO_Y, MOCK_GYRO_Z) @@ -184,8 +180,8 @@ def test_pressure(self): def test_altitude(self): MOCK_PRESSURE_A = 1000 MOCK_PRESSURE_B = 1030 - MOCK_ALTITUDE_A = 125.42 - MOCK_ALTITUDE_B = -123.93 + MOCK_ALTITUDE_A = 125.42255615546036 + MOCK_ALTITUDE_B = -123.93061640175468 SEA_LEVEL_PRESSURE = 1015 clue.sea_level_pressure = SEA_LEVEL_PRESSURE clue._Clue__state["pressure"] = MOCK_PRESSURE_A @@ -202,6 +198,6 @@ def test_pixel(self): MOCK_RED = (255, 0, 0) MOCK_WHITE = (255, 255, 255) clue.pixel.fill(MOCK_RED) - assert MOCK_RED == clue.pixel + assert [MOCK_RED] == clue.pixel clue.pixel.fill(MOCK_WHITE) - assert MOCK_WHITE == clue.pixel + assert [MOCK_WHITE] == clue.pixel From 7c295bdf81185352ae9329df912e5a6a53f91e2f Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 Apr 2020 15:14:07 -0700 Subject: [PATCH 10/48] fixed bugs in clue test --- src/clue/test/test_adafruit_clue.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/clue/test/test_adafruit_clue.py b/src/clue/test/test_adafruit_clue.py index 3f970763c..fe9102f66 100644 --- a/src/clue/test/test_adafruit_clue.py +++ b/src/clue/test/test_adafruit_clue.py @@ -91,7 +91,7 @@ def test_color(self): MOCK_COLOR_C = 4 MOCK_COLOR_R_B = 5 - clue._Clue__state["color"].update( + clue._Clue__state["color_sensor"].update( { "r": MOCK_COLOR_R_A, "g": MOCK_COLOR_G, @@ -100,7 +100,7 @@ def test_color(self): } ) assert clue.color == (MOCK_COLOR_R_A, MOCK_COLOR_G, MOCK_COLOR_B, MOCK_COLOR_C) - assert clue._Clue__state["color"]["r"] == MOCK_COLOR_R_B + assert clue._Clue__state["color_sensor"]["r"] == MOCK_COLOR_R_B assert clue.color == (MOCK_COLOR_R_B, MOCK_COLOR_G, MOCK_COLOR_B, MOCK_COLOR_C) def test_temperature(self): @@ -120,17 +120,9 @@ def test_magnetic(self): clue._Clue__state["magnetometer"].update( {"x": MOCK_MAGNETIC_X_A, "y": MOCK_MAGNETIC_Y, "z": MOCK_MAGNETIC_Z,} ) - assert clue.acceleration == ( - MOCK_MAGNETIC_X_A, - MOCK_MAGNETIC_Y, - MOCK_MAGNETIC_Z, - ) + assert clue.magnetic == (MOCK_MAGNETIC_X_A, MOCK_MAGNETIC_Y, MOCK_MAGNETIC_Z,) clue._Clue__state["magnetometer"]["x"] = MOCK_MAGNETIC_X_B - assert clue.acceleration == ( - MOCK_MAGNETIC_X_B, - MOCK_MAGNETIC_Y, - MOCK_MAGNETIC_Z, - ) + assert clue.magnetic == (MOCK_MAGNETIC_X_B, MOCK_MAGNETIC_Y, MOCK_MAGNETIC_Z,) def test_proximity(self): MOCK_DISTANCE_A = 10 @@ -198,6 +190,6 @@ def test_pixel(self): MOCK_RED = (255, 0, 0) MOCK_WHITE = (255, 255, 255) clue.pixel.fill(MOCK_RED) - assert [MOCK_RED] == clue.pixel + assert MOCK_RED == clue.pixel[0] clue.pixel.fill(MOCK_WHITE) - assert [MOCK_WHITE] == clue.pixel + assert MOCK_WHITE == clue.pixel[0] From a10f3eb1ac3b480ad0d584a01c3fd7fa5ccda357 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Wed, 1 Apr 2020 15:17:39 -0700 Subject: [PATCH 11/48] Add sliders for pressure and proximity --- src/view/components/clue/Clue.tsx | 3 ++ .../toolbar/clue/ClueModalContent.tsx | 24 ++++++++--- .../toolbar/clue/ClueSensorProperties.tsx | 42 +++++++++++++++++++ .../ThreeDimensionSlider.tsx | 8 +--- src/view/constants.ts | 3 ++ 5 files changed, 67 insertions(+), 13 deletions(-) diff --git a/src/view/components/clue/Clue.tsx b/src/view/components/clue/Clue.tsx index 992d63bac..d59379e7c 100644 --- a/src/view/components/clue/Clue.tsx +++ b/src/view/components/clue/Clue.tsx @@ -23,6 +23,9 @@ const DEFAULT_STATE = { [SENSOR_LIST.MOTION_X]: 0, [SENSOR_LIST.MOTION_Y]: 0, [SENSOR_LIST.MOTION_Z]: 0, + [SENSOR_LIST.HUMIDITY]: 0, + [SENSOR_LIST.PRESSURE]: 0, + [SENSOR_LIST.PROXIMITY]: 0, }, }; diff --git a/src/view/components/toolbar/clue/ClueModalContent.tsx b/src/view/components/toolbar/clue/ClueModalContent.tsx index d72920dcf..bf894d7cd 100644 --- a/src/view/components/toolbar/clue/ClueModalContent.tsx +++ b/src/view/components/toolbar/clue/ClueModalContent.tsx @@ -101,6 +101,9 @@ export const CLUE_HUMIDITY_MODAL_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { + const humiditySensorValues = { + H: sensorValues[SENSOR_LIST.HUMIDITY], + }; return { descriptionTitle: "toolbar-light-sensor.title", tagInput: TAG_INPUT_SVG, @@ -108,9 +111,10 @@ export const CLUE_HUMIDITY_MODAL_CONTENT = ( descriptionText: "toolbar-light-sensor.description", tryItDescription: "toolbar-light-sensor.tryItDescription", components: [ - , ], id: "light_sensor", @@ -139,6 +143,9 @@ export const CLUE_PROXIMITY_MODAL_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { + const proximitySensorValues = { + P: sensorValues[SENSOR_LIST.PROXIMITY], + }; return { descriptionTitle: "toolbar-light-sensor.title", tagInput: TAG_INPUT_SVG, @@ -146,9 +153,10 @@ export const CLUE_PROXIMITY_MODAL_CONTENT = ( descriptionText: "toolbar-light-sensor.description", tryItDescription: "toolbar-light-sensor.tryItDescription", components: [ - , ], id: "light_sensor", @@ -158,6 +166,9 @@ export const CLUE_PRESSURE_MODAL_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { + const pressureSensorValues = { + P: sensorValues[SENSOR_LIST.PRESSURE], + }; return { descriptionTitle: "toolbar-light-sensor.title", tagInput: TAG_INPUT_SVG, @@ -165,9 +176,10 @@ export const CLUE_PRESSURE_MODAL_CONTENT = ( descriptionText: "toolbar-light-sensor.description", tryItDescription: "toolbar-light-sensor.tryItDescription", components: [ - , ], id: "light_sensor", diff --git a/src/view/components/toolbar/clue/ClueSensorProperties.tsx b/src/view/components/toolbar/clue/ClueSensorProperties.tsx index 57cc76675..117a6f0c7 100644 --- a/src/view/components/toolbar/clue/ClueSensorProperties.tsx +++ b/src/view/components/toolbar/clue/ClueSensorProperties.tsx @@ -40,3 +40,45 @@ export const CLUE_LIGHT_PROPERTIES: ISensorProps = { sliderProps: [CLUE_SLIDER_R, CLUE_SLIDER_G, CLUE_SLIDER_B, CLUE_SLIDER_C], unitLabel: "Lux", }; +export const CLUE_HUMIDITY_PROPERTIES: ISensorProps = { + LABEL: "Humidity Sensor", + sliderProps: [ + { + axisLabel: "H", + maxLabel: "Max", + maxValue: 100, + minLabel: "Min", + minValue: 0, + type: SENSOR_LIST.HUMIDITY, + }, + ], + unitLabel: "%", +}; +export const CLUE__PROXIMITY_PROPERTIES: ISensorProps = { + LABEL: "Humidity Sensor", + sliderProps: [ + { + axisLabel: "P", + maxLabel: "Max", + maxValue: 100, + minLabel: "Min", + minValue: 0, + type: SENSOR_LIST.PROXIMITY, + }, + ], + unitLabel: "%", +}; +export const CLUE_PRESSURE_PROPERTIES: ISensorProps = { + LABEL: "Humidity Sensor", + sliderProps: [ + { + axisLabel: "P", + maxLabel: "Max", + maxValue: 100, + minLabel: "Min", + minValue: 0, + type: SENSOR_LIST.PRESSURE, + }, + ], + unitLabel: "%", +}; diff --git a/src/view/components/toolbar/motion/threeDimensionSlider/ThreeDimensionSlider.tsx b/src/view/components/toolbar/motion/threeDimensionSlider/ThreeDimensionSlider.tsx index 04ea4ec7b..4fb8fc175 100644 --- a/src/view/components/toolbar/motion/threeDimensionSlider/ThreeDimensionSlider.tsx +++ b/src/view/components/toolbar/motion/threeDimensionSlider/ThreeDimensionSlider.tsx @@ -1,12 +1,6 @@ import * as React from "react"; import { SENSOR_LIST } from "../../../../constants"; -import { - ISensorProps, - X_SLIDER_INDEX, - Y_SLIDER_INDEX, - Z_SLIDER_INDEX, - ISliderProps, -} from "../../../../viewUtils"; +import { ISensorProps, ISliderProps } from "../../../../viewUtils"; import InputSlider from "../../InputSlider"; interface IProps { diff --git a/src/view/constants.ts b/src/view/constants.ts index fc8826ff2..1a4351b43 100644 --- a/src/view/constants.ts +++ b/src/view/constants.ts @@ -103,6 +103,9 @@ export enum SENSOR_LIST { LIGHT_G = "light_g", LIGHT_B = "light_b", LIGHT_C = "light_c", + HUMIDITY = "humidity", + PRESSURE = "pressure", + PROXIMITY = "proximity", } export const GESTURES = [ From f744acf3a2d6f27ac8982ff61a3c1ced5d66e191 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 Apr 2020 15:31:42 -0700 Subject: [PATCH 12/48] fixed bug in tests --- src/clue/adafruit_clue.py | 8 ++++---- src/clue/test/test_adafruit_clue.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/clue/adafruit_clue.py b/src/clue/adafruit_clue.py index 1277d079c..49c8db2c6 100644 --- a/src/clue/adafruit_clue.py +++ b/src/clue/adafruit_clue.py @@ -203,7 +203,7 @@ def __init__(self): "button_a": False, "button_b": False, "pressed_buttons": set(), - "accelerometer": {"x": 0, "y": 0, "z": 0}, + "acceleration": {"x": 0, "y": 0, "z": 0}, "color_sensor": {"r": 0, "g": 0, "b": 0, "c": 0}, "magnetometer": {"x": 0, "y": 0, "z": 0}, "gyro": {"x": 0, "y": 0, "z": 0}, @@ -268,9 +268,9 @@ def acceleration(self): print("Accel: {:.2f} {:.2f} {:.2f}".format(*clue.acceleration)) """ return ( - self.__state["accelerometer"]["x"], - self.__state["accelerometer"]["y"], - self.__state["accelerometer"]["z"], + self.__state["acceleration"]["x"], + self.__state["acceleration"]["y"], + self.__state["acceleration"]["z"], ) @property diff --git a/src/clue/test/test_adafruit_clue.py b/src/clue/test/test_adafruit_clue.py index fe9102f66..b22f47c53 100644 --- a/src/clue/test/test_adafruit_clue.py +++ b/src/clue/test/test_adafruit_clue.py @@ -100,7 +100,7 @@ def test_color(self): } ) assert clue.color == (MOCK_COLOR_R_A, MOCK_COLOR_G, MOCK_COLOR_B, MOCK_COLOR_C) - assert clue._Clue__state["color_sensor"]["r"] == MOCK_COLOR_R_B + clue._Clue__state["color_sensor"]["r"] = MOCK_COLOR_R_B assert clue.color == (MOCK_COLOR_R_B, MOCK_COLOR_G, MOCK_COLOR_B, MOCK_COLOR_C) def test_temperature(self): From 89a3e189ef40d56c905f92ba32717a3e03419e71 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Wed, 1 Apr 2020 16:03:36 -0700 Subject: [PATCH 13/48] Add fields to en.json --- .../components/toolbar/motion/Gesture.tsx | 3 +- src/view/translations/en.json | 38 ++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/view/components/toolbar/motion/Gesture.tsx b/src/view/components/toolbar/motion/Gesture.tsx index b039833d1..bed510a09 100644 --- a/src/view/components/toolbar/motion/Gesture.tsx +++ b/src/view/components/toolbar/motion/Gesture.tsx @@ -5,6 +5,7 @@ import CONSTANTS, { GESTURES } from "../../../constants"; const GESTURE_BUTTON_MESSAGE = "Send Gesture"; interface IProps { + gestures: string[]; onSelectGestures?: (event: React.ChangeEvent) => void; onSendGesture?: (isActive: boolean) => void; } @@ -23,7 +24,7 @@ export class Gesture extends React.Component { > Date: Wed, 1 Apr 2020 16:06:57 -0700 Subject: [PATCH 14/48] added python side --- src/base_circuitpython/base_cp_constants.py | 2 +- src/clue/adafruit_clue.py | 47 ++++++++++++------- src/clue/test/test_adafruit_clue.py | 30 +++++------- .../toolbar/motion/Accelerometer.spec.tsx | 6 +-- 4 files changed, 47 insertions(+), 38 deletions(-) diff --git a/src/base_circuitpython/base_cp_constants.py b/src/base_circuitpython/base_cp_constants.py index e58d8cd21..917740ad0 100644 --- a/src/base_circuitpython/base_cp_constants.py +++ b/src/base_circuitpython/base_cp_constants.py @@ -9,4 +9,4 @@ EXPECTED_INPUT_BUTTONS = set(["button_a", "button_b"]) -ALL_EXPECTED_INPUT_EVENTS = set([]) +ALL_EXPECTED_INPUT_EVENTS = set(["temperature", "light_r", "light_g", "light_b", "light_c", "motion_x", "motion_y", "motion_z", "humidity", "pressure", "proximity"]) diff --git a/src/clue/adafruit_clue.py b/src/clue/adafruit_clue.py index 49c8db2c6..d7632e8a4 100644 --- a/src/clue/adafruit_clue.py +++ b/src/clue/adafruit_clue.py @@ -203,10 +203,6 @@ def __init__(self): "button_a": False, "button_b": False, "pressed_buttons": set(), - "acceleration": {"x": 0, "y": 0, "z": 0}, - "color_sensor": {"r": 0, "g": 0, "b": 0, "c": 0}, - "magnetometer": {"x": 0, "y": 0, "z": 0}, - "gyro": {"x": 0, "y": 0, "z": 0}, "sea_level_pressure": 1013.25, "temperature": 0, "proximity": 0, @@ -216,6 +212,23 @@ def __init__(self): "pixel": neopixel.NeoPixel( pin=CONSTANTS.CLUE_PIN, n=1, pixel_order=neopixel.RGB ), + # Accelerometer + "motion_x": 0, + "motion_y": 0, + "motion_z": 0, + # Light/color sensor + "light_r": 0, + "light_g": 0, + "light_b": 0, + "light_c": 0, + # Magnetometer + "magnet_x": 0, + "magnet_y": 0, + "magnet_z": 0, + # Gyroscope + "gyro_x": 0, + "gyro_y": 0, + "gyro_z": 0, } @property @@ -268,9 +281,9 @@ def acceleration(self): print("Accel: {:.2f} {:.2f} {:.2f}".format(*clue.acceleration)) """ return ( - self.__state["acceleration"]["x"], - self.__state["acceleration"]["y"], - self.__state["acceleration"]["z"], + self.__state["motion_x"], + self.__state["motion_y"], + self.__state["motion_z"], ) @property @@ -285,10 +298,10 @@ def color(self): print("Color: R: {} G: {} B: {} C: {}".format(*clue.color)) """ return ( - self.__state["color_sensor"]["r"], - self.__state["color_sensor"]["g"], - self.__state["color_sensor"]["b"], - self.__state["color_sensor"]["c"], + self.__state["light_r"], + self.__state["light_g"], + self.__state["light_b"], + self.__state["light_c"], ) @property @@ -313,9 +326,9 @@ def magnetic(self): print("Magnetic: {:.3f} {:.3f} {:.3f}".format(*clue.magnetic)) """ return ( - self.__state["magnetometer"]["x"], - self.__state["magnetometer"]["y"], - self.__state["magnetometer"]["z"], + self.__state["magnet_x"], + self.__state["magnet_y"], + self.__state["magnet_z"], ) @property @@ -338,9 +351,9 @@ def gyro(self): print("Gyro: {:.2f} {:.2f} {:.2f}".format(*clue.gyro)) """ return ( - self.__state["gyro"]["x"], - self.__state["gyro"]["y"], - self.__state["gyro"]["z"], + self.__state["gyro_x"], + self.__state["gyro_y"], + self.__state["gyro_z"], ) @property diff --git a/src/clue/test/test_adafruit_clue.py b/src/clue/test/test_adafruit_clue.py index b22f47c53..a67d333f3 100644 --- a/src/clue/test/test_adafruit_clue.py +++ b/src/clue/test/test_adafruit_clue.py @@ -77,9 +77,9 @@ def test_acceleration(self): MOCK_MOTION_Z = 3 MOCK_MOTION_X_B = 4 - clue._Clue__state["acceleration"].update( - {"x": MOCK_MOTION_X_A, "y": MOCK_MOTION_Y, "z": MOCK_MOTION_Z,} - ) + clue._Clue__state["motion_x"] = MOCK_MOTION_X_A + clue._Clue__state["motion_y"] = MOCK_MOTION_Y + clue._Clue__state["motion_z"] = MOCK_MOTION_Z assert clue.acceleration == (MOCK_MOTION_X_A, MOCK_MOTION_Y, MOCK_MOTION_Z) clue._Clue__state["acceleration"]["x"] = MOCK_MOTION_X_B assert clue.acceleration == (MOCK_MOTION_X_B, MOCK_MOTION_Y, MOCK_MOTION_Z) @@ -91,14 +91,10 @@ def test_color(self): MOCK_COLOR_C = 4 MOCK_COLOR_R_B = 5 - clue._Clue__state["color_sensor"].update( - { - "r": MOCK_COLOR_R_A, - "g": MOCK_COLOR_G, - "b": MOCK_COLOR_B, - "c": MOCK_COLOR_C, - } - ) + clue._Clue__state["light_r"] = MOCK_COLOR_R_A + clue._Clue__state["light_g"] = MOCK_COLOR_G + clue._Clue__state["light_b"] = MOCK_COLOR_B + clue._Clue__state["light_c"] = MOCK_COLOR_C assert clue.color == (MOCK_COLOR_R_A, MOCK_COLOR_G, MOCK_COLOR_B, MOCK_COLOR_C) clue._Clue__state["color_sensor"]["r"] = MOCK_COLOR_R_B assert clue.color == (MOCK_COLOR_R_B, MOCK_COLOR_G, MOCK_COLOR_B, MOCK_COLOR_C) @@ -117,9 +113,9 @@ def test_magnetic(self): MOCK_MAGNETIC_Z = 3 MOCK_MAGNETIC_X_B = 4 - clue._Clue__state["magnetometer"].update( - {"x": MOCK_MAGNETIC_X_A, "y": MOCK_MAGNETIC_Y, "z": MOCK_MAGNETIC_Z,} - ) + clue._Clue__state["magnet_x"] = MOCK_MAGNETIC_X_A + clue._Clue__state["magnet_y"] = MOCK_MAGNETIC_Y + clue._Clue__state["magnet_z"] = MOCK_MAGNETIC_Z assert clue.magnetic == (MOCK_MAGNETIC_X_A, MOCK_MAGNETIC_Y, MOCK_MAGNETIC_Z,) clue._Clue__state["magnetometer"]["x"] = MOCK_MAGNETIC_X_B assert clue.magnetic == (MOCK_MAGNETIC_X_B, MOCK_MAGNETIC_Y, MOCK_MAGNETIC_Z,) @@ -138,9 +134,9 @@ def test_gyro(self): MOCK_GYRO_Z = 3 MOCK_GYRO_X_B = 4 - clue._Clue__state["gyro"].update( - {"x": MOCK_GYRO_X_A, "y": MOCK_GYRO_Y, "z": MOCK_GYRO_Z,} - ) + clue._Clue__state["gyro_x"] = MOCK_GYRO_X_A + clue._Clue__state["gyro_y"] = MOCK_GYRO_Y + clue._Clue__state["gyro_z"] = MOCK_GYRO_Z assert clue.gyro == (MOCK_GYRO_X_A, MOCK_GYRO_Y, MOCK_GYRO_Z) clue._Clue__state["gyro"]["x"] = MOCK_GYRO_X_B assert clue.gyro == (MOCK_GYRO_X_B, MOCK_GYRO_Y, MOCK_GYRO_Z) diff --git a/src/view/components/toolbar/motion/Accelerometer.spec.tsx b/src/view/components/toolbar/motion/Accelerometer.spec.tsx index ec89b4ebf..548e496ff 100644 --- a/src/view/components/toolbar/motion/Accelerometer.spec.tsx +++ b/src/view/components/toolbar/motion/Accelerometer.spec.tsx @@ -7,9 +7,9 @@ import { Accelerometer } from "./Accelerometer"; describe("Accelerometer component ", () => { const mockProps = { axisValues: { - X_AXIS: 1, - Y_AXIS: 0, - Z_AXIS: 1, + X: 1, + Y: 0, + Z: 1, }, onUpdateValue: () => {}, }; From 9f9169eb1ac3229c17ab6f5bf52bcdb2e7ac0bf8 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Wed, 1 Apr 2020 16:35:56 -0700 Subject: [PATCH 15/48] Update sensors with gesture --- src/view/components/clue/Clue.tsx | 28 ++++++++++++++++++- src/view/components/microbit/Microbit.tsx | 4 +-- .../components/toolbar/SensorModalUtils.tsx | 24 ++++++---------- .../toolbar/clue/ClueModalContent.tsx | 21 ++++++-------- .../toolbar/motion/Accelerometer.tsx | 2 -- .../components/toolbar/motion/Gesture.tsx | 2 +- src/view/constants.ts | 3 +- 7 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/view/components/clue/Clue.tsx b/src/view/components/clue/Clue.tsx index d59379e7c..1a2bd17ad 100644 --- a/src/view/components/clue/Clue.tsx +++ b/src/view/components/clue/Clue.tsx @@ -2,16 +2,23 @@ // Licensed under the MIT license. import * as React from "react"; -import { SENSOR_LIST, VSCODE_MESSAGES_TO_WEBVIEW } from "../../constants"; +import { + SENSOR_LIST, + VSCODE_MESSAGES_TO_WEBVIEW, + GESTURES_CLUE, + WEBVIEW_MESSAGES, +} from "../../constants"; import "../../styles/Simulator.css"; import ToolBar from "../toolbar/ToolBar"; import { ClueSimulator } from "./ClueSimulator"; import { CLUE_TOOLBAR_ICON_ID } from "../toolbar/SensorModalUtils"; import * as TOOLBAR_SVG from "../../svgs/toolbar_svg"; +import { sendMessage } from "../../utils/MessageUtils"; // Component grouping the functionality for micro:bit functionalities interface IState { sensors: { [key: string]: number }; + currentSelectedGesture: string; } const DEFAULT_STATE = { sensors: { @@ -27,6 +34,7 @@ const DEFAULT_STATE = { [SENSOR_LIST.PRESSURE]: 0, [SENSOR_LIST.PROXIMITY]: 0, }, + currentSelectedGesture: GESTURES_CLUE[0], }; export class Clue extends React.Component<{}, IState> { @@ -57,6 +65,8 @@ export class Clue extends React.Component<{}, IState> { buttonList={CLUE_TOOLBAR_BUTTONS} onUpdateSensor={this.updateSensor} sensorValues={this.state.sensors} + onSelectGesture={this.updateGesture} + sendGesture={this.sendGesture} /> ); @@ -64,6 +74,22 @@ export class Clue extends React.Component<{}, IState> { updateSensor = (sensor: SENSOR_LIST, value: number) => { this.setState({ sensors: { ...this.state.sensors, [sensor]: value } }); }; + updateGesture = (event: React.ChangeEvent) => { + this.setState({ currentSelectedGesture: event.target.value }); + }; + sendGesture = (isActive: boolean) => { + if (this.state.currentSelectedGesture) { + if (isActive) { + sendMessage(WEBVIEW_MESSAGES.GESTURE, { + gesture: this.state.currentSelectedGesture, + }); + } else { + sendMessage(WEBVIEW_MESSAGES.GESTURE, { + gesture: "", + }); + } + } + }; } const CLUE_TOOLBAR_BUTTONS: Array<{ label: string; image: JSX.Element }> = [ diff --git a/src/view/components/microbit/Microbit.tsx b/src/view/components/microbit/Microbit.tsx index 792f72e9e..4132fa0e4 100644 --- a/src/view/components/microbit/Microbit.tsx +++ b/src/view/components/microbit/Microbit.tsx @@ -4,7 +4,7 @@ import * as React from "react"; import { MICROBIT_TOOLBAR_ICON_ID } from "../../components/toolbar/SensorModalUtils"; import { - GESTURES, + GESTURES_MICROBIT, SENSOR_LIST, VSCODE_MESSAGES_TO_WEBVIEW, WEBVIEW_MESSAGES, @@ -28,7 +28,7 @@ const DEFAULT_STATE = { [SENSOR_LIST.MOTION_Y]: 0, [SENSOR_LIST.MOTION_Z]: 0, }, - currentSelectedGesture: GESTURES[0], + currentSelectedGesture: GESTURES_MICROBIT[0], }; export class Microbit extends React.Component<{}, IState> { diff --git a/src/view/components/toolbar/SensorModalUtils.tsx b/src/view/components/toolbar/SensorModalUtils.tsx index eef7bba94..c9c5a0415 100644 --- a/src/view/components/toolbar/SensorModalUtils.tsx +++ b/src/view/components/toolbar/SensorModalUtils.tsx @@ -87,7 +87,7 @@ export const CLUE_TOOLBAR_ICON_ID = { PRESSURE: "toolbar-clue-pressure-sensor", HUMIDITY: "toolbar-clue-humidity-sensor", GESTURE: "toolbar-clue-gesture-sensor", - PROXIMITY: "toolbar--clue-proximity-sensor", + PROXIMITY: "toolbar-clue-proximity-sensor", BLUETOOTH: "toolbar-clue-bluetooth", }; @@ -291,9 +291,7 @@ export const TEMPERATURE_MODAL_CONTENT = ( export const ACCELEROMETER_MODAL_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, - sensorValues: { [key: string]: number }, - onSelectGestures?: (event: React.ChangeEvent) => void, - sendGesture?: (isActive: boolean) => void + sensorValues: { [key: string]: number } ): IModalContent => { // this object will be accessed with the axis label const accelerometerSensorValues = { @@ -306,8 +304,6 @@ export const ACCELEROMETER_MODAL_CONTENT = ( ), descriptionText: "toolbar-accelerometer-sensor.description", @@ -423,7 +419,6 @@ export const LABEL_TO_MODAL_CONTENT_CONSTRUCTOR = new Map([ [CLUE_TOOLBAR_ICON_ID.SOUND, CLUE_MODAL.CLUE_SOUND_MODAL_CONTENT], [CLUE_TOOLBAR_ICON_ID.PRESSURE, CLUE_MODAL.CLUE_PRESSURE_MODAL_CONTENT], [CLUE_TOOLBAR_ICON_ID.HUMIDITY, CLUE_MODAL.CLUE_HUMIDITY_MODAL_CONTENT], - [CLUE_TOOLBAR_ICON_ID.GESTURE, CLUE_MODAL.CLUE_GESTURE_MODAL_CONTENT], [CLUE_TOOLBAR_ICON_ID.PROXIMITY, CLUE_MODAL.CLUE_PROXIMITY_MODAL_CONTENT], [CLUE_TOOLBAR_ICON_ID.BLUETOOTH, CLUE_MODAL.CLUE_BLUETOOTH_CONTENT], [ @@ -439,18 +434,17 @@ export const getModalContent = ( onSelectGestures?: (event: React.ChangeEvent) => void, sendGesture?: (isActive: boolean) => void ) => { + if (label === CLUE_TOOLBAR_ICON_ID.GESTURE) { + console.log("gestures"); + return CLUE_MODAL.CLUE_GESTURE_MODAL_CONTENT( + onSelectGestures, + sendGesture + ); + } const modalContentConstructor = LABEL_TO_MODAL_CONTENT_CONSTRUCTOR.get( label ); if (modalContentConstructor) { - if (label === MICROBIT_TOOLBAR_ICON_ID.ACCELEROMETER) { - return ACCELEROMETER_MODAL_CONTENT( - onUpdateValue, - sensorValues, - onSelectGestures, - sendGesture - ); - } return modalContentConstructor(onUpdateValue, sensorValues); } else { return; diff --git a/src/view/components/toolbar/clue/ClueModalContent.tsx b/src/view/components/toolbar/clue/ClueModalContent.tsx index bf894d7cd..b7c44a166 100644 --- a/src/view/components/toolbar/clue/ClueModalContent.tsx +++ b/src/view/components/toolbar/clue/ClueModalContent.tsx @@ -1,11 +1,11 @@ import * as React from "react"; import { IModalContent, FEATURE_REQUEST_ON_GITHUB } from "../SensorModalUtils"; -import { SENSOR_LIST } from "../../../constants"; +import { SENSOR_LIST, GESTURES_CLUE } from "../../../constants"; import { TAG_INPUT_SVG } from "../../../svgs/tag_input_svg"; import TemperatureSensorBar from "../TemperatureSensorBar"; import { TAG_OUTPUT_SVG } from "../../../svgs/tag_output_svg"; import { Accelerometer } from "../motion/Accelerometer"; -import LightSensorBar from "../LightSensorBar"; +import { Gesture } from "../motion/Gesture"; import { ThreeDimensionSlider } from "../motion/threeDimensionSlider/ThreeDimensionSlider"; import * as SENSOR_PROPERTIES from "./ClueSensorProperties"; export const CLUE_TEMPERATURE_MODAL_CONTENT = ( @@ -44,9 +44,7 @@ export const CLUE_GPIO_MODAL_CONTENT = ( }; export const CLUE_ACCELEROMETER_MODAL_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, - sensorValues: { [key: string]: number }, - onSelectGestures?: (event: React.ChangeEvent) => void, - sendGesture?: (isActive: boolean) => void + sensorValues: { [key: string]: number } ): IModalContent => { const accelerometerSensorValues = { X: sensorValues[SENSOR_LIST.MOTION_X], @@ -58,8 +56,6 @@ export const CLUE_ACCELEROMETER_MODAL_CONTENT = ( ), descriptionText: "toolbar-accelerometer-sensor.description", @@ -121,8 +117,8 @@ export const CLUE_HUMIDITY_MODAL_CONTENT = ( }; }; export const CLUE_GESTURE_MODAL_CONTENT = ( - onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, - sensorValues: { [key: string]: number } + onSelectGestures?: (event: React.ChangeEvent) => void, + sendGesture?: (isActive: boolean) => void ): IModalContent => { return { descriptionTitle: "toolbar-light-sensor.title", @@ -131,9 +127,10 @@ export const CLUE_GESTURE_MODAL_CONTENT = ( descriptionText: "toolbar-light-sensor.description", tryItDescription: "toolbar-light-sensor.tryItDescription", components: [ - , ], id: "light_sensor", diff --git a/src/view/components/toolbar/motion/Accelerometer.tsx b/src/view/components/toolbar/motion/Accelerometer.tsx index 85c4fb6ad..c17f1dfd0 100644 --- a/src/view/components/toolbar/motion/Accelerometer.tsx +++ b/src/view/components/toolbar/motion/Accelerometer.tsx @@ -48,8 +48,6 @@ interface IProps { Z: number; }; onUpdateValue: (sensor: SENSOR_LIST, value: number) => void; - onSelectGestures?: (event: React.ChangeEvent) => void; - onSendGesture?: (isActive: boolean) => void; } export class Accelerometer extends React.Component { diff --git a/src/view/components/toolbar/motion/Gesture.tsx b/src/view/components/toolbar/motion/Gesture.tsx index bed510a09..a1f3c97db 100644 --- a/src/view/components/toolbar/motion/Gesture.tsx +++ b/src/view/components/toolbar/motion/Gesture.tsx @@ -1,7 +1,7 @@ import * as React from "react"; import SensorButton from "../SensorButton"; import { Dropdown } from "../../Dropdown"; -import CONSTANTS, { GESTURES } from "../../../constants"; +import { CONSTANTS } from "../../../constants"; const GESTURE_BUTTON_MESSAGE = "Send Gesture"; interface IProps { diff --git a/src/view/constants.ts b/src/view/constants.ts index 9358452ee..b48f256a2 100644 --- a/src/view/constants.ts +++ b/src/view/constants.ts @@ -109,7 +109,7 @@ export enum SENSOR_LIST { PROXIMITY = "proximity", } -export const GESTURES = [ +export const GESTURES_MICROBIT = [ "shake", "up", "down", @@ -122,6 +122,7 @@ export const GESTURES = [ "6g", "8g", ]; +export const GESTURES_CLUE = ["up", "down", "left", "right"]; export enum WEBVIEW_ATTRIBUTES_KEY { INITIAL_DEVICE = "initial_device", From 7078b9ef97b87f5d5b3c29feaed73316060ba60e Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Thu, 2 Apr 2020 09:44:13 -0700 Subject: [PATCH 16/48] Map out strings for modals --- .../components/toolbar/SensorModalUtils.tsx | 2 +- .../toolbar/clue/ClueModalContent.tsx | 86 +++++++++---------- src/view/translations/en.json | 28 +++--- 3 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/view/components/toolbar/SensorModalUtils.tsx b/src/view/components/toolbar/SensorModalUtils.tsx index c9c5a0415..5513a1876 100644 --- a/src/view/components/toolbar/SensorModalUtils.tsx +++ b/src/view/components/toolbar/SensorModalUtils.tsx @@ -76,7 +76,7 @@ export const MICROBIT_TOOLBAR_ICON_ID = { }; export const CLUE_TOOLBAR_ICON_ID = { - TEMPERATURE: "toolbar-temperature-sensor", + TEMPERATURE: "toolbar-clue-temperature-sensor", LIGHT: "toolbar-clue-light-sensor", ACCELEROMETER: "toolbar-clue-accelerometer-sensor", LEDS: "toolbar-clue-led", diff --git a/src/view/components/toolbar/clue/ClueModalContent.tsx b/src/view/components/toolbar/clue/ClueModalContent.tsx index b7c44a166..92149dffc 100644 --- a/src/view/components/toolbar/clue/ClueModalContent.tsx +++ b/src/view/components/toolbar/clue/ClueModalContent.tsx @@ -20,11 +20,11 @@ export const CLUE_TEMPERATURE_MODAL_CONTENT = ( />, ], descriptionText: "toolbar-clue-temperature-sensor.description", - descriptionTitle: "toolbar-temperature-sensor.title", + descriptionTitle: "toolbar-clue-temperature-sensor.title", id: "temperature", tagInput: TAG_INPUT_SVG, tagOutput: undefined, - tryItDescription: "toolbar-temperature-sensor.tryItDescription", + tryItDescription: "toolbar-clue-temperature-sensor.tryItDescription", }; }; @@ -33,11 +33,11 @@ export const CLUE_GPIO_MODAL_CONTENT = ( sensorValues: { [key: string]: number } ): IModalContent => { return { - descriptionTitle: "toolbar-gpio.title", + descriptionTitle: "toolbar-clue-gpio.title", tagInput: TAG_INPUT_SVG, tagOutput: TAG_OUTPUT_SVG, - descriptionText: "toolbar-gpio.description", - tryItDescription: "toolbar-gpio.tryItDescription", + descriptionText: "toolbar-clue-gpio.description", + tryItDescription: "toolbar-clue-gpio.tryItDescription", components: undefined, id: "GPIO", }; @@ -58,12 +58,12 @@ export const CLUE_ACCELEROMETER_MODAL_CONTENT = ( axisValues={accelerometerSensorValues} /> ), - descriptionText: "toolbar-accelerometer-sensor.description", - descriptionTitle: "toolbar-accelerometer-sensor.title", + descriptionText: "toolbar-clue-accelerometer-sensor.description", + descriptionTitle: "toolbar-clue-accelerometer-sensor.title", id: "accelerometer", tagInput: TAG_INPUT_SVG, tagOutput: undefined, - tryItDescription: "toolbar-accelerometer-sensor.tryItDescription", + tryItDescription: "toolbar-clue-accelerometer-sensor.tryItDescription", }; }; @@ -85,12 +85,12 @@ export const CLUE_LIGHT_MODAL_CONTENT = ( axisProperties={SENSOR_PROPERTIES.CLUE_LIGHT_PROPERTIES} /> ), - descriptionText: "toolbar-accelerometer-sensor.description", - descriptionTitle: "toolbar-accelerometer-sensor.title", - id: "accelerometer", + descriptionText: "toolbar-clue-light-sensor.description", + descriptionTitle: "toolbar-clue-light-sensor.title", + id: "light_sensor", tagInput: TAG_INPUT_SVG, tagOutput: undefined, - tryItDescription: "toolbar-accelerometer-sensor.tryItDescription", + tryItDescription: "toolbar-clue-light-sensor.tryItDescription", }; }; export const CLUE_HUMIDITY_MODAL_CONTENT = ( @@ -101,11 +101,11 @@ export const CLUE_HUMIDITY_MODAL_CONTENT = ( H: sensorValues[SENSOR_LIST.HUMIDITY], }; return { - descriptionTitle: "toolbar-light-sensor.title", + descriptionTitle: "toolbar-clue-humidity-sensor.title", tagInput: TAG_INPUT_SVG, tagOutput: undefined, - descriptionText: "toolbar-light-sensor.description", - tryItDescription: "toolbar-light-sensor.tryItDescription", + descriptionText: "toolbar-clue-humidity-sensor.description", + tryItDescription: "toolbar-clue-humidity-sensor.tryItDescription", components: [ , ], - id: "light_sensor", + id: "humidity_sensor", }; }; export const CLUE_GESTURE_MODAL_CONTENT = ( @@ -121,11 +121,11 @@ export const CLUE_GESTURE_MODAL_CONTENT = ( sendGesture?: (isActive: boolean) => void ): IModalContent => { return { - descriptionTitle: "toolbar-light-sensor.title", + descriptionTitle: "toolbar-clue-gesture-sensor.title", tagInput: TAG_INPUT_SVG, tagOutput: undefined, - descriptionText: "toolbar-light-sensor.description", - tryItDescription: "toolbar-light-sensor.tryItDescription", + descriptionText: "toolbar-clue-gesture-sensor.description", + tryItDescription: "toolbar-clue-gesture-sensor.tryItDescription", components: [ , ], - id: "light_sensor", + id: "gesture_sensor", }; }; export const CLUE_PROXIMITY_MODAL_CONTENT = ( @@ -144,11 +144,11 @@ export const CLUE_PROXIMITY_MODAL_CONTENT = ( P: sensorValues[SENSOR_LIST.PROXIMITY], }; return { - descriptionTitle: "toolbar-light-sensor.title", + descriptionTitle: "toolbar-clue-proximity-sensor.title", tagInput: TAG_INPUT_SVG, tagOutput: undefined, - descriptionText: "toolbar-light-sensor.description", - tryItDescription: "toolbar-light-sensor.tryItDescription", + descriptionText: "toolbar-clue-proximity-sensor.description", + tryItDescription: "toolbar-clue-proximity-sensor.tryItDescription", components: [ , ], - id: "light_sensor", + id: "proximity_sensor", }; }; export const CLUE_PRESSURE_MODAL_CONTENT = ( @@ -167,11 +167,11 @@ export const CLUE_PRESSURE_MODAL_CONTENT = ( P: sensorValues[SENSOR_LIST.PRESSURE], }; return { - descriptionTitle: "toolbar-light-sensor.title", + descriptionTitle: "toolbar-clue-pressure-sensor.title", tagInput: TAG_INPUT_SVG, tagOutput: undefined, - descriptionText: "toolbar-light-sensor.description", - tryItDescription: "toolbar-light-sensor.tryItDescription", + descriptionText: "toolbar-clue-pressure-sensor.description", + tryItDescription: "toolbar-clue-pressure-sensor.tryItDescription", components: [ , ], - id: "light_sensor", + id: "pressure_sensor", }; }; export const CLUE_BUTTON_CONTENT = ( @@ -187,11 +187,11 @@ export const CLUE_BUTTON_CONTENT = ( sensorValues: { [key: string]: number } ): IModalContent => { return { - descriptionTitle: "toolbar-microbit-a-b-push.title", + descriptionTitle: "toolbar-clue-a-b-push.title", tagInput: undefined, tagOutput: TAG_INPUT_SVG, - descriptionText: "toolbar-microbit-a-b-push.description", - tryItDescription: "toolbar-microbit-a-b-push.tryItDescription", + descriptionText: "toolbar-clue-a-b-push.description", + tryItDescription: "toolbar-clue-a-b-push.tryItDescription", components: undefined, id: "microbit_button", }; @@ -202,13 +202,13 @@ export const CLUE_BLUETOOTH_CONTENT = ( sensorValues: { [key: string]: number } ): IModalContent => { return { - descriptionTitle: "toolbar-microbit-a-b-push.title", + descriptionTitle: "toolbar-clue-bluetooth.title", tagInput: undefined, tagOutput: TAG_INPUT_SVG, - descriptionText: "toolbar-microbit-a-b-push.description", - tryItDescription: "toolbar-microbit-a-b-push.tryItDescription", + descriptionText: "toolbar-clue-bluetooth.description", + tryItDescription: "toolbar-clue-bluetooth.tryItDescription", components: undefined, - id: "microbit_button", + id: "bluetooth", }; }; @@ -217,13 +217,13 @@ export const CLUE_SOUND_MODAL_CONTENT = ( sensorValues: { [key: string]: number } ): IModalContent => { return { - descriptionTitle: "toolbar-speaker.title", + descriptionTitle: "toolbar-clue-sound-sensor.title", tagInput: undefined, tagOutput: TAG_OUTPUT_SVG, - descriptionText: "toolbar-speaker.description", - tryItDescription: "toolbar-speaker.tryItDescription", + descriptionText: "toolbar-clue-sound-sensor.description", + tryItDescription: "toolbar-clue-sound-sensor.tryItDescription", components: [FEATURE_REQUEST_ON_GITHUB], - id: "speaker", + id: "sound_sensor", }; }; export const CLUE_LED_CONTENT = ( @@ -231,12 +231,12 @@ export const CLUE_LED_CONTENT = ( sensorValues: { [key: string]: number } ): IModalContent => { return { - descriptionTitle: "toolbar-microbit-led.title", + descriptionTitle: "toolbar-clue-led.title", tagInput: undefined, tagOutput: TAG_OUTPUT_SVG, - descriptionText: "toolbar-microbit-led.description", - tryItDescription: "toolbar-microbit-led.tryItDescription", + descriptionText: "toolbar-clue-led.description", + tryItDescription: "toolbar-clue-led.tryItDescription", components: undefined, - id: "microbit_LED", + id: "clue_neopixel", }; }; diff --git a/src/view/translations/en.json b/src/view/translations/en.json index 661441c4a..6bc7419ed 100644 --- a/src/view/translations/en.json +++ b/src/view/translations/en.json @@ -50,40 +50,40 @@ "toolbar-microbit-wireless.title": "Bluetooth & Radio", "toolbar-microbit-wireless.description": "micro:bits can use radio waves and bluetooth services to communicate with each other", "toolbar-microbit-wireless.tryItDescription": "If you would like to see this sensor supported, please +1 the feature addition issue on GitHub! For now, you can try it on MakeCode!", + "toolbar-clue-temperature-sensor.title": "Temperature", + "toolbar-clue-temperature-sensor.description": "", + "toolbar-clue-temperature-sensor.tryItDescription": "", "toolbar-clue-light-sensor.title": "Light/Color Sensor", "toolbar-clue-light-sensor.description": "", "toolbar-clue-light-sensor.tryItDescription": "", - "toolbar-clue-accelerometer-sensor.title": "", + "toolbar-clue-accelerometer-sensor.title": "Accelerometer", "toolbar-clue-accelerometer-sensor.description": "", "toolbar-clue-accelerometer-sensor.tryItDescription": "", - "toolbar-clue-led.title": "", + "toolbar-clue-led.title": "Neopixel", "toolbar-clue-led.description": "", "toolbar-clue-led.tryItDescription": "", - "toolbar-clue-a-b-push.title": "", + "toolbar-clue-a-b-push.title": "Buttons", "toolbar-clue-a-b-push.description": "", "toolbar-clue-a-b-push.tryItDescription": "", - "toolbar-clue-gpio.title": "", + "toolbar-clue-gpio.title": "Input/Output (GPIO)", "toolbar-clue-gpio.description": "", "toolbar-clue-gpio.tryItDescription": "", - "toolbar-clue-sound-sensor.title": "", + "toolbar-clue-sound-sensor.title": "Sound", "toolbar-clue-sound-sensor.description": "", "toolbar-clue-sound-sensor.tryItDescription": "", - "toolbar-clue-pressure-sensor.title": "", + "toolbar-clue-pressure-sensor.title": "Pressure", "toolbar-clue-pressure-sensor.description": "", "toolbar-clue-pressure-sensor.tryItDescription": "", - "toolbar-clue-humidity-sensor.title": "", + "toolbar-clue-humidity-sensor.title": "Humidity", "toolbar-clue-humidity-sensor.description": "", "toolbar-clue-humidity-sensor.tryItDescription": "", - - "toolbar-clue-gesture-sensor.title": "", + "toolbar-clue-gesture-sensor.title": "Gesture", "toolbar-clue-gesture-sensor.description": "", "toolbar-clue-gesture-sensor.tryItDescription": "", - - "toolbar-clue-proximity-sensor.title": "", + "toolbar-clue-proximity-sensor.title": "Proximity", "toolbar-clue-proximity-sensor.description": "", "toolbar-clue-proximity-sensor.tryItDescription": "", - - "toolbar-clue-bluetooth.title": "", + "toolbar-clue-bluetooth.title": "Bluetooth", "toolbar-clue-bluetooth.description": "", "toolbar-clue-bluetooth.tryItDescription": "" -} +} \ No newline at end of file From f20540646930a6e29c18fd83a95fa71b3a0918a2 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Thu, 2 Apr 2020 12:13:20 -0700 Subject: [PATCH 17/48] Add the svgs --- src/view/components/clue/Clue.tsx | 8 +- src/view/svgs/toolbar_svg.tsx | 227 ++++++++++++++++++++++++++++++ 2 files changed, 231 insertions(+), 4 deletions(-) diff --git a/src/view/components/clue/Clue.tsx b/src/view/components/clue/Clue.tsx index 1a2bd17ad..7e8bc0637 100644 --- a/src/view/components/clue/Clue.tsx +++ b/src/view/components/clue/Clue.tsx @@ -115,19 +115,19 @@ const CLUE_TOOLBAR_BUTTONS: Array<{ label: string; image: JSX.Element }> = [ }, { label: CLUE_TOOLBAR_ICON_ID.HUMIDITY, - image: TOOLBAR_SVG.TEMPERATURE_SVG, + image: TOOLBAR_SVG.HUMIDITY_SVG, }, { label: CLUE_TOOLBAR_ICON_ID.PRESSURE, - image: TOOLBAR_SVG.TEMPERATURE_SVG, + image: TOOLBAR_SVG.PRESSURE_SVG, }, { label: CLUE_TOOLBAR_ICON_ID.PROXIMITY, - image: TOOLBAR_SVG.TEMPERATURE_SVG, + image: TOOLBAR_SVG.PROXIMITY_SVG, }, { label: CLUE_TOOLBAR_ICON_ID.GESTURE, - image: TOOLBAR_SVG.TEMPERATURE_SVG, + image: TOOLBAR_SVG.GESTURE_SVG, }, { label: CLUE_TOOLBAR_ICON_ID.GPIO, diff --git a/src/view/svgs/toolbar_svg.tsx b/src/view/svgs/toolbar_svg.tsx index 21eb734ab..9eeb96614 100644 --- a/src/view/svgs/toolbar_svg.tsx +++ b/src/view/svgs/toolbar_svg.tsx @@ -503,3 +503,230 @@ export const WIRELESS_SVG = ( ); export default LEFT_EDGE_SVG; + +export const GESTURE_SVG = ( + + + + + + +); +export const HUMIDITY_SVG = ( + + + + + + + + + + + + + +); +export const PRESSURE_SVG = ( + + + + + + + + + + + + + + + + + + + + + + + +); +export const PROXIMITY_SVG = ( + + + + + + + + + + + + +); From 9aff60604cc1d447e19e823b6554acfaf7b26bf3 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 2 Apr 2020 12:59:49 -0700 Subject: [PATCH 18/48] fixed up python backend to match frontend sensors --- src/base_circuitpython/base_cp_constants.py | 17 +- src/clue/adafruit_clue.py | 217 +++++++++++++++++++- src/clue/test/test_adafruit_clue.py | 8 +- 3 files changed, 235 insertions(+), 7 deletions(-) diff --git a/src/base_circuitpython/base_cp_constants.py b/src/base_circuitpython/base_cp_constants.py index 1b8349e0d..9be6e1c43 100644 --- a/src/base_circuitpython/base_cp_constants.py +++ b/src/base_circuitpython/base_cp_constants.py @@ -11,7 +11,22 @@ EXPECTED_INPUT_BUTTONS = set(["button_a", "button_b"]) -ALL_EXPECTED_INPUT_EVENTS = set(["temperature", "light_r", "light_g", "light_b", "light_c", "motion_x", "motion_y", "motion_z", "humidity", "pressure", "proximity"]) +ALL_EXPECTED_INPUT_EVENTS = set( + [ + "temperature", + "light_r", + "light_g", + "light_b", + "light_c", + "motion_x", + "motion_y", + "motion_z", + "humidity", + "pressure", + "proximity", + "gesture", + ] +) BMP_IMG = "BMP" diff --git a/src/clue/adafruit_clue.py b/src/clue/adafruit_clue.py index 27bf99058..55ac916d2 100644 --- a/src/clue/adafruit_clue.py +++ b/src/clue/adafruit_clue.py @@ -69,6 +69,7 @@ sys.path.insert(0, os.path.join(abs_path)) import neopixel from base_circuitpython import base_cp_constants as CONSTANTS +from common import utils # REVISED VERSION OF THE ADAFRUIT CLUE LIBRARY FOR DSX @@ -205,7 +206,7 @@ def __init__(self): "sea_level_pressure": 1013.25, "temperature": 0, "proximity": 0, - "gesture": 0, # Can only be 0, 1, 2, 3, 4 + "gesture": "", "humidity": 0, "pressure": 0, "pixel": neopixel.NeoPixel( @@ -285,6 +286,21 @@ def acceleration(self): self.__state["motion_z"], ) + def shake(self, shake_threshold=30, avg_count=10, total_delay=0.1): + """Not implemented! + Detect when the accelerometer is shaken. Optional parameters: + :param shake_threshold: Increase or decrease to change shake sensitivity. This + requires a minimum value of 10. 10 is the total + acceleration if the board is not moving, therefore + anything less than 10 will erroneously report a constant + shake detected. (Default 30) + :param avg_count: The number of readings taken and used for the average + acceleration. (Default 10) + :param total_delay: The total time in seconds it takes to obtain avg_count + readings from acceleration. (Default 0.1) + """ + utils.print_for_unimplemented_functions(Clue.shake.__name__) + @property def color(self): """The red, green, blue, and clear light values. (r, g, b, c) @@ -367,7 +383,8 @@ def gesture(self): while True: print("Gesture: {}".format(clue.gesture)) """ - return self.__state["gesture"] + gesture_mapping = {"": 0, "up": 1, "down": 2, "left": 3, "right": 4} + return gesture_mapping[self.__state["gesture"]] @property def humidity(self): @@ -439,6 +456,202 @@ def pixel(self): """ return self.__state["pixel"] + @property + def touch_0(self): + """Not Implemented! + + Detect touch on capacitive touch pad 0. + .. image :: ../docs/_static/pad_0.jpg + :alt: Pad 0 + This example prints when pad 0 is touched. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + while True: + if clue.touch_0: + print("Touched pad 0") + """ + utils.print_for_unimplemented_functions(Clue.touch_0.__name__) + + @property + def touch_1(self): + """Not Implemented! + + Detect touch on capacitive touch pad 1. + .. image :: ../docs/_static/pad_1.jpg + :alt: Pad 1 + This example prints when pad 1 is touched. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + while True: + if clue.touch_1: + print("Touched pad 1") + """ + utils.print_for_unimplemented_functions(Clue.touch_1.__name__) + + @property + def touch_2(self): + """Not Implemented! + + Detect touch on capacitive touch pad 2. + .. image :: ../docs/_static/pad_2.jpg + :alt: Pad 2 + This example prints when pad 2 is touched. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + while True: + if clue.touch_2: + print("Touched pad 2") + """ + utils.print_for_unimplemented_functions(Clue.touch_2.__name__) + + @property + def white_leds(self): + """Not Implemented! + + The red led next to the USB plug labeled LED. + .. image :: ../docs/_static/white_leds.jpg + :alt: White LEDs + This example turns on the white LEDs. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + clue.white_leds = True + """ + utils.print_for_unimplemented_functions(Clue.white_leds.__name__) + + @white_leds.setter + def white_leds(self, value): + """Not Implemented!""" + utils.print_for_unimplemented_functions(Clue.white_leds.__name__) + + @property + def red_led(self): + """Not Implemented! + + The red led next to the USB plug labeled LED. + .. image :: ../docs/_static/red_led.jpg + :alt: Red LED + This example turns on the red LED. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + clue.red_led = True + """ + utils.print_for_unimplemented_functions(Clue.red_led.__name__) + + @red_led.setter + def red_led(self, value): + """Not Implemented!""" + utils.print_for_unimplemented_functions(Clue.red_led.__name__) + + def play_tone(self, frequency, duration): + """ Not Implemented! + Produce a tone using the speaker. Try changing frequency to change + the pitch of the tone. + :param int frequency: The frequency of the tone in Hz + :param float duration: The duration of the tone in seconds + .. image :: ../docs/_static/speaker.jpg + :alt: Speaker + This example plays a 880 Hz tone for a duration of 1 second. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + clue.play_tone(880, 1) + """ + utils.print_for_unimplemented_functions(Clue.play_tone.__name__) + + def start_tone(self, frequency): + """ Not Implemented! + Produce a tone using the speaker. Try changing frequency to change + the pitch of the tone. + :param int frequency: The frequency of the tone in Hz + .. image :: ../docs/_static/speaker.jpg + :alt: Speaker + This example plays a 523Hz tone when button A is pressed and a 587Hz tone when button B is + pressed, only while the buttons are being pressed. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + while True: + if clue.button_a: + clue.start_tone(523) + elif clue.button_b: + clue.start_tone(587) + else: + clue.stop_tone() + """ + utils.print_for_unimplemented_functions(Clue.start_tone.__name__) + + def stop_tone(self): + """ Not Implemented! + Use with start_tone to stop the tone produced. + .. image :: ../docs/_static/speaker.jpg + :alt: Speaker + This example plays a 523Hz tone when button A is pressed and a 587Hz tone when button B is + pressed, only while the buttons are being pressed. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + while True: + if clue.button_a: + clue.start_tone(523) + elif clue.button_b: + clue.start_tone(587) + else: + clue.stop_tone() + """ + utils.print_for_unimplemented_functions(Clue.stop_tone.__name__) + + @property + def sound_level(self): + """Not Implemented! + Obtain the sound level from the microphone (sound sensor). + .. image :: ../docs/_static/microphone.jpg + :alt: Microphone (sound sensor) + This example prints the sound levels. Try clapping or blowing on + the microphone to see the levels change. + .. code-block:: python + from adafruit_clue import clue + while True: + print(clue.sound_level) + """ + utils.print_for_unimplemented_functions(Clue.sound_level.__name__) + + def loud_sound(self, sound_threshold=200): + """Not Implemented! + Utilise a loud sound as an input. + :param int sound_threshold: Threshold sound level must exceed to return true (Default: 200) + .. image :: ../docs/_static/microphone.jpg + :alt: Microphone (sound sensor) + This example turns the NeoPixel LED blue each time you make a loud sound. + Try clapping or blowing onto the microphone to trigger it. + .. code-block:: python + from adafruit_clue import clue + while True: + if clue.loud_sound(): + clue.pixel.fill((0, 50, 0)) + else: + clue.pixel.fill(0) + You may find that the code is not responding how you would like. + If this is the case, you can change the loud sound threshold to + make it more or less responsive. Setting it to a higher number + means it will take a louder sound to trigger. Setting it to a + lower number will take a quieter sound to trigger. The following + example shows the threshold being set to a higher number than + the default. + .. code-block:: python + from adafruit_clue import clue + while True: + if clue.loud_sound(sound_threshold=300): + clue.pixel.fill((0, 50, 0)) + else: + clue.pixel.fill(0) + """ + utils.print_for_unimplemented_functions(Clue.loud_sound.__name__) + @staticmethod def simple_text_display( title=None, diff --git a/src/clue/test/test_adafruit_clue.py b/src/clue/test/test_adafruit_clue.py index 4b5950924..4c1585541 100644 --- a/src/clue/test/test_adafruit_clue.py +++ b/src/clue/test/test_adafruit_clue.py @@ -149,12 +149,12 @@ def test_gyro(self): assert clue.gyro == (MOCK_GYRO_X_B, MOCK_GYRO_Y, MOCK_GYRO_Z) def test_gesture(self): - NONE = 0 - UP = 1 + NONE = "" + UP = "up" clue._Clue__state["gesture"] = NONE - assert NONE == clue.gesture + assert 0 == clue.gesture clue._Clue__state["gesture"] = UP - assert UP == clue.gesture + assert 1 == clue.gesture def test_humidity(self): MOCK_HUMIDITY_A = 10 From a08b688cd8e62f6b44161da063673b7e28683da7 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 2 Apr 2020 13:18:10 -0700 Subject: [PATCH 19/48] changed state keys to constants --- src/base_circuitpython/base_cp_constants.py | 56 +++++++-- src/clue/adafruit_clue.py | 127 ++++++++++---------- src/clue/test/test_adafruit_clue.py | 69 +++++------ 3 files changed, 140 insertions(+), 112 deletions(-) diff --git a/src/base_circuitpython/base_cp_constants.py b/src/base_circuitpython/base_cp_constants.py index 9be6e1c43..2613edc3a 100644 --- a/src/base_circuitpython/base_cp_constants.py +++ b/src/base_circuitpython/base_cp_constants.py @@ -1,3 +1,33 @@ +class CLUE_STATE: + BUTTON_A = "button_a" + BUTTON_B = "button_b" + PRESSED_BUTTONS = "pressed_buttons" + SEA_LEVEL_PRESSURE = "sea_level_pressure" + TEMPERATURE = "temperature" + PROXIMITY = "proximity" + GESTURE = "gesture" + HUMIDITY = "humidity" + PRESSURE = "pressure" + PIXEL = "pixel" + # Accelerometer + MOTION_X = "motion_x" + MOTION_Y = "motion_y" + MOTION_Z = "motion_z" + # Light/color sensor + LIGHT_R = "light_r" + LIGHT_G = "light_g" + LIGHT_B = "light_b" + LIGHT_C = "light_c" + # Magnetometer + MAGNET_X = "magnet_x" + MAGNET_Y = "magnet_y" + MAGNET_Z = "magnet_z" + # Gyroscope + GYRO_X = "gyro_x" + GYRO_Y = "gyro_y" + GYRO_Z = "gyro_z" + + CPX = "CPX" CLUE = "CLUE" PIXELS = "pixels" @@ -9,22 +39,22 @@ IMG_DIR_NAME = "img" SCREEN_HEIGHT_WIDTH = 240 -EXPECTED_INPUT_BUTTONS = set(["button_a", "button_b"]) +EXPECTED_INPUT_BUTTONS = set([CLUE_STATE.BUTTON_A, CLUE_STATE.BUTTON_B]) ALL_EXPECTED_INPUT_EVENTS = set( [ - "temperature", - "light_r", - "light_g", - "light_b", - "light_c", - "motion_x", - "motion_y", - "motion_z", - "humidity", - "pressure", - "proximity", - "gesture", + CLUE_STATE.TEMPERATURE, + CLUE_STATE.LIGHT_R, + CLUE_STATE.LIGHT_G, + CLUE_STATE.LIGHT_B, + CLUE_STATE.LIGHT_C, + CLUE_STATE.MOTION_X, + CLUE_STATE.MOTION_Y, + CLUE_STATE.MOTION_Z, + CLUE_STATE.HUMIDITY, + CLUE_STATE.PRESSURE, + CLUE_STATE.PROXIMITY, + CLUE_STATE.GESTURE, ] ) diff --git a/src/clue/adafruit_clue.py b/src/clue/adafruit_clue.py index 55ac916d2..0a130549c 100644 --- a/src/clue/adafruit_clue.py +++ b/src/clue/adafruit_clue.py @@ -199,37 +199,36 @@ class Clue: # pylint: disable=too-many-instance-attributes, too-many-public-met RAINBOW = (RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE) def __init__(self): - self.__state = { - "button_a": False, - "button_b": False, - "pressed_buttons": set(), - "sea_level_pressure": 1013.25, - "temperature": 0, - "proximity": 0, - "gesture": "", - "humidity": 0, - "pressure": 0, - "pixel": neopixel.NeoPixel( - pin=CONSTANTS.CLUE_PIN, n=1, pixel_order=neopixel.RGB - ), - # Accelerometer - "motion_x": 0, - "motion_y": 0, - "motion_z": 0, - # Light/color sensor - "light_r": 0, - "light_g": 0, - "light_b": 0, - "light_c": 0, - # Magnetometer - "magnet_x": 0, - "magnet_y": 0, - "magnet_z": 0, - # Gyroscope - "gyro_x": 0, - "gyro_y": 0, - "gyro_z": 0, - } + self.__state = {} + self.__state[CONSTANTS.CLUE_STATE.BUTTON_A] = False + self.__state[CONSTANTS.CLUE_STATE.BUTTON_B] = False + self.__state[CONSTANTS.CLUE_STATE.PRESSED_BUTTONS] = set() + self.__state[CONSTANTS.CLUE_STATE.SEA_LEVEL_PRESSURE] = 1013.25 + self.__state[CONSTANTS.CLUE_STATE.TEMPERATURE] = 0 + self.__state[CONSTANTS.CLUE_STATE.PROXIMITY] = 0 + self.__state[CONSTANTS.CLUE_STATE.GESTURE] = "" + self.__state[CONSTANTS.CLUE_STATE.HUMIDITY] = 0 + self.__state[CONSTANTS.CLUE_STATE.PRESSURE] = 0 + self.__state[CONSTANTS.CLUE_STATE.PIXEL] = neopixel.NeoPixel( + pin=CONSTANTS.CLUE_PIN, n=1, pixel_order=neopixel.RGB + ) + # Accelerometer + self.__state[CONSTANTS.CLUE_STATE.MOTION_X] = 0 + self.__state[CONSTANTS.CLUE_STATE.MOTION_Y] = 0 + self.__state[CONSTANTS.CLUE_STATE.MOTION_Z] = 0 + # Light/color sensor + self.__state[CONSTANTS.CLUE_STATE.LIGHT_R] = 0 + self.__state[CONSTANTS.CLUE_STATE.LIGHT_G] = 0 + self.__state[CONSTANTS.CLUE_STATE.LIGHT_B] = 0 + self.__state[CONSTANTS.CLUE_STATE.LIGHT_C] = 0 + # Magnetometer + self.__state[CONSTANTS.CLUE_STATE.MAGNET_X] = 0 + self.__state[CONSTANTS.CLUE_STATE.MAGNET_Y] = 0 + self.__state[CONSTANTS.CLUE_STATE.MAGNET_Z] = 0 + # Gyroscope + self.__state[CONSTANTS.CLUE_STATE.GYRO_X] = 0 + self.__state[CONSTANTS.CLUE_STATE.GYRO_Y] = 0 + self.__state[CONSTANTS.CLUE_STATE.GYRO_Z] = 0 @property def button_a(self): @@ -242,7 +241,7 @@ def button_a(self): if clue.button_a: print("Button A pressed") """ - return self.__state["button_a"] + return self.__state[CONSTANTS.CLUE_STATE.BUTTON_A] @property def button_b(self): @@ -255,7 +254,7 @@ def button_b(self): if clue.button_b: print("Button B pressed") """ - return self.__state["button_b"] + return self.__state[CONSTANTS.CLUE_STATE.BUTTON_B] @property def were_pressed(self): @@ -266,8 +265,8 @@ def were_pressed(self): while True: print(clue.were_pressed) """ - ret = self.__state["pressed_buttons"].copy() - self.__state["pressed_buttons"].clear() + ret = self.__state[CONSTANTS.CLUE_STATE.PRESSED_BUTTONS].copy() + self.__state[CONSTANTS.CLUE_STATE.PRESSED_BUTTONS].clear() return ret @property @@ -281,9 +280,9 @@ def acceleration(self): print("Accel: {:.2f} {:.2f} {:.2f}".format(*clue.acceleration)) """ return ( - self.__state["motion_x"], - self.__state["motion_y"], - self.__state["motion_z"], + self.__state[CONSTANTS.CLUE_STATE.MOTION_X], + self.__state[CONSTANTS.CLUE_STATE.MOTION_Y], + self.__state[CONSTANTS.CLUE_STATE.MOTION_Z], ) def shake(self, shake_threshold=30, avg_count=10, total_delay=0.1): @@ -313,10 +312,10 @@ def color(self): print("Color: R: {} G: {} B: {} C: {}".format(*clue.color)) """ return ( - self.__state["light_r"], - self.__state["light_g"], - self.__state["light_b"], - self.__state["light_c"], + self.__state[CONSTANTS.CLUE_STATE.LIGHT_R], + self.__state[CONSTANTS.CLUE_STATE.LIGHT_G], + self.__state[CONSTANTS.CLUE_STATE.LIGHT_B], + self.__state[CONSTANTS.CLUE_STATE.LIGHT_C], ) @property @@ -328,7 +327,7 @@ def temperature(self): from adafruit_clue import clue print("Temperature: {:.1f}C".format(clue.temperature)) """ - return self.__state["temperature"] + return self.__state[CONSTANTS.CLUE_STATE.TEMPERATURE] @property def magnetic(self): @@ -341,9 +340,9 @@ def magnetic(self): print("Magnetic: {:.3f} {:.3f} {:.3f}".format(*clue.magnetic)) """ return ( - self.__state["magnet_x"], - self.__state["magnet_y"], - self.__state["magnet_z"], + self.__state[CONSTANTS.CLUE_STATE.MAGNET_X], + self.__state[CONSTANTS.CLUE_STATE.MAGNET_Y], + self.__state[CONSTANTS.CLUE_STATE.MAGNET_Z], ) @property @@ -357,7 +356,7 @@ def proximity(self): while True: print("Proximity: {}".format(clue.proximity)) """ - return self.__state["proximity"] + return self.__state[CONSTANTS.CLUE_STATE.PROXIMITY] @property def gyro(self): @@ -366,9 +365,9 @@ def gyro(self): print("Gyro: {:.2f} {:.2f} {:.2f}".format(*clue.gyro)) """ return ( - self.__state["gyro_x"], - self.__state["gyro_y"], - self.__state["gyro_z"], + self.__state[CONSTANTS.CLUE_STATE.GYRO_X], + self.__state[CONSTANTS.CLUE_STATE.GYRO_Y], + self.__state[CONSTANTS.CLUE_STATE.GYRO_Z], ) @property @@ -384,7 +383,7 @@ def gesture(self): print("Gesture: {}".format(clue.gesture)) """ gesture_mapping = {"": 0, "up": 1, "down": 2, "left": 3, "right": 4} - return gesture_mapping[self.__state["gesture"]] + return gesture_mapping[self.__state[CONSTANTS.CLUE_STATE.GESTURE]] @property def humidity(self): @@ -396,7 +395,7 @@ def humidity(self): while True: print("Humidity: {:.1f}%".format(clue.humidity)) """ - return self.__state["humidity"] + return self.__state[CONSTANTS.CLUE_STATE.HUMIDITY] @property def pressure(self): @@ -407,7 +406,7 @@ def pressure(self): from adafruit_clue import clue print("Pressure: {:.3f}hPa".format(clue.pressure)) """ - return self.__state["pressure"] + return self.__state[CONSTANTS.CLUE_STATE.PRESSURE] @property def altitude(self): @@ -422,7 +421,9 @@ def altitude(self): altitude = 44330 * ( 1.0 - math.pow( - self.__state["pressure"] / self.__state["sea_level_pressure"], 0.1903 + self.__state[CONSTANTS.CLUE_STATE.PRESSURE] + / self.__state[CONSTANTS.CLUE_STATE.SEA_LEVEL_PRESSURE], + 0.1903, ) ) return altitude @@ -438,11 +439,11 @@ def sea_level_pressure(self): clue.sea_level_pressure = 1015 print("Pressure: {:.3f}hPa".format(clue.pressure)) """ - return self.__state["sea_level_pressure"] + return self.__state[CONSTANTS.CLUE_STATE.SEA_LEVEL_PRESSURE] @sea_level_pressure.setter def sea_level_pressure(self, value): - self.__state["sea_level_pressure"] = value + self.__state[CONSTANTS.CLUE_STATE.SEA_LEVEL_PRESSURE] = value @property def pixel(self): @@ -454,7 +455,7 @@ def pixel(self): while True: clue.pixel.fill((255, 0, 255)) """ - return self.__state["pixel"] + return self.__state[CONSTANTS.CLUE_STATE.PIXEL] @property def touch_0(self): @@ -729,14 +730,14 @@ def update_state(self, new_state): # helpers def __update_button(self, button, value): - if button == "button_a": + if button == CONSTANTS.CLUE_STATE.BUTTON_A: if value: - self.__state["pressed_buttons"].add("A") - self.__state["button_a"] = value - elif button == "button_b": + self.__state[CONSTANTS.CLUE_STATE.PRESSED_BUTTONS].add("A") + self.__state[CONSTANTS.CLUE_STATE.BUTTON_A] = value + elif button == CONSTANTS.CLUE_STATE.BUTTON_B: if value: - self.__state["pressed_buttons"].add("B") - self.__state["button_b"] = value + self.__state[CONSTANTS.CLUE_STATE.PRESSED_BUTTONS].add("B") + self.__state[CONSTANTS.CLUE_STATE.BUTTON_B] = value clue = Clue() # pylint: disable=invalid-name diff --git a/src/clue/test/test_adafruit_clue.py b/src/clue/test/test_adafruit_clue.py index 4c1585541..152ba7cc2 100644 --- a/src/clue/test/test_adafruit_clue.py +++ b/src/clue/test/test_adafruit_clue.py @@ -62,17 +62,14 @@ def _send_helper(self, image): self.main_img = image def test_buttons(self): - BUTTON_A = "button_a" - BUTTON_B = "button_b" - - clue._Clue__update_button(BUTTON_A, True) + clue._Clue__update_button(CONSTANTS.CLUE_STATE.BUTTON_A, True) assert clue.button_a - clue._Clue__update_button(BUTTON_A, False) + clue._Clue__update_button(CONSTANTS.CLUE_STATE.BUTTON_A, False) assert not clue.button_a - clue._Clue__update_button(BUTTON_B, True) + clue._Clue__update_button(CONSTANTS.CLUE_STATE.BUTTON_B, True) assert clue.button_b - clue._Clue__update_button(BUTTON_B, False) + clue._Clue__update_button(CONSTANTS.CLUE_STATE.BUTTON_B, False) assert not clue.button_b assert set(["A", "B"]) == clue.were_pressed @@ -84,11 +81,11 @@ def test_acceleration(self): MOCK_MOTION_Z = 3 MOCK_MOTION_X_B = 4 - clue._Clue__state["motion_x"] = MOCK_MOTION_X_A - clue._Clue__state["motion_y"] = MOCK_MOTION_Y - clue._Clue__state["motion_z"] = MOCK_MOTION_Z + clue._Clue__state[CONSTANTS.CLUE_STATE.MOTION_X] = MOCK_MOTION_X_A + clue._Clue__state[CONSTANTS.CLUE_STATE.MOTION_Y] = MOCK_MOTION_Y + clue._Clue__state[CONSTANTS.CLUE_STATE.MOTION_Z] = MOCK_MOTION_Z assert clue.acceleration == (MOCK_MOTION_X_A, MOCK_MOTION_Y, MOCK_MOTION_Z) - clue._Clue__state["acceleration"]["x"] = MOCK_MOTION_X_B + clue._Clue__state[CONSTANTS.CLUE_STATE.MOTION_X] = MOCK_MOTION_X_B assert clue.acceleration == (MOCK_MOTION_X_B, MOCK_MOTION_Y, MOCK_MOTION_Z) def test_color(self): @@ -98,20 +95,20 @@ def test_color(self): MOCK_COLOR_C = 4 MOCK_COLOR_R_B = 5 - clue._Clue__state["light_r"] = MOCK_COLOR_R_A - clue._Clue__state["light_g"] = MOCK_COLOR_G - clue._Clue__state["light_b"] = MOCK_COLOR_B - clue._Clue__state["light_c"] = MOCK_COLOR_C + clue._Clue__state[CONSTANTS.CLUE_STATE.LIGHT_R] = MOCK_COLOR_R_A + clue._Clue__state[CONSTANTS.CLUE_STATE.LIGHT_G] = MOCK_COLOR_G + clue._Clue__state[CONSTANTS.CLUE_STATE.LIGHT_B] = MOCK_COLOR_B + clue._Clue__state[CONSTANTS.CLUE_STATE.LIGHT_C] = MOCK_COLOR_C assert clue.color == (MOCK_COLOR_R_A, MOCK_COLOR_G, MOCK_COLOR_B, MOCK_COLOR_C) - clue._Clue__state["color_sensor"]["r"] = MOCK_COLOR_R_B + clue._Clue__state[CONSTANTS.CLUE_STATE.LIGHT_R] = MOCK_COLOR_R_B assert clue.color == (MOCK_COLOR_R_B, MOCK_COLOR_G, MOCK_COLOR_B, MOCK_COLOR_C) def test_temperature(self): MOCK_TEMP_A = 10 MOCK_TEMP_B = -10 - clue._Clue__state["temperature"] = MOCK_TEMP_A + clue._Clue__state[CONSTANTS.CLUE_STATE.TEMPERATURE] = MOCK_TEMP_A assert MOCK_TEMP_A == clue.temperature - clue._Clue__state["temperature"] = MOCK_TEMP_B + clue._Clue__state[CONSTANTS.CLUE_STATE.TEMPERATURE] = MOCK_TEMP_B assert MOCK_TEMP_B == clue.temperature def test_magnetic(self): @@ -120,19 +117,19 @@ def test_magnetic(self): MOCK_MAGNETIC_Z = 3 MOCK_MAGNETIC_X_B = 4 - clue._Clue__state["magnet_x"] = MOCK_MAGNETIC_X_A - clue._Clue__state["magnet_y"] = MOCK_MAGNETIC_Y - clue._Clue__state["magnet_z"] = MOCK_MAGNETIC_Z + clue._Clue__state[CONSTANTS.CLUE_STATE.MAGNET_X] = MOCK_MAGNETIC_X_A + clue._Clue__state[CONSTANTS.CLUE_STATE.MAGNET_Y] = MOCK_MAGNETIC_Y + clue._Clue__state[CONSTANTS.CLUE_STATE.MAGNET_Z] = MOCK_MAGNETIC_Z assert clue.magnetic == (MOCK_MAGNETIC_X_A, MOCK_MAGNETIC_Y, MOCK_MAGNETIC_Z,) - clue._Clue__state["magnetometer"]["x"] = MOCK_MAGNETIC_X_B + clue._Clue__state[CONSTANTS.CLUE_STATE.MAGNET_X] = MOCK_MAGNETIC_X_B assert clue.magnetic == (MOCK_MAGNETIC_X_B, MOCK_MAGNETIC_Y, MOCK_MAGNETIC_Z,) def test_proximity(self): MOCK_DISTANCE_A = 10 MOCK_DISTANCE_B = 250 - clue._Clue__state["proximity"] = MOCK_DISTANCE_A + clue._Clue__state[CONSTANTS.CLUE_STATE.PROXIMITY] = MOCK_DISTANCE_A assert MOCK_DISTANCE_A == clue.proximity - clue._Clue__state["proximity"] = MOCK_DISTANCE_B + clue._Clue__state[CONSTANTS.CLUE_STATE.PROXIMITY] = MOCK_DISTANCE_B assert MOCK_DISTANCE_B == clue.proximity def test_gyro(self): @@ -141,35 +138,35 @@ def test_gyro(self): MOCK_GYRO_Z = 3 MOCK_GYRO_X_B = 4 - clue._Clue__state["gyro_x"] = MOCK_GYRO_X_A - clue._Clue__state["gyro_y"] = MOCK_GYRO_Y - clue._Clue__state["gyro_z"] = MOCK_GYRO_Z + clue._Clue__state[CONSTANTS.CLUE_STATE.GYRO_X] = MOCK_GYRO_X_A + clue._Clue__state[CONSTANTS.CLUE_STATE.GYRO_Y] = MOCK_GYRO_Y + clue._Clue__state[CONSTANTS.CLUE_STATE.GYRO_Z] = MOCK_GYRO_Z assert clue.gyro == (MOCK_GYRO_X_A, MOCK_GYRO_Y, MOCK_GYRO_Z) - clue._Clue__state["gyro"]["x"] = MOCK_GYRO_X_B + clue._Clue__state[CONSTANTS.CLUE_STATE.GYRO_X] = MOCK_GYRO_X_B assert clue.gyro == (MOCK_GYRO_X_B, MOCK_GYRO_Y, MOCK_GYRO_Z) def test_gesture(self): NONE = "" UP = "up" - clue._Clue__state["gesture"] = NONE + clue._Clue__state[CONSTANTS.CLUE_STATE.GESTURE] = NONE assert 0 == clue.gesture - clue._Clue__state["gesture"] = UP + clue._Clue__state[CONSTANTS.CLUE_STATE.GESTURE] = UP assert 1 == clue.gesture def test_humidity(self): MOCK_HUMIDITY_A = 10 MOCK_HUMIDITY_B = 50 - clue._Clue__state["humidity"] = MOCK_HUMIDITY_A + clue._Clue__state[CONSTANTS.CLUE_STATE.HUMIDITY] = MOCK_HUMIDITY_A assert MOCK_HUMIDITY_A == clue.humidity - clue._Clue__state["humidity"] = MOCK_HUMIDITY_B + clue._Clue__state[CONSTANTS.CLUE_STATE.HUMIDITY] = MOCK_HUMIDITY_B assert MOCK_HUMIDITY_B == clue.humidity def test_pressure(self): MOCK_PRESSURE_A = 10 MOCK_PRESSURE_B = 50 - clue._Clue__state["pressure"] = MOCK_PRESSURE_A + clue._Clue__state[CONSTANTS.CLUE_STATE.PRESSURE] = MOCK_PRESSURE_A assert MOCK_PRESSURE_A == clue.pressure - clue._Clue__state["pressure"] = MOCK_PRESSURE_B + clue._Clue__state[CONSTANTS.CLUE_STATE.PRESSURE] = MOCK_PRESSURE_B assert MOCK_PRESSURE_B == clue.pressure def test_altitude(self): @@ -179,9 +176,9 @@ def test_altitude(self): MOCK_ALTITUDE_B = -123.93061640175468 SEA_LEVEL_PRESSURE = 1015 clue.sea_level_pressure = SEA_LEVEL_PRESSURE - clue._Clue__state["pressure"] = MOCK_PRESSURE_A + clue._Clue__state[CONSTANTS.CLUE_STATE.PRESSURE] = MOCK_PRESSURE_A assert MOCK_ALTITUDE_A == pytest.approx(clue.altitude) - clue._Clue__state["pressure"] = MOCK_PRESSURE_B + clue._Clue__state[CONSTANTS.CLUE_STATE.PRESSURE] = MOCK_PRESSURE_B assert MOCK_ALTITUDE_B == pytest.approx(clue.altitude) def test_sea_level_pressure(self): From b844f38fb0da782d9c460d98e83e604068a63df1 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Thu, 2 Apr 2020 13:43:43 -0700 Subject: [PATCH 20/48] Add correct text for sensors --- .../components/toolbar/SensorModalUtils.tsx | 1 + .../toolbar/clue/ClueModalContent.tsx | 14 +++++ src/view/translations/en.json | 51 ++++++++++--------- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/view/components/toolbar/SensorModalUtils.tsx b/src/view/components/toolbar/SensorModalUtils.tsx index 5513a1876..b7848fade 100644 --- a/src/view/components/toolbar/SensorModalUtils.tsx +++ b/src/view/components/toolbar/SensorModalUtils.tsx @@ -425,6 +425,7 @@ export const LABEL_TO_MODAL_CONTENT_CONSTRUCTOR = new Map([ CLUE_TOOLBAR_ICON_ID.ACCELEROMETER, CLUE_MODAL.CLUE_ACCELEROMETER_MODAL_CONTENT, ], + [CLUE_TOOLBAR_ICON_ID.SPEAKER, CLUE_MODAL.CLUE_SPEAKER_MODAL_CONTENT], ]); export const getModalContent = ( diff --git a/src/view/components/toolbar/clue/ClueModalContent.tsx b/src/view/components/toolbar/clue/ClueModalContent.tsx index 92149dffc..9bbbba37e 100644 --- a/src/view/components/toolbar/clue/ClueModalContent.tsx +++ b/src/view/components/toolbar/clue/ClueModalContent.tsx @@ -240,3 +240,17 @@ export const CLUE_LED_CONTENT = ( id: "clue_neopixel", }; }; +export const CLUE_SPEAKER_MODAL_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + return { + descriptionTitle: "toolbar-speaker.title", + tagInput: undefined, + tagOutput: TAG_OUTPUT_SVG, + descriptionText: "toolbar-clue-speaker.description", + tryItDescription: "toolbar-speaker.tryItDescription", + components: [FEATURE_REQUEST_ON_GITHUB], + id: "speaker", + }; +}; diff --git a/src/view/translations/en.json b/src/view/translations/en.json index 6bc7419ed..073050856 100644 --- a/src/view/translations/en.json +++ b/src/view/translations/en.json @@ -51,39 +51,40 @@ "toolbar-microbit-wireless.description": "micro:bits can use radio waves and bluetooth services to communicate with each other", "toolbar-microbit-wireless.tryItDescription": "If you would like to see this sensor supported, please +1 the feature addition issue on GitHub! For now, you can try it on MakeCode!", "toolbar-clue-temperature-sensor.title": "Temperature", - "toolbar-clue-temperature-sensor.description": "", - "toolbar-clue-temperature-sensor.tryItDescription": "", + "toolbar-clue-temperature-sensor.description": "CLUE uses the BMP280 sensor, an environmental sensor with temperature.This precision sensor from Bosch is the best low-cost, precision sensing solution for measuring temperature with ±1.0°C accuracy.", + "toolbar-clue-temperature-sensor.tryItDescription": "You can set the temperature range from your code!", "toolbar-clue-light-sensor.title": "Light/Color Sensor", - "toolbar-clue-light-sensor.description": "", - "toolbar-clue-light-sensor.tryItDescription": "", + "toolbar-clue-light-sensor.description": "The light sensor uses APDS9960 and is able to return the red, blue, green and clear light.", + "toolbar-clue-light-sensor.tryItDescription": "You can set the color values of the light detected.", "toolbar-clue-accelerometer-sensor.title": "Accelerometer", - "toolbar-clue-accelerometer-sensor.description": "", - "toolbar-clue-accelerometer-sensor.tryItDescription": "", + "toolbar-clue-accelerometer-sensor.description": " The 3-axis accelerometer, can tell you which direction is down towards the Earth (by measuring gravity) or how fast the board is accelerating in 3D space.", + "toolbar-clue-accelerometer-sensor.tryItDescription": "Set the acceleration with the sliders.", "toolbar-clue-led.title": "Neopixel", - "toolbar-clue-led.description": "", - "toolbar-clue-led.tryItDescription": "", + "toolbar-clue-led.description": "The CLUE has one full RGB LED on it's back", + "toolbar-clue-led.tryItDescription": "Run your code and see the cool effects on the simulator!", "toolbar-clue-a-b-push.title": "Buttons", - "toolbar-clue-a-b-push.description": "", - "toolbar-clue-a-b-push.tryItDescription": "", + "toolbar-clue-a-b-push.description": "There are two buttons on the front of the CLUE (labelled A and B). The third button is to trigger both A and B buttons. You can detect when these buttons are pressed, allowing you to trigger code on the device.", + "toolbar-clue-a-b-push.tryItDescription": "Click them with your mouse or by pressing “A” and/or “B” on your keyboard!", "toolbar-clue-gpio.title": "Input/Output (GPIO)", - "toolbar-clue-gpio.description": "", - "toolbar-clue-gpio.tryItDescription": "", + "toolbar-clue-gpio.description": "On the bottom edge of your CLUE, you have 25 pins. These pins allow you to really get creative. You can create circuits, connect external things like buzzers and motors and make your own fun projects.", + "toolbar-clue-gpio.tryItDescription": "If you would like to see this sensor supported, please +1 the feature addition issue on GitHub!", "toolbar-clue-sound-sensor.title": "Sound", - "toolbar-clue-sound-sensor.description": "", - "toolbar-clue-sound-sensor.tryItDescription": "", + "toolbar-clue-sound-sensor.description": "The CLUE uses a PDM MEMS microphone. PDM is a little like 1-bit PWM. You clock the mic with a 1 MHz - 3 MHz clock rate, and on the data line you'll get a square wave out that syncs with the clock.", + "toolbar-clue-sound-sensor.tryItDescription": "If you would like to see this sensor supported, please +1 the feature addition issue on GitHub!", "toolbar-clue-pressure-sensor.title": "Pressure", - "toolbar-clue-pressure-sensor.description": "", - "toolbar-clue-pressure-sensor.tryItDescription": "", + "toolbar-clue-pressure-sensor.description": "CLUE uses the BMP280 sensor for barometric pressure. Because pressure changes with altitude, and the pressure measurements are so good, you can also use it as an altimeter with ±1 meter accuracy.", + "toolbar-clue-pressure-sensor.tryItDescription": "You can set the pressure here.", "toolbar-clue-humidity-sensor.title": "Humidity", - "toolbar-clue-humidity-sensor.description": "", - "toolbar-clue-humidity-sensor.tryItDescription": "", + "toolbar-clue-humidity-sensor.description": "The SHT30-D sensor has an excellent ±2% relative humidity and ±0.5°C accuracy for most uses.", + "toolbar-clue-humidity-sensor.tryItDescription": "You can set the humidity % here.", "toolbar-clue-gesture-sensor.title": "Gesture", - "toolbar-clue-gesture-sensor.description": "", - "toolbar-clue-gesture-sensor.tryItDescription": "", + "toolbar-clue-gesture-sensor.description": "The gesture sensor can detect directional gestures (left to right, right to left, up to down, down to up), but in theory more complicated gestures like zig-zag, clockwise or counterclockwise circle, near to far, etc. could also be detected with additional code. ", + "toolbar-clue-gesture-sensor.tryItDescription": "Select a gesture and send it by clicking the button.", "toolbar-clue-proximity-sensor.title": "Proximity", - "toolbar-clue-proximity-sensor.description": "", - "toolbar-clue-proximity-sensor.tryItDescription": "", + "toolbar-clue-proximity-sensor.description": "The proximity sensor uses APDS9960 and is able to return how close an object is to the front of the sensor.", + "toolbar-clue-proximity-sensor.tryItDescription": "You can set the proximity here.", "toolbar-clue-bluetooth.title": "Bluetooth", - "toolbar-clue-bluetooth.description": "", - "toolbar-clue-bluetooth.tryItDescription": "" -} \ No newline at end of file + "toolbar-clue-bluetooth.description": "You can transmit data over Bluetooth to a computer or mobile device for data plotting and logging, or save it to the built in storage.", + "toolbar-clue-bluetooth.tryItDescription": "If you would like to see this sensor supported, please +1 the feature addition issue on GitHub! ", + "toolbar-clue-speaker.description": "The CLUE has a buzzer/speaker for playing tones and beeps." +} From 1fb33498ded0a455dba631eedbd053987f3ae606 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Thu, 2 Apr 2020 17:43:28 -0700 Subject: [PATCH 21/48] Update gesture for microbit --- src/view/components/microbit/Microbit.tsx | 4 + .../components/toolbar/SensorModalUtils.tsx | 150 +++--------------- .../toolbar/clue/ClueModalContent.tsx | 35 ++-- .../toolbar/microbit/MicrobitModalContent.tsx | 128 +++++++++++++++ src/view/translations/en.json | 5 +- 5 files changed, 183 insertions(+), 139 deletions(-) create mode 100644 src/view/components/toolbar/microbit/MicrobitModalContent.tsx diff --git a/src/view/components/microbit/Microbit.tsx b/src/view/components/microbit/Microbit.tsx index 4132fa0e4..c0e062e13 100644 --- a/src/view/components/microbit/Microbit.tsx +++ b/src/view/components/microbit/Microbit.tsx @@ -107,6 +107,10 @@ const MICROBIT_TOOLBAR_BUTTONS: Array<{ label: string; image: JSX.Element }> = [ image: TOOLBAR_SVG.MOTION_SVG, label: MICROBIT_TOOLBAR_ICON_ID.ACCELEROMETER, }, + { + image: TOOLBAR_SVG.GESTURE_SVG, + label: MICROBIT_TOOLBAR_ICON_ID.GESTURE, + }, { image: TOOLBAR_SVG.GPIO_SVG, label: MICROBIT_TOOLBAR_ICON_ID.GPIO, diff --git a/src/view/components/toolbar/SensorModalUtils.tsx b/src/view/components/toolbar/SensorModalUtils.tsx index b7848fade..402d30b27 100644 --- a/src/view/components/toolbar/SensorModalUtils.tsx +++ b/src/view/components/toolbar/SensorModalUtils.tsx @@ -10,6 +10,7 @@ import { Accelerometer } from "./motion/Accelerometer"; import MotionSensorBar from "./motion/MotionSensorBar"; import TemperatureSensorBar from "./TemperatureSensorBar"; import * as CLUE_MODAL from "./clue/ClueModalContent"; +import * as MICROBIT_MODAL from "./microbit/MicrobitModalContent"; export const TRY_IT_MAKE_CODE = (
@@ -73,6 +74,7 @@ export const MICROBIT_TOOLBAR_ICON_ID = { GPIO: "toolbar-gpio", SOUND: "toolbar-microbit-sound", WIRELESS: "toolbar-microbit-wireless", + GESTURE: "toolbar-microbit-gesture-sensor", }; export const CLUE_TOOLBAR_ICON_ID = { @@ -289,103 +291,6 @@ export const TEMPERATURE_MODAL_CONTENT = ( }; }; -export const ACCELEROMETER_MODAL_CONTENT = ( - onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, - sensorValues: { [key: string]: number } -): IModalContent => { - // this object will be accessed with the axis label - const accelerometerSensorValues = { - X: sensorValues[SENSOR_LIST.MOTION_X], - Y: sensorValues[SENSOR_LIST.MOTION_Y], - Z: sensorValues[SENSOR_LIST.MOTION_Z], - }; - return { - components: ( - - ), - descriptionText: "toolbar-accelerometer-sensor.description", - descriptionTitle: "toolbar-accelerometer-sensor.title", - id: "accelerometer", - tagInput: TAG_INPUT_SVG, - tagOutput: undefined, - tryItDescription: "toolbar-accelerometer-sensor.tryItDescription", - }; -}; -export const MICROBIT_LED_CONTENT = ( - onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, - sensorValues: { [key: string]: number } -): IModalContent => { - return { - descriptionTitle: "toolbar-microbit-led.title", - tagInput: undefined, - tagOutput: TAG_OUTPUT_SVG, - descriptionText: "toolbar-microbit-led.description", - tryItDescription: "toolbar-microbit-led.tryItDescription", - components: undefined, - id: "microbit_LED", - }; -}; - -export const MICROBIT_BUTTON_CONTENT = ( - onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, - sensorValues: { [key: string]: number } -): IModalContent => { - return { - descriptionTitle: "toolbar-microbit-a-b-push.title", - tagInput: undefined, - tagOutput: TAG_INPUT_SVG, - descriptionText: "toolbar-microbit-a-b-push.description", - tryItDescription: "toolbar-microbit-a-b-push.tryItDescription", - components: undefined, - id: "microbit_button", - }; -}; -export const MICROBIT_SOUND_MODAL_CONTENT = ( - onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, - sensorValues: { [key: string]: number } -): IModalContent => { - return { - descriptionTitle: "toolbar-microbit-sound.title", - tagInput: undefined, - tagOutput: TAG_OUTPUT_SVG, - descriptionText: "toolbar-microbit-sound.description", - tryItDescription: "toolbar-microbit-sound.tryItDescription", - components: [FEATURE_REQUEST_ON_GITHUB], - id: "microbit_sound", - }; -}; -export const MICROBIT_GPIO_MODAL_CONTENT = ( - onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, - sensorValues: { [key: string]: number } -): IModalContent => { - return { - descriptionTitle: "toolbar-microbit-gpio.title", - tagInput: TAG_INPUT_SVG, - tagOutput: TAG_OUTPUT_SVG, - descriptionText: "toolbar-microbit-gpio.description", - tryItDescription: "toolbar-microbit-gpio.tryItDescription", - components: [FEATURE_REQUEST_ON_GITHUB], - id: "microbit_gpio", - }; -}; -export const MICROBIT_WIRELESS_MODAL_CONTENT = ( - onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, - sensorValues: { [key: string]: number } -): IModalContent => { - return { - descriptionTitle: "toolbar-microbit-wireless.title", - tagInput: TAG_INPUT_SVG, - tagOutput: TAG_OUTPUT_SVG, - descriptionText: "toolbar-microbit-wireless.description", - tryItDescription: "toolbar-microbit-wireless.tryItDescription", - components: [FEATURE_REQUEST_ON_GITHUB], - id: "microbit_wireless", - }; -}; - export const LABEL_TO_MODAL_CONTENT_CONSTRUCTOR = new Map([ [CPX_TOOLBAR_ICON_ID.GPIO, GPIO_MODAL_CONTENT], [CPX_TOOLBAR_ICON_ID.IR, IR_MODAL_CONTENT], @@ -398,34 +303,28 @@ export const LABEL_TO_MODAL_CONTENT_CONSTRUCTOR = new Map([ [CPX_TOOLBAR_ICON_ID.SPEAKER, SPEAKER_MODAL_CONTENT], [CPX_TOOLBAR_ICON_ID.SWITCH, SWITCH_MODAL_CONTENT], [CPX_TOOLBAR_ICON_ID.TEMPERATURE, TEMPERATURE_MODAL_CONTENT], - [MICROBIT_TOOLBAR_ICON_ID.ACCELEROMETER, ACCELEROMETER_MODAL_CONTENT], - [MICROBIT_TOOLBAR_ICON_ID.LEDS, MICROBIT_LED_CONTENT], - [MICROBIT_TOOLBAR_ICON_ID.PUSH_BUTTON, MICROBIT_BUTTON_CONTENT], - [MICROBIT_TOOLBAR_ICON_ID.GPIO, MICROBIT_GPIO_MODAL_CONTENT], - [MICROBIT_TOOLBAR_ICON_ID.SOUND, MICROBIT_SOUND_MODAL_CONTENT], - [MICROBIT_TOOLBAR_ICON_ID.WIRELESS, MICROBIT_WIRELESS_MODAL_CONTENT], - [ - CLUE_TOOLBAR_ICON_ID.TEMPERATURE, - CLUE_MODAL.CLUE_TEMPERATURE_MODAL_CONTENT, - ], - [ - CLUE_TOOLBAR_ICON_ID.ACCELEROMETER, - CLUE_MODAL.CLUE_ACCELEROMETER_MODAL_CONTENT, - ], - [CLUE_TOOLBAR_ICON_ID.PUSH_BUTTON, CLUE_MODAL.CLUE_BUTTON_CONTENT], - [CLUE_TOOLBAR_ICON_ID.GPIO, CLUE_MODAL.CLUE_GPIO_MODAL_CONTENT], - [CLUE_TOOLBAR_ICON_ID.LIGHT, CLUE_MODAL.CLUE_LIGHT_MODAL_CONTENT], - [CLUE_TOOLBAR_ICON_ID.LEDS, CLUE_MODAL.CLUE_LED_CONTENT], - [CLUE_TOOLBAR_ICON_ID.SOUND, CLUE_MODAL.CLUE_SOUND_MODAL_CONTENT], - [CLUE_TOOLBAR_ICON_ID.PRESSURE, CLUE_MODAL.CLUE_PRESSURE_MODAL_CONTENT], - [CLUE_TOOLBAR_ICON_ID.HUMIDITY, CLUE_MODAL.CLUE_HUMIDITY_MODAL_CONTENT], - [CLUE_TOOLBAR_ICON_ID.PROXIMITY, CLUE_MODAL.CLUE_PROXIMITY_MODAL_CONTENT], - [CLUE_TOOLBAR_ICON_ID.BLUETOOTH, CLUE_MODAL.CLUE_BLUETOOTH_CONTENT], [ - CLUE_TOOLBAR_ICON_ID.ACCELEROMETER, - CLUE_MODAL.CLUE_ACCELEROMETER_MODAL_CONTENT, + MICROBIT_TOOLBAR_ICON_ID.ACCELEROMETER, + MICROBIT_MODAL.ACCELEROMETER_MODAL_CONTENT, ], - [CLUE_TOOLBAR_ICON_ID.SPEAKER, CLUE_MODAL.CLUE_SPEAKER_MODAL_CONTENT], + [MICROBIT_TOOLBAR_ICON_ID.LEDS, MICROBIT_MODAL.LED_CONTENT], + [MICROBIT_TOOLBAR_ICON_ID.PUSH_BUTTON, MICROBIT_MODAL.BUTTON_CONTENT], + [MICROBIT_TOOLBAR_ICON_ID.GPIO, MICROBIT_MODAL.GPIO_MODAL_CONTENT], + [MICROBIT_TOOLBAR_ICON_ID.SOUND, MICROBIT_MODAL.SOUND_MODAL_CONTENT], + [MICROBIT_TOOLBAR_ICON_ID.WIRELESS, MICROBIT_MODAL.WIRELESS_CONTENT], + [CLUE_TOOLBAR_ICON_ID.TEMPERATURE, CLUE_MODAL.TEMPERATURE_CONTENT], + [CLUE_TOOLBAR_ICON_ID.ACCELEROMETER, CLUE_MODAL.ACCELEROMETER_CONTENT], + [CLUE_TOOLBAR_ICON_ID.PUSH_BUTTON, CLUE_MODAL.BUTTON_CONTENT], + [CLUE_TOOLBAR_ICON_ID.GPIO, CLUE_MODAL.GPIO_CONTENT], + [CLUE_TOOLBAR_ICON_ID.LIGHT, CLUE_MODAL.LIGHT_CONTENT], + [CLUE_TOOLBAR_ICON_ID.LEDS, CLUE_MODAL.LED_CONTENT], + [CLUE_TOOLBAR_ICON_ID.SOUND, CLUE_MODAL.SOUND_CONTENT], + [CLUE_TOOLBAR_ICON_ID.PRESSURE, CLUE_MODAL.PRESSURE_CONTENT], + [CLUE_TOOLBAR_ICON_ID.HUMIDITY, CLUE_MODAL.HUMIDITY_CONTENT], + [CLUE_TOOLBAR_ICON_ID.PROXIMITY, CLUE_MODAL.PROXIMITY_CONTENT], + [CLUE_TOOLBAR_ICON_ID.BLUETOOTH, CLUE_MODAL.BLUETOOTH_CONTENT], + [CLUE_TOOLBAR_ICON_ID.ACCELEROMETER, CLUE_MODAL.ACCELEROMETER_CONTENT], + [CLUE_TOOLBAR_ICON_ID.SPEAKER, CLUE_MODAL.SPEAKER_CONTENT], ]); export const getModalContent = ( @@ -436,8 +335,9 @@ export const getModalContent = ( sendGesture?: (isActive: boolean) => void ) => { if (label === CLUE_TOOLBAR_ICON_ID.GESTURE) { - console.log("gestures"); - return CLUE_MODAL.CLUE_GESTURE_MODAL_CONTENT( + return CLUE_MODAL.GESTURE_CONTENT(onSelectGestures, sendGesture); + } else if (label === MICROBIT_TOOLBAR_ICON_ID.GESTURE) { + return MICROBIT_MODAL.GESTURE_MODAL_CONTENT( onSelectGestures, sendGesture ); diff --git a/src/view/components/toolbar/clue/ClueModalContent.tsx b/src/view/components/toolbar/clue/ClueModalContent.tsx index 9bbbba37e..164824c98 100644 --- a/src/view/components/toolbar/clue/ClueModalContent.tsx +++ b/src/view/components/toolbar/clue/ClueModalContent.tsx @@ -8,7 +8,8 @@ import { Accelerometer } from "../motion/Accelerometer"; import { Gesture } from "../motion/Gesture"; import { ThreeDimensionSlider } from "../motion/threeDimensionSlider/ThreeDimensionSlider"; import * as SENSOR_PROPERTIES from "./ClueSensorProperties"; -export const CLUE_TEMPERATURE_MODAL_CONTENT = ( + +export const TEMPERATURE_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { @@ -28,7 +29,7 @@ export const CLUE_TEMPERATURE_MODAL_CONTENT = ( }; }; -export const CLUE_GPIO_MODAL_CONTENT = ( +export const GPIO_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { @@ -42,7 +43,8 @@ export const CLUE_GPIO_MODAL_CONTENT = ( id: "GPIO", }; }; -export const CLUE_ACCELEROMETER_MODAL_CONTENT = ( + +export const ACCELEROMETER_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { @@ -67,7 +69,7 @@ export const CLUE_ACCELEROMETER_MODAL_CONTENT = ( }; }; -export const CLUE_LIGHT_MODAL_CONTENT = ( +export const LIGHT_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { @@ -93,7 +95,8 @@ export const CLUE_LIGHT_MODAL_CONTENT = ( tryItDescription: "toolbar-clue-light-sensor.tryItDescription", }; }; -export const CLUE_HUMIDITY_MODAL_CONTENT = ( + +export const HUMIDITY_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { @@ -116,7 +119,8 @@ export const CLUE_HUMIDITY_MODAL_CONTENT = ( id: "humidity_sensor", }; }; -export const CLUE_GESTURE_MODAL_CONTENT = ( + +export const GESTURE_CONTENT = ( onSelectGestures?: (event: React.ChangeEvent) => void, sendGesture?: (isActive: boolean) => void ): IModalContent => { @@ -136,7 +140,8 @@ export const CLUE_GESTURE_MODAL_CONTENT = ( id: "gesture_sensor", }; }; -export const CLUE_PROXIMITY_MODAL_CONTENT = ( + +export const PROXIMITY_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { @@ -159,7 +164,8 @@ export const CLUE_PROXIMITY_MODAL_CONTENT = ( id: "proximity_sensor", }; }; -export const CLUE_PRESSURE_MODAL_CONTENT = ( + +export const PRESSURE_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { @@ -182,7 +188,8 @@ export const CLUE_PRESSURE_MODAL_CONTENT = ( id: "pressure_sensor", }; }; -export const CLUE_BUTTON_CONTENT = ( + +export const BUTTON_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { @@ -197,7 +204,7 @@ export const CLUE_BUTTON_CONTENT = ( }; }; -export const CLUE_BLUETOOTH_CONTENT = ( +export const BLUETOOTH_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { @@ -212,7 +219,7 @@ export const CLUE_BLUETOOTH_CONTENT = ( }; }; -export const CLUE_SOUND_MODAL_CONTENT = ( +export const SOUND_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { @@ -226,7 +233,8 @@ export const CLUE_SOUND_MODAL_CONTENT = ( id: "sound_sensor", }; }; -export const CLUE_LED_CONTENT = ( + +export const LED_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { @@ -240,7 +248,8 @@ export const CLUE_LED_CONTENT = ( id: "clue_neopixel", }; }; -export const CLUE_SPEAKER_MODAL_CONTENT = ( + +export const SPEAKER_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { diff --git a/src/view/components/toolbar/microbit/MicrobitModalContent.tsx b/src/view/components/toolbar/microbit/MicrobitModalContent.tsx new file mode 100644 index 000000000..3ff0901bb --- /dev/null +++ b/src/view/components/toolbar/microbit/MicrobitModalContent.tsx @@ -0,0 +1,128 @@ +import * as React from "react"; +import { IModalContent, FEATURE_REQUEST_ON_GITHUB } from "../SensorModalUtils"; +import { + SENSOR_LIST, + GESTURES_CLUE, + GESTURES_MICROBIT, +} from "../../../constants"; +import { TAG_INPUT_SVG } from "../../../svgs/tag_input_svg"; +import { TAG_OUTPUT_SVG } from "../../../svgs/tag_output_svg"; +import { Accelerometer } from "../motion/Accelerometer"; +import { Gesture } from "../motion/Gesture"; + +export const ACCELEROMETER_MODAL_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + // this object will be accessed with the axis label + const accelerometerSensorValues = { + X: sensorValues[SENSOR_LIST.MOTION_X], + Y: sensorValues[SENSOR_LIST.MOTION_Y], + Z: sensorValues[SENSOR_LIST.MOTION_Z], + }; + return { + components: ( + + ), + descriptionText: "toolbar-accelerometer-sensor.description", + descriptionTitle: "toolbar-accelerometer-sensor.title", + id: "accelerometer", + tagInput: TAG_INPUT_SVG, + tagOutput: undefined, + tryItDescription: "toolbar-accelerometer-sensor.tryItDescription", + }; +}; +export const LED_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + return { + descriptionTitle: "toolbar-microbit-led.title", + tagInput: undefined, + tagOutput: TAG_OUTPUT_SVG, + descriptionText: "toolbar-microbit-led.description", + tryItDescription: "toolbar-microbit-led.tryItDescription", + components: undefined, + id: "microbit_LED", + }; +}; + +export const BUTTON_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + return { + descriptionTitle: "toolbar-microbit-a-b-push.title", + tagInput: undefined, + tagOutput: TAG_INPUT_SVG, + descriptionText: "toolbar-microbit-a-b-push.description", + tryItDescription: "toolbar-microbit-a-b-push.tryItDescription", + components: undefined, + id: "microbit_button", + }; +}; +export const SOUND_MODAL_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + return { + descriptionTitle: "toolbar-microbit-sound.title", + tagInput: undefined, + tagOutput: TAG_OUTPUT_SVG, + descriptionText: "toolbar-microbit-sound.description", + tryItDescription: "toolbar-microbit-sound.tryItDescription", + components: [FEATURE_REQUEST_ON_GITHUB], + id: "microbit_sound", + }; +}; +export const GPIO_MODAL_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + return { + descriptionTitle: "toolbar-microbit-gpio.title", + tagInput: TAG_INPUT_SVG, + tagOutput: TAG_OUTPUT_SVG, + descriptionText: "toolbar-microbit-gpio.description", + tryItDescription: "toolbar-microbit-gpio.tryItDescription", + components: [FEATURE_REQUEST_ON_GITHUB], + id: "microbit_gpio", + }; +}; +export const WIRELESS_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + return { + descriptionTitle: "toolbar-microbit-wireless.title", + tagInput: TAG_INPUT_SVG, + tagOutput: TAG_OUTPUT_SVG, + descriptionText: "toolbar-microbit-wireless.description", + tryItDescription: "toolbar-microbit-wireless.tryItDescription", + components: [FEATURE_REQUEST_ON_GITHUB], + id: "microbit_wireless", + }; +}; +export const GESTURE_MODAL_CONTENT = ( + onSelectGestures?: (event: React.ChangeEvent) => void, + sendGesture?: (isActive: boolean) => void +): IModalContent => { + return { + descriptionTitle: "toolbar-microbit-gesture-sensor.title", + tagInput: TAG_INPUT_SVG, + tagOutput: undefined, + descriptionText: "toolbar-microbit-gesture-sensor.description", + tryItDescription: "toolbar-microbit-gesture-sensor.tryItDescription", + components: [ + , + ], + id: "gesture_sensor", + }; +}; diff --git a/src/view/translations/en.json b/src/view/translations/en.json index 073050856..8a4c5cd81 100644 --- a/src/view/translations/en.json +++ b/src/view/translations/en.json @@ -34,7 +34,7 @@ "toolbar-temperature-sensor.tryItDescription": "You can set the temperature range from your code!", "toolbar-accelerometer-sensor.title": "Accelerometer", "toolbar-accelerometer-sensor.description": "An accelerometer measures the acceleration of your micro:bit; this component senses when the micro:bit is moved.", - "toolbar-accelerometer-sensor.tryItDescription": "Select a gesture and send it by clicking the button.", + "toolbar-accelerometer-sensor.tryItDescription": "Set the acceleration with the sliders.", "toolbar-microbit-led.title": "LEDs", "toolbar-microbit-led.description": "The microbit has 25 LEDs for you to play with. The LEDs have 9 levels of brightness.", "toolbar-microbit-led.tryItDescription": "Run your code and see the LEDs light up!", @@ -50,6 +50,9 @@ "toolbar-microbit-wireless.title": "Bluetooth & Radio", "toolbar-microbit-wireless.description": "micro:bits can use radio waves and bluetooth services to communicate with each other", "toolbar-microbit-wireless.tryItDescription": "If you would like to see this sensor supported, please +1 the feature addition issue on GitHub! For now, you can try it on MakeCode!", + "toolbar-microbit-gesture-sensor.title": "Gesture", + "toolbar-microbit-gesture-sensor.description": "If you move your BBC micro:bit in a certain way (as a gesture) then micro:bit is able to detect this. micro:bit is able to recognise the following gestures: up, down, left, right, face up, face down, freefall, 3g, 6g, 8g, shake.)", + "toolbar-microbit-gesture-sensor.tryItDescription": "Select a gesture and send it by clicking the button.", "toolbar-clue-temperature-sensor.title": "Temperature", "toolbar-clue-temperature-sensor.description": "CLUE uses the BMP280 sensor, an environmental sensor with temperature.This precision sensor from Bosch is the best low-cost, precision sensing solution for measuring temperature with ±1.0°C accuracy.", "toolbar-clue-temperature-sensor.tryItDescription": "You can set the temperature range from your code!", From 30c3e5f6f0f2f63705addbadf0f03c66197c6023 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Thu, 2 Apr 2020 17:47:43 -0700 Subject: [PATCH 22/48] Update tests for ui change --- src/extension.ts | 2 +- src/service/telemetryHandlerService.ts | 14 +- src/view/components/clue/Clue.tsx | 8 +- src/view/components/clue/Clue_svg.tsx | 2 +- .../clue/__snapshots__/Clue.spec.tsx.snap | 892 +++++++++++++++++- .../__snapshots__/Microbit.spec.tsx.snap | 71 ++ .../components/toolbar/SensorModalUtils.tsx | 4 +- .../toolbar/clue/ClueModalContent.tsx | 6 +- .../toolbar/clue/ClueSensorProperties.tsx | 3 +- .../toolbar/microbit/MicrobitModalContent.tsx | 8 +- .../components/toolbar/motion/Gesture.tsx | 4 +- .../__snapshots__/Accelerometer.spec.tsx.snap | 91 +- .../device/__snapshots__/Device.spec.tsx.snap | 71 ++ 13 files changed, 1058 insertions(+), 118 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index f691b7e5d..68a069d18 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -28,11 +28,11 @@ import { FileSelectionService } from "./service/fileSelectionService"; import { MessagingService } from "./service/messagingService"; import { PopupService } from "./service/PopupService"; import { SetupService } from "./service/SetupService"; +import { TelemetryHandlerService } from "./service/telemetryHandlerService"; import { WebviewService } from "./service/webviewService"; import { SimulatorDebugConfigurationProvider } from "./simulatorDebugConfigurationProvider"; import getPackageInfo from "./telemetry/getPackageInfo"; import TelemetryAI from "./telemetry/telemetryAI"; -import { TelemetryHandlerService } from "./service/telemetryHandlerService"; import { UsbDetector } from "./usbDetector"; import { VSCODE_MESSAGES_TO_WEBVIEW, diff --git a/src/service/telemetryHandlerService.ts b/src/service/telemetryHandlerService.ts index c48f3a2de..815525226 100644 --- a/src/service/telemetryHandlerService.ts +++ b/src/service/telemetryHandlerService.ts @@ -2,8 +2,8 @@ import * as open from "open"; import * as vscode from "vscode"; import { CONSTANTS, DialogResponses, TelemetryEventName } from "../constants"; import * as utils from "../extension_utils/utils"; -import { DeviceSelectionService } from "./deviceSelectionService"; import TelemetryAI from "../telemetry/telemetryAI"; +import { DeviceSelectionService } from "./deviceSelectionService"; export class TelemetryHandlerService { private telemetryAI: TelemetryAI; @@ -244,8 +244,8 @@ export class TelemetryHandlerService { break; } return { - deployTelemetryEvent: deployTelemetryEvent, - deployPerformanceTelemetryEvent: deployPerformanceTelemetryEvent, + deployTelemetryEvent, + deployPerformanceTelemetryEvent, }; }; @@ -383,8 +383,8 @@ export class TelemetryHandlerService { break; } return { - openSimulatorTelemetryEvent: openSimulatorTelemetryEvent, - openSimulatorPerformanceTelemetryEvent: openSimulatorPerformanceTelemetryEvent, + openSimulatorTelemetryEvent, + openSimulatorPerformanceTelemetryEvent, }; }; @@ -412,8 +412,8 @@ export class TelemetryHandlerService { break; } return { - newFileTelemetryEvent: newFileTelemetryEvent, - newFilePerformanceTelemetryEvent: newFilePerformanceTelemetryEvent, + newFileTelemetryEvent, + newFilePerformanceTelemetryEvent, }; }; } diff --git a/src/view/components/clue/Clue.tsx b/src/view/components/clue/Clue.tsx index 7e8bc0637..35111b288 100644 --- a/src/view/components/clue/Clue.tsx +++ b/src/view/components/clue/Clue.tsx @@ -3,17 +3,17 @@ import * as React from "react"; import { + GESTURES_CLUE, SENSOR_LIST, VSCODE_MESSAGES_TO_WEBVIEW, - GESTURES_CLUE, WEBVIEW_MESSAGES, } from "../../constants"; import "../../styles/Simulator.css"; -import ToolBar from "../toolbar/ToolBar"; -import { ClueSimulator } from "./ClueSimulator"; -import { CLUE_TOOLBAR_ICON_ID } from "../toolbar/SensorModalUtils"; import * as TOOLBAR_SVG from "../../svgs/toolbar_svg"; import { sendMessage } from "../../utils/MessageUtils"; +import { CLUE_TOOLBAR_ICON_ID } from "../toolbar/SensorModalUtils"; +import ToolBar from "../toolbar/ToolBar"; +import { ClueSimulator } from "./ClueSimulator"; // Component grouping the functionality for micro:bit functionalities interface IState { diff --git a/src/view/components/clue/Clue_svg.tsx b/src/view/components/clue/Clue_svg.tsx index f5963309f..759b18b44 100644 --- a/src/view/components/clue/Clue_svg.tsx +++ b/src/view/components/clue/Clue_svg.tsx @@ -2,9 +2,9 @@ // Licensed under the MIT license. import * as React from "react"; +import CONSTANTS from "../../constants"; import "../../styles/SimulatorSvg.css"; import { DEFAULT_CLUE_STATE } from "./ClueSimulator"; -import CONSTANTS from "../../constants"; export interface IRefObject { [key: string]: React.RefObject; } diff --git a/src/view/components/clue/__snapshots__/Clue.spec.tsx.snap b/src/view/components/clue/__snapshots__/Clue.spec.tsx.snap index 099a3de7a..7d497690c 100644 --- a/src/view/components/clue/__snapshots__/Clue.spec.tsx.snap +++ b/src/view/components/clue/__snapshots__/Clue.spec.tsx.snap @@ -1153,7 +1153,897 @@ Array [ >
+ > +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
, ] diff --git a/src/view/components/microbit/__snapshots__/Microbit.spec.tsx.snap b/src/view/components/microbit/__snapshots__/Microbit.spec.tsx.snap index 947b8762c..8848754ea 100644 --- a/src/view/components/microbit/__snapshots__/Microbit.spec.tsx.snap +++ b/src/view/components/microbit/__snapshots__/Microbit.spec.tsx.snap @@ -2968,6 +2968,77 @@ Array [
+
+ +
diff --git a/src/view/components/toolbar/clue/ClueModalContent.tsx b/src/view/components/toolbar/clue/ClueModalContent.tsx index 164824c98..fed768ab5 100644 --- a/src/view/components/toolbar/clue/ClueModalContent.tsx +++ b/src/view/components/toolbar/clue/ClueModalContent.tsx @@ -1,12 +1,12 @@ import * as React from "react"; -import { IModalContent, FEATURE_REQUEST_ON_GITHUB } from "../SensorModalUtils"; -import { SENSOR_LIST, GESTURES_CLUE } from "../../../constants"; +import { GESTURES_CLUE, SENSOR_LIST } from "../../../constants"; import { TAG_INPUT_SVG } from "../../../svgs/tag_input_svg"; -import TemperatureSensorBar from "../TemperatureSensorBar"; import { TAG_OUTPUT_SVG } from "../../../svgs/tag_output_svg"; import { Accelerometer } from "../motion/Accelerometer"; import { Gesture } from "../motion/Gesture"; import { ThreeDimensionSlider } from "../motion/threeDimensionSlider/ThreeDimensionSlider"; +import { FEATURE_REQUEST_ON_GITHUB, IModalContent } from "../SensorModalUtils"; +import TemperatureSensorBar from "../TemperatureSensorBar"; import * as SENSOR_PROPERTIES from "./ClueSensorProperties"; export const TEMPERATURE_CONTENT = ( diff --git a/src/view/components/toolbar/clue/ClueSensorProperties.tsx b/src/view/components/toolbar/clue/ClueSensorProperties.tsx index 117a6f0c7..7aaf17a27 100644 --- a/src/view/components/toolbar/clue/ClueSensorProperties.tsx +++ b/src/view/components/toolbar/clue/ClueSensorProperties.tsx @@ -1,5 +1,6 @@ -import { ISliderProps, ISensorProps } from "../../../viewUtils"; import { SENSOR_LIST } from "../../../constants"; +import { ISensorProps, ISliderProps } from "../../../viewUtils"; + const CLUE_SLIDER_R: ISliderProps = { axisLabel: "R", maxLabel: "Max", diff --git a/src/view/components/toolbar/microbit/MicrobitModalContent.tsx b/src/view/components/toolbar/microbit/MicrobitModalContent.tsx index 3ff0901bb..c34b6058d 100644 --- a/src/view/components/toolbar/microbit/MicrobitModalContent.tsx +++ b/src/view/components/toolbar/microbit/MicrobitModalContent.tsx @@ -1,14 +1,10 @@ import * as React from "react"; -import { IModalContent, FEATURE_REQUEST_ON_GITHUB } from "../SensorModalUtils"; -import { - SENSOR_LIST, - GESTURES_CLUE, - GESTURES_MICROBIT, -} from "../../../constants"; +import { GESTURES_MICROBIT, SENSOR_LIST } from "../../../constants"; import { TAG_INPUT_SVG } from "../../../svgs/tag_input_svg"; import { TAG_OUTPUT_SVG } from "../../../svgs/tag_output_svg"; import { Accelerometer } from "../motion/Accelerometer"; import { Gesture } from "../motion/Gesture"; +import { FEATURE_REQUEST_ON_GITHUB, IModalContent } from "../SensorModalUtils"; export const ACCELEROMETER_MODAL_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, diff --git a/src/view/components/toolbar/motion/Gesture.tsx b/src/view/components/toolbar/motion/Gesture.tsx index a1f3c97db..934c19345 100644 --- a/src/view/components/toolbar/motion/Gesture.tsx +++ b/src/view/components/toolbar/motion/Gesture.tsx @@ -1,7 +1,7 @@ import * as React from "react"; -import SensorButton from "../SensorButton"; -import { Dropdown } from "../../Dropdown"; import { CONSTANTS } from "../../../constants"; +import { Dropdown } from "../../Dropdown"; +import SensorButton from "../SensorButton"; const GESTURE_BUTTON_MESSAGE = "Send Gesture"; interface IProps { diff --git a/src/view/components/toolbar/motion/__snapshots__/Accelerometer.spec.tsx.snap b/src/view/components/toolbar/motion/__snapshots__/Accelerometer.spec.tsx.snap index 622281da2..a6938db0e 100644 --- a/src/view/components/toolbar/motion/__snapshots__/Accelerometer.spec.tsx.snap +++ b/src/view/components/toolbar/motion/__snapshots__/Accelerometer.spec.tsx.snap @@ -4,96 +4,6 @@ exports[`Accelerometer component should render correctly 1`] = `
-
-
- - -
-
-
-

- Set the acceleration manually here -

-
@@ -294,6 +204,7 @@ exports[`Accelerometer component should render correctly 1`] = `
+
`; diff --git a/src/view/container/device/__snapshots__/Device.spec.tsx.snap b/src/view/container/device/__snapshots__/Device.spec.tsx.snap index 66935248b..538e073f0 100644 --- a/src/view/container/device/__snapshots__/Device.spec.tsx.snap +++ b/src/view/container/device/__snapshots__/Device.spec.tsx.snap @@ -2970,6 +2970,77 @@ exports[`Device component should render correctly 1`] = `
+
+ +
Date: Thu, 2 Apr 2020 17:58:19 -0700 Subject: [PATCH 23/48] Remove unused imports --- src/view/components/toolbar/SensorModalUtils.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/view/components/toolbar/SensorModalUtils.tsx b/src/view/components/toolbar/SensorModalUtils.tsx index 8d44e05af..8da9575ce 100644 --- a/src/view/components/toolbar/SensorModalUtils.tsx +++ b/src/view/components/toolbar/SensorModalUtils.tsx @@ -8,7 +8,6 @@ import { TAG_OUTPUT_SVG } from "../../svgs/tag_output_svg"; import * as CLUE_MODAL from "./clue/ClueModalContent"; import LightSensorBar from "./LightSensorBar"; import * as MICROBIT_MODAL from "./microbit/MicrobitModalContent"; -import { Accelerometer } from "./motion/Accelerometer"; import MotionSensorBar from "./motion/MotionSensorBar"; import TemperatureSensorBar from "./TemperatureSensorBar"; From db67d0d0b9a99c1de3cc29629174618a4c8b1d3f Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Thu, 2 Apr 2020 17:59:57 -0700 Subject: [PATCH 24/48] Change wording --- src/view/translations/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/view/translations/en.json b/src/view/translations/en.json index 8a4c5cd81..038aae9ad 100644 --- a/src/view/translations/en.json +++ b/src/view/translations/en.json @@ -7,7 +7,7 @@ "toolbar-ir-sensor.tryItDescription": "If you would like to see this sensor supported, please +1 the feature addition issue on GitHub! For now, you can try it on MakeCode!", "toolbar-light-sensor.description": "An analog light sensor can be used to detect ambient light, with similar spectral response to the human eye.", "toolbar-light-sensor.title": "Light Sensor", - "toolbar-light-sensor.tryItDescription": "Change the brightness from 0 - 255 here!", + "toolbar-light-sensor.tryItDescription": "Change the brightness detected by the sensor here!", "toolbar-motion-sensor.description": "Detects acceleration in X, Y and Z orientations. It can also detect 'tap' and 'double tap' strikes on the board and when the board is shaken.", "toolbar-motion-sensor.title": "Motion Sensor", "toolbar-motion-sensor.tryItDescription": "Change the acceleration here and click or click on the button to simulate a shake. The tap feature is not supported by the Device Simulator Express. If you would like to see the 'tap' feature implemented, please +1 the feature addition issue on GitHub! For now, you can try it on MakeCode!", From bedd197fc52f52fbb260d6940bf6b0b8d8dbfc6a Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Thu, 2 Apr 2020 18:15:18 -0700 Subject: [PATCH 25/48] Change range values --- .../components/toolbar/clue/ClueSensorProperties.tsx | 10 +++++----- src/view/translations/en.json | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/view/components/toolbar/clue/ClueSensorProperties.tsx b/src/view/components/toolbar/clue/ClueSensorProperties.tsx index 7aaf17a27..fc058559e 100644 --- a/src/view/components/toolbar/clue/ClueSensorProperties.tsx +++ b/src/view/components/toolbar/clue/ClueSensorProperties.tsx @@ -61,13 +61,13 @@ export const CLUE__PROXIMITY_PROPERTIES: ISensorProps = { { axisLabel: "P", maxLabel: "Max", - maxValue: 100, + maxValue: 255, minLabel: "Min", minValue: 0, type: SENSOR_LIST.PROXIMITY, }, ], - unitLabel: "%", + unitLabel: "", }; export const CLUE_PRESSURE_PROPERTIES: ISensorProps = { LABEL: "Humidity Sensor", @@ -75,11 +75,11 @@ export const CLUE_PRESSURE_PROPERTIES: ISensorProps = { { axisLabel: "P", maxLabel: "Max", - maxValue: 100, + maxValue: 1100, minLabel: "Min", - minValue: 0, + minValue: 800, type: SENSOR_LIST.PRESSURE, }, ], - unitLabel: "%", + unitLabel: "hPa", }; diff --git a/src/view/translations/en.json b/src/view/translations/en.json index 038aae9ad..3d54e3927 100644 --- a/src/view/translations/en.json +++ b/src/view/translations/en.json @@ -31,7 +31,7 @@ "toolbar-speaker.tryItDescription": "Right now the tones are not supported on the simulator. If you would like to see tones implemented, please +1 the feature addition issue on GitHub! Regardless, you can play it on your device!", "toolbar-temperature-sensor.description": "This sensor uses an NTC thermistor to sense temperature an calculate it with the analog voltage on analog pin #A9.", "toolbar-temperature-sensor.title": "Temperature Sensor", - "toolbar-temperature-sensor.tryItDescription": "You can set the temperature range from your code!", + "toolbar-temperature-sensor.tryItDescription": "You can set the temperature in degrees Celsius.", "toolbar-accelerometer-sensor.title": "Accelerometer", "toolbar-accelerometer-sensor.description": "An accelerometer measures the acceleration of your micro:bit; this component senses when the micro:bit is moved.", "toolbar-accelerometer-sensor.tryItDescription": "Set the acceleration with the sliders.", @@ -76,16 +76,16 @@ "toolbar-clue-sound-sensor.tryItDescription": "If you would like to see this sensor supported, please +1 the feature addition issue on GitHub!", "toolbar-clue-pressure-sensor.title": "Pressure", "toolbar-clue-pressure-sensor.description": "CLUE uses the BMP280 sensor for barometric pressure. Because pressure changes with altitude, and the pressure measurements are so good, you can also use it as an altimeter with ±1 meter accuracy.", - "toolbar-clue-pressure-sensor.tryItDescription": "You can set the pressure here.", + "toolbar-clue-pressure-sensor.tryItDescription": "You can set the pressure here in hectoPascals (hPa).", "toolbar-clue-humidity-sensor.title": "Humidity", "toolbar-clue-humidity-sensor.description": "The SHT30-D sensor has an excellent ±2% relative humidity and ±0.5°C accuracy for most uses.", - "toolbar-clue-humidity-sensor.tryItDescription": "You can set the humidity % here.", + "toolbar-clue-humidity-sensor.tryItDescription": "You can set the humidity in percentage (%) here.", "toolbar-clue-gesture-sensor.title": "Gesture", "toolbar-clue-gesture-sensor.description": "The gesture sensor can detect directional gestures (left to right, right to left, up to down, down to up), but in theory more complicated gestures like zig-zag, clockwise or counterclockwise circle, near to far, etc. could also be detected with additional code. ", "toolbar-clue-gesture-sensor.tryItDescription": "Select a gesture and send it by clicking the button.", "toolbar-clue-proximity-sensor.title": "Proximity", "toolbar-clue-proximity-sensor.description": "The proximity sensor uses APDS9960 and is able to return how close an object is to the front of the sensor.", - "toolbar-clue-proximity-sensor.tryItDescription": "You can set the proximity here.", + "toolbar-clue-proximity-sensor.tryItDescription": "Set relative proximity to the sensor in values from 0 - 255", "toolbar-clue-bluetooth.title": "Bluetooth", "toolbar-clue-bluetooth.description": "You can transmit data over Bluetooth to a computer or mobile device for data plotting and logging, or save it to the built in storage.", "toolbar-clue-bluetooth.tryItDescription": "If you would like to see this sensor supported, please +1 the feature addition issue on GitHub! ", From fe0eb3d35e0530f45e1f37c56a6f1cb33a03ccc8 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Fri, 3 Apr 2020 11:32:54 -0700 Subject: [PATCH 26/48] Add shake gesture --- src/view/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/view/constants.ts b/src/view/constants.ts index b48f256a2..a34dc2564 100644 --- a/src/view/constants.ts +++ b/src/view/constants.ts @@ -122,7 +122,7 @@ export const GESTURES_MICROBIT = [ "6g", "8g", ]; -export const GESTURES_CLUE = ["up", "down", "left", "right"]; +export const GESTURES_CLUE = ["up", "down", "left", "right", "shake"]; export enum WEBVIEW_ATTRIBUTES_KEY { INITIAL_DEVICE = "initial_device", From fa9154d2e641690672066f0f726d305dc7416426 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 3 Apr 2020 12:18:48 -0700 Subject: [PATCH 27/48] added shake --- src/clue/adafruit_clue.py | 8 ++++---- src/clue/test/test_adafruit_clue.py | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/clue/adafruit_clue.py b/src/clue/adafruit_clue.py index 0a130549c..3a8ecbb1f 100644 --- a/src/clue/adafruit_clue.py +++ b/src/clue/adafruit_clue.py @@ -286,8 +286,7 @@ def acceleration(self): ) def shake(self, shake_threshold=30, avg_count=10, total_delay=0.1): - """Not implemented! - Detect when the accelerometer is shaken. Optional parameters: + """Detect when the accelerometer is shaken. Optional parameters: :param shake_threshold: Increase or decrease to change shake sensitivity. This requires a minimum value of 10. 10 is the total acceleration if the board is not moving, therefore @@ -298,7 +297,8 @@ def shake(self, shake_threshold=30, avg_count=10, total_delay=0.1): :param total_delay: The total time in seconds it takes to obtain avg_count readings from acceleration. (Default 0.1) """ - utils.print_for_unimplemented_functions(Clue.shake.__name__) + is_shaken = self.__state[CONSTANTS.CLUE_STATE.GESTURE] == "shake" + return is_shaken @property def color(self): @@ -383,7 +383,7 @@ def gesture(self): print("Gesture: {}".format(clue.gesture)) """ gesture_mapping = {"": 0, "up": 1, "down": 2, "left": 3, "right": 4} - return gesture_mapping[self.__state[CONSTANTS.CLUE_STATE.GESTURE]] + return gesture_mapping.get(self.__state[CONSTANTS.CLUE_STATE.GESTURE], 0) @property def humidity(self): diff --git a/src/clue/test/test_adafruit_clue.py b/src/clue/test/test_adafruit_clue.py index 152ba7cc2..76904094e 100644 --- a/src/clue/test/test_adafruit_clue.py +++ b/src/clue/test/test_adafruit_clue.py @@ -153,6 +153,14 @@ def test_gesture(self): clue._Clue__state[CONSTANTS.CLUE_STATE.GESTURE] = UP assert 1 == clue.gesture + def test_shake(self): + NONE = "none" + SHAKE = "shake" + clue._Clue__state[CONSTANTS.CLUE_STATE.GESTURE] = SHAKE + assert clue.shake() + clue._Clue__state[CONSTANTS.CLUE_STATE.GESTURE] = NONE + assert not clue.shake() + def test_humidity(self): MOCK_HUMIDITY_A = 10 MOCK_HUMIDITY_B = 50 From 64e5d4518765febefe6300f8787f6a16bd086a61 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Fri, 3 Apr 2020 15:39:10 -0700 Subject: [PATCH 28/48] Name change for generic slider content --- ...eDimensionSlider.tsx => GenericSliderComponent.tsx} | 10 +++++----- src/view/components/toolbar/clue/ClueModalContent.tsx | 10 +++++----- src/view/components/toolbar/motion/Accelerometer.tsx | 4 ++-- src/view/components/toolbar/motion/MotionSensorBar.tsx | 4 ++-- .../motion/__snapshots__/Accelerometer.spec.tsx.snap | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) rename src/view/components/toolbar/{motion/threeDimensionSlider/ThreeDimensionSlider.tsx => GenericSliderComponent.tsx} (80%) diff --git a/src/view/components/toolbar/motion/threeDimensionSlider/ThreeDimensionSlider.tsx b/src/view/components/toolbar/GenericSliderComponent.tsx similarity index 80% rename from src/view/components/toolbar/motion/threeDimensionSlider/ThreeDimensionSlider.tsx rename to src/view/components/toolbar/GenericSliderComponent.tsx index 4fb8fc175..0f7e24b92 100644 --- a/src/view/components/toolbar/motion/threeDimensionSlider/ThreeDimensionSlider.tsx +++ b/src/view/components/toolbar/GenericSliderComponent.tsx @@ -1,7 +1,7 @@ import * as React from "react"; -import { SENSOR_LIST } from "../../../../constants"; -import { ISensorProps, ISliderProps } from "../../../../viewUtils"; -import InputSlider from "../../InputSlider"; +import { SENSOR_LIST } from "../../constants"; +import { ISensorProps, ISliderProps } from "../../viewUtils"; +import InputSlider from "./InputSlider"; interface IProps { axisProperties: ISensorProps; @@ -11,9 +11,9 @@ interface IProps { }; onUpdateValue: (sensor: SENSOR_LIST, value: number) => void; } -export const ThreeDimensionSlider: React.FC = props => { +export const GenericSliderComponent: React.FC = props => { return ( -
+
{props.axisProperties.sliderProps.map( (sliderProperties: ISliderProps, index: number) => { return ( diff --git a/src/view/components/toolbar/clue/ClueModalContent.tsx b/src/view/components/toolbar/clue/ClueModalContent.tsx index fed768ab5..7d8ba8928 100644 --- a/src/view/components/toolbar/clue/ClueModalContent.tsx +++ b/src/view/components/toolbar/clue/ClueModalContent.tsx @@ -4,7 +4,7 @@ import { TAG_INPUT_SVG } from "../../../svgs/tag_input_svg"; import { TAG_OUTPUT_SVG } from "../../../svgs/tag_output_svg"; import { Accelerometer } from "../motion/Accelerometer"; import { Gesture } from "../motion/Gesture"; -import { ThreeDimensionSlider } from "../motion/threeDimensionSlider/ThreeDimensionSlider"; +import { GenericSliderComponent } from "../GenericSliderComponent"; import { FEATURE_REQUEST_ON_GITHUB, IModalContent } from "../SensorModalUtils"; import TemperatureSensorBar from "../TemperatureSensorBar"; import * as SENSOR_PROPERTIES from "./ClueSensorProperties"; @@ -81,7 +81,7 @@ export const LIGHT_CONTENT = ( }; return { components: ( - { render() { return (
- { />

-
Date: Sun, 5 Apr 2020 16:59:40 -0700 Subject: [PATCH 29/48] Modify css to fix wrong colors on modals --- src/view/styles/Button.css | 1 + src/view/styles/ToolBar.css | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/view/styles/Button.css b/src/view/styles/Button.css index 78c8372a5..c30ed1360 100644 --- a/src/view/styles/Button.css +++ b/src/view/styles/Button.css @@ -7,6 +7,7 @@ .button-icon { fill: var(--vscode-badgeForegroundOverride); } + .button-rectangle { stroke: var(--vscode-badgeForegroundOverride); } diff --git a/src/view/styles/ToolBar.css b/src/view/styles/ToolBar.css index af054a093..5e3ec7da1 100644 --- a/src/view/styles/ToolBar.css +++ b/src/view/styles/ToolBar.css @@ -14,6 +14,10 @@ border-color: var(--vscode-highContrastButtonBorderOverride-color); border-width: 1px; border-style: solid; + display: flex; + flex-direction: column; + align-content: center; + align-items: center; } .toolbar-icon { @@ -38,7 +42,6 @@ height: fit-content; padding-left: 16px; box-shadow: none; - background: var(--vscode-debugToolBar-background); margin-left: 1px; } From 1e417057adadfe440bd2605b61905227d6203c52 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Sun, 5 Apr 2020 17:00:12 -0700 Subject: [PATCH 30/48] Add svg for gyro and magnet --- src/view/svgs/toolbar_svg.tsx | 80 +++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/view/svgs/toolbar_svg.tsx b/src/view/svgs/toolbar_svg.tsx index 9eeb96614..568f13a17 100644 --- a/src/view/svgs/toolbar_svg.tsx +++ b/src/view/svgs/toolbar_svg.tsx @@ -730,3 +730,83 @@ export const PROXIMITY_SVG = ( ); +export const MAGNET_SVG = ( + + + + + +); +export const GYROSCOPE_SVG = ( + + + + + + + + + + + + + +); From 75a7607694a6db39ddd8d84cf01810cb90dc3b45 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Sun, 5 Apr 2020 17:00:37 -0700 Subject: [PATCH 31/48] Add modal for compass, gyro and magnet --- src/view/components/clue/Clue.tsx | 14 +++++ src/view/components/microbit/Microbit.tsx | 4 ++ .../components/toolbar/SensorModalUtils.tsx | 18 +++--- .../toolbar/clue/ClueModalContent.tsx | 50 +++++++++++++++ .../toolbar/clue/ClueSensorProperties.tsx | 63 +++++++++++++++++++ .../toolbar/microbit/MicrobitModalContent.tsx | 22 +++++-- src/view/constants.ts | 6 ++ 7 files changed, 166 insertions(+), 11 deletions(-) diff --git a/src/view/components/clue/Clue.tsx b/src/view/components/clue/Clue.tsx index 35111b288..294b2fcc0 100644 --- a/src/view/components/clue/Clue.tsx +++ b/src/view/components/clue/Clue.tsx @@ -33,6 +33,12 @@ const DEFAULT_STATE = { [SENSOR_LIST.HUMIDITY]: 0, [SENSOR_LIST.PRESSURE]: 0, [SENSOR_LIST.PROXIMITY]: 0, + [SENSOR_LIST.GYRO_X]: 0, + [SENSOR_LIST.GYRO_Y]: 0, + [SENSOR_LIST.GYRO_Z]: 0, + [SENSOR_LIST.MAGNET_X]: 0, + [SENSOR_LIST.MAGNET_Y]: 0, + [SENSOR_LIST.MAGNET_Z]: 0, }, currentSelectedGesture: GESTURES_CLUE[0], }; @@ -129,6 +135,14 @@ const CLUE_TOOLBAR_BUTTONS: Array<{ label: string; image: JSX.Element }> = [ label: CLUE_TOOLBAR_ICON_ID.GESTURE, image: TOOLBAR_SVG.GESTURE_SVG, }, + { + label: CLUE_TOOLBAR_ICON_ID.GYROSCOPE, + image: TOOLBAR_SVG.GYROSCOPE_SVG, + }, + { + label: CLUE_TOOLBAR_ICON_ID.MAGNETOSCOPE, + image: TOOLBAR_SVG.MAGNET_SVG, + }, { label: CLUE_TOOLBAR_ICON_ID.GPIO, image: TOOLBAR_SVG.GPIO_SVG, diff --git a/src/view/components/microbit/Microbit.tsx b/src/view/components/microbit/Microbit.tsx index c0e062e13..c1380ec99 100644 --- a/src/view/components/microbit/Microbit.tsx +++ b/src/view/components/microbit/Microbit.tsx @@ -115,6 +115,10 @@ const MICROBIT_TOOLBAR_BUTTONS: Array<{ label: string; image: JSX.Element }> = [ image: TOOLBAR_SVG.GPIO_SVG, label: MICROBIT_TOOLBAR_ICON_ID.GPIO, }, + { + image: TOOLBAR_SVG.GYROSCOPE_SVG, + label: MICROBIT_TOOLBAR_ICON_ID.COMPASS, + }, { image: TOOLBAR_SVG.SPEAKER_SVG, label: MICROBIT_TOOLBAR_ICON_ID.SOUND, diff --git a/src/view/components/toolbar/SensorModalUtils.tsx b/src/view/components/toolbar/SensorModalUtils.tsx index 8da9575ce..b49979fa9 100644 --- a/src/view/components/toolbar/SensorModalUtils.tsx +++ b/src/view/components/toolbar/SensorModalUtils.tsx @@ -74,6 +74,7 @@ export const MICROBIT_TOOLBAR_ICON_ID = { SOUND: "toolbar-microbit-sound", WIRELESS: "toolbar-microbit-wireless", GESTURE: "toolbar-microbit-gesture-sensor", + COMPASS: "toolbar-microbit-compass-sensor", }; export const CLUE_TOOLBAR_ICON_ID = { @@ -90,6 +91,8 @@ export const CLUE_TOOLBAR_ICON_ID = { GESTURE: "toolbar-clue-gesture-sensor", PROXIMITY: "toolbar-clue-proximity-sensor", BLUETOOTH: "toolbar-clue-bluetooth", + MAGNETOSCOPE: "toolbar-clue-magnet-sensor", + GYROSCOPE: "toolbar-clue-gyroscope-sensor", }; export interface IModalContent { @@ -304,13 +307,15 @@ export const LABEL_TO_MODAL_CONTENT_CONSTRUCTOR = new Map([ [CPX_TOOLBAR_ICON_ID.TEMPERATURE, TEMPERATURE_MODAL_CONTENT], [ MICROBIT_TOOLBAR_ICON_ID.ACCELEROMETER, - MICROBIT_MODAL.ACCELEROMETER_MODAL_CONTENT, + MICROBIT_MODAL.ACCELEROMETER_CONTENT, ], + [MICROBIT_TOOLBAR_ICON_ID.COMPASS, MICROBIT_MODAL.COMPASS_CONTENT], [MICROBIT_TOOLBAR_ICON_ID.LEDS, MICROBIT_MODAL.LED_CONTENT], [MICROBIT_TOOLBAR_ICON_ID.PUSH_BUTTON, MICROBIT_MODAL.BUTTON_CONTENT], - [MICROBIT_TOOLBAR_ICON_ID.GPIO, MICROBIT_MODAL.GPIO_MODAL_CONTENT], - [MICROBIT_TOOLBAR_ICON_ID.SOUND, MICROBIT_MODAL.SOUND_MODAL_CONTENT], + [MICROBIT_TOOLBAR_ICON_ID.GPIO, MICROBIT_MODAL.GPIO_CONTENT], + [MICROBIT_TOOLBAR_ICON_ID.SOUND, MICROBIT_MODAL.SOUND_CONTENT], [MICROBIT_TOOLBAR_ICON_ID.WIRELESS, MICROBIT_MODAL.WIRELESS_CONTENT], + [MICROBIT_TOOLBAR_ICON_ID.COMPASS, MICROBIT_MODAL.COMPASS_CONTENT], [CLUE_TOOLBAR_ICON_ID.TEMPERATURE, CLUE_MODAL.TEMPERATURE_CONTENT], [CLUE_TOOLBAR_ICON_ID.ACCELEROMETER, CLUE_MODAL.ACCELEROMETER_CONTENT], [CLUE_TOOLBAR_ICON_ID.PUSH_BUTTON, CLUE_MODAL.BUTTON_CONTENT], @@ -324,6 +329,8 @@ export const LABEL_TO_MODAL_CONTENT_CONSTRUCTOR = new Map([ [CLUE_TOOLBAR_ICON_ID.BLUETOOTH, CLUE_MODAL.BLUETOOTH_CONTENT], [CLUE_TOOLBAR_ICON_ID.ACCELEROMETER, CLUE_MODAL.ACCELEROMETER_CONTENT], [CLUE_TOOLBAR_ICON_ID.SPEAKER, CLUE_MODAL.SPEAKER_CONTENT], + [CLUE_TOOLBAR_ICON_ID.GYROSCOPE, CLUE_MODAL.GYROSCOPE_CONTENT], + [CLUE_TOOLBAR_ICON_ID.MAGNETOSCOPE, CLUE_MODAL.MAGNETOSCOPE_CONTENT], ]); export const getModalContent = ( @@ -336,10 +343,7 @@ export const getModalContent = ( if (label === CLUE_TOOLBAR_ICON_ID.GESTURE) { return CLUE_MODAL.GESTURE_CONTENT(onSelectGestures, sendGesture); } else if (label === MICROBIT_TOOLBAR_ICON_ID.GESTURE) { - return MICROBIT_MODAL.GESTURE_MODAL_CONTENT( - onSelectGestures, - sendGesture - ); + return MICROBIT_MODAL.GESTURE_CONTENT(onSelectGestures, sendGesture); } const modalContentConstructor = LABEL_TO_MODAL_CONTENT_CONSTRUCTOR.get( label diff --git a/src/view/components/toolbar/clue/ClueModalContent.tsx b/src/view/components/toolbar/clue/ClueModalContent.tsx index 7d8ba8928..bdd2ceb1d 100644 --- a/src/view/components/toolbar/clue/ClueModalContent.tsx +++ b/src/view/components/toolbar/clue/ClueModalContent.tsx @@ -68,6 +68,56 @@ export const ACCELEROMETER_CONTENT = ( tryItDescription: "toolbar-clue-accelerometer-sensor.tryItDescription", }; }; +export const GYROSCOPE_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + const gyroSensorValues = { + X: sensorValues[SENSOR_LIST.GYRO_X], + Y: sensorValues[SENSOR_LIST.GYRO_Y], + Z: sensorValues[SENSOR_LIST.GYRO_Z], + }; + return { + components: ( + + ), + descriptionText: "toolbar-clue-gyroscope-sensor.description", + descriptionTitle: "toolbar-clue-gyroscope-sensor.title", + id: "gyroscope", + tagInput: TAG_INPUT_SVG, + tagOutput: undefined, + tryItDescription: "toolbar-clue-gyroscope-sensor.tryItDescription", + }; +}; +export const MAGNETOSCOPE_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + const magnetSensorValues = { + X: sensorValues[SENSOR_LIST.MAGNET_X], + Y: sensorValues[SENSOR_LIST.MAGNET_Y], + Z: sensorValues[SENSOR_LIST.MAGNET_Z], + }; + return { + components: ( + + ), + descriptionText: "toolbar-clue-magnet-sensor.description", + descriptionTitle: "toolbar-clue-magnet-sensor.title", + id: "magnetoscope", + tagInput: TAG_INPUT_SVG, + tagOutput: undefined, + tryItDescription: "toolbar-clue-magnet-sensor.tryItDescription", + }; +}; export const LIGHT_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, diff --git a/src/view/components/toolbar/clue/ClueSensorProperties.tsx b/src/view/components/toolbar/clue/ClueSensorProperties.tsx index fc058559e..0dc2e5e3f 100644 --- a/src/view/components/toolbar/clue/ClueSensorProperties.tsx +++ b/src/view/components/toolbar/clue/ClueSensorProperties.tsx @@ -41,6 +41,69 @@ export const CLUE_LIGHT_PROPERTIES: ISensorProps = { sliderProps: [CLUE_SLIDER_R, CLUE_SLIDER_G, CLUE_SLIDER_B, CLUE_SLIDER_C], unitLabel: "Lux", }; + +// Range for magnet found here https://www.adafruit.com/product/4479 +const CLUE_MAGNET_X: ISliderProps = { + axisLabel: "X", + maxLabel: "Max", + minLabel: "Min", + maxValue: 1600, + minValue: 400, + type: SENSOR_LIST.MAGNET_X, +}; +const CLUE_MAGNET_Y: ISliderProps = { + axisLabel: "Y", + maxLabel: "Max", + minLabel: "Min", + maxValue: 1600, + minValue: 400, + type: SENSOR_LIST.MAGNET_Y, +}; +const CLUE_MAGNET_Z: ISliderProps = { + axisLabel: "Z", + maxLabel: "Max", + minLabel: "Min", + maxValue: 1600, + minValue: 400, + type: SENSOR_LIST.MAGNET_Z, +}; + +export const CLUE_MAGNET_PROPERTIES: ISensorProps = { + LABEL: "Magnetoscope", + sliderProps: [CLUE_MAGNET_X, CLUE_MAGNET_Y, CLUE_MAGNET_Z], + unitLabel: "μT", +}; +const CLUE_GYRO_X: ISliderProps = { + axisLabel: "X", + maxLabel: "Max", + minLabel: "Min", + maxValue: 1000, + minValue: -1000, + type: SENSOR_LIST.GYRO_X, +}; +const CLUE_GYRO_Y: ISliderProps = { + axisLabel: "Y", + maxLabel: "Max", + minLabel: "Min", + maxValue: 1000, + minValue: -1000, + type: SENSOR_LIST.GYRO_Y, +}; +const CLUE_GYRO_Z: ISliderProps = { + axisLabel: "Z", + maxLabel: "Max", + minLabel: "Min", + maxValue: 1000, + minValue: -1000, + type: SENSOR_LIST.GYRO_Z, +}; + +export const CLUE_GYRO_PROPERTIES: ISensorProps = { + LABEL: "Gyroscope", + sliderProps: [CLUE_GYRO_X, CLUE_GYRO_Y, CLUE_GYRO_Z], + unitLabel: "deg/s", +}; + export const CLUE_HUMIDITY_PROPERTIES: ISensorProps = { LABEL: "Humidity Sensor", sliderProps: [ diff --git a/src/view/components/toolbar/microbit/MicrobitModalContent.tsx b/src/view/components/toolbar/microbit/MicrobitModalContent.tsx index c34b6058d..9eb4fd8a3 100644 --- a/src/view/components/toolbar/microbit/MicrobitModalContent.tsx +++ b/src/view/components/toolbar/microbit/MicrobitModalContent.tsx @@ -6,7 +6,7 @@ import { Accelerometer } from "../motion/Accelerometer"; import { Gesture } from "../motion/Gesture"; import { FEATURE_REQUEST_ON_GITHUB, IModalContent } from "../SensorModalUtils"; -export const ACCELEROMETER_MODAL_CONTENT = ( +export const ACCELEROMETER_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { @@ -60,7 +60,7 @@ export const BUTTON_CONTENT = ( id: "microbit_button", }; }; -export const SOUND_MODAL_CONTENT = ( +export const SOUND_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { @@ -74,7 +74,7 @@ export const SOUND_MODAL_CONTENT = ( id: "microbit_sound", }; }; -export const GPIO_MODAL_CONTENT = ( +export const GPIO_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } ): IModalContent => { @@ -88,6 +88,20 @@ export const GPIO_MODAL_CONTENT = ( id: "microbit_gpio", }; }; +export const COMPASS_CONTENT = ( + onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, + sensorValues: { [key: string]: number } +): IModalContent => { + return { + descriptionTitle: "toolbar-microbit-compass-sensor.title", + tagInput: TAG_INPUT_SVG, + tagOutput: TAG_OUTPUT_SVG, + descriptionText: "toolbar-microbit-compass-sensor.description", + tryItDescription: "toolbar-microbit-compass-sensor.tryItDescription", + components: [FEATURE_REQUEST_ON_GITHUB], + id: "microbit_compass", + }; +}; export const WIRELESS_CONTENT = ( onUpdateValue: (sensor: SENSOR_LIST, value: number) => void, sensorValues: { [key: string]: number } @@ -102,7 +116,7 @@ export const WIRELESS_CONTENT = ( id: "microbit_wireless", }; }; -export const GESTURE_MODAL_CONTENT = ( +export const GESTURE_CONTENT = ( onSelectGestures?: (event: React.ChangeEvent) => void, sendGesture?: (isActive: boolean) => void ): IModalContent => { diff --git a/src/view/constants.ts b/src/view/constants.ts index a34dc2564..b3719e124 100644 --- a/src/view/constants.ts +++ b/src/view/constants.ts @@ -107,6 +107,12 @@ export enum SENSOR_LIST { HUMIDITY = "humidity", PRESSURE = "pressure", PROXIMITY = "proximity", + MAGNET_X = "magnet_x", + MAGNET_Y = "magnet_y", + MAGNET_Z = "magnet_z", + GYRO_X = "gyro_x", + GYRO_Y = "gyro_y", + GYRO_Z = "gyro_z", } export const GESTURES_MICROBIT = [ From 83d853742ee160b57de4cb80b8c3b0e5e6a45cfa Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Sun, 5 Apr 2020 17:00:49 -0700 Subject: [PATCH 32/48] Add proper text strings for 3 sensors --- src/view/translations/en.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/view/translations/en.json b/src/view/translations/en.json index 3d54e3927..7f7b3cab3 100644 --- a/src/view/translations/en.json +++ b/src/view/translations/en.json @@ -53,6 +53,9 @@ "toolbar-microbit-gesture-sensor.title": "Gesture", "toolbar-microbit-gesture-sensor.description": "If you move your BBC micro:bit in a certain way (as a gesture) then micro:bit is able to detect this. micro:bit is able to recognise the following gestures: up, down, left, right, face up, face down, freefall, 3g, 6g, 8g, shake.)", "toolbar-microbit-gesture-sensor.tryItDescription": "Select a gesture and send it by clicking the button.", + "toolbar-microbit-compass-sensor.title": "Compass", + "toolbar-microbit-compass-sensor.description": "A digital compass is an input sensor that detects magnetic fields. Your BBC micro:bit has an inbuilt compass that can detect the direction in which it is facing.", + "toolbar-microbit-compass-sensor.tryItDescription": "If you would like to see this sensor supported, please +1 the feature addition issue on GitHub!", "toolbar-clue-temperature-sensor.title": "Temperature", "toolbar-clue-temperature-sensor.description": "CLUE uses the BMP280 sensor, an environmental sensor with temperature.This precision sensor from Bosch is the best low-cost, precision sensing solution for measuring temperature with ±1.0°C accuracy.", "toolbar-clue-temperature-sensor.tryItDescription": "You can set the temperature range from your code!", @@ -89,5 +92,11 @@ "toolbar-clue-bluetooth.title": "Bluetooth", "toolbar-clue-bluetooth.description": "You can transmit data over Bluetooth to a computer or mobile device for data plotting and logging, or save it to the built in storage.", "toolbar-clue-bluetooth.tryItDescription": "If you would like to see this sensor supported, please +1 the feature addition issue on GitHub! ", - "toolbar-clue-speaker.description": "The CLUE has a buzzer/speaker for playing tones and beeps." + "toolbar-clue-speaker.description": "The CLUE has a buzzer/speaker for playing tones and beeps.", + "toolbar-clue-magnet-sensor.title": "Magnetometer", + "toolbar-clue-magnet-sensor.description": "Sense the magnetic fields that surround us with this handy triple-axis magnetometer (compass) module. Magnetometers can sense where the strongest magnetic force is coming from, generally used to detect magnetic north, but can also be used for measuring magnetic fields.", + "toolbar-clue-magnet-sensor.tryItDescription": "You can set the magnetic field value in microTeslas (uT)", + "toolbar-clue-gyroscope-sensor.title": "Gyroscope", + "toolbar-clue-gyroscope-sensor.description": "The 3-axis gyroscope that can measure spin and twist users LSM6DS33", + "toolbar-clue-gyroscope-sensor.tryItDescription": "Set the angular velocity in degrees/second." } From f7f138e43a22ae524e0762eb9349249d62193654 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Sun, 5 Apr 2020 17:06:51 -0700 Subject: [PATCH 33/48] Set min width to toolbar for less resizing --- src/view/styles/ToolBar.css | 1 + 1 file changed, 1 insertion(+) diff --git a/src/view/styles/ToolBar.css b/src/view/styles/ToolBar.css index 5e3ec7da1..ef35688a9 100644 --- a/src/view/styles/ToolBar.css +++ b/src/view/styles/ToolBar.css @@ -21,6 +21,7 @@ } .toolbar-icon { + min-width: 360px; box-shadow: 0px 0px 20px rgba(0, 0, 0, 30%); border-color: var(--vscode-highContrastButtonBorderOverride-color); border-width: 1px; From a3e18d490a363ae1d6b19030ce6da0ae2f395819 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Mon, 6 Apr 2020 09:57:24 -0700 Subject: [PATCH 34/48] Update tests with latest css changes --- .../clue/__snapshots__/Clue.spec.tsx.snap | 142 ++++++++++++++++++ .../__snapshots__/Microbit.spec.tsx.snap | 97 ++++++++++++ .../device/__snapshots__/Device.spec.tsx.snap | 97 ++++++++++++ 3 files changed, 336 insertions(+) diff --git a/src/view/components/clue/__snapshots__/Clue.spec.tsx.snap b/src/view/components/clue/__snapshots__/Clue.spec.tsx.snap index 7d497690c..15dcfbd9b 100644 --- a/src/view/components/clue/__snapshots__/Clue.spec.tsx.snap +++ b/src/view/components/clue/__snapshots__/Clue.spec.tsx.snap @@ -1851,6 +1851,148 @@ Array [
+
+ +
+
+ +
+
+ +
+
+ +
Date: Mon, 6 Apr 2020 11:02:15 -0700 Subject: [PATCH 35/48] addressed pr comments and added gyro and magnetic sensors to backend --- src/base_circuitpython/base_cp_constants.py | 6 + src/clue/adafruit_clue.py | 15 +- src/clue/test/test_adafruit_clue.py | 214 +++++++++----------- 3 files changed, 107 insertions(+), 128 deletions(-) diff --git a/src/base_circuitpython/base_cp_constants.py b/src/base_circuitpython/base_cp_constants.py index 2613edc3a..0949385e4 100644 --- a/src/base_circuitpython/base_cp_constants.py +++ b/src/base_circuitpython/base_cp_constants.py @@ -55,6 +55,12 @@ class CLUE_STATE: CLUE_STATE.PRESSURE, CLUE_STATE.PROXIMITY, CLUE_STATE.GESTURE, + CLUE_STATE.GYRO_X, + CLUE_STATE.GYRO_Y, + CLUE_STATE.GYRO_Z, + CLUE_STATE.MAGNET_X, + CLUE_STATE.MAGNET_Y, + CLUE_STATE.MAGNET_Z, ] ) diff --git a/src/clue/adafruit_clue.py b/src/clue/adafruit_clue.py index 82639d61c..3b4b229c6 100644 --- a/src/clue/adafruit_clue.py +++ b/src/clue/adafruit_clue.py @@ -730,14 +730,13 @@ def update_state(self, new_state): # helpers def __update_button(self, button, value): - if button == CONSTANTS.CLUE_STATE.BUTTON_A: - if value: - self.__state[CONSTANTS.CLUE_STATE.PRESSED_BUTTONS].add("A") - self.__state[CONSTANTS.CLUE_STATE.BUTTON_A] = value - elif button == CONSTANTS.CLUE_STATE.BUTTON_B: - if value: - self.__state[CONSTANTS.CLUE_STATE.PRESSED_BUTTONS].add("B") - self.__state[CONSTANTS.CLUE_STATE.BUTTON_B] = value + buttonMapping = { + CONSTANTS.CLUE_STATE.BUTTON_A: "A", + CONSTANTS.CLUE_STATE.BUTTON_B: "B", + } + if value: + self.__state[button].add(buttonMapping[button]) + self.__state[button] = value clue = Clue() # pylint: disable=invalid-name diff --git a/src/clue/test/test_adafruit_clue.py b/src/clue/test/test_adafruit_clue.py index 76904094e..608ee3b76 100644 --- a/src/clue/test/test_adafruit_clue.py +++ b/src/clue/test/test_adafruit_clue.py @@ -72,86 +72,66 @@ def test_buttons(self): clue._Clue__update_button(CONSTANTS.CLUE_STATE.BUTTON_B, False) assert not clue.button_b - assert set(["A", "B"]) == clue.were_pressed - assert set() == clue.were_pressed - - def test_acceleration(self): - MOCK_MOTION_X_A = 1 - MOCK_MOTION_Y = 2 - MOCK_MOTION_Z = 3 - MOCK_MOTION_X_B = 4 - - clue._Clue__state[CONSTANTS.CLUE_STATE.MOTION_X] = MOCK_MOTION_X_A - clue._Clue__state[CONSTANTS.CLUE_STATE.MOTION_Y] = MOCK_MOTION_Y - clue._Clue__state[CONSTANTS.CLUE_STATE.MOTION_Z] = MOCK_MOTION_Z - assert clue.acceleration == (MOCK_MOTION_X_A, MOCK_MOTION_Y, MOCK_MOTION_Z) - clue._Clue__state[CONSTANTS.CLUE_STATE.MOTION_X] = MOCK_MOTION_X_B - assert clue.acceleration == (MOCK_MOTION_X_B, MOCK_MOTION_Y, MOCK_MOTION_Z) - - def test_color(self): - MOCK_COLOR_R_A = 1 - MOCK_COLOR_G = 2 - MOCK_COLOR_B = 3 - MOCK_COLOR_C = 4 - MOCK_COLOR_R_B = 5 - - clue._Clue__state[CONSTANTS.CLUE_STATE.LIGHT_R] = MOCK_COLOR_R_A - clue._Clue__state[CONSTANTS.CLUE_STATE.LIGHT_G] = MOCK_COLOR_G - clue._Clue__state[CONSTANTS.CLUE_STATE.LIGHT_B] = MOCK_COLOR_B - clue._Clue__state[CONSTANTS.CLUE_STATE.LIGHT_C] = MOCK_COLOR_C - assert clue.color == (MOCK_COLOR_R_A, MOCK_COLOR_G, MOCK_COLOR_B, MOCK_COLOR_C) - clue._Clue__state[CONSTANTS.CLUE_STATE.LIGHT_R] = MOCK_COLOR_R_B - assert clue.color == (MOCK_COLOR_R_B, MOCK_COLOR_G, MOCK_COLOR_B, MOCK_COLOR_C) - - def test_temperature(self): - MOCK_TEMP_A = 10 - MOCK_TEMP_B = -10 - clue._Clue__state[CONSTANTS.CLUE_STATE.TEMPERATURE] = MOCK_TEMP_A - assert MOCK_TEMP_A == clue.temperature - clue._Clue__state[CONSTANTS.CLUE_STATE.TEMPERATURE] = MOCK_TEMP_B - assert MOCK_TEMP_B == clue.temperature - - def test_magnetic(self): - MOCK_MAGNETIC_X_A = 1 - MOCK_MAGNETIC_Y = 2 - MOCK_MAGNETIC_Z = 3 - MOCK_MAGNETIC_X_B = 4 - - clue._Clue__state[CONSTANTS.CLUE_STATE.MAGNET_X] = MOCK_MAGNETIC_X_A - clue._Clue__state[CONSTANTS.CLUE_STATE.MAGNET_Y] = MOCK_MAGNETIC_Y - clue._Clue__state[CONSTANTS.CLUE_STATE.MAGNET_Z] = MOCK_MAGNETIC_Z - assert clue.magnetic == (MOCK_MAGNETIC_X_A, MOCK_MAGNETIC_Y, MOCK_MAGNETIC_Z,) - clue._Clue__state[CONSTANTS.CLUE_STATE.MAGNET_X] = MOCK_MAGNETIC_X_B - assert clue.magnetic == (MOCK_MAGNETIC_X_B, MOCK_MAGNETIC_Y, MOCK_MAGNETIC_Z,) - - def test_proximity(self): - MOCK_DISTANCE_A = 10 - MOCK_DISTANCE_B = 250 - clue._Clue__state[CONSTANTS.CLUE_STATE.PROXIMITY] = MOCK_DISTANCE_A - assert MOCK_DISTANCE_A == clue.proximity - clue._Clue__state[CONSTANTS.CLUE_STATE.PROXIMITY] = MOCK_DISTANCE_B - assert MOCK_DISTANCE_B == clue.proximity - - def test_gyro(self): - MOCK_GYRO_X_A = 1 - MOCK_GYRO_Y = 2 - MOCK_GYRO_Z = 3 - MOCK_GYRO_X_B = 4 - - clue._Clue__state[CONSTANTS.CLUE_STATE.GYRO_X] = MOCK_GYRO_X_A - clue._Clue__state[CONSTANTS.CLUE_STATE.GYRO_Y] = MOCK_GYRO_Y - clue._Clue__state[CONSTANTS.CLUE_STATE.GYRO_Z] = MOCK_GYRO_Z - assert clue.gyro == (MOCK_GYRO_X_A, MOCK_GYRO_Y, MOCK_GYRO_Z) - clue._Clue__state[CONSTANTS.CLUE_STATE.GYRO_X] = MOCK_GYRO_X_B - assert clue.gyro == (MOCK_GYRO_X_B, MOCK_GYRO_Y, MOCK_GYRO_Z) - - def test_gesture(self): - NONE = "" - UP = "up" - clue._Clue__state[CONSTANTS.CLUE_STATE.GESTURE] = NONE - assert 0 == clue.gesture - clue._Clue__state[CONSTANTS.CLUE_STATE.GESTURE] = UP - assert 1 == clue.gesture + assert clue.were_pressed == set(["A", "B"]) + assert clue.were_pressed == set() + + @pytest.mark.parametrize( + "mock_x, mock_y, mock_z", [(1, 2, 3), (0, 0, 0), (4, 6, 100)] + ) + def test_acceleration(self, mock_x, mock_y, mock_z): + clue._Clue__state[CONSTANTS.CLUE_STATE.MOTION_X] = mock_x + clue._Clue__state[CONSTANTS.CLUE_STATE.MOTION_Y] = mock_y + clue._Clue__state[CONSTANTS.CLUE_STATE.MOTION_Z] = mock_z + assert clue.acceleration == (mock_x, mock_y, mock_z) + + @pytest.mark.parametrize( + "mock_color_r, mock_color_g,mock_color_b,mock_color_c", + [(1, 2, 3, 4), (255, 255, 255, 255), (120, 140, 160)], + ) + def test_color(self, mock_color_r, mock_color_g, mock_color_b, mock_color_c): + clue._Clue__state[CONSTANTS.CLUE_STATE.LIGHT_R] = mock_color_r + clue._Clue__state[CONSTANTS.CLUE_STATE.LIGHT_G] = mock_color_g + clue._Clue__state[CONSTANTS.CLUE_STATE.LIGHT_B] = mock_color_b + clue._Clue__state[CONSTANTS.CLUE_STATE.LIGHT_C] = mock_color_c + assert clue.color == (mock_color_r, mock_color_g, mock_color_b, mock_color_c) + + @pytest.mark.parametrize("mock_temperature", [-10, 0, 10]) + def test_temperature(self, mock_temperature): + clue._Clue__state[CONSTANTS.CLUE_STATE.TEMPERATURE] = mock_temperature + assert clue.temperature == mock_temperature + + @pytest.mark.parametrize( + "mock_magnetic_x, mock_magnetic_y, mock_magnetic_z", + [(1, 2, 3), (100, 150, 200), (10, 5, 15)], + ) + def test_magnetic(self, mock_magnetic_x, mock_magnetic_y, mock_magnetic_z): + clue._Clue__state[CONSTANTS.CLUE_STATE.MAGNET_X] = mock_magnetic_x + clue._Clue__state[CONSTANTS.CLUE_STATE.MAGNET_Y] = mock_magnetic_y + clue._Clue__state[CONSTANTS.CLUE_STATE.MAGNET_Z] = mock_magnetic_z + assert clue.magnetic == (mock_magnetic_x, mock_magnetic_y, mock_magnetic_z,) + + @pytest.mark.parametrize("mock_distance", (0, 10, 250, 255)) + def test_proximity(self, mock_distance): + clue._Clue__state[CONSTANTS.CLUE_STATE.PROXIMITY] = mock_distance + assert clue.proximity == mock_distance + + @pytest.mark.parametrize( + "mock_gyro_x, mock_gyro_y, mock_gyro_z", + [(1, 2, 3), (100, 150, 200), (10, 5, 15)], + ) + def test_gyro(self, mock_gyro_x, mock_gyro_y, mock_gyro_z): + clue._Clue__state[CONSTANTS.CLUE_STATE.GYRO_X] = mock_gyro_x + clue._Clue__state[CONSTANTS.CLUE_STATE.GYRO_Y] = mock_gyro_y + clue._Clue__state[CONSTANTS.CLUE_STATE.GYRO_Z] = mock_gyro_z + assert clue.gyro == (mock_gyro_x, mock_gyro_y, mock_gyro_z) + + @pytest.mark.parametrize( + "gesture_word, gesture_number", + [("", 0), ("up", 1), ("down", 2), ("left", 3), ("right", 4)], + ) + def test_gesture(self, gesture_word, gesture_number): + clue._Clue__state[CONSTANTS.CLUE_STATE.GESTURE] = gesture_word + assert clue.gesture == gesture_number def test_shake(self): NONE = "none" @@ -161,43 +141,37 @@ def test_shake(self): clue._Clue__state[CONSTANTS.CLUE_STATE.GESTURE] = NONE assert not clue.shake() - def test_humidity(self): - MOCK_HUMIDITY_A = 10 - MOCK_HUMIDITY_B = 50 - clue._Clue__state[CONSTANTS.CLUE_STATE.HUMIDITY] = MOCK_HUMIDITY_A - assert MOCK_HUMIDITY_A == clue.humidity - clue._Clue__state[CONSTANTS.CLUE_STATE.HUMIDITY] = MOCK_HUMIDITY_B - assert MOCK_HUMIDITY_B == clue.humidity - - def test_pressure(self): - MOCK_PRESSURE_A = 10 - MOCK_PRESSURE_B = 50 - clue._Clue__state[CONSTANTS.CLUE_STATE.PRESSURE] = MOCK_PRESSURE_A - assert MOCK_PRESSURE_A == clue.pressure - clue._Clue__state[CONSTANTS.CLUE_STATE.PRESSURE] = MOCK_PRESSURE_B - assert MOCK_PRESSURE_B == clue.pressure - - def test_altitude(self): - MOCK_PRESSURE_A = 1000 - MOCK_PRESSURE_B = 1030 - MOCK_ALTITUDE_A = 125.42255615546036 - MOCK_ALTITUDE_B = -123.93061640175468 - SEA_LEVEL_PRESSURE = 1015 - clue.sea_level_pressure = SEA_LEVEL_PRESSURE - clue._Clue__state[CONSTANTS.CLUE_STATE.PRESSURE] = MOCK_PRESSURE_A - assert MOCK_ALTITUDE_A == pytest.approx(clue.altitude) - clue._Clue__state[CONSTANTS.CLUE_STATE.PRESSURE] = MOCK_PRESSURE_B - assert MOCK_ALTITUDE_B == pytest.approx(clue.altitude) - - def test_sea_level_pressure(self): - MOCK_PRESSURE = 1040 - clue.sea_level_pressure = MOCK_PRESSURE - assert MOCK_PRESSURE == clue.sea_level_pressure - - def test_pixel(self): - MOCK_RED = (255, 0, 0) - MOCK_WHITE = (255, 255, 255) - clue.pixel.fill(MOCK_RED) - assert MOCK_RED == clue.pixel[0] - clue.pixel.fill(MOCK_WHITE) - assert MOCK_WHITE == clue.pixel[0] + @pytest.mark.parametrize("mock_humidity", [0, 10, 50, 100]) + def test_humidity(self, mock_humidity): + clue._Clue__state[CONSTANTS.CLUE_STATE.HUMIDITY] = mock_humidity + assert clue.humidity == mock_humidity + + @pytest.mark.parametrize("mock_pressure", [0, 10, 50, 100]) + def test_pressure(self, mock_pressure): + clue._Clue__state[CONSTANTS.CLUE_STATE.PRESSURE] = mock_pressure + assert clue.pressure == mock_pressure + + @pytest.mark.parametrize( + "mock_pressure, mock_sea_level_pressure, expected_altitude", + [ + (1000, 1015, 125.42255615546036), + (1030, 1015, -123.93061640175468), + (1020, 1013, -58.13176263932101), + ], + ) + def test_altitude(self, mock_pressure, mock_sea_level_pressure, expected_altitude): + clue.sea_level_pressure = mock_sea_level_pressure + clue._Clue__state[CONSTANTS.CLUE_STATE.PRESSURE] = mock_pressure + assert expected_altitude == pytest.approx(clue.altitude) + + @pytest.mark.parametrize("mock_sea_level_pressure", [1040, 1015, 1013]) + def test_sea_level_pressure(self, mock_sea_level_pressure): + clue.sea_level_pressure = mock_sea_level_pressure + assert mock_sea_level_pressure == clue.sea_level_pressure + + @pytest.mark.parametrize( + "mock_color", [(255, 0, 0), (255, 255, 255), (123, 123, 123)] + ) + def test_pixel(self, mock_color): + clue.pixel.fill(mock_color) + assert clue.pixel[0] == mock_color From d046c215baf24830bddd9115a726e0fc390bf065 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Apr 2020 11:12:58 -0700 Subject: [PATCH 36/48] Fixed bug in color test --- src/clue/test/test_adafruit_clue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clue/test/test_adafruit_clue.py b/src/clue/test/test_adafruit_clue.py index 608ee3b76..fcd3f7e3e 100644 --- a/src/clue/test/test_adafruit_clue.py +++ b/src/clue/test/test_adafruit_clue.py @@ -86,7 +86,7 @@ def test_acceleration(self, mock_x, mock_y, mock_z): @pytest.mark.parametrize( "mock_color_r, mock_color_g,mock_color_b,mock_color_c", - [(1, 2, 3, 4), (255, 255, 255, 255), (120, 140, 160)], + [(1, 2, 3, 4), (255, 255, 255, 255), (120, 140, 160, 180)], ) def test_color(self, mock_color_r, mock_color_g, mock_color_b, mock_color_c): clue._Clue__state[CONSTANTS.CLUE_STATE.LIGHT_R] = mock_color_r From 03b721613d473231bb6c097178d3dadadeead195 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Apr 2020 11:39:23 -0700 Subject: [PATCH 37/48] fixed bug in update_button --- src/clue/adafruit_clue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clue/adafruit_clue.py b/src/clue/adafruit_clue.py index 3b4b229c6..12604dc72 100644 --- a/src/clue/adafruit_clue.py +++ b/src/clue/adafruit_clue.py @@ -735,7 +735,7 @@ def __update_button(self, button, value): CONSTANTS.CLUE_STATE.BUTTON_B: "B", } if value: - self.__state[button].add(buttonMapping[button]) + self.__state[CONSTANTS.CLUE_STATE.PRESSED_BUTTONS].add(buttonMapping[button]) self.__state[button] = value From 86bced36281dd23ccaa1fad28dcf59e705a5d2c5 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Apr 2020 11:45:27 -0700 Subject: [PATCH 38/48] formatted --- src/clue/adafruit_clue.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/clue/adafruit_clue.py b/src/clue/adafruit_clue.py index 12604dc72..11dd03da5 100644 --- a/src/clue/adafruit_clue.py +++ b/src/clue/adafruit_clue.py @@ -735,7 +735,9 @@ def __update_button(self, button, value): CONSTANTS.CLUE_STATE.BUTTON_B: "B", } if value: - self.__state[CONSTANTS.CLUE_STATE.PRESSED_BUTTONS].add(buttonMapping[button]) + self.__state[CONSTANTS.CLUE_STATE.PRESSED_BUTTONS].add( + buttonMapping[button] + ) self.__state[button] = value From 32c3b4c39b769ad757a0495b271431d0c847891d Mon Sep 17 00:00:00 2001 From: Kevin Nguyen Date: Mon, 6 Apr 2020 13:13:40 -0700 Subject: [PATCH 39/48] Update src/view/translations/en.json Co-Authored-By: Vandy Liu <33995460+vandyliu@users.noreply.github.com> --- src/view/translations/en.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/view/translations/en.json b/src/view/translations/en.json index 7f7b3cab3..26be1678b 100644 --- a/src/view/translations/en.json +++ b/src/view/translations/en.json @@ -48,7 +48,8 @@ "toolbar-microbit-gpio.description": "On the bottom edge of your BBC micro:bit there are 25 gold strips, called pins. These pins allow you to really get creative. You can create circuits, connect external things like buzzers and motors and make your own fun projects.", "toolbar-microbit-gpio.tryItDescription": "If you would like to see this sensor supported, please +1 the feature addition issue on GitHub! For now, you can try it on MakeCode!", "toolbar-microbit-wireless.title": "Bluetooth & Radio", - "toolbar-microbit-wireless.description": "micro:bits can use radio waves and bluetooth services to communicate with each other", + "toolbar-microbit-wireless.description": "micro:bits can use radio waves and bluetooth services to communicate with each other.", + "toolbar-microbit-wireless.tryItDescription": "If you would like to see this sensor supported, please +1 the feature addition issue on GitHub! For now, you can try it on MakeCode!", "toolbar-microbit-gesture-sensor.title": "Gesture", "toolbar-microbit-gesture-sensor.description": "If you move your BBC micro:bit in a certain way (as a gesture) then micro:bit is able to detect this. micro:bit is able to recognise the following gestures: up, down, left, right, face up, face down, freefall, 3g, 6g, 8g, shake.)", From 1558c3dcaac15603aa14527d1c56196314766ea0 Mon Sep 17 00:00:00 2001 From: Kevin Nguyen Date: Mon, 6 Apr 2020 13:14:01 -0700 Subject: [PATCH 40/48] Update src/view/translations/en.json Co-Authored-By: Vandy Liu <33995460+vandyliu@users.noreply.github.com> --- src/view/translations/en.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/view/translations/en.json b/src/view/translations/en.json index 26be1678b..d4bc98f41 100644 --- a/src/view/translations/en.json +++ b/src/view/translations/en.json @@ -67,7 +67,8 @@ "toolbar-clue-accelerometer-sensor.description": " The 3-axis accelerometer, can tell you which direction is down towards the Earth (by measuring gravity) or how fast the board is accelerating in 3D space.", "toolbar-clue-accelerometer-sensor.tryItDescription": "Set the acceleration with the sliders.", "toolbar-clue-led.title": "Neopixel", - "toolbar-clue-led.description": "The CLUE has one full RGB LED on it's back", + "toolbar-clue-led.description": "The CLUE has one full RGB LED (NeoPixel) on the back of the device", + "toolbar-clue-led.tryItDescription": "Run your code and see the cool effects on the simulator!", "toolbar-clue-a-b-push.title": "Buttons", "toolbar-clue-a-b-push.description": "There are two buttons on the front of the CLUE (labelled A and B). The third button is to trigger both A and B buttons. You can detect when these buttons are pressed, allowing you to trigger code on the device.", From 4662fbaf6c8e426deb7c2b51c60f42a201a4acdf Mon Sep 17 00:00:00 2001 From: Kevin Nguyen Date: Mon, 6 Apr 2020 13:14:17 -0700 Subject: [PATCH 41/48] Update src/view/translations/en.json Co-Authored-By: Vandy Liu <33995460+vandyliu@users.noreply.github.com> --- src/view/translations/en.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/view/translations/en.json b/src/view/translations/en.json index d4bc98f41..4284974e9 100644 --- a/src/view/translations/en.json +++ b/src/view/translations/en.json @@ -52,7 +52,8 @@ "toolbar-microbit-wireless.tryItDescription": "If you would like to see this sensor supported, please +1 the feature addition issue on GitHub! For now, you can try it on MakeCode!", "toolbar-microbit-gesture-sensor.title": "Gesture", - "toolbar-microbit-gesture-sensor.description": "If you move your BBC micro:bit in a certain way (as a gesture) then micro:bit is able to detect this. micro:bit is able to recognise the following gestures: up, down, left, right, face up, face down, freefall, 3g, 6g, 8g, shake.)", + "toolbar-microbit-gesture-sensor.description": "If you move your BBC micro:bit in a certain way (as a gesture) then the micro:bit is able to detect this. It can recognize the following gestures: up, down, left, right, face up, face down, freefall, 3g, 6g, 8g, and shake.", + "toolbar-microbit-gesture-sensor.tryItDescription": "Select a gesture and send it by clicking the button.", "toolbar-microbit-compass-sensor.title": "Compass", "toolbar-microbit-compass-sensor.description": "A digital compass is an input sensor that detects magnetic fields. Your BBC micro:bit has an inbuilt compass that can detect the direction in which it is facing.", From 835c219a444f34d8bd39d649ec84d9d3491a0fc0 Mon Sep 17 00:00:00 2001 From: Kevin Nguyen Date: Mon, 6 Apr 2020 13:14:30 -0700 Subject: [PATCH 42/48] Update src/view/translations/en.json Co-Authored-By: Vandy Liu <33995460+vandyliu@users.noreply.github.com> --- src/view/translations/en.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/view/translations/en.json b/src/view/translations/en.json index 4284974e9..92943793f 100644 --- a/src/view/translations/en.json +++ b/src/view/translations/en.json @@ -60,7 +60,8 @@ "toolbar-microbit-compass-sensor.tryItDescription": "If you would like to see this sensor supported, please +1 the feature addition issue on GitHub!", "toolbar-clue-temperature-sensor.title": "Temperature", "toolbar-clue-temperature-sensor.description": "CLUE uses the BMP280 sensor, an environmental sensor with temperature.This precision sensor from Bosch is the best low-cost, precision sensing solution for measuring temperature with ±1.0°C accuracy.", - "toolbar-clue-temperature-sensor.tryItDescription": "You can set the temperature range from your code!", + "toolbar-clue-temperature-sensor.tryItDescription": "You can simulate the temperature in your code!", + "toolbar-clue-light-sensor.title": "Light/Color Sensor", "toolbar-clue-light-sensor.description": "The light sensor uses APDS9960 and is able to return the red, blue, green and clear light.", "toolbar-clue-light-sensor.tryItDescription": "You can set the color values of the light detected.", From 194fdba3cc0b55b06226492f8fac694864260a2d Mon Sep 17 00:00:00 2001 From: Kevin Nguyen Date: Mon, 6 Apr 2020 13:14:38 -0700 Subject: [PATCH 43/48] Update src/view/translations/en.json Co-Authored-By: Vandy Liu <33995460+vandyliu@users.noreply.github.com> --- src/view/translations/en.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/view/translations/en.json b/src/view/translations/en.json index 92943793f..13f7c55dd 100644 --- a/src/view/translations/en.json +++ b/src/view/translations/en.json @@ -82,7 +82,8 @@ "toolbar-clue-sound-sensor.description": "The CLUE uses a PDM MEMS microphone. PDM is a little like 1-bit PWM. You clock the mic with a 1 MHz - 3 MHz clock rate, and on the data line you'll get a square wave out that syncs with the clock.", "toolbar-clue-sound-sensor.tryItDescription": "If you would like to see this sensor supported, please +1 the feature addition issue on GitHub!", "toolbar-clue-pressure-sensor.title": "Pressure", - "toolbar-clue-pressure-sensor.description": "CLUE uses the BMP280 sensor for barometric pressure. Because pressure changes with altitude, and the pressure measurements are so good, you can also use it as an altimeter with ±1 meter accuracy.", + "toolbar-clue-pressure-sensor.description": "CLUE uses the BMP280 sensor for barometric pressure. Because pressure changes with altitude, you can also use it as an altimeter with ±1 meter accuracy.", + "toolbar-clue-pressure-sensor.tryItDescription": "You can set the pressure here in hectoPascals (hPa).", "toolbar-clue-humidity-sensor.title": "Humidity", "toolbar-clue-humidity-sensor.description": "The SHT30-D sensor has an excellent ±2% relative humidity and ±0.5°C accuracy for most uses.", From 1f37fa9faf5f8f208e97f582fe81406fa98a47b2 Mon Sep 17 00:00:00 2001 From: Kevin Nguyen Date: Mon, 6 Apr 2020 13:14:51 -0700 Subject: [PATCH 44/48] Update src/view/translations/en.json Co-Authored-By: Vandy Liu <33995460+vandyliu@users.noreply.github.com> --- src/view/translations/en.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/view/translations/en.json b/src/view/translations/en.json index 13f7c55dd..d89f68897 100644 --- a/src/view/translations/en.json +++ b/src/view/translations/en.json @@ -59,7 +59,8 @@ "toolbar-microbit-compass-sensor.description": "A digital compass is an input sensor that detects magnetic fields. Your BBC micro:bit has an inbuilt compass that can detect the direction in which it is facing.", "toolbar-microbit-compass-sensor.tryItDescription": "If you would like to see this sensor supported, please +1 the feature addition issue on GitHub!", "toolbar-clue-temperature-sensor.title": "Temperature", - "toolbar-clue-temperature-sensor.description": "CLUE uses the BMP280 sensor, an environmental sensor with temperature.This precision sensor from Bosch is the best low-cost, precision sensing solution for measuring temperature with ±1.0°C accuracy.", + "toolbar-clue-temperature-sensor.description": "CLUE uses the BMP280 sensor, an environmental sensor with temperature. This precision sensor from Bosch is the best low-cost, precision sensing solution for measuring temperature with ±1.0°C accuracy.", + "toolbar-clue-temperature-sensor.tryItDescription": "You can simulate the temperature in your code!", "toolbar-clue-light-sensor.title": "Light/Color Sensor", From f4cf0c1d104870ea5f7f3a99ad4313e2aaae7036 Mon Sep 17 00:00:00 2001 From: Kevin Nguyen Date: Mon, 6 Apr 2020 13:15:04 -0700 Subject: [PATCH 45/48] Update src/view/translations/en.json Co-Authored-By: Vandy Liu <33995460+vandyliu@users.noreply.github.com> --- src/view/translations/en.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/view/translations/en.json b/src/view/translations/en.json index d89f68897..fcdbf5e9d 100644 --- a/src/view/translations/en.json +++ b/src/view/translations/en.json @@ -93,7 +93,8 @@ "toolbar-clue-gesture-sensor.description": "The gesture sensor can detect directional gestures (left to right, right to left, up to down, down to up), but in theory more complicated gestures like zig-zag, clockwise or counterclockwise circle, near to far, etc. could also be detected with additional code. ", "toolbar-clue-gesture-sensor.tryItDescription": "Select a gesture and send it by clicking the button.", "toolbar-clue-proximity-sensor.title": "Proximity", - "toolbar-clue-proximity-sensor.description": "The proximity sensor uses APDS9960 and is able to return how close an object is to the front of the sensor.", + "toolbar-clue-proximity-sensor.description": "The proximity sensor uses APDS9960 and is able to return how close an object is to the front of the sensor. This is a number from 0 to 255 where the higher the number the closer an object is to the sensor. You won't be able to translate this into an absolute value in units like inches or millimeters, you can only see how it changes relative to other values", + "toolbar-clue-proximity-sensor.tryItDescription": "Set relative proximity to the sensor in values from 0 - 255", "toolbar-clue-bluetooth.title": "Bluetooth", "toolbar-clue-bluetooth.description": "You can transmit data over Bluetooth to a computer or mobile device for data plotting and logging, or save it to the built in storage.", From ff9cc72bf29c964e3fc908726f08947da2c8c2ea Mon Sep 17 00:00:00 2001 From: Kevin Nguyen Date: Mon, 6 Apr 2020 13:15:13 -0700 Subject: [PATCH 46/48] Update src/view/translations/en.json Co-Authored-By: Vandy Liu <33995460+vandyliu@users.noreply.github.com> --- src/view/translations/en.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/view/translations/en.json b/src/view/translations/en.json index fcdbf5e9d..960ebe3d8 100644 --- a/src/view/translations/en.json +++ b/src/view/translations/en.json @@ -95,7 +95,8 @@ "toolbar-clue-proximity-sensor.title": "Proximity", "toolbar-clue-proximity-sensor.description": "The proximity sensor uses APDS9960 and is able to return how close an object is to the front of the sensor. This is a number from 0 to 255 where the higher the number the closer an object is to the sensor. You won't be able to translate this into an absolute value in units like inches or millimeters, you can only see how it changes relative to other values", - "toolbar-clue-proximity-sensor.tryItDescription": "Set relative proximity to the sensor in values from 0 - 255", + "toolbar-clue-proximity-sensor.tryItDescription": "Set relative proximity to the sensor in values from 0 - 255, where 0 means very close and 255 means very far.", + "toolbar-clue-bluetooth.title": "Bluetooth", "toolbar-clue-bluetooth.description": "You can transmit data over Bluetooth to a computer or mobile device for data plotting and logging, or save it to the built in storage.", "toolbar-clue-bluetooth.tryItDescription": "If you would like to see this sensor supported, please +1 the feature addition issue on GitHub! ", From cfad2e71f76645f52f63a3f05a8fe5347eb1e277 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Apr 2020 13:49:03 -0700 Subject: [PATCH 47/48] address pr comments --- src/base_circuitpython/base_cp_constants.py | 1 + src/clue/adafruit_clue.py | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/base_circuitpython/base_cp_constants.py b/src/base_circuitpython/base_cp_constants.py index 0949385e4..3736fa333 100644 --- a/src/base_circuitpython/base_cp_constants.py +++ b/src/base_circuitpython/base_cp_constants.py @@ -31,6 +31,7 @@ class CLUE_STATE: CPX = "CPX" CLUE = "CLUE" PIXELS = "pixels" +SHAKE = "shake" CLUE_PIN = "D18" diff --git a/src/clue/adafruit_clue.py b/src/clue/adafruit_clue.py index 11dd03da5..c2809daec 100644 --- a/src/clue/adafruit_clue.py +++ b/src/clue/adafruit_clue.py @@ -229,6 +229,10 @@ def __init__(self): self.__state[CONSTANTS.CLUE_STATE.GYRO_X] = 0 self.__state[CONSTANTS.CLUE_STATE.GYRO_Y] = 0 self.__state[CONSTANTS.CLUE_STATE.GYRO_Z] = 0 + self.button_mapping = { + CONSTANTS.CLUE_STATE.BUTTON_A: "A", + CONSTANTS.CLUE_STATE.BUTTON_B: "B", + } @property def button_a(self): @@ -297,7 +301,7 @@ def shake(self, shake_threshold=30, avg_count=10, total_delay=0.1): :param total_delay: The total time in seconds it takes to obtain avg_count readings from acceleration. (Default 0.1) """ - is_shaken = self.__state[CONSTANTS.CLUE_STATE.GESTURE] == "shake" + is_shaken = self.__state[CONSTANTS.CLUE_STATE.GESTURE] == CONSTANTS.SHAKE return is_shaken @property @@ -418,6 +422,7 @@ def altitude(self): clue.sea_level_pressure = 1015 print("Altitude: {:.1f}m".format(clue.altitude)) """ + # National Oceanic and Atmospheric Administration (NOAA) formula for converting atmospheric pressure to pressure altitude. altitude = 44330 * ( 1.0 - math.pow( @@ -730,13 +735,9 @@ def update_state(self, new_state): # helpers def __update_button(self, button, value): - buttonMapping = { - CONSTANTS.CLUE_STATE.BUTTON_A: "A", - CONSTANTS.CLUE_STATE.BUTTON_B: "B", - } if value: self.__state[CONSTANTS.CLUE_STATE.PRESSED_BUTTONS].add( - buttonMapping[button] + self.button_mapping[button] ) self.__state[button] = value From 5e1ccd60aec51fc8fc62f7ebd1c093676a7757e3 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Apr 2020 14:10:35 -0700 Subject: [PATCH 48/48] added constants to altitude formula --- src/clue/adafruit_clue.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/clue/adafruit_clue.py b/src/clue/adafruit_clue.py index c2809daec..189ab988b 100644 --- a/src/clue/adafruit_clue.py +++ b/src/clue/adafruit_clue.py @@ -423,12 +423,16 @@ def altitude(self): print("Altitude: {:.1f}m".format(clue.altitude)) """ # National Oceanic and Atmospheric Administration (NOAA) formula for converting atmospheric pressure to pressure altitude. - altitude = 44330 * ( - 1.0 + OUTSIDE_MULTIPLER_CONSTANT = 44330 + POWER_CONSTANT = 0.1903 + WHOLE_CONSTANT = 1 + + altitude = OUTSIDE_MULTIPLER_CONSTANT * ( + WHOLE_CONSTANT - math.pow( self.__state[CONSTANTS.CLUE_STATE.PRESSURE] / self.__state[CONSTANTS.CLUE_STATE.SEA_LEVEL_PRESSURE], - 0.1903, + POWER_CONSTANT, ) ) return altitude