Home made cellphone project.

 
 

How do icons start panels?

There is a global variable in litlOS called nextPanel. All you need to do is set that to the panel ID you want to run. litlOS takes care of the rest. Therefore all you need your icon button to do is set its saved value into that global when touched.


So, the bottom line?

  1. A)All sketches you want to run become panels.

  2. B)Icon buttons only need to set nextPanel variable to their desired panel ID.

  3. C)Your version of litlOS has a method that that you fill out to delete, create and launch your different panels.

  4. D)Only one panel is loaded in RAM at a time. This means there is not much of a limit to how many panels you can have.

Gluing all the software bits together.

Its the panel class!

Cellphones have apps. Click an icon, your cellphone switches screens and its doing something completely different. I needed to find a way to make an Arduino behave like that.


So.. Adruino programs, called sketches, all start off with two functions, setup() and loop(). setup() is called one time as your program starts then loop() is called over and over as fast as possible. You, as a programmer fill in what you want done at startup in setup() and fill in what you want done forever more in loop(). You can create as many other functions and things you want. But it all starts with setup() and loop().


Now the original Arduinos only had 2k of RAM. Not a lot of memory. The Teensys I use have 64k of RAM. Still, not all that much, you have to be careful. Because I wanted to have all sorts of stuff running. Different screens for different things. Phone dialer, Text messaging, contact list, my calculator, heck maybe even some games. How to fit all this in there?


The solution turned out to be relatively simple. I created two classes. A panel class having setup() and loop() methods, just like your Arduino sketches. And, a litlOS class to manage all the your panels.


Each program/sketch you want to run becomes a type of panel. Move your global variables to class members of that panel. Its functions become methods of that panel. And panels already have their own setup() and loop() methods ready for you to fill in. As far as it knows, its the only program running.


How do you use this?

In your main sketch’s setup(), initalize all your hardware as you would typically do. Then, call your version of litlOS’s begin() method. In your main sketch’s loop() function, all you call is idle() to give your background processes time, and then your litlOS’s loop() method. This will run the loop() method of whatever panel is running.

void loop() {     // During loop..

  idle();         // Idlers get their time.

  ourOS.loop();   // ourOS gets a kick to pass on to the current panel.

}