Skip to content

Release Candidate v0.6 #30

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 13 commits into from
Dec 29, 2022
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Install Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: '14'
node-version: '16'
registry-url: 'https://registry.npmjs.org'

# - name: Install Python 2.7
Expand Down
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ ipcMain.handle('rename-file', (event, folder, filename, newFilename) => {
return newFilename
})

ipcMain.handle('set-window-size', (event, minWidth, minHeight) => {
console.log('ipcMain', 'set-window-size', minWidth, minHeight)
if (!win) {
console.log('No window defined')
return false
}

win.setMinimumSize(minWidth, minHeight)
})

// START APP
function createWindow () {
// Create the browser window.
Expand Down
58 changes: 43 additions & 15 deletions micropython.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ class MicroPythonBoard {
async open(device) {
if (device) {
this.device = device
}
if (!this.device) {
throw new Error(`No device specified`)
} else {
return Promise.reject(
new Error(`No device specified`)
)
}
if (this.serial && this.serial.isOpen) {
await this.serial.close()
Expand Down Expand Up @@ -73,8 +74,10 @@ class MicroPythonBoard {
timeout = null,
data_consumer = () => false
} = options || {}
const parser = this.serial.pipe(
new ReadlineParser({ delimiter: ending })
)
return new Promise((resolve, reject) => {
const parser = this.serial.pipe(new ReadlineParser({ delimiter: ending }))
let waiting = 0
if (timeout) {
waiting = setTimeout(() => {
Expand Down Expand Up @@ -196,11 +199,31 @@ class MicroPythonBoard {
return Promise.reject()
}

async fs_ls() {
async fs_exists(filePath) {
filePath = filePath || ''
let command = `try:\n`
command += ` f = open("${filePath}", "r")\n`
command += ` print(1)\n`
command += `except OSError:\n`
command += ` print(0)\n`
await this.enter_raw_repl()
const output = await this.exec_raw({
command: `import uos\nprint(uos.listdir())`
})
let output = await this.exec_raw({ command: command })
await this.exit_raw_repl()
// Extract output
output = output.split('OK')
let result = output[2] || ''
return Promise.resolve(result[0] === '1')
}

async fs_ls(folderPath) {
folderPath = folderPath || ''
let command = `import uos\n`
command += `try:\n`
command += ` print(uos.listdir("${folderPath}"))\n`
command += `except OSError:\n`
command += ` print([])\n`
await this.enter_raw_repl()
const output = await this.exec_raw({ command: command })
await this.exit_raw_repl()
return Promise.resolve(output)
}
Expand Down Expand Up @@ -267,29 +290,34 @@ class MicroPythonBoard {
const output = await this.exec_raw({
command: `import uos\nuos.mkdir('${filePath}')`
})
console.log(output)
return this.exit_raw_repl()
}
return Promise.reject()
}

async fs_rmdir() {
if (filePath) {
let command = `import uos\n`
command += `try:\n`
command += ` uos.rmdir("${filePath}")\n`
command += `except OSError:\n`
command += ` print(0)\n`
await this.enter_raw_repl()
const output = await this.exec_raw({
command: `import uos\nuos.rmdir('${filePath}')`
})
const output = await this.exec_raw({ command: command })
return this.exit_raw_repl()
}
return Promise.reject()
}

async fs_rm(filePath) {
if (filePath) {
let command = `import uos\n`
command += `try:\n`
command += ` uos.remove("${filePath}")\n`
command += `except OSError:\n`
command += ` print(0)\n`
await this.enter_raw_repl()
const output = await this.exec_raw({
command: `import uos\nuos.remove('${filePath}')`
})
const output = await this.exec_raw({ command: command })
return this.exit_raw_repl()
}
return Promise.reject()
Expand Down
Loading