Make strings dynamically generated.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { arrayToString } = require('./util');
|
||||
|
||||
const FONT_CHARACTER_FIRST = 33;
|
||||
@@ -10,18 +11,25 @@ const getCodeFrom = l => {
|
||||
return cc - FONT_CHARACTER_FIRST + FONT_DATA_POSITION
|
||||
}
|
||||
|
||||
const string2gb = (string, name) => {
|
||||
const string2gb = (string, name, dirOut) => {
|
||||
const letters = [];
|
||||
for(let i = 0; i < string.length; i++) {
|
||||
letters.push(getCodeFrom(string[i]));
|
||||
}
|
||||
|
||||
out = '#include "libs.h"\n\n';
|
||||
out += `#define STR_${name}_LENGTH ${string.length}\n`;
|
||||
out += `extern const uint8_t STR_${name}_DATA[];\n\n\n`
|
||||
out += `const uint8_t STR_${name}_DATA[] = {\n` + arrayToString(letters) + `\n};`;
|
||||
let outH = '#include "libs.h"\n\n';
|
||||
outH += `#define STR_${name}_LENGTH ${string.length}\n`;
|
||||
outH += `extern const uint8_t STR_${name}_DATA[];`;
|
||||
|
||||
let outC = `#include "${name}.h"\n\n`;
|
||||
outC += `const uint8_t STR_${name}_DATA[] = {\n` + arrayToString(letters) + `\n};`;
|
||||
|
||||
const fileH = path.join(dirOut, `${name}.h`);
|
||||
const fileC = path.join(dirOut, `${name}.c`);
|
||||
|
||||
fs.writeFileSync('out.c', out);
|
||||
fs.writeFileSync(fileH, outH);
|
||||
fs.writeFileSync(fileC, outC);
|
||||
return { fileH, fileC };
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
Reference in New Issue
Block a user