Skip to content

Commit

Permalink
download to flash (instead of RAM) to support larger directions, prel…
Browse files Browse the repository at this point in the history
…oad main to free more RAM #1206
  • Loading branch information
phoddie committed Sep 7, 2023
1 parent 3b7a255 commit 3307c2a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
54 changes: 42 additions & 12 deletions examples/commodetto/epaper-mini-travel-time/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ import parseRLE from "commodetto/parseRLE";
import Poco from "commodetto/Poco";
import Resource from "Resource";
import Timer from "timer";
import Flash from "flash";

let render = new Poco(screen, { displayListLength: 2048, rotation: config.rotation });
let flash;

let black = render.makeColor(0, 0, 0);
let white = render.makeColor(255, 255, 255);
let render;

let OpenSans18 = parseBMF(new Resource("OpenSans-Regular-18.bf4"));
let OpenSans35 = parseBMF(new Resource("OpenSans-Regular-35.bf4"));
let black, white;

let arrow = parseRLE(new Resource("arrow-alpha.bm4"));
let OpenSans18, OpenSans35;

let arrow;

function getTimeEstimate() {
const API_KEY = config.API_KEY;
Expand Down Expand Up @@ -58,8 +59,23 @@ function getTimeEstimate() {
});

request.callback = function(message, value, etc) {
if (Request.responseComplete == message) {
let result = JSON.parse(value, ["routes", "legs", "duration", "duration_in_traffic", "text", "value"]);
if (Request.status === message) {
flash.offset = 0;
flash.erase(0);
}
else if (Request.responseFragment === message) {
const buffer = this.read(ArrayBuffer);
const byteLength = buffer.byteLength;
let start = Math.idiv(flash.offset, flash.blockSize);
const end = Math.idiv(flash.offset + byteLength, flash.blockSize);
while (start < end)
flash.erase(++start);
flash.write(flash.offset, buffer.byteLength, buffer);
flash.offset += buffer.byteLength;
}
else if (Request.responseComplete === message) {
let result = flash.readString(0, flash.offset);
result = JSON.parse(result, ["routes", "legs", "duration", "duration_in_traffic", "text", "value"]);
let route = result.routes[0];
if (!route) {
trace(`No route found\n`);
Expand Down Expand Up @@ -106,7 +122,21 @@ function updateDisplay(time) {
render.end();
}

getTimeEstimate();
Timer.repeat(() => {
getTimeEstimate();
}, 1000*60*10);
export default function() {
flash = new Flash("storage");

render = new Poco(screen, { displayListLength: 2048, rotation: config.rotation });

black = render.makeColor(0, 0, 0);
white = render.makeColor(255, 255, 255);

OpenSans18 = parseBMF(new Resource("OpenSans-Regular-18.bf4"));
OpenSans35 = parseBMF(new Resource("OpenSans-Regular-35.bf4"));

arrow = parseRLE(new Resource("arrow-alpha.bm4"));

getTimeEstimate();
Timer.repeat(() => {
getTimeEstimate();
}, 1000*60*10);
}
6 changes: 4 additions & 2 deletions examples/commodetto/epaper-mini-travel-time/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"$(MODDABLE)/examples/manifest_base.json",
"$(MODDABLE)/examples/manifest_net.json",
"$(MODDABLE)/examples/manifest_commodetto.json",
"$(MODDABLE)/modules/crypt/tls.json"
"$(MODDABLE)/modules/crypt/tls.json",
"$(MODDABLE)/modules/files/flash/manifest.json"
],
"modules": {
"*": [
Expand All @@ -23,7 +24,8 @@
]
},
"preload": [
"http"
"http",
"main"
],
"resources":{
"*-mask": [
Expand Down

0 comments on commit 3307c2a

Please sign in to comment.