Git Product home page Git Product logo

Comments (4)

undera avatar undera commented on July 28, 2024

The original LED peripheral code did not contain any functions for subscribing to get sensor data. After your change that introduced "sensor properties", you have added one. It seems that LED should not have that property, as it does not support getting the LED state...

If I am wrong, please point me to the place, where old implementation were accessing that information.

from pylgbst.

ysard avatar ysard commented on July 28, 2024

Properties are just bindings of pre-existing functions; the old code is here:

def _decode_port_data(self, msg):
if len(msg.payload) == 3:
return usbyte(msg.payload, 0), usbyte(msg.payload, 1), usbyte(msg.payload, 2),
else:
return usbyte(msg.payload, 0),

I may be misinterpreting the API but to me it means that this data can be obtained from the hub via get_sensor_data().
Subscribing to this color data is showed on the old doc :
LED

Example:

print("ATTACH callback")
def callback(*args):
    print("Color has changed:", args)
myhub.led.subscribe(callback)

print("led set to red")
myhub.led.set_color(9)  
print("led set to green")
myhub.led.set_color(6)  

print("current color - mode 0", myhub.led.get_sensor_data(0))
print("current color - mode 1", myhub.led.get_sensor_data(1))

Result:

ATTACH callback
led set to red
led set to green
current color - mode 0 (0,)
Color has changed: (0,)
current color - mode 1 (0, 0, 0)
Color has changed: (0, 0, 0)

Indeed, I can see that it's the explicit access via get_sensor_data() that triggers the callback and that the callback showed
in the doc is never called otherwise.

If these functions (get_sensor_data() and _decode_port_data()) shouldn't be used in this class, maybe they should be overwritten to raise something like "NotImplementedError". And the doc should be updated to remove any callback reference.
All this to avoid misuse.

I can propose a PR to fix all of this, according to your choice.

Some review of other projects:

Returns: tuple (int r,int g,int b) each has a value between 0 and 255. Only if no arguments are given.

Note: => I'm more likely to believe the unofficial doc than the partial and out of date Lego one.

from pylgbst.

undera avatar undera commented on July 28, 2024

Thanks for the thorough investigation.

I'm starting to remember that in my early experiments I saw that LED peripheral does send some data back, thus I have included the code to decode the messages. It is highly likely that HW sends those messages, but it's a sort of "incomplete" functionality on HW side.

When I've done "capabilities" scan on Hub's peripherals, some undocumented sensor modes come out. I tried to include them all into the library, even if it's a not documented (by LEGO) functionality.

I guess we can just put a note in documentation, saying that sensor data getting from LED does not produce meaningful results.

from pylgbst.

ysard avatar ysard commented on July 28, 2024

Thanks for the feedback, you're totally right; similarly, the headlight device brightness recovery shouldn't work either as it's not documented but it does...
The PR should fix that;

I was mistaken because the description of the 2 devices is similar:
=> no input_modes, 1, some output_modes for both

LEDRGB:

modes: {'mode_count': 2, 'input_modes': [], 'output_modes': [{'Mode': 0, 'Name': 'COL O', 'Raw range': [0.0, 10.0], 'Percent range': [0.0, 100.0], 'SI value range': [0.0, 10.0], 'Units': '', 'Mapping': {'input': [], 'output': ['Discrete [0, 1, 2, 3]', 'Supports Functional Mapping 2.0+']}, 'Value encoding': {'datasets': 1, 'type': '8 bit', 'total_figures': 1, 'decimals': 0}}, {'Mode': 1, 'Name': 'RGB O', 'Raw range': [0.0, 255.0], 'Percent range': [0.0, 100.0], 'SI value range': [0.0, 255.0], 'Units': '', 'Mapping': {'input': [], 'output': ['Absolute [min..max]']}, 'Value encoding': {'datasets': 3, 'type': '8 bit', 'total_figures': 3, 'decimals': 0}}], 'capabilities': {'logically_combinable': False, 'synchronizable': False, 'can_output': True, 'can_input': False}

Headlight:

modes: {'mode_count': 1, 'input_modes': [], 'output_modes': [{'Mode': 0, 'Name': 'LPF2-LIGHT', 'Raw range': [-10.0, 10.0], 'Percent range': [-100.0, 100.0], 'SI value range': [-10.0, 10.0], 'Units': '', 'Mapping': {'input': [], 'output': ['Relative [-1..1]']}, 'Value encoding': {'datasets': 1, 'type': '8 bit', 'total_figures': 1, 'decimals': 0}}], 'capabilities': {'logically_combinable': False, 'synchronizable': False, 'can_output': True, 'can_input': False},

from pylgbst.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.