From 04bc57682efb1368ca58be02a5105b16ac990364 Mon Sep 17 00:00:00 2001 From: Murilo Polese Date: Tue, 4 Jul 2023 17:29:47 +0200 Subject: [PATCH 1/4] rejecting run promise before running again, stop and reset --- micropython.js | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/micropython.js b/micropython.js index 96424b3..d24820b 100644 --- a/micropython.js +++ b/micropython.js @@ -28,6 +28,7 @@ class MicroPythonBoard { constructor() { this.port = null this.serial = null + this.reject_run = null } list_ports() { @@ -113,7 +114,10 @@ class MicroPythonBoard { } async get_prompt() { - const out = await this.write_and_read_until(`\r\x02\x03`, '\r\n>>>') + await sleep(100) + await this.stop() + await sleep(100) + const out = await this.write_and_read_until(`\r\x03\x02`, '\r\n>>>') return Promise.resolve(out) } @@ -147,10 +151,21 @@ class MicroPythonBoard { async run(code, data_consumer) { data_consumer = data_consumer || function() {} - await this.enter_raw_repl() - const output = await this.exec_raw(code || '#', data_consumer) - await this.exit_raw_repl() - return Promise.resolve(output) + return new Promise(async (resolve, reject) => { + if (this.reject_run) { + this.reject_run('re run') + this.reject_run = null + } + this.reject_run = reject + try { + await this.enter_raw_repl() + const output = await this.exec_raw(code || '#', data_consumer) + await this.exit_raw_repl() + return resolve(output) + } catch (e) { + reject(e) + } + }) } async eval(k) { @@ -159,12 +174,20 @@ class MicroPythonBoard { } async stop() { + if (this.reject_run) { + this.reject_run('pre stop') + this.reject_run = null + } // Dismiss any data with ctrl-C await this.serial.write(Buffer.from(`\x03`)) return Promise.resolve() } async reset() { + if (this.reject_run) { + this.reject_run('pre reset') + this.reject_run = null + } // Dismiss any data with ctrl-C await this.serial.write(Buffer.from(`\x03`)) // Soft reboot From 5d295cbbe09febb800e7ede6270d8866c20fe51d Mon Sep 17 00:00:00 2001 From: Murilo Polese Date: Tue, 4 Jul 2023 19:14:26 +0200 Subject: [PATCH 2/4] Bump version Better later than never. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e02baf1..cbcf564 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "micropython.js", - "version": "1.3.5", + "version": "1.4.1", "description": "Interpretation of pyboard.py in javascript", "main": "micropython.js", "scripts": { From e6ebed2df2280d986b0d35a5377ce7e4ade84c4b Mon Sep 17 00:00:00 2001 From: Murilo Polese Date: Wed, 5 Jul 2023 12:20:44 +0200 Subject: [PATCH 3/4] Setting run promise to null on catch --- micropython.js | 1 + 1 file changed, 1 insertion(+) diff --git a/micropython.js b/micropython.js index d24820b..a0612f2 100644 --- a/micropython.js +++ b/micropython.js @@ -164,6 +164,7 @@ class MicroPythonBoard { return resolve(output) } catch (e) { reject(e) + this.reject_run = null } }) } From 17661ab983937282974e98c64be0cc7ebec4e8c4 Mon Sep 17 00:00:00 2001 From: Murilo Polese Date: Wed, 5 Jul 2023 12:20:58 +0200 Subject: [PATCH 4/4] Rejecting promises with erros instead of strings --- micropython.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/micropython.js b/micropython.js index a0612f2..e11b534 100644 --- a/micropython.js +++ b/micropython.js @@ -153,7 +153,7 @@ class MicroPythonBoard { data_consumer = data_consumer || function() {} return new Promise(async (resolve, reject) => { if (this.reject_run) { - this.reject_run('re run') + this.reject_run(new Error('re-run')) this.reject_run = null } this.reject_run = reject @@ -176,7 +176,7 @@ class MicroPythonBoard { async stop() { if (this.reject_run) { - this.reject_run('pre stop') + this.reject_run(new Error('pre stop')) this.reject_run = null } // Dismiss any data with ctrl-C @@ -186,7 +186,7 @@ class MicroPythonBoard { async reset() { if (this.reject_run) { - this.reject_run('pre reset') + this.reject_run(new Error('pre reset')) this.reject_run = null } // Dismiss any data with ctrl-C pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy