@openhps/sphero
Version:
Open Hybrid Positioning System - Sphero component
35 lines • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../utils");
const types_1 = require("./types");
const encodeNumberLM = (n) => {
const absN = Math.abs(n * 3968);
const nFirstHalfByte1 = n === 0 ? 0 : n > 0 ? 0x30 : 0xb0;
const nSecondHalfByte1 = (absN >> 8) & 0x0f;
return [
nFirstHalfByte1 | nSecondHalfByte1,
absN & 0xff,
(0 >> 8) & 0xff,
0 & 0xff
];
};
exports.default = (generator) => {
const encode = generator(types_1.DeviceId.driving);
return {
drive: (speed, heading, flags) => encode({
commandId: types_1.DrivingCommandIds.driveWithHeading,
targetId: 0x12,
payload: [
speed,
(heading >> 8) & 0xff,
heading & 0xff,
(0, utils_1.combineFlags)(flags)
]
}),
driveAsRc: (heading, speed) => encode({
commandId: types_1.DrivingCommandIds.driveAsRc,
payload: [...encodeNumberLM(heading), ...encodeNumberLM(speed)]
})
};
};
//# sourceMappingURL=driving.js.map