7 years, 4 months ago.

Base class for DigitalIn DigitalOut AnalogIn ?

Hi, is there a base class for DigitalIn, DigitalOut and AnalogIn I can use to create a single array of different pins?

I found those classes inherited from a same class named "Base" in the past (https://developer.mbed.org/users/screamer/code/mbed/file/aff670d0d510/Base.h and )

but this seems to be no more true in newer mbed-dev versions.. (https://developer.mbed.org/users/mbed_official/code/mbed/file/0ab6a29f35bf/drivers and https://developer.mbed.org/users/mbed_official/code/mbed-dev/file/02e0a0aed4ec/drivers)

Is it still possible to instantiate a single array of pins object, regardless of their type?

1 Answer

7 years, 4 months ago.

You can make a single array of pins, since they are of their own type (well the PinNames). But I don't think it is possible anymore to do what you want. The question is: Why do you want that? It isn't like they really have common functions you can iterate over in an array.

Hi, I would like to initialize/reconfigure pins of RedBear BLE Nano dinamically at runtime via ble, exactly like the RedBear BLEController.ino sketch fro Arduino does (https://github.com/RedBearLab/nRF8001/blob/master/examples/BLEControllerSketch/BLEControllerSketch.ino), so I was thinking of allocating pins dinamically as Base class object and then cast them dinamically to the right class at run-time.

Currently I bypassed this issue by using 3 straight maps, one for DigitalIn, DigitalOut and AnalogIn, which are dinamically allocated.

std::map <int, DigitalIn*> digitalIns; pins that have been already initialized as digital inputs

std::map <int, DigitalOut*> digitalOuts; pins that have been already initialized as digital outputs

std::map <int, AnalogIn*> analogIns; pins that have been already initialized as analog inputs

Each time a new "ble initialize pin" message comes, I initialize the pin as requested and put it into the correct map, in this way:

digitalIns[pinNo] = new DigitalIn(pinNames[pinNo]);

But now another issue has raised:

Currently I am using both BLE_API to interact with nano pins, and the Serial class to have some log messages from Nano to my notebook to know what is going on. The problem is: if I initialize a pin before the ble.init() function call, the pin gets correctly initialized, but if I place the same code after the ble.init() function, the same code does not work. Thus currently I cannot initialize them dinamically via ble.

1) Is there a timeout for pin initialization? After some time pins cannot be anymore initialized?

2) Are there some threading issues in working at the same time with ble classes, pin initialization and serial class?

Thanks in advance!! ;)

posted by gio wild 17 Nov 2016

I am not that familiar with the BLE API, but in general creating pins dynamically should be perfectly fine. That seems to me to be the bug, or at least the unwanted behavior.

posted by Erik - 17 Nov 2016