Skip to content

Commit

Permalink
add onGesture and onGesture
Browse files Browse the repository at this point in the history
  • Loading branch information
baorepo committed Jul 31, 2019
1 parent 2ee4f55 commit 43674e0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ A Microsoft MakeCode package for for Seeed Studio Grove module.
get gesture model.

```blocks
grove.onGesture(GroveGesture.Up, () => {
basic.showString("Up");
})
grove.onGesture(GroveGesture.Down, () => {
basic.showString("Down");
})
grove.initGesture()
basic.forever(function () {
if (grove.getGestureModel() == 1) {
Expand Down
45 changes: 45 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,4 +538,49 @@ namespace grove {
return joystick.read(xpin, ypin);
}


/**
* Do something when a gesture is detected by Grove - Gesture
* @param gesture type of gesture to detect
* @param handler code to run
*/
//% blockId=grove_gesture_create_event block="on Gesture|%gesture"
export function onGesture(gesture: GroveGesture, handler: () => void) {
control.onEvent(gestureEventId, gesture, handler);
paj7620.init();
control.inBackground(() => {
while(true) {
const gesture = paj7620.read();
if (gesture != lastGesture) {
lastGesture = gesture;
control.raiseEvent(gestureEventId, lastGesture);
}
basic.pause(50);
}
})
}


/**
* Do something when a key is detected by Grove - Thumb Joystick
* @param key type of joystick to detect
* @param xpin
* @param ypin
* @param handler code to run
*/
//% blockId=grove_joystick_create_event block="on Key|%key"
export function onJoystick(key: GroveJoystickKey, xpin: AnalogPin, ypin: AnalogPin, handler: () => void) {
control.onEvent(joystickEventID, key, handler);
control.inBackground(() => {
while(true) {
const key = joystick.read(xpin, ypin);
if (key != lastJoystick) {
lastJoystick = key;
control.raiseEvent(joystickEventID, lastJoystick);
}
basic.pause(50);
}
})

}
}
2 changes: 1 addition & 1 deletion pxt.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Grove",
"version": "0.1.4",
"version": "0.1.5",
"description": "A Microsoft MakeCode package for Seeed Studio Grove module",
"license": "MIT",
"dependencies": {
Expand Down

0 comments on commit 43674e0

Please sign in to comment.