particle-iot / particle-usb

A library for accessing Particle USB devices
Apache License 2.0
5 stars 1 forks source link

Allow entering safe mode from DFU #111

Closed sergeuz closed 3 months ago

sergeuz commented 4 months ago

Extend the enterSafeMode() method to use a custom DfuSe command for entering safe mode when the device is in DFU mode.

Test app:

const { getDevices } = require('particle-usb');

async function run() {
  let dev;
  try {
    // Open the first found USB device
    const devs = await getDevices();
    if (!devs.length) {
      throw new Error('No devices found');
    }
    dev = devs[0];
    if (!dev.isInDfuMode) {
      throw new Error('Device is not in DFU mode');
    }
    await dev.open();

    await dev.enterSafeMode();

  } catch (err) {
    console.error(err);
    process.exit(1);
  } finally {
    if (dev) {
      await dev.close();
    }
  }
}

run();