Thursday, September 26, 2013

New release of Wise Clock 4 software

Some of the latest software features have already been introduced (see this post). Since then, a few bugs have been fixed (again, thanks Mike!), the code was streamlined even more, and some apps (Countdown, Score, Stopwatch, Quote) have been expanded and improved.

Below is a list of the most recent code changes:
  • added PWRON setup option to select app to run when the clock starts up;
  • compilations options (add/remove features) moved to file "UserConf.h". That is:
- Instead of editing WiseClock.cpp to select applications to build, edit "UserConf.h".
- Instead of editing WiseClockVer.h to select WiseClock 3 or 4, edit "UserConf.h".
- Instead of editing HT1632.h to select the number of displays, edit "UserConf.h".
  • on dual display, Countdown includes days as well, in the format DD:HH:MM:SS;
  • Countdown shows the correct amount of time left even if power was down for a while (this is done by saving the end time in eeprom); for this feature, the PWRON must be set to "CNTDWN";
  • similar to Countdown, app Score has been extended to "remember" the numbers even after the power was out for a while; in either case, the respective app must be selected in PWRON;
  • ability to display quotes randomly, if the user selects "RND" in app Quote;
  • on dual display, Stopwatch is now using regular-size font (still using tiny font on single display);
  • Stopwatch has a new mode, "Conventional", in addition to the previous one (called "Rattrapante"); the conventional mode accumulates the time passed between consecutive presses of the start/stop button, as a mechanical chronometer would do; "rattrapante" mode shows the amount of time passed from the moment it was first started, regardless of how many times the chronometer was stopped;
  • on dual display, with "Font+" selected, Score and Stopwatch are using big font and no longer show the current time on the bottom line (they show as before with "Font-" selected); 

One of the challenges in writing complex code for embedded systems is the compromise between following an Object Oriented approach and trying to minimize the amount of RAM at runtime. Let me elaborate a bit. Each C++ object, once created (at runtime), used or not, takes some RAM, storing data members and the vtable (when using virtual functions). Wise Clock software is trying to follow an OO design. Each App class is derived from an abstract base class. The base class defines 2 pure virtual functions (init and run), which must be implemented by every App class.
At runtime, each app is created as a static object. Therefore, if 12 apps are declared (through the use of ifdefs in UserConf.h), 12 objects will be created in RAM, each one storing its own data and its own vtable. That's a pretty big price to pay in the world of embedded systems with little RAM space (just a guess, based on my very limited experience).

A non OO approach would create and use variables only for the app that is in current use, as the code is being executed. Although this solution would use less RAM, the current complexity would make the code unmanageable.

So back to the compromise, how does one solve it? (This is not a rhetorical question.)

7 comments:

  1. Hooray for the new code! I will try it with a dual display set up. As for the non-rhetorical question, I'm afraid that's above my pay grade...;-) More RAM? Can you offload anything to the SD card?

    ReplyDelete
    Replies
    1. "Offloading" to SD card would be a great thing to do. At that moment, this software will actually become an operating system :)
      As they (was it Engels?) say, "quantitative accumulation leads to qualitative jump".

      Delete
    2. On the other hand, the more code and complexity one adds, the more ideas are born. I guess that's natural (Darwinian, that is) :)

      Delete
    3. Also, another avenue worth investigating is adding a second processor. That would take care of just communications, for example.

      Delete
  2. Is this software update for the ATMega1284 only ? because when I try to upload it to a 644 it keeps saying the sketch is too big, I am using Arduino 1.0.5

    ReplyDelete
    Replies
    1. For 644 you need to cut some functionality (and thus reduce the sketch size), by commenting out some of the defines in UserConf.h:

      //
      // Select the applications you want included
      // Comment out the #define line of the
      // applications you don't want.
      //
      #define WANT_APP_QUOTE // scroll of quotations
      #define WANT_APP_UTC // analog or text clock of UTC
      #define WANT_APP_BIG // various "big" fonts
      #define WANT_APP_LIFE // Conway's game of life
      #define WANT_APP_DEMO // demo of most of the apps
      #define WANT_APP_PONG // pong display, score is time
      #define WANT_APP_PACMAN // animated pacman on the minute
      #define WANT_APP_LIVED // elapsed time since date on SD card
      #define WANT_APP_SCORE // two-person score
      #define WANT_APP_STOPW // stop watch
      #define WANT_APP_CNT_DOWN // count down timer
      #define WANT_APP_WORDS // display time in words
      #define WANT_APP_TCLOK // time spent on different projects
      #define WANT_APP_TIX // TIX clock display
      #define WANT_APP_LINES // random lines bounce on display
      //#define WANT_APP_SUN // day/night graph, needs map overlay
      #define WANT_APP_ANIM // animations read from SD card

      Delete
    2. Thanks, got it to upload now so I can play around with it abit

      Delete