Statechart assignment

Practical information

Problem statement

In this assignment, you will design a Statechart model specifying the reactive behaviour of a Digital Watch (inspired by the 1981 Texas Instruments LCD Alarm Chronograph). Below is a snapshot of "DWatch" (the Designed Watch), the application you will build.

You will first model the reactive behaviour of the watch in the DCharts formalism (a variant of Statecharts) in the tool AToM3. The Statechart simulator SVM (as a plugin of AToM3) will allow you to check, by means of simulation, whether your model behaves according to the requirements. Note that it is good practice to start modelling and simulating small parts of the desired behaviour in isolation. These can be saved and later loaded to build the full solution Statechart.

The model (saved as DigitalWatchStatechart_DCharts_MDL.py) and its visual representation must both be included in your index.html solution page. The visual representation is obtained by exporting the model as Postscript from AToM3 as DigitalWatchStatechart_DCharts_MDL.eps and subsequently converting it to a bitmap (e.g., DigitalWatchStatechart_DCharts_MDL.gif).

When you are satisfied with the simulated behaviour, you are ready to build a Digital Watch software application. The application's reactive behaviour will be generated from the Statechart.

The software application (DigitalWatch.py) is composed of a static component, a controller and a dynamic component.

The static component (DigitalWatchGUI.py) implements the visual aspects of the watch such as buttons, the display and the Indiglo light and organizes them into a graphical user interface (built using Tkinter, the standard Python interface to the Tk GUI toolkit).

The dynamic component (DigitalWatchStatechart.py) will be automatically generated from your Statechart model.

The communication between the static and the dynamic components is handled by the controller (found in DigitalWatchGUI.py). User events such as button press/release are passed from the GUI to the Statechart (as strings) by the controller. Conversely, the Statechart modifies the (visual) state of the GUI by invoking the controller's methods.

Note that the Statechart receives a reference to the controller object as a parameter of the start event when, at application startup time, it goes from its initial state Setup to the state Running.

Behaviour requirements

  1. The time value should be updated every second, even when it is not displayed (as for example, when the chrono is running). However, time is not updated when it is being edited.
  2. Pressing the top right button turns on the Indiglo light. The light stays on for as long as the button remains pressed. From the moment the button is released, the light stays on for 2 more seconds, after which it is turned off.
  3. Pressing the top left button alternates between the chrono and the time display modes. The system starts in the time display mode. In this mode, the time (hh:mm:ss) and date (MM/DD/YY) are displayed.
  4. When in chrono display mode, the elapsed time is displayed mm:ss:cc (with cc hundreths of a second). Initially, the chrono starts at 00:00:00. The bottom right button is used to start the chrono. The running chrono updates in 1/100 second increments. Subsequently pressing the bottom right button will pause/resume the chrono. Pressing the bottom left button resets the chrono to 00:00:00. The chrono will keep running (when in running mode) or keep its value (when in paused mode), even when the watch is in a different display mode (for example, when the time is displayed).
  5. When in time display mode, the watch will go into time editing mode when the bottom right button is held pressed for at least 1.5 seconds.
  6. When in time display mode, the alarm can be displayed and set on or off by pressing the bottom left button. If the bottom left button is held for 1.5 seconds or more, the watch goes into alarm editing mode. Initially, the alarm time is set to 12:00:00.
  7. When in (either time or alarm) editing mode, briefly pressing the bottom left button will increase the current selection. Note that it is only possible to increase the current selection, there is no way to decrease or reset the current selection. If the bottom left button is held down, the current selection is incremented automatically every 0.3 seconds. Editing mode should be exited if no editing event occurs for 5 seconds. Holding the bottom right button down for 2 seconds will also exit the editing mode. Pressing the bottom right button for less than 2 seconds will move to the next selection (for example, from editing hours to editing minutes).

Interface provided by the controller

refreshTimeDisplay()

  Redraws the time with the current internal time value.
  The display does not need to be cleared before calling
  this function. For instance, if the alarm is currently
  displayed, it will be deleted before drawing the time.
      
refreshChronoDisplay

  Analogous to refreshTimeDisplay().
  
refreshDateDisplay()

  Analogous to refreshTimeDisplay().
  
refreshAlarmDisplay()

  Analogous to refreshTimeDisplay().  
    
resetChrono()

  Resets the internal chrono to 00:00:00.
          
startSelection()

  Selects the leftmost/first digit group currently displayed on the screen.
    
selectNext()
  
  Selects the next digit group, looping back to the leftmost/first digit group when
  the rightmost digit group is currently selected. If the time is currently 
  displayed on the screen, select also visits the date digits. If the alarm
  is displayed on the screen, the date digits are not visited. 
  
stopSelection()

  Returns from selection mode.

increaseSelection(self):
  
  Increases the currently selected digit group's value by one.
                      
increaseTimeByOne()

  Increases the time by one second. Note how minutes, hours, 
  days, month and year will be modified appropriately, if needed
  (for example, when increaseTimeByOne() is called at time
   11:59:59, the new time will be 12:00:00 of the next day).
    
increaseChronoByOne()

  Increases the chrono by 1/100 second.
    
setIndiglo()

  Turns on the display background light.
    
unsetIndiglo()

  Turns off the display background light.
    
setAlarm()

  Flags the alarm to be on or off.
  
  
Button events sent to the Statechart (as strings):

- topRightPressed
- topRightReleased
- topLeftPressed
- topLeftReleased
- bottomRightPressed
- bottomRightReleased
- bottomLeftPressed
- bottomRightReleased

Starting point

Download basicExamples.tgz to get the examples shown in class.

Dowload TrafficLight.tgz for a complete example of a Statechart model which gets compiled and linked with external GUI code. The README file describes the process in great detail.

The archive startingPoint.tgz contains a small example wristwatch (with very minimal functionality).

Practical information

AToM3 is installed on the Trottier lab machines and can be started with /usr/local/pkgs/atom3/atom3.sh. You will find some example models in the central Models DCharts directory. The svm simulator is installed in the External/ directory of the AToM3 central installation. It is available as a plugin from AToM3. The scc Statechart compiler can be found in svm's installation directory and can be started with /usr/local/pkgs/atom3/External/svm-0.3beta3-src/scc. The script compile.sh calls scc with the appropriate arguments. There is extensive documentation on SVM and SCC. For those interested in more in-depth information on SVM and SCC, have a look at Thomas Feng's M.Sc. thesis.
Or you can download the SVM plugin SVM.tar.gz and unpack it in the External/ directory of your own AToM3 installation.