How do I use .registerInitialiseFunction?

Michael Vogt , Niels de Klerk and others,

I assumed the .registerInitialiseFunction world register a callback function which would be called when a device has been added and it would be called with the device id. This seems not to be the case or I seem to misunderstand the usage.

When adding a device from a dynamic list of devices, I would like to know which device has been added, if any. How do I do this?

Reply
3replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Was looking through the code base just now since I didn't recognize that function - looks like it's a callback when the SDK starts

    As for your question - there is no API (that I'm aware of) that will let you know that directly.  Indirectly, when the brain adds a device - it will ask for the values of all the sensors.  So you can kinda get that as a side effect to the sensor request.  The other options is to have a thread constantly polling for the device keys and detecting changes to them (then you'd know when a device is added).  That is a little heavy though depending on how often you poll

    Like
  • I'll try to clarify the registerInitialiseFunction callback. It is used to initialize the driver rather than a specific device. It allows having a lazy initialization for example to save resources. So if a specific driver uses a lot of resource it can use the registerInitialiseFunction to only start when initialize is called (before a command is sent or before discovery).

    A device specific callback when a device is added (or removed) isn't currently available in the SDK (as of version 0.49.10). We're aware that this makes it hard to know which devices are currently added on the Brain, new callbacks to handle that will be added in an upcoming release.

    Like
Like Follow