mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-27 21:26:38 +00:00
Update sys-class-rgb-led from 2.1.1 to 3.0.0
Update sys-class-rgb-led from 2.1.1 to 3.0.0 Changelog-entry: Update sys-class-rgb-led from 2.1.1 to 3.0.0 Change-type: patch
This commit is contained in:
parent
a0f07082f2
commit
d3df2fe57e
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import { AnimationFunction, Color, RGBLed } from 'sys-class-rgb-led';
|
import { Animator, AnimationFunction, Color, RGBLed } from 'sys-class-rgb-led';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
isSourceDrive,
|
isSourceDrive,
|
||||||
@ -25,23 +25,7 @@ import * as settings from './settings';
|
|||||||
import { DEFAULT_STATE, observe } from './store';
|
import { DEFAULT_STATE, observe } from './store';
|
||||||
|
|
||||||
const leds: Map<string, RGBLed> = new Map();
|
const leds: Map<string, RGBLed> = new Map();
|
||||||
|
const animator = new Animator([], 10);
|
||||||
function setLeds(
|
|
||||||
drivesPaths: Set<string>,
|
|
||||||
colorOrAnimation: Color | AnimationFunction,
|
|
||||||
frequency?: number,
|
|
||||||
) {
|
|
||||||
for (const path of drivesPaths) {
|
|
||||||
const led = leds.get(path);
|
|
||||||
if (led) {
|
|
||||||
if (Array.isArray(colorOrAnimation)) {
|
|
||||||
led.setStaticColor(colorOrAnimation);
|
|
||||||
} else {
|
|
||||||
led.setAnimation(colorOrAnimation, frequency);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const red: Color = [1, 0, 0];
|
const red: Color = [1, 0, 0];
|
||||||
const green: Color = [0, 1, 0];
|
const green: Color = [0, 1, 0];
|
||||||
@ -61,16 +45,20 @@ function createAnimationFunction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function blink(t: number) {
|
function blink(t: number) {
|
||||||
return Math.floor(t / 1000) % 2;
|
return Math.floor(t) % 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
function breathe(t: number) {
|
function one(_t: number) {
|
||||||
return (1 + Math.sin(t / 1000)) / 2;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const breatheBlue = createAnimationFunction(breathe, blue);
|
|
||||||
const blinkGreen = createAnimationFunction(blink, green);
|
const blinkGreen = createAnimationFunction(blink, green);
|
||||||
const blinkPurple = createAnimationFunction(blink, purple);
|
const blinkPurple = createAnimationFunction(blink, purple);
|
||||||
|
const staticRed = createAnimationFunction(one, red);
|
||||||
|
const staticGreen = createAnimationFunction(one, green);
|
||||||
|
const staticBlue = createAnimationFunction(one, blue);
|
||||||
|
const staticWhite = createAnimationFunction(one, white);
|
||||||
|
const staticBlack = createAnimationFunction(one, black);
|
||||||
|
|
||||||
interface LedsState {
|
interface LedsState {
|
||||||
step: 'main' | 'flashing' | 'verifying' | 'finish';
|
step: 'main' | 'flashing' | 'verifying' | 'finish';
|
||||||
@ -80,6 +68,17 @@ interface LedsState {
|
|||||||
failedDrives: string[];
|
failedDrives: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setLeds(animation: AnimationFunction, drivesPaths: Set<string>) {
|
||||||
|
const rgbLeds: RGBLed[] = [];
|
||||||
|
for (const path of drivesPaths) {
|
||||||
|
const led = leds.get(path);
|
||||||
|
if (led) {
|
||||||
|
rgbLeds.push(led);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { animation, rgbLeds };
|
||||||
|
}
|
||||||
|
|
||||||
// Source slot (1st slot): behaves as a target unless it is chosen as source
|
// Source slot (1st slot): behaves as a target unless it is chosen as source
|
||||||
// No drive: black
|
// No drive: black
|
||||||
// Drive plugged: blue - on
|
// Drive plugged: blue - on
|
||||||
@ -110,6 +109,7 @@ export function updateLeds({
|
|||||||
// Remove selected devices from plugged set
|
// Remove selected devices from plugged set
|
||||||
for (const d of selectedOk) {
|
for (const d of selectedOk) {
|
||||||
plugged.delete(d);
|
plugged.delete(d);
|
||||||
|
unplugged.delete(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove plugged devices from unplugged set
|
// Remove plugged devices from unplugged set
|
||||||
@ -122,38 +122,42 @@ export function updateLeds({
|
|||||||
selectedOk.delete(d);
|
selectedOk.delete(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mapping: Array<{
|
||||||
|
animation: AnimationFunction;
|
||||||
|
rgbLeds: RGBLed[];
|
||||||
|
}> = [];
|
||||||
// Handle source slot
|
// Handle source slot
|
||||||
if (sourceDrive !== undefined) {
|
if (sourceDrive !== undefined) {
|
||||||
if (unplugged.has(sourceDrive)) {
|
if (plugged.has(sourceDrive)) {
|
||||||
unplugged.delete(sourceDrive);
|
|
||||||
// TODO
|
|
||||||
setLeds(new Set([sourceDrive]), breatheBlue, 2);
|
|
||||||
} else if (plugged.has(sourceDrive)) {
|
|
||||||
plugged.delete(sourceDrive);
|
plugged.delete(sourceDrive);
|
||||||
setLeds(new Set([sourceDrive]), blue);
|
mapping.push(setLeds(staticBlue, new Set([sourceDrive])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (step === 'main') {
|
if (step === 'main') {
|
||||||
setLeds(unplugged, black);
|
mapping.push(
|
||||||
setLeds(plugged, black);
|
setLeds(staticBlack, new Set([...unplugged, ...plugged])),
|
||||||
setLeds(selectedOk, white);
|
setLeds(staticWhite, new Set([...selectedOk, ...selectedFailed])),
|
||||||
setLeds(selectedFailed, white);
|
);
|
||||||
} else if (step === 'flashing') {
|
} else if (step === 'flashing') {
|
||||||
setLeds(unplugged, black);
|
mapping.push(
|
||||||
setLeds(plugged, black);
|
setLeds(staticBlack, new Set([...unplugged, ...plugged])),
|
||||||
setLeds(selectedOk, blinkPurple, 2);
|
setLeds(blinkPurple, selectedOk),
|
||||||
setLeds(selectedFailed, red);
|
setLeds(staticRed, selectedFailed),
|
||||||
|
);
|
||||||
} else if (step === 'verifying') {
|
} else if (step === 'verifying') {
|
||||||
setLeds(unplugged, black);
|
mapping.push(
|
||||||
setLeds(plugged, black);
|
setLeds(staticBlack, new Set([...unplugged, ...plugged])),
|
||||||
setLeds(selectedOk, blinkGreen, 2);
|
setLeds(blinkGreen, selectedOk),
|
||||||
setLeds(selectedFailed, red);
|
setLeds(staticRed, selectedFailed),
|
||||||
|
);
|
||||||
} else if (step === 'finish') {
|
} else if (step === 'finish') {
|
||||||
setLeds(unplugged, black);
|
mapping.push(
|
||||||
setLeds(plugged, black);
|
setLeds(staticBlack, new Set([...unplugged, ...plugged])),
|
||||||
setLeds(selectedOk, green);
|
setLeds(staticGreen, selectedOk),
|
||||||
setLeds(selectedFailed, red);
|
setLeds(staticRed, selectedFailed),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
animator.mapping = mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DeviceFromState {
|
interface DeviceFromState {
|
||||||
|
8
npm-shrinkwrap.json
generated
8
npm-shrinkwrap.json
generated
@ -15006,9 +15006,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"sys-class-rgb-led": {
|
"sys-class-rgb-led": {
|
||||||
"version": "2.1.1",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/sys-class-rgb-led/-/sys-class-rgb-led-2.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/sys-class-rgb-led/-/sys-class-rgb-led-3.0.0.tgz",
|
||||||
"integrity": "sha512-CPx01dR22xsqqgpGQ0BcKWf1hCJNTK/Y/gK/hvNEZX5PyuvUzrCYsBWgletzlaruc47RYGi/0be+ZbkIIiQjnA==",
|
"integrity": "sha512-e5vMYgWgDFfXMN67lbTW6niSxzm3eiD8A8hEciUtOUexfYGM6lpd6dH6bERq2LL99mmBYFSxYFZTMWHga4xe7Q==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"tapable": {
|
"tapable": {
|
||||||
@ -17509,4 +17509,4 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -103,7 +103,7 @@
|
|||||||
"string-replace-loader": "^2.3.0",
|
"string-replace-loader": "^2.3.0",
|
||||||
"styled-components": "^5.1.0",
|
"styled-components": "^5.1.0",
|
||||||
"sudo-prompt": "github:zvin/sudo-prompt#7cdede2f0da28fbcc2db48402d7d935f3a825c91",
|
"sudo-prompt": "github:zvin/sudo-prompt#7cdede2f0da28fbcc2db48402d7d935f3a825c91",
|
||||||
"sys-class-rgb-led": "^2.1.1",
|
"sys-class-rgb-led": "^3.0.0",
|
||||||
"tmp": "^0.2.1",
|
"tmp": "^0.2.1",
|
||||||
"ts-loader": "^8.0.0",
|
"ts-loader": "^8.0.0",
|
||||||
"ts-node": "^9.0.0",
|
"ts-node": "^9.0.0",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user