Skip to content

Commit

Permalink
implement of infra transceiver
Browse files Browse the repository at this point in the history
add zh-cn lang
  • Loading branch information
xmeow committed Mar 26, 2019
1 parent 2b064ba commit 49ac8da
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
8 changes: 8 additions & 0 deletions _locales/zh/joyfrog-strings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"joyfrog.joyfrog_init|block": "青蛙手柄 初始化",
"joyfrog.on_btn_pressed|block": "当按钮 |%button 按下",
"joyfrog.on_joystick_pushed|block": "当推动摇杆",
"joyfrog.joystick_value|block": "摇杆值 %dir",
"joyfrog.on_infra_data|block": "当收到红外数据",
"joyfrog.infra_send|block": "红外发送 %data"
}
29 changes: 25 additions & 4 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace joyfrog {

let btnCb: { [key: number]: EvtAct } = {};
let joyCb: EvtAct;
let infraRxCb: (data: string) => void;
let joyX: number;
let joyY: number;

Expand Down Expand Up @@ -83,14 +84,14 @@ namespace joyfrog {
if (v.charAt(0) == 'M') {
v = v.substr(1, v.length - 1) + ' '
let cmd = parseInt(seekNext())
let arg1 = parseInt(seekNext())
serial.writeString("# "+ cmd +" "+ arg1)
if (cmd == 2) {
// serial.writeString("$ " + btnCb[arg1])
let arg1 = parseInt(seekNext())
if (btnCb[arg1]) {
btnCb[arg1]();
}
} else if (cmd == 1) {
let arg1 = parseInt(seekNext())
joyX = parseInt(seekNext())
joyY = parseInt(seekNext())
if (btnCb[arg1]) {
Expand All @@ -99,6 +100,10 @@ namespace joyfrog {
if (joyCb){
joyCb();
}
} else if (cmd == 4){
if (infraRxCb){
infraRxCb(seekNext());
}
}
}
})
Expand Down Expand Up @@ -134,16 +139,32 @@ namespace joyfrog {
}

//% blockId=on_joystick_pushed block="on Joystick Pushed"
//% weight=98
//% weight=97
export function on_joystick_pushed(handler: () => void): void {
joyCb = handler;
}

//% blockId=joystick_value block="Joystick %dir"
//% weight=91
//% weight=96
//% blockGap=50
export function joystick_value(dir: JoyDirection): number {
return dir == JoyDirection.X ? joyX : joyY;
}

//% blockId=on_infra_data block="on Infra Rx"
//% weight=89
export function on_infra_data(handler: (data: string) => void): void {
infraRxCb = handler;
}

/**
* Send infra data
* @param data Data to send; eg: ff906f
*/
//% blockId=infra_send block="Infra Tx %data"
//% weight=89
export function infra_send(data: string): void {
serial.writeLine("M3 "+data)
}

}
3 changes: 2 additions & 1 deletion pxt.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"files": [
"README.md",
"main.cpp",
"main.ts"
"main.ts",
"_locales/zh/joyfrog-strings.json"
],
"public": true
}

0 comments on commit 49ac8da

Please sign in to comment.