Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/typescript/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ <h3> Program </h3>
<thead class="thead-light">
<tr>
<th>Flash Address</th>
<th>Encrypt file ?</th>
<th>File</th>
<th></th>
</tr>
Expand Down
67 changes: 39 additions & 28 deletions examples/typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,35 +155,43 @@ addFileButton.onclick = () => {
element1.value = "0x1000";
cell1.appendChild(element1);

// Column 2 - File selector
// Column 2 - Encrypt file ?
const cell2 = row.insertCell(1);
const element2 = document.createElement("input");
element2.type = "file";
element2.id = "selectFile" + rowCount;
element2.name = "selected_File" + rowCount;
element2.addEventListener("change", handleFileSelect, false);
element2.type = "checkbox";
element2.id = "file_encrypted" + rowCount;
element2.checked = false;
cell2.appendChild(element2);

// Column 3 - Progress
// Column 3 - File selector
const cell3 = row.insertCell(2);
cell3.classList.add("progress-cell");
cell3.style.display = "none";
cell3.innerHTML = `<progress value="0" max="100"></progress>`;

// Column 4 - Remove File
const element3 = document.createElement("input");
element3.type = "file";
element3.id = "selectFile" + rowCount;
element3.name = "selected_File" + rowCount;
element3.addEventListener("change", handleFileSelect, false);
cell3.appendChild(element3);

// Column 4 - Progress
const cell4 = row.insertCell(3);
cell4.classList.add("action-cell");
cell4.classList.add("progress-cell");
cell4.style.display = "none";
cell4.innerHTML = `<progress value="0" max="100"></progress>`;

// Column 5 - Remove File
const cell5 = row.insertCell(4);
cell5.classList.add("action-cell");
if (rowCount > 1) {
const element4 = document.createElement("input");
element4.type = "button";
const element5 = document.createElement("input");
element5.type = "button";
const btnName = "button" + rowCount;
element4.name = btnName;
element4.setAttribute("class", "btn");
element4.setAttribute("value", "Remove"); // or element1.value = "button";
element4.onclick = function () {
element5.name = btnName;
element5.setAttribute("class", "btn");
element5.setAttribute("value", "Remove"); // or element1.value = "button";
element5.onclick = function () {
removeRow(row);
};
cell4.appendChild(element4);
cell5.appendChild(element5);
}
};

Expand Down Expand Up @@ -299,7 +307,7 @@ function validateProgramInputs() {
else if (offsetArr.includes(offset)) return "Offset field in row " + index + " is already in use!";
else offsetArr.push(offset);

const fileObj = row.cells[1].childNodes[0];
const fileObj = row.cells[2].childNodes[0];
fileData = fileObj.data;
if (fileData == null) return "No file selected for row " + index + "!";
}
Expand All @@ -319,7 +327,7 @@ programButton.onclick = async () => {
// Hide error message
alertDiv.style.display = "none";

const fileArray = [];
const fileArray: { data: string; address: number; encrypted: boolean }[] = [];
const progressBars = [];

for (let index = 1; index < table.rows.length; index++) {
Expand All @@ -328,16 +336,19 @@ programButton.onclick = async () => {
const offSetObj = row.cells[0].childNodes[0] as HTMLInputElement;
const offset = parseInt(offSetObj.value);

const fileObj = row.cells[1].childNodes[0] as ChildNode & { data: string };
const progressBar = row.cells[2].childNodes[0];
const encryptedObj = row.cells[1].childNodes[0] as HTMLInputElement;
const encryptFlag = encryptedObj.checked;

const fileObj = row.cells[2].childNodes[0] as ChildNode & { data: string };

const progressBar = row.cells[3].childNodes[0];
progressBar.textContent = "0";
progressBars.push(progressBar);

row.cells[2].style.display = "initial";
row.cells[3].style.display = "none";
row.cells[3].style.display = "initial";
row.cells[4].style.display = "none";

fileArray.push({ data: fileObj.data, address: offset });
fileArray.push({ data: fileObj.data, address: offset, encrypted: encryptFlag });
}

try {
Expand All @@ -358,8 +369,8 @@ programButton.onclick = async () => {
} finally {
// Hide progress bars and show erase buttons
for (let index = 1; index < table.rows.length; index++) {
table.rows[index].cells[2].style.display = "none";
table.rows[index].cells[3].style.display = "initial";
table.rows[index].cells[3].style.display = "none";
table.rows[index].cells[4].style.display = "initial";
}
}
};
Expand Down
Loading