nathankellenicki / node-poweredup

A Javascript module to interface with LEGO Powered Up components.
https://nathankellenicki.github.io/node-poweredup/
MIT License
477 stars 59 forks source link

add RGB and HSV to Technic Color Sensor #172

Open tylerfowle opened 1 year ago

tylerfowle commented 1 year ago

Add the ability to get the RGB and/or HSV values from the Technic Color Sensor. https://docs.pybricks.com/en/stable/pupdevices/colorsensor.html#pybricks.pupdevices.ColorSensor.hsv

Add the ability to customize the default detectable colors. Similar to what pybricks does. https://docs.pybricks.com/en/stable/pupdevices/colorsensor.html#pybricks.pupdevices.ColorSensor.detectable_colors

Additionally, it would be nice if these could be getter functions so you can query the color at a specific time, rather than the current Event system.

Debenben commented 1 year ago

@tylerfowle I made a proposal for implementing some of the missing sensor modes. Until the changes are merged to the main repo here, you can use my fork https://www.npmjs.com/package/@debenben/node-poweredup where a couple of other pull requests are merged, too.

This library will never be as fast as pybricks when getting sensor values. To have something like a getter, you could do:

const hsvValue = await new Promise(res => {sensor.once('hsvAmbient', val => res(val))});

or use the undocumented function

sensor.requestUpdate();

which triggers an update of the sensor value regardless of changes.