Skip to content

Commit

Permalink
Add sleep block
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed Feb 20, 2024
1 parent 2f4bfa8 commit 43d892c
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 8 deletions.
100 changes: 93 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,102 @@ TODO: [Change the Types from String to Number](https://github.com/lupyuen/nuttx-
},
"next": {
"block": {
"type": "posix_close",
"id": "EC[Xwv%F4i0/(TKVDq[a",
"type": "posix_sleep",
"id": "ruh/q4F7dW*CQ,5J]E%w",
"inputs": {
"TEXT": {
"MS": {
"block": {
"type": "variables_get",
"id": "(g?H1/q8Lei7d0WHqv5)",
"type": "math_number",
"id": "9~q0@ABEg4VXP:1HN-$1",
"fields": {
"VAR": {
"id": "A/TX@37C_h*^vbRp@1fz"
"NUM": 60000
}
}
}
},
"next": {
"block": {
"type": "variables_set",
"id": "e;BNsjvbN}9vTTc[O#bY",
"fields": {
"VAR": {
"id": "xH3`F~]tadlX:/zKQ!Xx"
}
},
"inputs": {
"VALUE": {
"block": {
"type": "posix_ioctl",
"id": "-G5x~Y4iAyVUAWuwNh#H",
"inputs": {
"FD": {
"block": {
"type": "variables_get",
"id": "vtt5Gid0B|iK![$4Ct*D",
"fields": {
"VAR": {
"id": "A/TX@37C_h*^vbRp@1fz"
}
}
}
},
"REQ": {
"block": {
"type": "variables_get",
"id": "pd~f}Oqz2(`o3Oz;8ax`",
"fields": {
"VAR": {
"id": ":,DB,f}1q3KOBim#j66["
}
}
}
},
"ARG": {
"block": {
"type": "math_number",
"id": "OS(uQV)!%iqZ=N}s1H(L",
"fields": {
"NUM": 0
}
}
}
}
}
}
},
"next": {
"block": {
"type": "posix_sleep",
"id": "{X9leD=Rgr4=o5E2(#Z,",
"inputs": {
"MS": {
"block": {
"type": "math_number",
"id": "eEq(yXcGPbVtZT|CunT0",
"fields": {
"NUM": 60000
}
}
}
},
"next": {
"block": {
"type": "posix_close",
"id": "EC[Xwv%F4i0/(TKVDq[a",
"inputs": {
"TEXT": {
"block": {
"type": "variables_get",
"id": "(g?H1/q8Lei7d0WHqv5)",
"fields": {
"VAR": {
"id": "A/TX@37C_h*^vbRp@1fz"
}
}
}
}
}
}
}
}
}
Expand Down
21 changes: 20 additions & 1 deletion src/blocks/posix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,27 @@ const posixIoctl = {
'helpUrl': '',
};

// POSIX Sleep Block
const posixSleep = {
'type': 'posix_sleep',
'message0': 'Sleep (ms) %1',
'args0': [
{
'type': 'input_value',
'name': 'MS',
'check': 'Number',
},
],
'previousStatement': null,
'nextStatement': null,
'output': 'Number',
'colour': 160,
'tooltip': '',
'helpUrl': '',
};

// Create the block definitions for the JSON-only blocks.
// This does not register their definitions with Blockly.
// This file has no side effects!
export const posixBlocks = Blockly.common.createBlockDefinitionsFromJsonArray(
[posixOpen, posixClose, posixIoctl]);
[posixOpen, posixClose, posixIoctl, posixSleep]);
13 changes: 13 additions & 0 deletions src/generators/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ forBlock['posix_ioctl'] = function (
return [code, Order.ATOMIC];
};

// POSIX Sleep Block
forBlock['posix_sleep'] = function (
block: Blockly.Block,
generator: Blockly.CodeGenerator
) {
const ms = generator.valueToCode(block, 'MS', Order.NONE) || "''";

// Generate the function call for this block.
const code = `os.sleep(${ms});\n`;
return code;
};

// Demo: Add Text Block
forBlock['add_text'] = function (
block: Blockly.Block,
generator: Blockly.CodeGenerator
Expand Down
7 changes: 7 additions & 0 deletions src/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,13 @@ export const toolbox = {
'inputs': {
},
},
// POSIX Sleep Block
{
'kind': 'block',
'type': 'posix_sleep',
'inputs': {
},
},
],
},
{
Expand Down

0 comments on commit 43d892c

Please sign in to comment.