Skip to content

Commit b41aeba

Browse files
committed
refactor: improve formatting and structure in Modulino extension files
1 parent 9d79bf2 commit b41aeba

File tree

5 files changed

+67
-51
lines changed

5 files changed

+67
-51
lines changed

python/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def on_matrix_draw(_, data):
1717
def on_modulino_button_pressed(btn):
1818
ui.send_message("modulino_buttons_pressed", {"btn": btn})
1919

20+
2021
Bridge.provide("modulino_button_pressed", on_modulino_button_pressed)
2122

2223
App.run()
23-
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { createTestSuite } from "$testing";
2-
import Extension from '.';
2+
import Extension from ".";
33

4-
createTestSuite({ Extension, __dirname },
5-
{
6-
unitTests: undefined,
7-
integrationTests: undefined
8-
}
9-
);
4+
createTestSuite({ Extension, __dirname }, {
5+
unitTests: undefined,
6+
integrationTests: undefined,
7+
});
Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { scratch, extension, type ExtensionMenuDisplayDetails, type BlockUtilityWithID, type Environment } from "$common";
1+
import {
2+
type BlockUtilityWithID,
3+
type Environment,
4+
extension,
5+
type ExtensionMenuDisplayDetails,
6+
scratch,
7+
} from "$common";
28
import { io, type Socket } from "socket.io-client";
39
import ButtonArgument from "./ButtonArgument.svelte";
410

@@ -17,16 +23,15 @@ export default class ModulinoButtons extends extension({
1723
description: "Control your Arduino Modulinos",
1824
iconURL: "modulinos.png", // png
1925
insetIconURL: "modulino-buttons.svg", // svg
20-
tags :["Arduino UNO Q"],
26+
tags: ["Arduino UNO Q"],
2127
blockColor: "#00878F",
2228
menuColor: "#8C7965",
2329
menuSelectColor: "#62AEB2",
2430
}, "customArguments") {
31+
private socket: Socket | null = null;
32+
private button_pressed: string = "";
2533

26-
private socket: Socket | null = null;
27-
private button_pressed:string = "";
28-
29-
init(env: Environment) {
34+
init(env: Environment) {
3035
const arduinoBoardHost = getArduinoBoardHost();
3136
var serverURL = `wss://${arduinoBoardHost}:7000`;
3237

@@ -36,23 +41,21 @@ export default class ModulinoButtons extends extension({
3641
autoConnect: true,
3742
});
3843

39-
this.socket.on("connect", () => {
44+
this.socket.on("connect", () => {
4045
console.log(`Connected to Arduino UNO Q`, serverURL);
4146
});
4247

4348
this.socket.on("disconnect", (reason) => {
4449
console.log(`Disconnected from Arduino UNO Q: ${reason}`);
4550
});
4651

47-
this.socket.on("modulino_buttons_pressed", (data) => {
52+
this.socket.on("modulino_buttons_pressed", (data) => {
4853
console.log(`Modulino button pressed event received: ${data.btn}`);
4954
this.button_pressed = data.btn.toUpperCase();
5055
});
51-
5256
}
5357

54-
55-
@(scratch.hat(function (instance, tag) {
58+
@scratch.hat(function(instance, tag) {
5659
const arg = instance.makeCustomArgument({
5760
component: ButtonArgument,
5861
initial: {
@@ -61,12 +64,12 @@ export default class ModulinoButtons extends extension({
6164
},
6265
});
6366
return tag`When modulino button ${arg} pressed`;
64-
}))
67+
})
6568
whenModulinoButtonsPressed(button: string, util: BlockUtilityWithID) {
66-
if ( button.toUpperCase() === this.button_pressed) {
67-
this.button_pressed = "";
68-
return true;
69+
if (button.toUpperCase() === this.button_pressed) {
70+
this.button_pressed = "";
71+
return true;
6972
}
7073
return false;
7174
}
72-
}
75+
}

scratch-prg-extensions/extensions/src/arduino_modulino/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
"dependencies": {
1616
"socket.io-client": "^4.8.1"
1717
}
18-
}
18+
}

scratch-prg-extensions/extensions/src/arduino_modulino/pnpm-lock.yaml

Lines changed: 41 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)