firmware maker
parent
cad2427c20
commit
e7a6cbedfd
|
|
@ -0,0 +1,48 @@
|
|||
function toJS(txt) {
|
||||
return JSON.stringify(txt);
|
||||
}
|
||||
|
||||
var AppInfo = {
|
||||
getFiles : (app,fileGetter) => {
|
||||
return new Promise((resolve,reject) => {
|
||||
// Load all files
|
||||
Promise.all(app.storage.map(storageFile => {
|
||||
if (storageFile.content)
|
||||
return Promise.resolve(storageFile);
|
||||
else if (storageFile.url)
|
||||
return fileGetter("apps/"+storageFile.url).then(content => {
|
||||
return {
|
||||
name : storageFile.name,
|
||||
content : content,
|
||||
evaluate : storageFile.evaluate
|
||||
}});
|
||||
else return Promise.resolve();
|
||||
})).then(fileContents => { // now we just have a list of files + contents...
|
||||
// filter out empty files
|
||||
fileContents = fileContents.filter(x=>x!==undefined);
|
||||
// then map each file to a command to load into storage
|
||||
fileContents.forEach(storageFile => {
|
||||
// check if this is the JSON file
|
||||
if (storageFile.name[0]=="+") {
|
||||
storageFile.evaluate = true;
|
||||
var json = {};
|
||||
try {
|
||||
json = JSON.parse(storageFile.content);
|
||||
} catch (e) {
|
||||
reject(storageFile.name+" is not valid JSON");
|
||||
}
|
||||
json.files = fileContents.map(storageFile=>storageFile.name).join(",");
|
||||
storageFile.content = JSON.stringify(json);
|
||||
}
|
||||
// format ready for Espruino
|
||||
var js = storageFile.evaluate ? storageFile.content.trim() : toJS(storageFile.content);
|
||||
storageFile.cmd = `\x10require('Storage').write(${toJS(storageFile.name)},${js});`;
|
||||
});
|
||||
resolve(fileContents);
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
if ("undefined"!=typeof module)
|
||||
module.exports = AppInfo;
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/nodejs
|
||||
/*
|
||||
Mashes together a bunch of different apps to make
|
||||
a single firmware JS file which can be uploaded.
|
||||
*/
|
||||
|
||||
var path = require('path');
|
||||
var ROOTDIR = path.join(__dirname, '..');
|
||||
var APPDIR = ROOTDIR+'/apps';
|
||||
var APPJSON = ROOTDIR+'/apps.json';
|
||||
var OUTFILE = ROOTDIR+'/firmware.js';
|
||||
var APPS = [ // IDs of apps to install
|
||||
"boot",
|
||||
"mclock",
|
||||
"setting",
|
||||
"trex",
|
||||
"gpstime",
|
||||
"compass",
|
||||
"sbat",
|
||||
"funrun5",
|
||||
"nceuwid",
|
||||
//"start"
|
||||
];
|
||||
|
||||
var fs = require("fs");
|
||||
var AppInfo = require(ROOTDIR+"/appinfo.js");
|
||||
var appjson = JSON.parse(fs.readFileSync(APPJSON).toString());
|
||||
var appfiles = [];
|
||||
|
||||
function fileGetter(url) {
|
||||
console.log("Loading "+url)
|
||||
if (url.endsWith(".js")) {
|
||||
// minify?
|
||||
}
|
||||
return Promise.resolve(fs.readFileSync(url).toString());
|
||||
}
|
||||
|
||||
Promise.all(APPS.map(appid => {
|
||||
var app = appjson.find(app=>app.id==appid);
|
||||
if (app===undefined) throw new Error(`App ${appid} not found`);
|
||||
return AppInfo.getFiles(app, fileGetter).then(files => {
|
||||
appfiles = appfiles.concat(files);
|
||||
});
|
||||
})).then(() => {
|
||||
//console.log(appfiles);
|
||||
var js = "";
|
||||
appfiles.forEach((file) => {
|
||||
js += file.cmd+"\n";
|
||||
});
|
||||
fs.writeFileSync(OUTFILE, js);
|
||||
console.log("Output written to "+OUTFILE);
|
||||
});
|
||||
47
comms.js
47
comms.js
|
|
@ -1,55 +1,10 @@
|
|||
Puck.debug=3;
|
||||
|
||||
/* 'app' is of the form:
|
||||
{ name: "T-Rex",
|
||||
icon: "trex.png",
|
||||
description: "T-Rex game in the style of Chrome's offline game",
|
||||
storage: [
|
||||
{name:"+trex",file:"trex.json"},
|
||||
{name:"-trex",file:"trex.js"},
|
||||
{name:"*trex",file:"trex-icon.js"}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
// FIXME: use UART lib so that we handle errors properly
|
||||
var Comms = {
|
||||
uploadApp : app => {
|
||||
return AppInfo.getFiles(app, httpGet).then(fileContents => {
|
||||
return new Promise((resolve,reject) => {
|
||||
// Load all files
|
||||
Promise.all(app.storage.map(storageFile => {
|
||||
if (storageFile.content)
|
||||
return Promise.resolve(storageFile);
|
||||
else if (storageFile.url)
|
||||
return httpGet("apps/"+storageFile.url).then(content => {
|
||||
return {
|
||||
name : storageFile.name,
|
||||
content : content,
|
||||
evaluate : storageFile.evaluate
|
||||
}});
|
||||
else return Promise.resolve();
|
||||
})).then(fileContents => { // now we just have a list of files + contents...
|
||||
// filter out empty files
|
||||
fileContents = fileContents.filter(x=>x!==undefined);
|
||||
// then map each file to a command to load into storage
|
||||
fileContents.forEach(storageFile => {
|
||||
// check if this is the JSON file
|
||||
if (storageFile.name[0]=="+") {
|
||||
storageFile.evaluate = true;
|
||||
var json = {};
|
||||
try {
|
||||
json = JSON.parse(storageFile.content);
|
||||
} catch (e) {
|
||||
reject(storageFile.name+" is not valid JSON");
|
||||
}
|
||||
json.files = fileContents.map(storageFile=>storageFile.name).join(",");
|
||||
storageFile.content = JSON.stringify(json);
|
||||
}
|
||||
// format ready for Espruino
|
||||
var js = storageFile.evaluate ? storageFile.content.trim() : toJS(storageFile.content);
|
||||
storageFile.cmd = `\x10require('Storage').write(${toJS(storageFile.name)},${js});`;
|
||||
});
|
||||
|
||||
fileContents = fileContents.map(storageFile=>storageFile.cmd).join("\n")+"\n";
|
||||
console.log("uploadApp",fileContents);
|
||||
// reset to ensure we have enough memory to upload what we need to
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -108,6 +108,7 @@
|
|||
<script src="https://www.puck-js.com/puck.js"></script>
|
||||
<script src="utils.js"></script>
|
||||
<script src="comms.js"></script>
|
||||
<script src="appinfo.js"></script>
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Reference in New Issue