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

Commit

Permalink
Separate accelerometer from gestures
Browse files Browse the repository at this point in the history
  • Loading branch information
xnkevinnguyen committed Apr 1, 2020
1 parent 4fa9340 commit 4c32700
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 82 deletions.
44 changes: 44 additions & 0 deletions src/view/components/clue/Clue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
];
29 changes: 16 additions & 13 deletions src/view/components/toolbar/SensorModalUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
<div className="link-parent">
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 = (
Expand Down
6 changes: 3 additions & 3 deletions src/view/components/toolbar/modalContent/ClueModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLSelectElement>) => void,
Expand Down Expand Up @@ -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 => {
Expand All @@ -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 => {
Expand Down
68 changes: 2 additions & 66 deletions src/view/components/toolbar/motion/Accelerometer.tsx
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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<IProps> {
private sensorButtonRef: React.RefObject<SensorButton> = React.createRef();
render() {
return (
<div className="accelerometer">
<br />
<div
className="gesture"
style={{
display: "flex",
flexDirection: "column",
justifyContent: "space-between",
height: "75px",
}}
>
<Dropdown
name="gesture selection"
options={GESTURES}
onSelect={this.props.onSelectGestures}
/>
<SensorButton
ref={this.sensorButtonRef}
label={GESTURE_BUTTON_MESSAGE}
onMouseDown={() => {
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"
/>
</div>
<br />
<div>
<p>{MANUAL_ACCELERATION_MESSAGE}</p>
</div>

<ThreeDimensionSlider
axisProperties={MOTION_SENSOR_PROPERTIES}
onUpdateValue={this.props.onUpdateValue}
Expand All @@ -107,25 +64,4 @@ export class Accelerometer extends React.Component<IProps> {
</div>
);
}
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);
}
}
};
}
70 changes: 70 additions & 0 deletions src/view/components/toolbar/motion/Gesture.tsx
Original file line number Diff line number Diff line change
@@ -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<HTMLSelectElement>) => void;
onSendGesture?: (isActive: boolean) => void;
}
export class Gesture extends React.Component<IProps> {
private sensorButtonRef: React.RefObject<SensorButton> = React.createRef();
render() {
return (
<div
className="gesture"
style={{
display: "flex",
flexDirection: "column",
justifyContent: "space-between",
height: "75px",
}}
>
<Dropdown
name="gesture selection"
options={GESTURES}
onSelect={this.props.onSelectGestures}
/>
<SensorButton
ref={this.sensorButtonRef}
label={GESTURE_BUTTON_MESSAGE}
onMouseDown={() => {
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"
/>
</div>
);
}
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);
}
}
};
}

0 comments on commit 4c32700

Please sign in to comment.