Skip to content
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
17 changes: 17 additions & 0 deletions js/common/ble-file-transfer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
import {FileTransferClient as BLEFileTransferClient} from '@adafruit/ble-file-transfer-js';
//import {FileTransferClient as BLEFileTransferClient} from '../../../ble-file-transfer-js/adafruit-ble-file-transfer.js';

// Wrapper for BLEFileTransferClient to add additional functionality
class FileTransferClient extends BLEFileTransferClient {
constructor(bleDevice, bufferSize) {
super(bleDevice, bufferSize);
}

async readOnly() {
let readonly = false;
return false;
// Check if the device is read only
console.log("Checking if device is read only");
// Attempt to write a 0-byte temp file and remove it
const testPath = '/._ble_readonly_check';
try {
await this.writeFile(testPath, 0, new Uint8Array(0));
await this.deleteFile(testPath);
} catch (e) {
readonly = true;
}
return readonly;
}

async versionInfo() {
// Possibly open /boot_out.txt and read the version info
let versionInfo = {};
Expand Down
4 changes: 4 additions & 0 deletions js/common/dialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ class GenericModal {
this._closeModal();
}

isOpen() {
return this._currentModal !== null;
}

isVisible() {
var style = window.getComputedStyle(this._currentModal);
return style.display !== 'none';
Expand Down
21 changes: 12 additions & 9 deletions js/common/file_dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,12 @@ class FileDialog extends GenericModal {
}

for (let filename of filenames) {
// Delete the item
await this._showBusy(this._fileHelper.delete(filename));
await this._showBusy(this._fileHelper.delete(this._currentPath + filename));
}

// Refresh the file list
await this._openFolder();
};
}

async _handleUploadButton() {
if (this._readOnlyMode) return;
Expand Down Expand Up @@ -670,12 +669,16 @@ class FileDialog extends GenericModal {
}

// Rename the file, by moving in the same folder
await this._showBusy(
this._fileHelper.move(
this._currentPath + oldName,
this._currentPath + newName
)
);
try {
await this._showBusy(
this._fileHelper.move(
this._currentPath + oldName,
this._currentPath + newName
)
);
} catch (error) {
console.error(error);
}

// Refresh the file list
await this._openFolder();
Expand Down
13 changes: 12 additions & 1 deletion js/common/fsapi-file-transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,18 @@ class FileTransferClient {
const [parentFolder, itemName] = this._splitPath(path);
const parentFolderHandle = await this._getSubfolderHandle(parentFolder);

await parentFolderHandle.removeEntry(itemName);
try {
await parentFolderHandle.removeEntry(itemName, {recursive: true});
} catch (error) {
// If this was a folder with items inside, a NotFoundError is thrown due to a bug in the browser
if (error.name == 'NotFoundError') {
// Recursive items should be removed at this point,
// so attempt again without recursive
await parentFolderHandle.removeEntry(itemName);
} else {
throw error;
}
}

return true;
}
Expand Down
14 changes: 10 additions & 4 deletions js/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,24 @@ function refitTerminal() {
let viewportHeight = window.innerHeight;
let terminalHeight = viewportHeight - headerHeight - footerBarHeight - serialBarHeight;
let terminalWidth = document.getElementById('serial-page').offsetWidth;
let screen = document.querySelector('.xterm-screen');
if (screen) {
let xterm_screen = document.querySelector('.xterm-screen');
if (xterm_screen) {
let cols = Math.floor(terminalWidth / TERMINAL_COL_WIDTH);
let rows = Math.floor(terminalHeight / TERMINAL_ROW_HEIGHT);
console.log(rows, cols, terminalHeight, terminalWidth, TERMINAL_ROW_HEIGHT, TERMINAL_COL_WIDTH);
if (cols < MINIMUM_COLS) {
cols = MINIMUM_COLS;
}
if (rows < MINIMUM_ROWS) {
rows = MINIMUM_ROWS;
}
screen.style.width = (cols * TERMINAL_COL_WIDTH) + 'px';
screen.style.height = (rows * TERMINAL_ROW_HEIGHT) + 'px';
xterm_screen.style.width = (cols * TERMINAL_COL_WIDTH) + 'px';
xterm_screen.style.height = (rows * TERMINAL_ROW_HEIGHT) + 'px';
let xterm_rows = document.querySelector('.xterm-rows');
if (xterm_rows) {
xterm_rows.style.height = (rows * TERMINAL_ROW_HEIGHT) + 'px';
}
state.terminal.resize(cols, rows);
}
});
});
Expand Down
32 changes: 16 additions & 16 deletions js/workflows/ble.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {CONNTYPE} from '../constants.js';
import {Workflow} from './workflow.js';
import {GenericModal, DeviceInfoModal} from '../common/dialogs.js';
import {sleep} from '../common/utilities.js';
import {bluetooth} from 'webbluetooth';

const bleNusServiceUUID = 'adaf0001-4369-7263-7569-74507974686e';
const bleNusCharRXUUID = 'adaf0002-4369-7263-7569-74507974686e';
Expand Down Expand Up @@ -72,8 +71,7 @@ class BLEWorkflow extends Workflow {
}
try {
this.clearConnectStatus();
const devices = await bluetooth.getDevices();
console.log(devices);
const devices = await navigator.bluetooth.getDevices();
this.connectionStep(devices.length > 0 ? 2 : 1);
} catch (error) {
console.error(error);
Expand Down Expand Up @@ -119,7 +117,7 @@ class BLEWorkflow extends Workflow {
if (!this.connectionStatus()) {
try {
console.log('Getting existing permitted Bluetooth devices...');
const devices = await bluetooth.getDevices();
const devices = await navigator.bluetooth.getDevices();

console.log('> Found ' + devices.length + ' Bluetooth device(s).');
// These devices may not be powered on or in range, so scan for
Expand All @@ -137,7 +135,7 @@ class BLEWorkflow extends Workflow {

// Bring up a dialog to request a device
async requestDevice() {
return bluetooth.requestDevice({
return navigator.bluetooth.requestDevice({
filters: [{services: [0xfebb]},], // <- Prefer filters to save energy & show relevant devices.
optionalServices: [0xfebb, bleNusServiceUUID]
});
Expand Down Expand Up @@ -171,11 +169,11 @@ class BLEWorkflow extends Workflow {
device.removeEventListener('advertisementreceived', onAdvertisementReceived.bind(this));
device.addEventListener('advertisementreceived', onAdvertisementReceived.bind(this));

this.debugLog("connecting to " + device.name);
this.debugLog("Attempting to connect to " + device.name + "...");
try {
this.clearConnectStatus();
console.log('Watching advertisements from "' + device.name + '"...');
console.log('If no advertisements are received, make sure the device is powered on and in range. You can also try resetting the device');
console.log('If no advertisements are received, make sure the device is powered on and in range. You can also try resetting the device.');
await device.watchAdvertisements({signal: abortController.signal});
}
catch (error) {
Expand All @@ -194,22 +192,24 @@ class BLEWorkflow extends Workflow {
await this.connectToBluetoothDevice(device);
}

async onConnected(e) {
this.debugLog("Connected to " + this.bleDevice.name);
await super.onConnected(e);
}

async switchToDevice(device) {
console.log(device);
this.bleDevice = device;
this.bleDevice.removeEventListener("gattserverdisconnected", this.onDisconnected.bind(this));
this.bleDevice.addEventListener("gattserverdisconnected", this.onDisconnected.bind(this));
//this.bleServer = this.bleDevice.gatt;
console.log("connected", this.bleServer);
let services;

console.log(device.gatt.connected);
//try {
try {
let services;
services = await this.bleServer.getPrimaryServices();
/*} catch (e) {
console.log(services);
} catch (e) {
console.log(e, e.stack);
}*/
console.log(services);
}

console.log('Initializing File Transfer Client...');
this.initFileClient(new FileTransferClient(this.bleDevice, 65536));
Expand Down Expand Up @@ -253,7 +253,7 @@ class BLEWorkflow extends Workflow {
}
// Is this a new connection?
if (!this.bleDevice) {
let devices = await bluetooth.getDevices();
let devices = await navigator.bluetooth.getDevices();
for (const device of devices) {
await this.connectToBluetoothDevice(device);
}
Expand Down
1 change: 1 addition & 0 deletions js/workflows/usb.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class USBWorkflow extends Workflow {
async onConnected(e) {
this.connectDialog.close();
await this.loadEditor();
this.debugLog("connected");
super.onConnected(e);
}

Expand Down
1 change: 1 addition & 0 deletions js/workflows/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class WebWorkflow extends Workflow {
}

async onConnected(e) {
this.debugLog("connected");
await super.onConnected(e);
//this.connIntervalId = setInterval(this._checkConnection.bind(this), PING_INTERVAL_MS);
}
Expand Down
12 changes: 11 additions & 1 deletion js/workflows/workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Workflow {
}

async onDisconnected(e, reconnect = true) {
console.log("onDisconnected called in workflow");
this.debugLog("disconnected");
this.updateConnected(CONNSTATE.disconnected);
// Update Common UI Elements
Expand All @@ -115,7 +116,6 @@ class Workflow {
}

async onConnected(e) {
this.debugLog("connected");
console.log("Connected!");
this.updateConnected(CONNSTATE.connected);
if (this.connectDialog) {
Expand Down Expand Up @@ -314,6 +314,11 @@ class Workflow {

// Handle the different button states for various connection steps
connectionStep(step) {
// Check if a dialog exists
if (!this.connectDialog.isOpen()) {
return;
}

if (step < 0) step = 0;
if (step > this.buttonStates.length - 1) step = this.buttonStates.length - 1;

Expand All @@ -340,6 +345,11 @@ class Workflow {
}

clearConnectStatus(modal) {
// Check if a dialog exists
if (!this.connectDialog.isOpen()) {
return;
}

try {
const modal = this.connectDialog.getModal();
modal.querySelector('.connect-status').hidden = true;
Expand Down
Loading