<?xml version="1.0"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml"
       name="microwave"
       version="1.0"
       datamodel="ecmascript"
       initial="off">

  <!--  trivial 5 second microwave oven example -->
  <datamodel>
    <data id="cook_time" expr="5"/>
    <data id="door_closed" expr="true"/>
    <data id="timer" expr="0"/>
  </datamodel>

  <state id="off">
    <!-- off state -->
    <transition event="turn.on" target="on">
      <log label="EVENT" expr="'Powering on'"/>
    </transition>
  </state>

  <state id="on">
    <initial>
        <transition target="idle">
          <log expr="'Idling'"/>
        </transition>
    </initial>
    <!-- on/pause state -->

    <transition event="turn.off" target="off">
      <log label="EVENT" expr="'Powering off'"/>
    </transition>
    <transition cond="timer >= cook_time" target="off">
      <log label="COND" expr="'Powering off'"/>
    </transition>

    <state id="idle">
      <!-- default immediate transition if door is shut -->
      <transition cond="door_closed" target="cooking">
          <log label="COND" expr="'Cooking'"/>
        </transition>
      <transition event="door.close" target="cooking">
        <assign location="door_closed" expr="true"/>
        <log label="EVENT" expr="'Door Closed'"/>
        <log expr="'Door Closed Status: ' + door_closed"/>
        <!-- start cooking -->
      </transition>
    </state>

    <state id="cooking">
      <transition event="door.open" target="idle">
        <assign location="door_closed" expr="false"/>
        <log label="EVENT" expr="'Door Opened'"/>
        <log expr="'Door Closed Status: ' + door_closed"/>
      </transition>

      <!-- a 'time' event is seen once a second -->
      <transition event="time">
        <assign location="timer" expr="timer + 1"/>
        <log label="EVENT" expr="'Tick: ' + timer"/>
      </transition>
    </state>

  </state>

</scxml>