Posts

Showing posts from September, 2020

Making C++ wrapper libraries for Swift for Arduino - part 1

I have just started adding a library to use the Adafruit Bluefruit LE, which is a great little shield made by Adafruit. Problem is, as ever, their software they give away is to make the shield work with Arduino/C++. What to do? Since version 2.9 of Swift for Arduino, it has been possible to use a special category of library files in addition to the usual ones from the community github site. Just like the usual library files, these are of the form XXX.swift, are all kept in the github community site for general use (https://github.com/swiftforarduino/community see the community libraries). This new type are named unsafeXXX.swift to be clear that they contain a core of unsafe C++ (usually legacy) code. In nearly every case, the code could be ported to pure swift at some point but it can be a lot of work, so in order to make it possible to get up and running faster and to leverage existing legacy code, it can be wrapped in Swift. The basic way this works is this: 1) make a new p