10000 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 all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to 10000
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
26 changes: 18 additions & 8 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 @@ -240,11 +241,13 @@ class MicroPythonBoard {
let command = `import uos\n`
command += `try:\n`
command += ` l=[]\n`
command += ` for file in uos.ilistdir("${folderPath}"):\n`
command += ` l.append(list(file))\n`
command += ` for f in uos.ilistdir("${folderPath}"):\n`
command += ` l.append(list(f))\n`
command += ` print(l)\n`
command += `except OSError:\n`
command += ` print([])\n`
command += `del l\n`
command += `del f\n`
await this.enter_raw_repl()
let output = await this.exec_raw(command)
await this.exit_raw_repl()
Expand All @@ -259,9 +262,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 +283,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 +307,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 +328,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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "micropython.js",
"version": "1.5.0",
"version": "1.5.1",
"description": "Interpretation of pyboard.py in javascript",
"main": "micropython.js",
"scripts": {
Expand Down
0