Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset all circuit playground components #28593

Merged
merged 2 commits into from Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions apps/src/lib/kits/maker/CircuitPlaygroundBoard.js
Expand Up @@ -9,6 +9,7 @@ import Firmata from 'firmata';
import {
createCircuitPlaygroundComponents,
destroyCircuitPlaygroundComponents,
resetCircuitPlaygroundComponents,
componentConstructors
} from './PlaygroundComponents';
import {
Expand Down Expand Up @@ -205,10 +206,7 @@ export default class CircuitPlaygroundBoard extends EventEmitter {
}

reset() {
const {led, buzzer, colorLeds} = this.prewiredComponents_;
led.off();
colorLeds.forEach(led => led.off());
buzzer.off();
resetCircuitPlaygroundComponents(this.prewiredComponents_);
}

/**
Expand Down
38 changes: 38 additions & 0 deletions apps/src/lib/kits/maker/PlaygroundComponents.js
Expand Up @@ -69,6 +69,44 @@ export function createCircuitPlaygroundComponents(board) {
});
}

export function resetCircuitPlaygroundComponents(components) {
if (components.colorLeds) {
components.colorLeds.forEach(led => {
led.color('white');
led.intensity(100);
led.stop();
led.off();
});
}

if (components.led) {
components.led.intensity(100);
components.led.off();
components.led.stop();
}

if (components.buzzer) {
components.buzzer.off();
components.buzzer.stop();
}

if (components.soundSensor) {
components.soundSensor.disable();
}

if (components.lightSensor) {
components.lightSensor.disable();
}

if (components.tempSensor) {
components.tempSensor.disable();
}

if (components.accelerometer) {
components.accelerometer.stop();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems correct. It'd be nice to deduplicate this code with destroyCircuitPlaygroundComponents, below.


/**
* De-initializes any Johnny-Five components that might have been created
* by createCircuitPlaygroundComponents
Expand Down