Skip to content

Commit

Permalink
adapt to pxt5 of makecode mbit~
Browse files Browse the repository at this point in the history
  • Loading branch information
xmeow committed Jun 19, 2019
1 parent 7f6065e commit e410bf9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
16 changes: 0 additions & 16 deletions main.cpp

This file was deleted.

25 changes: 14 additions & 11 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ namespace joyfrog {

type EvtAct = () => void;

// let btnCb: { [key: number]: EvtAct } = {};
let btnCb: { [key: number]: EvtAct } = {};

let btnCb: KeyHandler[] = []
// let btnCb: KeyHandler[] = []

export class KeyHandler {
key: number;
Expand Down Expand Up @@ -104,25 +104,24 @@ namespace joyfrog {
if (cmd == 2) {
// serial.writeString("$ " + btnCb[arg1])
let arg1 = parseInt(seekNext())
for (let i=0;i<btnCb.length;i++){
if (btnCb[i].key == arg1){
/*
for (let i = 0; i < btnCb.length; i++) {
if (btnCb[i].key == arg1) {
btnCb[i].fn()
}
}
/*
*/
if (btnCb[arg1]) {
btnCb[arg1]();
}
*/
} else if (cmd == 1) {
let arg1 = parseInt(seekNext())
joyX = -255 - parseInt(seekNext())
joyY = -255 - parseInt(seekNext())
/*
if (btnCb[arg1]) {
btnCb[arg1]();
}
*/
}
/*
for (let i = 0; i < btnCb.length; i++) {
if (btnCb[i].key == arg1) {
btnCb[i].fn()
Expand All @@ -131,6 +130,7 @@ namespace joyfrog {
if (joyCb) {
joyCb();
}
*/
} else if (cmd == 4) {
if (infraRxCb) {
infraRxCb(seekNext());
Expand Down Expand Up @@ -167,7 +167,8 @@ namespace joyfrog {
BaudRate.BaudRate115200
)
basic.pause(100)
setSerialBuffer(64);
serial.setTxBufferSize(64)
serial.setRxBufferSize(64)
serial.readString()
serial.writeString('\n\n')
basic.pause(100)
Expand All @@ -182,11 +183,13 @@ namespace joyfrog {
//% blockId=on_btn_pressed block="on Button |%button pressed"
//% weight=98
export function on_btn_pressed(button: JoyBtns, handler: () => void): void {
// btnCb[button] = handler;
btnCb[button] = handler;
/*
let btnHandler = new KeyHandler()
btnHandler.fn = handler
btnHandler.key = button
btnCb.push(btnHandler)
*/
}

//% blockId=on_joystick_pushed block="on Joystick Pushed"
Expand Down
3 changes: 1 addition & 2 deletions pxt.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"name": "joyfrog",
"version": "0.1.3",
"version": "0.1.4",
"description": "Extension for Kittenbot Joystick Frog",
"license": "MIT",
"dependencies": {
"core": "*"
},
"files": [
"README.md",
"main.cpp",
"main.ts",
"_locales/zh/joyfrog-strings.json"
],
Expand Down

0 comments on commit e410bf9

Please sign in to comment.