Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make sure leaphyProgram() function is always called last #109

Merged
merged 3 commits into from
Jun 16, 2024
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"dist",
"media"
],
"version": "3.0.3",
"version": "3.0.4",
"description": "Leaphy custom Blockly blocks and arduino code generator",
"name": "@leaphy-robotics/leaphy-blocks"
}
12 changes: 7 additions & 5 deletions src/generators/arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,18 @@ export class Arduino extends Blockly.Generator {
if (includes.length) includes.push("\n");
if (definitions.length) definitions.push("\n");

// userSetupCode added at the end of the setup function without leading spaces
if (this.setups_["userSetupCode"])
this.setups_["userSetupCode"] =
`\n ${this.setups_["userSetupCode"]}`;
// userSetupCode is always added at the very end of the setup function
const userSetup = this.setups_["userSetupCode"] || "";
delete this.setups_["userSetupCode"];
const setups = Object.values(this.setups_);

this.nameDB_?.reset();

const allDefs = includes.join("\n") + definitions.join("\n");
const setup = "void setup() {\n\t" + setups.join("\n ") + "\n}\n\n";
const setup =
"void setup() {\n\t" +
setups.join("\n ") +
`\n ${userSetup}\n}\n\n`;
const loop = "void loop() {\n " + code.replace(/\n/g, "\n ") + "\n}";

return allDefs + setup + loop;
Expand Down
Loading