Over the last few weeks I have been exploring OpenFL and Haxe.
I was particularly interested in getting OpenFL to run on the Raspberry Pi.
One of the cool things about the Raspberry Pi of course is the GPIO-ports.
So after I got a version of OpenFL running on the Pi it was time to take the next step and look into the development of native extensions for OpenFL.
I don’t really have a background in c or c++, but I’m able to read through other people’s code if it’s not to complicated.
I had a look at the hxSerial extension and for the most part was able to see what was going on.
I had already been playing around with the wiringPi library and the c-examples that came with it, and I knew how to blink an led and how to read from a digital input port.
Last but not least I had a look at a post on player03.com
So by combining the things I saw in these examples I took the first step towards creating my hxPiGpio extension.
I’ll probably make a separate post in the near future on how to create an openfl c++ extension. But for now I’m focusing on how to use my Extension.
I wrapped the wiringPi setup functions , the digitalRead and digitalWrite functions and some static inline vars for the pinmodes.
If you would like to try out the extension follow these steps: (WARNING EXPERIMENTAL CODE)
First of all you need to run Raspbian Jessie! if you want to be able to test using the ‘openfl test linux’ command.
This is because on Wheezy the gpio ports require the use of the sudo command, while on Jessie you can access them without the sudo command if you add a file to /etc/dev/rules.d/
Next of course get openfl working through the steps of my earlier post.
If that’s working go ahead and install wiringPi and make sure you are using version 2.29 following the steps on this page
do not forget to add the file to /etc/dev/rules.d/ as mentioned and shutdown your pi.
While your pi is off it’s a good time to connect an led and button in the following fashion and restart your pi.
( at your own risk of course, I am not responsible for any damage to your pi )
Checkout the extension from my github page to the directory where you keep the development haxelib modules
( I keep the ones I get from ‘haxelib install ..’, separate from the ones I compile from source)
Now compile the extension
git clone https://github.com/gepatto/hxPiGpio.git
haxelib dev hxPiGpio hxPiGpio
lime rebuild . linux -rpi
now you checkout the testProject in the directory where you keep your projects, and compile
git clone https://github.com/gepatto/hxPiGpioTest
openfl test linux
hopefully, if I didn’t miss any steps, you’ll see something like this:
and you will be able to click on the led on screen and have it turn on the actual led, and press the button to toggle the color-version of the raspi logo.
the latest version of this testproject is trying to connect to SPI so it might not work if you have not enabled it in raspi-config.
( haven’t tried this yet with spi disabled)
You can probably also comment out the line in Main.hx that says
This is all still experimental / proof of concept. I’m not concerned with coding conventions or even proper code at the moment.
That will happen if I decide to put the extension up on haxelib and my c++ skills have improved.
Feel free to fork and improve the code if you have more experience in c++