Skip to content

Commit

Permalink
Improve memory management when unloading apps
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Livesey committed Feb 3, 2021
1 parent 5f114a7 commit 9d965e6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 26 deletions.
8 changes: 3 additions & 5 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
Licenced by the Subnodal Open-Source Licence, which can be found at LICENCE.md.
*/

const PIN_REFERENCES = [A0, A1, A2, A3, A4, A5];

exports._communicators = "";

exports.OS_VERSION = require("config").OS_VERSION;
Expand Down Expand Up @@ -262,8 +260,8 @@ exports.br = {
*/
exports.readPin = function(pin) {
typePin(pin);
return analogRead(PIN_REFERENCES[pin]);

return analogRead(pin + 14); // Analog pins start at 14
};

/*
Expand All @@ -281,7 +279,7 @@ exports.writePin = function(pin, value) {
throw new TypeError("Value must be a positive real number within the bounds 0 to 1 inclusive");
}

analogWrite(PIN_REFERENCES[pin], value);
analogWrite(pin + 14, value); // Analog pins start at 14
};

/*
Expand Down
16 changes: 15 additions & 1 deletion appload.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class ErrorScreen extends uiScreen {

start() {
print("<error type=\"app\">" + this.errorMessage + "</error>");

g.setBgColor(0);
g.setColor(1);
}

tick(event) {
Expand Down Expand Up @@ -147,6 +150,8 @@ class AppScreen extends uiScreen {
";[start,loop,_status]"
);

program = "";

return {
start: __objects[0] || function() {},
loop: __objects[1] || function() {},
Expand Down Expand Up @@ -199,6 +204,12 @@ class AppScreen extends uiScreen {
this.close();
}
}

close() {
Modules.removeCached("api");

super.close();
}
}

exports.getApps = function() {
Expand All @@ -224,10 +235,13 @@ exports.getHomeScreenIcons = function(homeScreen) {

iconData.push({
text: manifest["name"][require("l10n").getLocaleCode()] || apps[i].split(".")[0],
icon: typeof(manifest["icon"]) == "string" ? {width: 44, height: 17, buffer: atob(manifest["icon"])} : require("images").defaultIcon,
icon: typeof(manifest["icon"]) == "string" ? {width: 44, height: 17, buffer: atob(manifest["icon"])} : null,
action: function() {
try {
homeScreen.open(new AppScreen(require("Storage").read(apps[i])));

g.setBgColor(0);
g.setColor(1);
} catch (e) {
print(e);
}
Expand Down
4 changes: 2 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
Licenced by the Subnodal Open-Source Licence, which can be found at LICENCE.md.
*/

exports.OS_VERSION = "0.2.3";
exports.OS_VERNUM = 3;
exports.OS_VERSION = "0.2.4";
exports.OS_VERNUM = 4;

exports.properties = {
language: "en_GB",
Expand Down
38 changes: 20 additions & 18 deletions home.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@

var uiScreen = require("ui").Screen;

const ICON_PLACEMENT = new Uint8Array([
17, 10,
65, 10,
17, 31,
65, 31
]);

exports.HomeScreen = class extends uiScreen {
constructor(items) {
super();
Expand All @@ -23,13 +30,6 @@ exports.HomeScreen = class extends uiScreen {
}

tick(event) {
var iconPlacement = [
[17, 10],
[65, 10],
[17, 31],
[65, 31]
];

if (event.buttons.tl == 1) {
this.close();
}
Expand Down Expand Up @@ -89,7 +89,7 @@ exports.HomeScreen = class extends uiScreen {

require("display").drawCharsFromCell(textToShow, 2, 3);

g.fillRect(iconPlacement[i][0] + 1, iconPlacement[i][1] + 1, iconPlacement[i][0] + 44, iconPlacement[i][1] + 17);
g.fillRect(ICON_PLACEMENT[i * 2] + 1, ICON_PLACEMENT[i * 2 + 1] + 1, ICON_PLACEMENT[i * 2] + 44, ICON_PLACEMENT[i * 2 + 1] + 17);

g.setBgColor(1);
g.setColor(0);
Expand All @@ -98,22 +98,24 @@ exports.HomeScreen = class extends uiScreen {
g.setColor(1);
}

if (this.items[(this.page * 4) + i].icon.width <= 44 && this.items[(this.page * 4) + i].icon.height <= 17) {
g.drawImage(this.items[(this.page * 4) + i].icon, iconPlacement[i][0] + 1, iconPlacement[i][1] + 1);
var appIcon = this.items[(this.page * 4) + i].icon || require("images").defaultIcon;

if (appIcon.width <= 44 && appIcon.height <= 17) {
g.drawImage(appIcon, ICON_PLACEMENT[i * 2] + 1, ICON_PLACEMENT[i * 2 + 1] + 1);
}

g.setBgColor(0);
g.setColor(1);

g.drawLine(iconPlacement[i][0] + 2, iconPlacement[i][1], iconPlacement[i][0] + 43, iconPlacement[i][1]);
g.drawLine(iconPlacement[i][0] + 2, iconPlacement[i][1] + 18, iconPlacement[i][0] + 43, iconPlacement[i][1] + 18);
g.drawLine(iconPlacement[i][0], iconPlacement[i][1] + 2, iconPlacement[i][0], iconPlacement[i][1] + 16);
g.drawLine(iconPlacement[i][0] + 45, iconPlacement[i][1] + 2, iconPlacement[i][0] + 45, iconPlacement[i][1] + 16);
g.drawLine(ICON_PLACEMENT[i * 2] + 2, ICON_PLACEMENT[i * 2 + 1], ICON_PLACEMENT[i * 2] + 43, ICON_PLACEMENT[i * 2 + 1]);
g.drawLine(ICON_PLACEMENT[i * 2] + 2, ICON_PLACEMENT[i * 2 + 1] + 18, ICON_PLACEMENT[i * 2] + 43, ICON_PLACEMENT[i * 2 + 1] + 18);
g.drawLine(ICON_PLACEMENT[i * 2], ICON_PLACEMENT[i * 2 + 1] + 2, ICON_PLACEMENT[i * 2], ICON_PLACEMENT[i * 2 + 1] + 16);
g.drawLine(ICON_PLACEMENT[i * 2] + 45, ICON_PLACEMENT[i * 2 + 1] + 2, ICON_PLACEMENT[i * 2] + 45, ICON_PLACEMENT[i * 2 + 1] + 16);

g.setPixel(iconPlacement[i][0] + 1, iconPlacement[i][1] + 1);
g.setPixel(iconPlacement[i][0] + 44, iconPlacement[i][1] + 1);
g.setPixel(iconPlacement[i][0] + 1, iconPlacement[i][1] + 17);
g.setPixel(iconPlacement[i][0] + 44, iconPlacement[i][1] + 17);
g.setPixel(ICON_PLACEMENT[i * 2] + 1, ICON_PLACEMENT[i * 2 + 1] + 1);
g.setPixel(ICON_PLACEMENT[i * 2] + 44, ICON_PLACEMENT[i * 2 + 1] + 1);
g.setPixel(ICON_PLACEMENT[i * 2] + 1, ICON_PLACEMENT[i * 2 + 1] + 17);
g.setPixel(ICON_PLACEMENT[i * 2] + 44, ICON_PLACEMENT[i * 2 + 1] + 17);
}
}

Expand Down

0 comments on commit 9d965e6

Please sign in to comment.