fighting bugs in mobile processing

For the further development of our Social Display prototype we were in need for a transceiver, a display and some computing power. All of this can be found nicly bundled into a state-of-the-art mobile phone. I had heard of a mobile version of processing and after a quick view (when I found a cool example-code for some bluetooth-tricks by Francis Li), we decided to give it a try.

In the end, it took me some time to get the code to the point of satisfying me and some questions remain unresolved. I began to try things in processing and the “port” it to mobile p5 but that is not a too good idea as the mobile version really lacks some esential functionality compared to its older brother. As mobile p5 can be considered as emerging software I will try to explain what I did in order to give my colleagues a look inside and maybe even someone else a little help.

Basically I want to check via bluetooth whether there are devices around that are “known”, i.e. can be found in an existing list (that is meant to be the addressbook later). In this case an image individually linked to each contact will be displayed.
In detail the phone looks for available devices permanently, checks whether they are in the “addressbook” and saves all found contacts into an array. Later the draw()-function will cycle through that array and display the corresponding images one after another. Finally, some fading-cream gets on top.

I hope the comments will explain it as well in the sourcecode

problems
Compared to the handling of arrays I experienced with php (foreach(), push(), etc) the possibilties offered by Java and its relatives seem to be limited. p5 mobile has always the smallest set of orders because of the (diverse) cellphone hardware and the J2ME middleware. I tried to write my own push()-function and a lower-leveled addElement()-function, both did not work. I found it quite difficult to work with arrays of different lengths. In the end I discovered that something like

arrayobject[arrayobject_index++] = new Object();

does fill the existing slots in a fixed-length array easily, updating the (external) arrayobject_index (an integer) and assigning a new value in one line.

The mathematical basics of mobile p5 turned out to be another interesting field. For a fading effect I wanted to use a sinus-function. While running from 0 to 3.14 (or 314, as mobile p5 doesn’t accept integers in variables) some other things should happen as well but they didn’t. The error was hard to hunt down and I finally found that π is not 3.14 in mobile p5 but

PI = 804.

This is true from the PI and TWO_PI constants to sin(PI) = 0 and, consequently at last, sin(402) = 1.

no Responses so far to fighting bugs in mobile processing