formatting

This commit is contained in:
javl
2023-05-05 20:25:28 +02:00
parent 293a0406e7
commit 916594f56b
+17 -18
View File
@@ -473,29 +473,30 @@ function placeImage(_image) {
} }
} }
function update() { // Handle drawing each of our images
images.each((image) => { placeImage(image); }); function updateAllImages() {
images.each((image) => {
placeImage(image);
});
} }
// Easy way to update settings controlled by a textfield // Easy way to update settings controlled by a textfield
function updateInteger(fieldName) { function updateInteger(fieldName) {
settings[fieldName] = parseInt(document.getElementById(fieldName).value); settings[fieldName] = parseInt(document.getElementById(fieldName).value);
update(); updateAllImages();
} }
// Easy way to update settings controlled by a checkbox // Easy way to update settings controlled by a checkbox
// eslint-disable-next-line no-unused-vars
function updateBoolean(fieldName) { function updateBoolean(fieldName) {
settings[fieldName] = document.getElementById(fieldName).checked; settings[fieldName] = document.getElementById(fieldName).checked;
update(); updateAllImages();
} }
// Convert hex to binary // Convert hex to binary
function hexToBinary(s) { function hexToBinary(s) {
let i; let i;
let ret = ''; let ret = '';
// lookup table for easier conversion. "0" characters are // lookup table for easier conversion. "0" characters are padded for "1" to "7"
// padded for "1" to "7"
const lookupTable = { const lookupTable = {
0: '0000', 0: '0000',
1: '0001', 1: '0001',
@@ -533,7 +534,7 @@ function hexToBinary(s) {
// get the type (in arduino code) of the output image // get the type (in arduino code) of the output image
// this is a bit of a hack, it's better to make this a property of the conversion function (should probably turn it into objects) // this is a bit of a hack, it's better to make this a property of the conversion function (should probably turn it into objects)
function getType() { function getImageType() {
if (settings.conversionFunction === ConversionFunctions.horizontal565) { if (settings.conversionFunction === ConversionFunctions.horizontal565) {
return 'uint16_t'; return 'uint16_t';
} if (settings.conversionFunction === ConversionFunctions.horizontal888) { } if (settings.conversionFunction === ConversionFunctions.horizontal888) {
@@ -546,9 +547,7 @@ function getType() {
function listToImageHorizontal(list, canvas) { function listToImageHorizontal(list, canvas) {
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.clearRect(0, 0, canvas.width, canvas.height);
const imgData = ctx.createImageData(canvas.width, canvas.height); const imgData = ctx.createImageData(canvas.width, canvas.height);
let index = 0; let index = 0;
// round the width up to the next byte // round the width up to the next byte
@@ -560,7 +559,7 @@ function listToImageHorizontal(list, canvas) {
let binString = hexToBinary(list[i]); let binString = hexToBinary(list[i]);
if (!binString.valid) { if (!binString.valid) {
// eslint-disable-next-line no-alert // eslint-disable-next-line no-alert
alert('Something went wrong converting the string. Did you forget to remove any comments from the input?'); alert('Something went wrong converting the string. Make sure there are no comments in your input?');
console.log('invalid hexToBinary: ', binString.s); console.log('invalid hexToBinary: ', binString.s);
return; return;
} }
@@ -795,7 +794,7 @@ function handleImageSelection(evt) {
settings.screenWidth = img.width; settings.screenWidth = img.width;
w.oninput = () => { w.oninput = () => {
canvas.width = this.value; canvas.width = this.value;
update(); updateAllImages();
updateInteger('screenWidth'); updateInteger('screenWidth');
}; };
@@ -809,7 +808,7 @@ function handleImageSelection(evt) {
settings.screenHeight = img.height; settings.screenHeight = img.height;
h.oninput = () => { h.oninput = () => {
canvas.height = this.value; canvas.height = this.value;
update(); updateAllImages();
updateInteger('screenHeight'); updateInteger('screenHeight');
}; };
@@ -856,7 +855,7 @@ function handleImageSelection(evt) {
el.style.display = 'block'; el.style.display = 'block';
}); });
} }
update(); updateAllImages();
}; };
rb.onclick = removeButtonOnClick; rb.onclick = removeButtonOnClick;
@@ -931,7 +930,7 @@ function generateOutputString() {
const varname = getIdentifier() + image.glyph.replace(/[^a-zA-Z0-9]/g, '_'); const varname = getIdentifier() + image.glyph.replace(/[^a-zA-Z0-9]/g, '_');
varQuickArray.push(varname); varQuickArray.push(varname);
code = `${comment}const ${getType()} ${varname} [] PROGMEM = {\n${code}};\n`; code = `${comment}const ${getImageType()} ${varname} [] PROGMEM = {\n${code}};\n`;
outputString += code; outputString += code;
}); });
// -- // --
@@ -939,7 +938,7 @@ function generateOutputString() {
// -- // --
outputString += `\n// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = ${bytesUsed})\n`; outputString += `\n// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = ${bytesUsed})\n`;
outputString += `const int ${getIdentifier()}allArray_LEN = ${varQuickArray.length};\n`; outputString += `const int ${getIdentifier()}allArray_LEN = ${varQuickArray.length};\n`;
outputString += `const ${getType()}* ${getIdentifier()}allArray[${varQuickArray.length}] = {\n\t${varQuickArray.join(',\n\t')}\n};\n`; outputString += `const ${getImageType()}* ${getIdentifier()}allArray[${varQuickArray.length}] = {\n\t${varQuickArray.join(',\n\t')}\n};\n`;
// -- // --
break; break;
} }
@@ -955,7 +954,7 @@ function generateOutputString() {
outputString = outputString.replace(/,\s*$/, ''); outputString = outputString.replace(/,\s*$/, '');
outputString = `const ${getType()} ${ outputString = `const ${getImageType()} ${
+getIdentifier() +getIdentifier()
} [] PROGMEM = {` } [] PROGMEM = {`
+ `\n${outputString}\n};`; + `\n${outputString}\n};`;
@@ -1129,7 +1128,7 @@ function updateRadio(fieldName) {
settings[fieldName] = radioGroup[i].value; settings[fieldName] = radioGroup[i].value;
} }
} }
update(); updateAllImages();
} }
window.onload = () => { window.onload = () => {