Skip to content
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

Accurate device state detection for devices in DFU #115

Merged
merged 4 commits into from
Jul 30, 2024

Conversation

keeramis
Copy link
Contributor

@keeramis keeramis commented Jul 26, 2024

Problem

Currently, there is no way to distinguish between Open and Protected Devices in Service Mode when the device is in DFU mode.

Solution

This PR obtains and parses the result of the string descriptor with the correct index for the device state
Device-OS changes are in this PR (estimated 6.1.2)

Testing

Use this Device-OS PR -
Use a script like this

#!/usr/bin/env node

const { getDevices } = require('/path/to/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();
    const res = await dev.getProtectionState();
    console.log('Protection state:', res);

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

run();

Copy link
Member

@monkbroc monkbroc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@keeramis keeramis merged commit 1eb9d87 into main Jul 30, 2024
4 checks passed
@keeramis keeramis deleted the feature/improve-device-state-detection branch July 30, 2024 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants