I've written an Arduino library for ESP32 and ESP8266.
I would like to add examples that utilize interrupts in the processor, the problem is that both processors handle interrupts slightly different. Is there a way to tell Arduino IDE to only show Exampel#1 if ESP8266 is selected and only show Example#2 when ESP32 is selected?
The Arduino IDE does have some features along these lines:
- Examples of boards platform bundled libraries are only shown in the File > Examples menu when a board of that platform is selected.
- Examples of libraries that don't have an entry in their library.properties "architectures" field matching the architecture of the currently selected board are shown under the File > Examples > INCOMPATIBLE menu.
However, neither of those are of help to you. The closest thing would be for you to split the library into two libraries; one for ESP8266, the other for ESP32. However, if there is a significant amount of code in the library shared between the two architectures, then that would result in extra effort to maintain the duplicate code.
What you could do is put the architecture-specific examples under dedicated subfolders:
| |_ SomeUniversalExampleSketch
| |_ SomeUniversalExampleSketch.ino
| |_ SomeESP32ExampleSketch
| |_ SomeESP32ExampleSketch.ino
This will result in the universal examples being under the File > Examples > MyLibrary > Universal menu, the ESP32-specific examples being under the File > Examples > MyLibrary > ESP32 menu, and the ESP8266-specific examples being under the File > Examples > MyLibrary > ESP8266 menu.
Of course, you can chose the folder structure and names as you like. This is only an example to demonstrate that the examples menu is organized according to subfolders. I have seen some library authors take this approach.
Also is there a way to change the name in the library manager once the library is published?
For the sake of continuity, libraries in the Library Manager list are locked in to the name they had at the time they were added to the list. If you wish to change the name it will need to be done manually by request:
- Change the name value in your library.properties file and update the version.
- Create a release or tag that matches the updated version value in library.properties.
- Submit an issue report requesting the name be changed and the URL of your library's repository.
Will it "break" if I just change the name in the properties file?
If you do that, all releases of the library made after the name change will be rejected by the Library Manager indexer. So those releases will not be available for installation via Library Manager.
This issue will not occur if you follow the procedure I quoted above.