Mario gesture support

This commit is contained in:
Nathan Kellenicki 2020-12-23 10:24:59 -08:00
parent 5094c8269f
commit df4ea5dd86
2 changed files with 16 additions and 4 deletions

View File

@ -18,8 +18,8 @@ poweredUP.on("discover", async (hub) => { // Wait to discover hubs
await mario.connect(); // Connect to Mario await mario.connect(); // Connect to Mario
console.log(`Connected to Mario!`); console.log(`Connected to Mario!`);
mario.on("accel", (_, { x, y, z }) => { mario.on("gesture", (_, { gesture }) => {
console.log("Accelerometer", x, y, z); console.log("Gesture", gesture);
}); });
mario.on("pants", (_, { pants }) => { mario.on("pants", (_, { pants }) => {

View File

@ -32,15 +32,27 @@ export class MarioAccelerometer extends Device {
const z = message[6]; const z = message[6];
this.notify("accel", { x, y, z }); this.notify("accel", { x, y, z });
break; break;
case Mode.GEST:
/**
* Emits when a gesture is detected
* @event MarioAccelerometer#gest
* @type {object}
* @param {number} gesture
*/
const gesture = message[4];
this.notify("gesture", { gesture });
break;
} }
} }
} }
export enum Mode { export enum Mode {
ACCEL = 0x00 ACCEL = 0x00,
GEST = 0x01,
} }
export const ModeMap: {[event: string]: number} = { export const ModeMap: {[event: string]: number} = {
"accel": Mode.ACCEL "accel": Mode.ACCEL,
"gesture": Mode.GEST,
}; };