Skip to content

Commit

Permalink
version bump (#52)
Browse files Browse the repository at this point in the history
* support 50 slots by default on web flasher
start work on new controls for improve wait and sync for startup
update all libraries and sync dev branch with local
add update bootstrap, a bunch of updates, code refactoring, and add in new features for dev work

* Update index.html
  • Loading branch information
spiceywasabi authored Nov 14, 2023
1 parent b5dc2ee commit 6f76fc1
Show file tree
Hide file tree
Showing 16 changed files with 149 additions and 1,764 deletions.
23 changes: 11 additions & 12 deletions js/esptool.js → core/esptool.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class EspLoader {
* Opens a Web Serial connection to a micro:bit and sets up the input and
* output stream.
*/
async connect() {
async connect(tries=5) {
// - Request a port and open a connection.
const filter = { usbVendorId: 0x10c4 };
var filters = []
Expand All @@ -395,11 +395,8 @@ class EspLoader {

const signals = await port.getSignals();

this.logMsg("Connected successfully.")
this.logMsg("Serial connection opened...")

this.logMsg("Try to reset.")
await this.hardReset(true);

outputStream = port.writable;
inputStream = port.readable;
}
Expand Down Expand Up @@ -617,8 +614,8 @@ class EspLoader {
* Put into ROM bootload mode & attempt to synchronize with the
* ESP ROM bootloader, we will retry a few times
*/
async sync() {
for (let i = 0; i < 5; i++) {
async sync(syncCount=3) {
for (let i = 0; i < syncCount; i++) {
inputBuffer = []
let response = await this._sync();
if (response) {
Expand All @@ -627,8 +624,8 @@ class EspLoader {
}
await this.sleep(100);
}

throw("Couldn't sync to O.MG Device. Try unplugging & replugging the programmer and try again.");
return false;
//throw("Couldn't sync to O.MG Device. Try unplugging & replugging the programmer and try again.");
};

/**
Expand Down Expand Up @@ -899,18 +896,18 @@ class EspLoader {
}
}

async hardReset(r = false) {
async reset(r = false, baseTimeout=500, timeoutMultiplier=1) {
logMsg("Trying Serial Reset....")
await port.setSignals({
dataTerminalReady: false,
requestToSend: true,
});
await new Promise((resolve) => setTimeout(resolve, 500));
await new Promise((resolve) => setTimeout(resolve, baseTimeout*timeoutMultiplier));
await port.setSignals({
dataTerminalReady: r,
requestToSend: false,
});
await new Promise((resolve) => setTimeout(resolve, 1500));
await new Promise((resolve) => setTimeout(resolve, baseTimeout));
}

async getStubCode() {
Expand Down Expand Up @@ -976,6 +973,8 @@ class EspLoader {
}
}
this.logMsg("Running stub...")
console.log("stub loaded")
console.log(stub)
await this.memFinish(stub['entry']);

let p = await this.readBuffer(500);
Expand Down
File renamed without changes.
88 changes: 78 additions & 10 deletions js/script.js → core/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
var espTool;

const baudRates = [115200];
const connectionBaseDelay = 500;
const connectionAttempts = 4;
const bufferSize = 512;
const eraseFillByte = 0x00;

Expand Down Expand Up @@ -46,6 +48,7 @@ const statusStep1 = document.getElementById("programmerStep1-status");
const statusStep2 = document.getElementById("programmerStep2-status");
const statusStep3 = document.getElementById("programmerStep3-status");
const butHardware = document.getElementById("btnConnectHw");
const butReleaseNotes = document.getElementById("btnReleaseNotes");
const butProgram = document.getElementById("btnProgram");

const progress = document.querySelectorAll(".progress-bar");
Expand Down Expand Up @@ -80,6 +83,8 @@ var settings = {
"skipWelcome": butSkipWelcome
}

var releaseDataCache = {}

const url_memmap = "assets/memmap.json";
const url_releases = "https://api.github.com/repos/O-MG/O.MG-Firmware/releases?per_page=100"; // move to proper spot later.
const url_branches = "https://api.github.com/repos/O-MG/O.MG-Firmware/branches";
Expand Down Expand Up @@ -119,7 +124,7 @@ document.addEventListener("DOMContentLoaded", () => {
}

let urlloc = String(window.location.href);
if(urlloc.includes("localhost") || urlloc.includes("Test")){
if(urlloc.includes("localhost")|| urlloc.includes("127.0.0.1") || urlloc.includes("Test")){
debugState=true;
skipWelcome=false;
toggleDevConf(true);
Expand Down Expand Up @@ -194,6 +199,7 @@ document.addEventListener("DOMContentLoaded", () => {
butDiagnosticFirmware.addEventListener("click",toggleDiagnostics)
butHardware.addEventListener("click", clickHardware);
butProgram.addEventListener("click", clickProgramErase);
butReleaseNotes.addEventListener("click",clickReleaseNotes)
butDownload.addEventListener("click", clickDownload);
butClear.addEventListener("click", clickClear);
autoscroll.addEventListener("click", clickAutoscroll);
Expand Down Expand Up @@ -257,10 +263,12 @@ async function fetchWithRetry(url, options = {}, maxRetries = 3, retryDelay = 10

async function connect() {
logMsg("Connecting...")
await espTool.connect()
let synced = await espTool.connect()
readLoop().catch((error) => {
toggleUIConnected(false);
return false
});
return synced
}

function initBaudRate() {
Expand Down Expand Up @@ -521,14 +529,30 @@ async function clickConnect() {
}
butConnect.textContent = " Connecting";
butConnect.insertAdjacentHTML('afterbegin', '<span class="spinner-border spinner-border-sm"></span> ');

let sync_status = false;
await connect();
for(let i=0;i<connectionAttempts;i++){
let delay = (i+1)*connectionBaseDelay;
logMsg("Trying to initiate connection with O.MG Device...")
await espTool.reset(true,delay);
sync_status = await espTool.sync();
console.log(sync_status)
if(sync_status){
logMsg("Obtained synchronization with O.MG Device")
break;
} else {
logMsg("Failed to connect to O.MG Device, lost synchronization. Resetting connection after "+delay+" ms.")
}
}
try {
if (await espTool.sync()) {
if (sync_status) {
toggleUIConnected(true);
let baud = parseInt(baudRate.value);
// get our chip info
logMsg("Connected to " + await espTool.chipName());
logMsg("Connected to O.MG Device")
if (debugState) {
logMsg("Connected to " + await espTool.chipName());
console.log(espTool);
}
logMsg("MAC Address: " + formatMacAddr(espTool.macAddr()));
Expand All @@ -547,11 +571,7 @@ async function clickConnect() {
await espTool.chipName();
// and proceed
if (baud != ESP_ROM_BAUD) {
if (await espTool.chipType() == ESP32) {
logMsg("WARNING: ESP32 is having issues working at speeds faster than 115200. Continuing at 115200 for now...")
} else {
await changeBaudRate(baud);
}
await changeBaudRate(baud);
}
}
isConnected = true;
Expand Down Expand Up @@ -600,6 +620,46 @@ async function clickDarkMode() {
//saveSetting("darkmode", darkMode.checked);
}

async function clickReleaseNotes(){
let selected_version = butBranch.value;
let display_text = selected_version;
try {
let display_text = butBranch.options[butBranch.selectedIndex].text;
} catch(error) {
console.log(error);
}
let intro_element = document.getElementById("release-notes-modal-intro");
let title_element = document.getElementById("release-notes-modal-title");
let notes_element = document.getElementById("release-notes");

let title_value = "Release Notes for " + selected_version;
let intro_value = "Version release notes for the O.MG Unified Firmware version " + display_text + "."

intro_element.textContent = intro_value;
title_element.textContent = title_value;

let release_notes = "<p>Unable to read release notes data...</p>"
let releases = Object.keys(releaseDataCache)
if(releases.length>=1){
for(let release_name in releaseDataCache){
if(release_name.includes(selected_version,0)){
let reldata = releaseDataCache[release_name]
if(debugState){
console.log("Found potential match for: " + release_name);
console.log(reldata);
}
if("body" in reldata){
release_notes = "<p>";
release_notes += reldata["body"].replace(/\\r|\r/g,"").replace(/\\n|\n/g, '<br>\n');
release_notes += "</p>\r\n";
}
}
}
}
notes_element.innerHTML = release_notes
console.log("I've been called.");
}

async function getDiagnosticFirmwareFiles(erase = false, bytes = 0x00) {

const readUploadedFileAsArrayBuffer = (inputFile) => {
Expand Down Expand Up @@ -769,6 +829,12 @@ async function buildReleaseSelectors(dr=["beta","stable"]){
}
}
}
// set the cache
if(debugState){
console.log("setting release cache for user");
console.log(releases);
}
releaseDataCache = releases;
// reset our list
butBranch.innerHTML="";
// get our defaults
Expand All @@ -786,6 +852,7 @@ async function buildReleaseSelectors(dr=["beta","stable"]){
// ADD DEBUG IF
console.log("Adding a new release " + dr_str + " with tag " + dr_tag);
console.log(dr);
releaseDataCache[dr_tag]=releases[dr[i]];
butBranch.options.add(new Option(dr_str, dr_tag,no_default,no_default));
}
delete(releases[dr[i]]);
Expand All @@ -796,8 +863,10 @@ async function buildReleaseSelectors(dr=["beta","stable"]){
if(debugState){
console.log(details);
}
releaseDataCache[details["tag_name"]]=details;
butBranch.options.add(new Option(details["name"], details["tag_name"],no_default,no_default));
}

}

async function getFirmwareFiles(branch, erase = false, bytes = 0x00) {
Expand Down Expand Up @@ -1652,7 +1721,6 @@ function saveSettings() {

}


function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
19 changes: 19 additions & 0 deletions css/style.css → core/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,25 @@ button.fancy:hover::after {
color: #000;
}

#release-notes {
max-width: 100%;
text-align: left;
font-family: pt-mono, monospace;
font-style: normal;
font-weight: 400;
height: 256px;
font-size: 16px;
overflow-x: hidden;
overflow-x: auto;
transition : color 0.1s linear;
padding: 0 20px;
border: 20px solid #eee;
-ms-overflow-style: none;
scrollbar-width: none;
background-color: #eee;
color: #000;
}


.accordion-details {
padding: 8px 8px;
Expand Down
File renamed without changes.
Loading

0 comments on commit 6f76fc1

Please sign in to comment.