Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 89 additions & 41 deletions assets/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
return /******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({

/***/ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/scratch3_arduino/index.js":
/*!********************************************************************************************************!*\
!*** ../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/scratch3_arduino/index.js ***!
\********************************************************************************************************/
/***/ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_basics/index.js":
/*!******************************************************************************************************!*\
!*** ../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_basics/index.js ***!
\******************************************************************************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {

// const formatMessage = require('../../../../../../scratch-editor/node_modules/format-message');
const BlockType = __webpack_require__(/*! ../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/block-type */ "../scratch-vm/src/extension-support/block-type.js");
const ArgumentType = __webpack_require__(/*! ../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/argument-type */ "../scratch-vm/src/extension-support/argument-type.js");
const io = __webpack_require__(/*! ./socket.io.min.js */ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/scratch3_arduino/socket.io.min.js");
const io = __webpack_require__(/*! ../socket.io.min.js */ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/socket.io.min.js");

/**
* Url of icon to be displayed at the left edge of each extension block.
Expand All @@ -36,28 +36,21 @@ const iconURI = '';
// eslint-disable-next-line max-len
const menuIconURI = '';
const wsServerURL = "".concat(window.location.protocol, "//").concat(window.location.hostname, ":7000");
class Scratch3Arduino {
class ArduinoBasics {
constructor(runtime) {
this.runtime = runtime;
this.io = io(wsServerURL, {
path: '/socket.io',
transports: ['polling', 'websocket'],
autoConnect: true
});

// TODO: move to ModulinoPeripheral
this._button_pressed = '';
this.io.on('modulino_buttons_pressed', data => {
console.log("Modulino button pressed event received: ".concat(data.btn));
this._button_pressed = data.btn.toUpperCase();
});
}
}
;
Scratch3Arduino.prototype.getInfo = function () {
ArduinoBasics.prototype.getInfo = function () {
return {
id: 'arduino',
name: "Arduino",
id: 'arduinobasics',
name: "Arduino Basics",
menuIconURI: menuIconURI,
blockIconURI: iconURI,
blocks: [{
Expand All @@ -71,7 +64,68 @@ Scratch3Arduino.prototype.getInfo = function () {
defaultValue: '0101010101100010101000100'
}
}
}, {
}]
};
};
ArduinoBasics.prototype.matrixDraw = function (args) {
console.log("Drawing frame on matrix: ".concat(args));
this.io.emit("matrix_draw", {
frame: args.FRAME
});
};
module.exports = ArduinoBasics;

/***/ }),

/***/ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_modulino/index.js":
/*!********************************************************************************************************!*\
!*** ../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_modulino/index.js ***!
\********************************************************************************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {

const BlockType = __webpack_require__(/*! ../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/block-type */ "../scratch-vm/src/extension-support/block-type.js");
const ArgumentType = __webpack_require__(/*! ../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/argument-type */ "../scratch-vm/src/extension-support/argument-type.js");
const io = __webpack_require__(/*! ../socket.io.min.js */ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/socket.io.min.js");

/**
* Url of icon to be displayed at the left edge of each extension block.
* @type {string}
*/
// eslint-disable-next-line max-len
const iconURI = '';

/**
* Url of icon to be displayed in the toolbox menu for the extension category.
* @type {string}
*/
// eslint-disable-next-line max-len
const menuIconURI = '';
const wsServerURL = "".concat(window.location.protocol, "//").concat(window.location.hostname, ":7000");
class ArduinoModulino {
constructor(runtime) {
this.runtime = runtime;
this.io = io(wsServerURL, {
path: '/socket.io',
transports: ['polling', 'websocket'],
autoConnect: true
});

// TODO: move to ModulinoPeripheral
this._button_pressed = '';
this.io.on('modulino_buttons_pressed', data => {
console.log("Modulino button pressed event received: ".concat(data.btn));
this._button_pressed = data.btn.toUpperCase();
});
}
}
;
ArduinoModulino.prototype.getInfo = function () {
return {
id: 'arduinomodulino',
name: "Arduino Modulino",
menuIconURI: menuIconURI,
blockIconURI: iconURI,
blocks: [{
opcode: 'whenModulinoButtonsPressed',
blockType: BlockType.HAT,
text: 'when modulino button [BTN] pressed',
Expand All @@ -89,27 +143,21 @@ Scratch3Arduino.prototype.getInfo = function () {
}
};
};
Scratch3Arduino.prototype.matrixDraw = function (args) {
console.log("Drawing frame on matrix: ".concat(args));
this.io.emit("matrix_draw", {
frame: args.FRAME
});
};
Scratch3Arduino.prototype.whenModulinoButtonsPressed = function (args) {
ArduinoModulino.prototype.whenModulinoButtonsPressed = function (args) {
if (args.BTN === this._button_pressed) {
this._button_pressed = '';
return true;
}
return false;
};
module.exports = Scratch3Arduino;
module.exports = ArduinoModulino;

/***/ }),

/***/ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/scratch3_arduino/socket.io.min.js":
/*!****************************************************************************************************************!*\
!*** ../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/scratch3_arduino/socket.io.min.js ***!
\****************************************************************************************************************/
/***/ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/socket.io.min.js":
/*!***********************************************************************************************!*\
!*** ../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/socket.io.min.js ***!
\***********************************************************************************************/
/***/ (function(module) {

/*!
Expand Down Expand Up @@ -376463,7 +376511,8 @@ const builtinExtensions = {
gdxfor: () => __webpack_require__(/*! ../extensions/scratch3_gdx_for */ "../scratch-vm/src/extensions/scratch3_gdx_for/index.js"),
faceSensing: () => __webpack_require__(/*! ../extensions/scratch3_face_sensing */ "../scratch-vm/src/extensions/scratch3_face_sensing/index.js")
};
builtinExtensions.Scratch3Arduino = () => __webpack_require__(/*! ../extensions/scratch3_arduino */ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/scratch3_arduino/index.js");
builtinExtensions.ArduinoBasics = () => __webpack_require__(/*! ../extensions/arduino_basics */ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_basics/index.js");
builtinExtensions.ArduinoModulino = () => __webpack_require__(/*! ../extensions/arduino_modulino */ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_modulino/index.js");

/**
* @typedef {object} ArgumentInfo - Information about an extension block argument
Expand Down Expand Up @@ -398054,17 +398103,16 @@ const {
__webpack_require__(/*! canvas-toBlob */ "../../node_modules/canvas-toBlob/canvas-toBlob.js");
const RESERVED_NAMES = ['_mouse_', '_stage_', '_edge_', '_myself_', '_random_'];
const CORE_EXTENSIONS = [
// 'motion',
// 'looks',
// 'sound',
// 'events',
// 'control',
// 'sensing',
// 'operators',
// 'variables',
// 'myBlocks'
];
CORE_EXTENSIONS.push('Scratch3Arduino');
// 'motion',
// 'looks',
// 'sound',
// 'events',
// 'control',
// 'sensing',
// 'operators',
// 'variables',
// 'myBlocks'
'ArduinoBasics', 'ArduinoModulino'];

/**
* Handles connections between blocks, stage, and extensions.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// const formatMessage = require('../../../../../../scratch-editor/node_modules/format-message');
const BlockType = require('../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/block-type');
const ArgumentType = require('../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/argument-type');
const io = require('../socket.io.min.js');

/**
* Url of icon to be displayed at the left edge of each extension block.
* @type {string}
*/
// eslint-disable-next-line max-len
const iconURI = '';

/**
* Url of icon to be displayed in the toolbox menu for the extension category.
* @type {string}
*/
// eslint-disable-next-line max-len
const menuIconURI = ''

const wsServerURL = `${window.location.protocol}//${window.location.hostname}:7000`;

class ArduinoBasics {
constructor(runtime) {
this.runtime = runtime;

this.io = io(wsServerURL, {
path: '/socket.io',
transports: ['polling', 'websocket'],
autoConnect: true
});
}
};

ArduinoBasics.prototype.getInfo = function () {
return {
id: 'arduinobasics',
name: "Arduino Basics",
menuIconURI: menuIconURI,
blockIconURI: iconURI,
blocks: [
{
opcode: 'matrixDraw',
blockType: BlockType.COMMAND,
text: 'draw [FRAME] on matrix',
func: 'matrixDraw',
arguments: {
FRAME: {
type: ArgumentType.MATRIX,
defaultValue: '0101010101100010101000100'
}
}
}
]
};
}

ArduinoBasics.prototype.matrixDraw = function (args) {
console.log(`Drawing frame on matrix: ${args}`);
this.io.emit("matrix_draw", { frame: args.FRAME });
};

module.exports = ArduinoBasics;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// const formatMessage = require('../../../../../../scratch-editor/node_modules/format-message');
const BlockType = require('../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/block-type');
const ArgumentType = require('../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/argument-type');
const io = require('./socket.io.min.js');
const io = require('../socket.io.min.js');


/**
* Url of icon to be displayed at the left edge of each extension block.
Expand All @@ -19,7 +19,7 @@ const menuIconURI = ''

const wsServerURL = `${window.location.protocol}//${window.location.hostname}:7000`;

class Scratch3Arduino {
class ArduinoModulino {
constructor(runtime) {
this.runtime = runtime;
this.io = io(wsServerURL, {
Expand All @@ -37,25 +37,13 @@ class Scratch3Arduino {
}
};

Scratch3Arduino.prototype.getInfo = function () {
ArduinoModulino.prototype.getInfo = function () {
return {
id: 'arduino',
name: "Arduino",
id: 'arduinomodulino',
name: "Arduino Modulino",
menuIconURI: menuIconURI,
blockIconURI: iconURI,
blocks: [
{
opcode: 'matrixDraw',
blockType: BlockType.COMMAND,
text: 'draw [FRAME] on matrix',
func: 'matrixDraw',
arguments: {
FRAME: {
type: ArgumentType.MATRIX,
defaultValue: '0101010101100010101000100'
}
}
},
{
opcode: 'whenModulinoButtonsPressed',
blockType: BlockType.HAT,
Expand All @@ -76,17 +64,12 @@ Scratch3Arduino.prototype.getInfo = function () {
};
}

Scratch3Arduino.prototype.matrixDraw = function (args) {
console.log(`Drawing frame on matrix: ${args}`);
this.io.emit("matrix_draw", { frame: args.FRAME });
};

Scratch3Arduino.prototype.whenModulinoButtonsPressed = function (args) {
ArduinoModulino.prototype.whenModulinoButtonsPressed = function (args) {
if (args.BTN === this._button_pressed) {
this._button_pressed = '';
return true;
}
return false;
};

module.exports = Scratch3Arduino;
module.exports = ArduinoModulino;
9 changes: 5 additions & 4 deletions scratch-arduino-extensions/scripts/patch-gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ const path = require("path");
const fs = require("fs");

const extensions = [
{ name: "Scratch3Arduino", directory: "scratch3_arduino" },
{ name: "ArduinoBasics", directory: "arduino_basics" },
{ name: "ArduinoModulino", directory: "arduino_modulino" }
];

// base dir is the 'scratch-arduino-extensions' folder
const BaseDir = path.resolve(__dirname, "../");

extensions.forEach(extension => {
console.log(`${extension.name} (${extension.directory})`);
console.log(`\n${extension.name} (${extension.directory})`);

process.stdout.write("\t - add symbolic link: ");
const scratchVmExtensionsDir = path.resolve(BaseDir,"../scratch-editor/packages/scratch-vm/src/extensions",extension.directory);
Expand Down Expand Up @@ -39,8 +40,8 @@ extensions.forEach(extension => {
if (!vmCode.includes(extension.name)) {
fs.copyFileSync(scratchVmVirtualMachineFile, `${scratchVmVirtualMachineFile}.orig`);
vmCode = vmCode.replace(
/CORE_EXTENSIONS = \[[\s\S]*?\];/,
`$&\n\nCORE_EXTENSIONS.push('${extension.name}');`,
/(CORE_EXTENSIONS = \[[\s\S]*?)\];/,
`$1'${extension.name}',\n];`,
);
fs.writeFileSync(scratchVmVirtualMachineFile, vmCode);
process.stdout.write("done\n");
Expand Down