Hello,
I am using bela as the processor for a framework for musical expression, in which the user may connect any combination of a number of pre-specified sensors (ToF Distance, Accelerometer, etc.) - each of which have i2c driver classes written for them. Currently, the p5 GUI has a dropdown that allows them to create a modulation matrix, connecting various sensor output channels to audio parameters. When a new connection is made, the GUI sends JSON control messages to C++, which are parsed by the callback function and stored in a Connection class.
Each of the sensor classes has a variable _labels = {"AccX", "AccY", "AccZ", "GyrX", "GyrY", "GyrZ"};
In setup() the various connected sensors are detected and their labels are added to a globalLabels vector. I would like to send this list of valid sensor output channels to the GUI, so that the user can only select from the connected sensor output channels in the modulation matrix, rather than all channels that have been implemented (even if not connected). This way, the user also only has to create a new i2c driver class for any new sensor they wish to connect, and they don't have to modify any p5 code (like updating magic numbers that would encode for unique sensor channels, if they were to be passed through bela's buffers the usual way).
I would like to implement this with a JSON handshake protocol similar to the modulation matrix, except this requires that a vector of strings is passed from C++ to p5 - I am unsure how to do this or if it is even possible? The order of events would be:
- C++ runs setup() and detects sensors (always in the same order), and generates globalLabels
- GUI loads (with empty dropdown) and requests list of sensor channels with a control signal
- C++ sends the list of sensor channels (as a JSON object?)
- GUI populates dropdown with list of connected channel labels.
Please let me know if this is the right way to go about this (and if so, how)! It is safe to assume that the list connected sensors will not change during runtime.
Thanks 🙂