Update: 更新ampy

This commit is contained in:
王立帮
2024-08-17 23:59:17 +08:00
parent 29f15dd7d4
commit edce8ed5bc
8 changed files with 46 additions and 34 deletions

View File

@@ -5,6 +5,17 @@ goog.provide('Mixly.Ampy');
class Ampy {
constructor() {}
unhexlify(hexString) {
if (hexString.length % 2 !== 0) {
hexString = hexString + '0';
}
let bytes = [];
for (let c = 0; c < hexString.length; c += 2) {
bytes.push(parseInt(hexString.substr(c, 2), 16));
}
return new Uint8Array(bytes);
}
async get() {}
async ls() {}
async mkdir() {}

View File

@@ -1529,6 +1529,7 @@
"Mustache",
"Mixly.Env",
"Mixly.Msg",
"Mixly.Ampy",
"Mixly.Web"
],
"provide": [

View File

@@ -130,7 +130,7 @@ class AmpyFS extends FS {
let stdout = [], error = null;
try {
const output = await this.#ampy_.ls(this.#port_, this.#baud_, folderPath);
const dirs = Array.from(output.stdout.split('\r\n'));
const dirs = Array.from(new Set(output.stdout.split('\r\n')));
for (let i in dirs) {
if (!dirs[i]) {
continue;

View File

@@ -329,12 +329,10 @@ ArduShell.upload = (boardType, port) => {
}
ArduShell.runCmd(layerNum, 'upload', cmdStr,
function () {
setTimeout(() => {
mainStatusBarTabs.add('serial', port);
mainStatusBarTabs.changeTo(port);
const statusBarSerial = mainStatusBarTabs.getStatusBarById(port);
statusBarSerial.open();
}, 1000);
mainStatusBarTabs.add('serial', port);
mainStatusBarTabs.changeTo(port);
const statusBarSerial = mainStatusBarTabs.getStatusBarById(port);
statusBarSerial.open();
}
);
}

View File

@@ -170,7 +170,7 @@ class AmpyFS extends FS {
}
async readDirectory(folderPath) {
let stdout = '', error = null, ampy = null;
let stdout = [], error = null, ampy = null;
try {
ampy = await this.getAmpy();
await ampy.enter();

View File

@@ -4,13 +4,19 @@ goog.require('path');
goog.require('Mustache');
goog.require('Mixly.Env');
goog.require('Mixly.Msg');
goog.require('Mixly.Ampy');
goog.require('Mixly.Web');
goog.provide('Mixly.Web.Ampy');
const { Env, Msg, Web } = Mixly;
const {
Env,
Msg,
Ampy,
Web
} = Mixly;
class Ampy {
class AmpyExt extends Ampy {
static {
this.LS = goog.get(path.join(Env.templatePath, 'python/ls.py'));
this.LS_RECURSIVE = goog.get(path.join(Env.templatePath, 'python/ls-recursive.py'));
@@ -28,6 +34,7 @@ class Ampy {
#writeBuffer_ = false;
#active_ = false;
constructor(device) {
super();
this.#device_ = device;
this.#addEventsListener_();
}
@@ -43,17 +50,6 @@ class Ampy {
});
}
#unhexlify_(hexString) {
if (hexString.length % 2 !== 0) {
hexString = hexString + '0';
}
let bytes = [];
for (let c = 0; c < hexString.length; c += 2) {
bytes.push(parseInt(hexString.substr(c, 2), 16));
}
return new Uint8Array(bytes);
}
isActive() {
return this.#active_;
}
@@ -186,7 +182,7 @@ class Ampy {
if (!this.isActive()) {
throw new Error('串口未打开');
}
const code = Mustache.render(Ampy.GET, {
const code = Mustache.render(AmpyExt.GET, {
path: filename
});
await this.exec(code);
@@ -197,7 +193,7 @@ class Ampy {
let str = await this.readUntil('>', false, timeout);
str = str.replace('\x04\x04', '');
if (str.indexOf('OSError') === -1) {
str = this.#device_.decode(this.#unhexlify_(str));
str = this.#device_.decode(this.unhexlify(str));
return str;
}
return false;
@@ -232,15 +228,15 @@ class Ampy {
}
let code = '';
if (longFormat) {
code = Mustache.render(Ampy.LS_LONG_FORMAT, {
code = Mustache.render(AmpyExt.LS_LONG_FORMAT, {
path: directory
});
} else if (recursive) {
code = Mustache.render(Ampy.LS_RECURSIVE, {
code = Mustache.render(AmpyExt.LS_RECURSIVE, {
path: directory
});
} else {
code = Mustache.render(Ampy.LS, {
code = Mustache.render(AmpyExt.LS, {
path: directory
});
}
@@ -262,7 +258,7 @@ class Ampy {
if (!this.isActive()) {
throw new Error('串口未打开');
}
const code = Mustache.render(Ampy.MKDIR, {
const code = Mustache.render(AmpyExt.MKDIR, {
path: directory
});
await this.exec(code);
@@ -281,7 +277,7 @@ class Ampy {
if (!this.isActive()) {
throw new Error('串口未打开');
}
const code = Mustache.render(Ampy.MKFILE, {
const code = Mustache.render(AmpyExt.MKFILE, {
path: file
});
await this.exec(code);
@@ -300,7 +296,7 @@ class Ampy {
if (!this.isActive()) {
throw new Error('串口未打开');
}
const code = Mustache.render(Ampy.RENAME, {
const code = Mustache.render(AmpyExt.RENAME, {
oldPath: oldname,
newPath: newname
});
@@ -320,7 +316,7 @@ class Ampy {
if (!this.isActive()) {
throw new Error('串口未打开');
}
const code = Mustache.render(Ampy.RM, {
const code = Mustache.render(AmpyExt.RM, {
path: filename
});
await this.exec(code);
@@ -339,7 +335,7 @@ class Ampy {
if (!this.isActive()) {
throw new Error('串口未打开');
}
const code = Mustache.render(Ampy.RMDIR, {
const code = Mustache.render(AmpyExt.RMDIR, {
path: directory
});
await this.exec(code);
@@ -365,6 +361,6 @@ class Ampy {
}
}
Web.Ampy = Ampy;
Web.Ampy = AmpyExt;
});

View File

@@ -31,7 +31,10 @@ def listdir(directory):
dirs = sorted([directory + '/' + f for f in os.listdir(directory)])
for dir in dirs:
output.append([dir, check_path(dir)])
info = check_path(dir)
if info == 'none':
continue
output.append([dir, info])
return output
print(listdir('{{&path}}'))

View File

@@ -170,7 +170,10 @@ class Files(object):
dirs = sorted([directory + '/' + f for f in os.listdir(directory)])
for dir in dirs:
output.append([dir, check_path(dir)])
info = check_path(dir)
if info == 'none':
continue
output.append([dir, info])
return output\n"""
# Execute os.listdir() command on the board.