8000 Fix/del leftover symbols - v 1.5.1 by ubidefeo · Pull Request #20 · arduino/micropython.js · GitHub
[go: up one dir, main page]

Skip to content

Fix/del leftover symbols - v 1.5.1 #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Refactored commands. Delete f,w,l leftover symbols.
Signed-off-by: ubi de feo <me@ubidefeo.com>
  • Loading branch information
ubidefeo committed Dec 7, 2024
commit 63a140244f5f88438c92d0893f5aa2f660f3f2c9
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const executeString = (args, port, dataConsumer) => {
const code = args[0] || ''
return board.open(port)
.then(() => board.enter_raw_repl())
.then(() => board.exec_raw({ command: code, data_consumer: dataConsumer }))
.then(() => board.exec_raw(code, dataConsumer))
.then(async (out) => {
await board.exit_raw_repl()
await board.close()
Expand Down
21 changes: 15 additions & 6 deletions micropython.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class MicroPythonBoard {
command += ` print(1)\n`
command += `except OSError:\n`
command += ` print(0)\n`
command += `del f\n`
await this.enter_raw_repl()
let output = await this.exec_raw(command)
await this.exit_raw_repl()
Expand Down Expand Up @@ -245,6 +246,7 @@ class MicroPythonBoard {
command += ` print(l)\n`
command += `except OSError:\n`
command += ` print([])\n`
command += `del l\n`
await this.enter_raw_repl()
let output = await this.exec_raw(command)
await this.exit_raw_repl()
Expand All @@ -259,9 +261,16 @@ class MicroPythonBoard {
async fs_cat_binary(filePath) {
if (filePath) {
await this.enter_raw_repl()
let output = await this.exec_raw(
`with open('${filePath}','rb') as f:\n while 1:\n b=f.read(256)\n if not b:break\n print(",".join(str(e) for e in b),end=',')`
)
const chunkSize = 256
let command = `with open('${filePath}','rb') as f:\n`
command += ` while 1:\n`
command += ` b=f.read(${chunkSize})\n`
command += ` if not b:break\n`
command += ` print(",".join(str(e) for e in b),end=',')\n`
command += `del f\n`
command += `del b\n`
let output = await this.exec_raw(command)

await this.exit_raw_repl()
output = extractBytes(output, 2, 4)
return Promise.resolve((output))
Expand All @@ -273,7 +282,7 @@ class MicroPythonBoard {
if (filePath) {
await this.enter_raw_repl()
let output = await this.exec_raw(
`with open('${filePath}','r') as f:\n while 1:\n b=f.read(256)\n if not b:break\n print(b,end='')`
`with open('${filePath}','r') as f:\n while 1:\n b=f.read(256)\n if not b:break\n print(b,end='')\ndel f\ndel b\n`
)
await this.exit_raw_repl()
output = extract(output)
Expand All @@ -297,7 +306,7 @@ class MicroPythonBoard {
out += await this.exec_raw(line)
data_consumer( parseInt((i / contentBuffer.length) * 100) + '%')
}
out += await this.exec_raw(`f.close()`)
out += await this.exec_raw(`f.close()\ndel f\ndel w\n`)
out += await this.exit_raw_repl()
return Promise.resolve(out)
}
Expand All @@ -318,7 +327,7 @@ class MicroPythonBoard {
out += await this.exec_raw(line)
data_consumer( parseInt((i / contentBuffer.length) * 100) + '%')
}
out += await this.exec_raw(`f.close()`)
out += await this.exec_raw(`f.close()\ndel f\ndel w\n`)
out += await this.exit_raw_repl()
return Promise.resolve(out)
} else {
Expand Down
0