Added support for Duplo color sensor RGB values, reflectivity, and Duplo train system sounds
This commit is contained in:
parent
ecbf489148
commit
28fd0b5578
@ -32,15 +32,47 @@ export class DuploTrainBaseColorSensor extends Device {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Mode.REFLECTIVITY:
|
||||||
|
const reflect = message[4];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emits when the light reflectivity changes.
|
||||||
|
* @event DuploTrainBaseColorSensor#reflect
|
||||||
|
* @type {object}
|
||||||
|
* @param {number} reflect Percentage, from 0 to 100.
|
||||||
|
*/
|
||||||
|
this.notify("reflect", { reflect });
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Mode.RGB:
|
||||||
|
const red = Math.floor(message.readUInt16LE(4) / 4);
|
||||||
|
const green = Math.floor(message.readUInt16LE(6) / 4);
|
||||||
|
const blue = Math.floor(message.readUInt16LE(8) / 4);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emits when the light reflectivity changes.
|
||||||
|
* @event DuploTrainBaseColorSensor#rgb
|
||||||
|
* @type {object}
|
||||||
|
* @param {number} red
|
||||||
|
* @param {number} green
|
||||||
|
* @param {number} blue
|
||||||
|
*/
|
||||||
|
this.notify("rgb", { red, green, blue });
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum Mode {
|
export enum Mode {
|
||||||
COLOR = 0x00
|
COLOR = 0x00,
|
||||||
|
REFLECTIVITY = 0x02,
|
||||||
|
RGB = 0x03
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ModeMap: {[event: string]: number} = {
|
export const ModeMap: {[event: string]: number} = {
|
||||||
"color": Mode.COLOR
|
"color": Mode.COLOR,
|
||||||
|
"reflect": Mode.REFLECTIVITY,
|
||||||
|
"rgb": Mode.RGB
|
||||||
};
|
};
|
||||||
|
@ -28,8 +28,14 @@ export class DuploTrainBaseSpeaker extends Device {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public playTone (tone: number) {
|
||||||
|
this.subscribe(Mode.TONE);
|
||||||
|
this.writeDirect(0x02, Buffer.from([tone]));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum Mode {
|
export enum Mode {
|
||||||
SOUND = 0x01
|
SOUND = 0x01,
|
||||||
|
TONE = 0x02
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user