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
6 changes: 3 additions & 3 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ tasks:
scratch:install:
dir: scratch-editor
cmds:
- npm install
- npm build
- npm install
- npm run build

scratch:patch:
cmds:
Expand All @@ -54,4 +54,4 @@ tasks:
- cp build/index.html ../../../assets/index.html
- cp build/gui.js ../../../assets/gui.js
## copy (some) of the static files
- mkdir -p ../../../assets/static/blocks-media && cp -r build/static/blocks-media ../../../assets/static/
- mkdir -p ../../../assets/static/blocks-media && cp -r build/static/blocks-media ../../../assets/static/
33 changes: 5 additions & 28 deletions assets/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,10 @@ class Scratch3Arduino {
});

// TODO: move to ModulinoPeripheral
this._button_a_pressed = false;
this._button_b_pressed = false;
this._button_c_pressed = false;
this._button_pressed = '';
this.io.on('modulino_buttons_pressed', data => {
console.log("Modulino button pressed event received: ".concat(data.btn));
if (data.btn.toUpperCase() == 'A') {
this._button_a_pressed = true;
this._button_b_pressed = false;
this._button_c_pressed = false;
return;
}
if (data.btn.toUpperCase() == 'B') {
this._button_a_pressed = false;
this._button_b_pressed = true;
this._button_c_pressed = false;
return;
}
if (data.btn.toUpperCase() == 'C') {
this._button_a_pressed = false;
this._button_b_pressed = false;
this._button_c_pressed = true;
return;
}
return;
this._button_pressed = data.btn.toUpperCase();
});
}
}
Expand Down Expand Up @@ -116,12 +96,9 @@ Scratch3Arduino.prototype.matrixDraw = function (args) {
});
};
Scratch3Arduino.prototype.whenModulinoButtonsPressed = function (args) {
if (args.BTN === 'A') {
return this._button_a_pressed;
} else if (args.BTN === 'B') {
return this._button_b_pressed;
} else if (args.BTN === 'C') {
return this._button_c_pressed;
if (args.BTN === this._button_pressed) {
this._button_pressed = '';
return true;
}
return false;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,109 +8,85 @@ const io = require('./socket.io.min.js');
* @type {string}
*/
// eslint-disable-next-line max-len
const iconURI = '';
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 menuIconURI = ''

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

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

// TODO: move to ModulinoPeripheral
this._button_a_pressed = false;
this._button_b_pressed = false;
this._button_c_pressed = false;

this.io.on('modulino_buttons_pressed', (data) => {
console.log(`Modulino button pressed event received: ${data.btn}`);
if (data.btn.toUpperCase() == 'A'){
this._button_a_pressed = true;
this._button_b_pressed = false;
this._button_c_pressed = false;
return;
}
if (data.btn.toUpperCase() == 'B'){
this._button_a_pressed = false;
this._button_b_pressed = true;
this._button_c_pressed = false;
return;
}
if (data.btn.toUpperCase() == 'C'){
this._button_a_pressed = false;
this._button_b_pressed = false;
this._button_c_pressed = true;
return;
}
return;
});
}
// TODO: move to ModulinoPeripheral
this._button_pressed = '';
this.io.on('modulino_buttons_pressed', (data) => {
console.log(`Modulino button pressed event received: ${data.btn}`);
this._button_pressed = data.btn.toUpperCase();
});
}
};

Scratch3Arduino.prototype.getInfo = function () {
return {
id: 'arduino',
name: "Arduino",
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,
text: 'when modulino button [BTN] pressed',
func: 'whenModulinoButtonsPressed',
arguments: {
BTN: {
type: ArgumentType.STRING,
menu: 'modulinoButtons',
defaultValue: "A"
}
}
},
],
menus: {
modulinoButtons: ["A", "B", "C"]
}
};
return {
id: 'arduino',
name: "Arduino",
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,
text: 'when modulino button [BTN] pressed',
func: 'whenModulinoButtonsPressed',
arguments: {
BTN: {
type: ArgumentType.STRING,
menu: 'modulinoButtons',
defaultValue: "A"
}
}
},
],
menus: {
modulinoButtons: ["A", "B", "C"]
}
};
}

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

Scratch3Arduino.prototype.whenModulinoButtonsPressed = function (args) {
if (args.BTN === 'A') {
return this._button_a_pressed
} else if (args.BTN === 'B') {
return this._button_b_pressed
} else if (args.BTN === 'C') {
return this._button_c_pressed;
}
return false;
if (args.BTN === this._button_pressed) {
this._button_pressed = '';
return true;
}
return false;
};

module.exports = Scratch3Arduino;
module.exports = Scratch3Arduino;