Skip to content

Using boost color and distance sensor in mode 1 returns distance as color #55

Description

@aileo

I tried to subscribe to a color and distance sensor on a PUP hub on port A using this code (based on the web_bluetooth example):

const poweredUP = new PoweredUP.PoweredUP();
poweredUP.autoSubscribe = false;
poweredUP.on("discover", async (hub) => { // Wait to discover hubs
    await hub.connect(); // Connect to hub
    log(`Connected to ${hub.name}!`);
    hub.sleep(1000)
    hub.subscribe('A', 1);
    hub.on('distance', (port, ...values) => log(`distance on A: ${ JSON.stringify(values) }`));
    hub.on('color', (port, ...values) => log(`color on A: ${ JSON.stringify(values) }`));
    hub.on('colorAndDistance', (port, ...values) => log(`colorAndDistance on A: ${ JSON.stringify(values) }`));
});

And I get this output when I get the sensor closer to an obstacle:

Connected to PoweredUp!
color on A: [10]
distance on A: [null]
colorAndDistance on A: [10,null]
color on A: [9]
distance on A: [null]
colorAndDistance on A: [9,null]
color on A: [8]
distance on A: [null]
colorAndDistance on A: [8,null]
color on A: [7]
distance on A: [null]
colorAndDistance on A: [7,null]
color on A: [6]
distance on A: [null]
colorAndDistance on A: [6,null]
color on A: [5]
distance on A: [null]
colorAndDistance on A: [5,null]
color on A: [4]
distance on A: [null]
colorAndDistance on A: [4,null]
color on A: [2]
distance on A: [null]
colorAndDistance on A: [2,null]
color on A: [3]
distance on A: [null]
colorAndDistance on A: [3,null]
color on A: [2]
distance on A: [null]
colorAndDistance on A: [2,null]

Message structure depends on device mode and I don't think message contains the device mode.
I think it should be relevant to store mode in port informations to handle this. If others thinks the same I can work on a PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions