forked from microsoft/microbit-robot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessages.ts
26 lines (24 loc) · 776 Bytes
/
messages.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
namespace robot.messages {
export enum RobotEvents {
None = 0,
Any = ~0,
LineAny = 1 << 0,
LineLeftRight = 1 << 1,
LineLeftMiddleRight = 1 << 2,
LineOuterLeftLeftRightOuterRight = 1 << 3,
ObstacleDistance = 1 << 4,
}
let events: RobotEvents = RobotEvents.None
export function raiseEvent(event: RobotEvents, code: robots.RobotCompactCommand) {
if (events & event)
control.raiseEvent(configuration.ROBOT_EVENT_ID, code & 0xffff)
}
export function onEvent(
event: RobotEvents,
code: robots.RobotCompactCommand,
handler: () => void
) {
events |= event
control.onEvent(configuration.ROBOT_EVENT_ID, code & 0xffff, handler)
}
}