<single_instance_cd>
  <delta>1 ms</delta>

  <statechart>
    <semantics
      big_step_maximality="take_one"
      internal_event_lifeline="next_small_step"
      input_event_lifeline="whole"
    />

    <inport name="in">
      <event name="bottomLeftPressed"/>
      <event name="bottomLeftReleased"/>
      <event name="bottomRightPressed"/>
      <event name="bottomRightReleased"/>
      <event name="topLeftPressed"/>
      <event name="topLeftReleased"/>
      <event name="topRightPressed"/>
      <event name="topRightReleased"/>
      <event name="alarmStart"/>
    </inport>

    <outport name="out">
      <event name="checkTime"/>
      <event name="refreshTimeDisplay"/>
      <event name="refreshChronoDisplay"/>
      <event name="refreshDateDisplay"/>
      <event name="refreshAlarmDisplay"/>
      <event name="resetChrono"/>
      <event name="startSelection"/>
      <event name="increaseSelection"/>
      <event name="selectNext"/>
      <event name="stopSelection"/>
      <event name="increaseTimeByOne"/>
      <event name="increaseChronoByOne"/>
      <event name="setIndiglo"/>
      <event name="unsetIndiglo"/>
      <event name="setAlarm"/>
    </outport>

    <root>
      <parallel id="P">
        <state id="Alarm" initial="Off">
          <state id="Off">
            <transition event="bottomLeftPressed" cond='INSTATE(["/P/Display/TimeUpdate"])' target="../On"/>
          </state>

          <state id="On" initial="NotBlinking">
            <onentry>
              <raise event="setAlarm"/>
            </onentry>
            <onexit>
              <raise event="setAlarm"/>
            </onexit>

            <state id="NotBlinking">
              <transition event="alarmStart" target="../Blinking"/>
              <transition event="bottomLeftPressed" cond='INSTATE(["/P/Display/TimeUpdate"])' target="../../Off"/>
            </state>

            <state id="Blinking" initial="On">
              <onexit>
                <raise event="unsetIndiglo"/>
              </onexit>
              <state id="On">
                <onentry>
                  <raise event="setIndiglo"/>
                </onentry>
                <transition after="500 ms" target="../Off"/>
              </state>
              <state id="Off">
                <onentry>
                  <raise event="unsetIndiglo"/>
                </onentry>
                <transition after="500 ms" target="../On"/>
              </state>
              <!-- user interrupt alarm: also toggle off alarm -->
              <transition event="topRightPressed" target="../../Off"/>
              <transition event="topLeftPressed" target="../../Off"/>
              <transition event="bottomRightPressed" target="../../Off"/>
              <transition event="bottomLeftPressed" target="../../Off"/>
              <!-- alarm over, everything remains like it was -->
              <transition after="4 s" target="../NotBlinking"/>
            </state>
          </state>
        </state>


        <state id="Indiglo" initial="Off">
          <state id="Off">
            <transition event="topRightPressed" target="../Pushed">
              <raise event="setIndiglo"/>
            </transition>
          </state>

          <state id="Pushed">
            <transition event="topRightReleased" target="../Released"/>
          </state>

          <state id="Released">
            <transition event="topRightPressed" target="../Pushed"/>
            <transition after="2 s" target="../Off">
              <raise event="unsetIndiglo"/>
            </transition>
          </state>
        </state>


        <state id="ChronoWrapper">
          <state id="Chrono" initial="Stopped">
            <state id="Stopped">
              <transition event="bottomRightPressed" cond='INSTATE(["/P/Display/ChronoUpdate"])' target="../Running"/>
            </state>

            <state id="Running">
              <transition after="10 ms" target=".">
                <raise event="increaseChronoByOne"/>
                <raise event="int_refresh_chrono"/>
              </transition>
              <transition event="bottomRightPressed" cond='INSTATE(["/P/Display/ChronoUpdate"])' target="../Stopped"/>
            </state>

            <transition event="bottomLeftPressed" cond='INSTATE(["/P/Display/ChronoUpdate"])' target="Stopped">
                <raise event="resetChrono"/>
                <raise event="int_refresh_chrono"/>
            </transition>
          </state>
        </state>


        <state id="Display" initial="TimeUpdate">
          <state id="TimeUpdate">
            <onentry>
              <raise event="refreshTimeDisplay"/>
            </onentry>
            <transition event="int_refresh_time" target="."/>
            <transition event="topLeftPressed" target="../ChronoUpdate"/>
            <transition event="bottomRightPressed" target="../WaitingToEdit"/>
            <transition event="bottomLeftPressed" target="../WaitingForAlarm"/>
          </state>

          <state id="WaitingToEdit">
            <transition after="1500 ms" target="../EditingTime">
              <raise event="time_edit"/>
            </transition>
            <transition event="bottomRightReleased" target="../TimeUpdate"/>
          </state>

          <state id="WaitingForAlarm">
            <onentry>
              <raise event="refreshAlarmDisplay"/>
            </onentry>
            <transition after="1500 ms" target="../EditingTime">
              <raise event="alarm_edit"/>
            </transition>
            <transition event="bottomLeftReleased" target="../TimeUpdate"/>
          </state>

          <state id="EditingTime" initial="Waiting">
            <onentry>
              <raise event="startSelection"/>
            </onentry>
            <onexit>
              <raise event="stopSelection"/>
            </onexit>

            <state id="Waiting">
              <transition event="bottomLeftPressed" target="../Increasing"/>
              <transition event="bottomRightPressed" target="../GoingToNext"/>
              <transition after="5 s" target="../../TimeUpdate">
                <raise event="edit_done"/>
              </transition>
            </state>

            <state id="GoingToNext">
              <transition event="bottomRightReleased" target="../Waiting">
                <raise event="selectNext"/>
              </transition>
              <transition after="2 s" target="../../TimeUpdate">
                <raise event="edit_done"/>
              </transition>
            </state>

            <state id="Increasing">
              <onentry>
                <raise event="increaseSelection"/>
              </onentry>
              <transition after="100 ms" target="."/>
              <transition event="bottomLeftReleased" target="../Waiting"/>
            </state>
          </state>

          <state id="ChronoUpdate">
            <onentry>
              <raise event="refreshChronoDisplay"/>
            </onentry>
            <transition event="topLeftPressed" target="../TimeUpdate"/>
            <transition event="int_refresh_chrono" target="."/>
          </state>
        </state>


        <state id="Time" initial="Increasing">
          <state id="Increasing">
            <transition after="1 s" cond='INSTATE(["/P/Alarm/On"])' target=".">
              <raise event="increaseTimeByOne"/>
              <raise event="checkTime"/>
              <raise event="int_refresh_time"/>
            </transition>
            <transition after="1 s" target=".">
              <raise event="increaseTimeByOne"/>
              <raise event="int_refresh_time"/>
            </transition>
            <transition event="time_edit" target="../Editing"/>
          </state>
          <state id="Editing">
            <transition event="edit_done" target="../Increasing"/>
          </state>
        </state>
      </parallel>
    </root>
  </statechart>
</single_instance_cd>