Created
December 23, 2019 11:41
-
-
Save astagi/b59c53b7d85079960c1b8ef285c97763 to your computer and use it in GitHub Desktop.
R2D2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MSG_ROTATE = [0x0A,0x17,0x0F]; | |
let convertDegreeToHex = (degree) => { | |
var view = new DataView(new ArrayBuffer(4)); | |
view.setFloat32(0, degree); | |
return Array | |
.apply(null, { length: 4 }) | |
.map((_, i) => view.getUint8(i)) | |
} | |
let droidAddress = 'd7:1b:52:17:7b:d6'; | |
connectTheDroid(droidAddress).then(characteristic => { | |
characteristic.subscribe(async(error) => { | |
if (error) { | |
console.error('Error subscribing to char.'); | |
} else { | |
console.log("Wait for init!"); | |
await writePacket(characteristic, buildPacket(MSG_INIT), true, 5000); | |
console.log('Rotate the droid!'); | |
for (let degrees = -160 ; degrees <= 180 ; degrees+=5) { | |
await writePacket( | |
characteristic, | |
buildPacket(MSG_ROTATE, convertDegreeToHex(degrees)), | |
false, | |
); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment