Skip to content

Commit

Permalink
fix serial errors
Browse files Browse the repository at this point in the history
  • Loading branch information
spiceywasabi committed Sep 25, 2024
1 parent 0306bb7 commit b130c5c
Show file tree
Hide file tree
Showing 7 changed files with 4,099 additions and 97 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/dev-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,18 @@ jobs:
id: prep
run: |
COMMIT="${GITHUB_SHA::8}"
echo ::set-output name=commit::${COMMIT}
echo "::set-output name=branch::${GITHUB_REF#refs/heads/}"
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
echo "commit=${COMMIT}" >> $GITHUB_OUTPUT
echo "short_commit=${SHORT_COMMIT}" >> $GITHUB_OUTPUT
echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
#echo ::set-output name=commit::${COMMIT}
#echo "::set-output name=branch::${GITHUB_REF#refs/heads/}"
#echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Update script.js
run: |
COMMIT="${GITHUB_SHA::8}"
sed -i "s/^const wf_ver = .*/const wf_ver = '${COMMIT}';/" core/script.js || true
sed -i "s/^const wf_ver = .*/const wf_ver = '${COMMIT}';/" js/script.js || true
- name: Push to Dev Repo
run: |
MAINNAME="main"
Expand Down
50 changes: 50 additions & 0 deletions branches.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"name": "apply-stable-flasher",
"commit": {
"sha": "de8ccb75229b94fd6889c4ec104a833f8da3bf7e",
"url": "https://api.github.com/repos/O-MG/O.MG-Firmware/commits/de8ccb75229b94fd6889c4ec104a833f8da3bf7e"
},
"protected": false
},
{
"name": "beta",
"commit": {
"sha": "e43987b908f8aa7fd27917ce533ed61c7f59484b",
"url": "https://api.github.com/repos/O-MG/O.MG-Firmware/commits/e43987b908f8aa7fd27917ce533ed61c7f59484b"
},
"protected": false
},
{
"name": "legacy-2.5",
"commit": {
"sha": "56ed074784065f709e19d90c57b92e25e2f644e4",
"url": "https://api.github.com/repos/O-MG/O.MG-Firmware/commits/56ed074784065f709e19d90c57b92e25e2f644e4"
},
"protected": false
},
{
"name": "legacy-v1.5",
"commit": {
"sha": "f9851f604a20e1b37f6d2b85176902e932899e26",
"url": "https://api.github.com/repos/O-MG/O.MG-Firmware/commits/f9851f604a20e1b37f6d2b85176902e932899e26"
},
"protected": false
},
{
"name": "legacy-v2.0",
"commit": {
"sha": "49c52f60b09fcd285e051eaad7f5b03fb25a03ff",
"url": "https://api.github.com/repos/O-MG/O.MG-Firmware/commits/49c52f60b09fcd285e051eaad7f5b03fb25a03ff"
},
"protected": false
},
{
"name": "stable",
"commit": {
"sha": "363b28520736bde60a90a3508e5c6e1611a43eb6",
"url": "https://api.github.com/repos/O-MG/O.MG-Firmware/commits/363b28520736bde60a90a3508e5c6e1611a43eb6"
},
"protected": false
}
]
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ <h5>DuckScript Support</h5>
<div id="qbox-container" class="p-4">
<div id="steps-container" class="p-5">
<div class="step" id="step-welcome">
<h2>O.MG Web Flasher</h2>
<h2 class="flasher-title">O.MG Web Flasher</h2>
<p>This tool is used exclusively to flash firmware to O.MG Devices</p>
<div class="m-2 bg-white agreement-modal" id="agreement-modal">
<h4>Agreement</h4>
Expand Down Expand Up @@ -152,7 +152,7 @@ <h4>Terms of Use</h4>
<div class="step d-none" id="modular-stepper">
<div class="d-flex justify-content-between bd-highlight mb-3">
<div class="p-2 bd-highlight"></div>
<div class="p-2 bd-highlight"><h2>O.MG Web Flasher</h2></div>
<div class="p-2 bd-highlight"><h2 class="flasher-title">O.MG Web Flasher</h2></div>
<div class="p-2 bd-highlight">
<button type="button" class="btn btn-secondary" data-bs-toggle="modal" data-bs-target="#modalConsole">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-terminal" viewBox="0 0 16 16">
Expand Down Expand Up @@ -258,7 +258,7 @@ <h2 class="accordion-header" id="programmerStep3">
<div id="step-success" class="step d-none">
<div class="d-flex justify-content-between bd-highlight mb-3">
<div class="p-2 bd-highlight"></div>
<div class="p-2 bd-highlight"><h2>O.MG Web Flasher</h2></div>
<div class="p-2 bd-highlight"><h2 class="flasher-title">O.MG Web Flasher</h2></div>
<div class="p-2 bd-highlight">
<button type="button" class="btn btn-secondary" data-bs-toggle="modal" data-bs-target="#modalConsole">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-terminal" viewBox="0 0 16 16">
Expand Down
72 changes: 52 additions & 20 deletions js/esptool.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,35 +378,48 @@ class EspLoader {
* output stream.
*/
async connect(bypassRequest = false) {
const filter = { usbVendorId: 0x10c4 };
var filters = []
if (!this.debug) {
filters.push(filter);
}
if (!bypassRequest) {
const filter = { usbVendorId: 0x10c4 };
var filters = []
if (!this.debug) {
filters.push(filter);
}
port = await navigator.serial.requestPort({ filters: filters });
if (this.getChromeVersion() < 86) {
await port.open({ baudrate: ESP_ROM_BAUD });
} else {
await port.open({ baudRate: ESP_ROM_BAUD });
}

/*if (port) {
try {
await disconnect();
} catch(e) {
console.log("caught error in disconnect:" + e)
}
}*/

if (this.getChromeVersion() < 86) {
await port.open({ baudrate: ESP_ROM_BAUD });
} else {
await port.open({ baudRate: ESP_ROM_BAUD });
}

const signals = await port.getSignals();

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

let ms = 2000;
if(!bypassRequest){
this.logMsg("Try to reset.")
await this.preferredReset(true);
ms = 3000;
}


this.logMsg("Trying to reset...")
//await this.hardReset(true);
await this.preferredReset(true,ms);

outputStream = port.writable;
inputStream = port.readable;
}

connected() {
if (port) {
if (port&&port.connected) {
return true;
}
return false;
Expand All @@ -427,8 +440,26 @@ class EspLoader {
outputStream = null;
}

await port.close();
port = null;
console.log(port)
try {
// note: port.connected will show open even if the port isn't open in another tab
if(port.connected&&port.writable){
this.logMsg("Port is opened by this current session and will be closed.");
await port.close();
} else if(port.connected&&!port.writable){
this.logMsg("Warning: Port may be active on another tab or was previously activated.");
try {
await port.close();
} catch(e) {
console.log(e);
}
} else {
this.logMsg("Serial port is ready to be opened.");
}
} catch(e) {
console.log(e)
}
//port = null;
}

/**
Expand Down Expand Up @@ -906,31 +937,32 @@ class EspLoader {
dataTerminalReady: false,
requestToSend: true,
});
await new Promise((resolve) => setTimeout(resolve, 100));
await new Promise((resolve) => setTimeout(resolve, 2000));
await port.setSignals({
dataTerminalReady: r,
requestToSend: false,
break: false,
});
await new Promise((resolve) => setTimeout(resolve, 500));
await new Promise((resolve) => setTimeout(resolve, 2000));
}

async preferredReset(r = false) {
async preferredReset(r = false,ms=2000) {
logMsg("Power Off...")
await port.setSignals({
dataTerminalReady: false,
requestToSend: true,
});
await new Promise((resolve) => setTimeout(resolve, 2000));
await new Promise((resolve) => setTimeout(resolve, ms));
await port.setSignals({
dataTerminalReady: r,
requestToSend: false,
//break: false,
});
await new Promise((resolve) => setTimeout(resolve, 1000))
await new Promise((resolve) => setTimeout(resolve, (ms/2 < 1000 ? 1000 : ms/ 2)))
}



async getStubCode() {
let response = await fetch('stubs/' + this.getStubFile() + '.json');
let stubcode = await response.json();
Expand Down
Loading

0 comments on commit b130c5c

Please sign in to comment.