Skip to content

Commit

Permalink
Add ioctl block
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed Feb 18, 2024
1 parent cafe416 commit 29e060a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/blocks/posix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as Blockly from 'blockly/core';

// Create a custom block
// POSIX Open Block
const posixOpen = {
'type': 'posix_open',
'message0': 'Open File %1 with color %2',
Expand All @@ -28,7 +28,7 @@ const posixOpen = {
'helpUrl': '',
};

// Create a custom block
// POSIX Close Block
const posixClose = {
'type': 'posix_close',
'message0': 'Close File Descriptor %1 with color %2',
Expand All @@ -49,10 +49,33 @@ const posixClose = {
'colour': 160,
'tooltip': '',
'helpUrl': '',
};

};

// POSIX Ioctl Block
const posixIoctl = {
'type': 'posix_ioctl',
'message0': 'IOCtl File Descriptor %1 with color %2',
'args0': [
{
'type': 'input_value',
'name': 'TEXT',
'check': 'String',
},
{
'type': 'input_value',
'name': 'COLOR',
'check': 'Colour',
},
],
'previousStatement': null,
'nextStatement': null,
'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]);
[posixOpen, posixClose, posixIoctl]);
14 changes: 14 additions & 0 deletions src/generators/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,17 @@ forBlock['posix_close'] = function (
const code = `// os.close(${text});\n`;
return code;
};

// POSIX Ioctl Block
forBlock['posix_ioctl'] = function (
block: Blockly.Block,
generator: Blockly.CodeGenerator
) {
const text = generator.valueToCode(block, 'TEXT', Order.NONE) || "''";
const color =
generator.valueToCode(block, 'COLOR', Order.ATOMIC) || "'#ffffff'";

// Generate the function call for this block.
const code = `// os.ioctl(${text});\n`;
return code;
};
23 changes: 23 additions & 0 deletions src/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,29 @@ export const toolbox = {
},
},
},
// POSIX Ioctl Block
{
'kind': 'block',
'type': 'posix_ioctl',
'inputs': {
'TEXT': {
'shadow': {
'type': 'text',
'fields': {
'TEXT': 'abc',
},
},
},
'COLOR': {
'shadow': {
'type': 'colour_picker',
'fields': {
'COLOUR': '#aa00cc',
},
},
},
},
},
],
},
{
Expand Down

0 comments on commit 29e060a

Please sign in to comment.