Just before Christmas, I put together an application for an Aviva installation in Waterloo station, in association with We Make Stuff Happen, so that passers-by could vote for their choice of the safest driver in that day’s category.
The installation had two buttons which would cast a vote by posting the user’s choice to Twitter. The buttons would light up red when pressed, sounding a bell when the vote was successfully cast.
Under the covers, this was all powered by a single JavaFX application running on a laptop hidden in the plinth. We used basic USB buttons, which were programmable, after a fashion: the buttons send a key combination, which can be set using a Windows application, as can the button colour (for both “pressed” and “not pressed” states). My initial plan was to send colour codes to the buttons from the Java application, so that the colours could be customised if necessary, but it became apparent this would take much too long and wasn’t required – the buttons just needed to be red when pressed, and could be plain white the remainder of the time. (The libraries to configure the buttons were Windows only, and while I did find an open source Linux variant, there was no support for the simple USB Buttons we were using; in addition, the libraries were all C++, so I would have had to write my own Java adapter, and that would probably have taken us over budget.)
I used the hid4java library to receive the messages from the buttons, and spent some time experimenting with the key combinations, and discovered that the shortest possible message would get the job done – the application seemed to pick up one message for every character sent, building up from a single character to the full content (ie. for the string “hello”, we would get six messages, starting with a dummy character, then “h”, then “he”, and so on). I didn’t manage to discover if this was a property of the button or the library, but sending a single character got the job done with the least duplication checking required.
The application had a simple front-end, to allow the brand ambassadors staffing the installation to choose which question was being voted on each day, as well as to configure the buttons (since the buttons were effectively identical, the application needed to be told which was button 1, and which button 2). The button, when pressed, would trigger a Twitter update with a particular hashtag that corresponded to the user’s choice – this was the easiest part of the application, and used the tried and trusted Twitter4J library. Finally, once the message had been transmitted, the application would sound a boxing ring sound, from SoundBible.com.
This was my first experience using JavaFX to put together a front-end application, and it all seemed to go pretty well, once I’d got past the inevitable initial hiccups you come across when working with any new library.
Sadly, I didn’t get to see the installation in action – the laptop was handed over to WMSH after installing the software, and I was with another client in a different part of the country on the setup date. I didn’t get any support calls while the installation was live though, and the project manager was entirely happy with how things worked, so a job well done!
Source code, for anyone interested, is on bitbucket.org.