using System.Threading;
using Microsoft.SPOT;

namespace CPF
{
    public enum ProfilerEvents { OpenDoor = Signal.User, CloseDoor, Toasting, Baking, ReportPressure, ReportTick, SD_Card_Inserted, Unformatted_SD_Card_inserted, SD_Card_Removed };

    //
    // Oven State Hierachy
    //

    // ovenOff
    //   heating
    //     toasting
    //     baking
    // doorOpen

    class CPF_HSM : HSM
    {
        public CPF_HSM()
        {
            Initialize(oven);
        }

        State oven(Event e)
        {
            switch (e._signal)
            {
                case Signal.Entry:
                    Debug.Print("Entering Oven State");
                    return null;
                case Signal.Init:
                    Debug.Print("Initializing Oven State");
                    InitTransitionState(heating);
                    return null;
                case Signal.Exit:
                    Debug.Print("Exiting Oven State");
                    return null;
            }
            return null;
        }

        State heating(Event e)
        {
            switch (e._signal)
            {
                case Signal.Entry:
                    Debug.Print("\tEntering Heating State");
                    return null;
                case Signal.Init:
                    Debug.Print("\tInitializing Heating State");
                    InitTransitionState(toasting);
                    return null;
                case Signal.DeepHistory:
                    return null;
                case Signal.Exit:
                    Debug.Print("\tExiting Heating State");
                    return null;
                case (Signal)ProfilerEvents.OpenDoor:
                    Debug.Print("\tHeating: OPEN_DOOR signal!");
                    TransitionState(doorOpen);
                    return null;
                case (Signal)ProfilerEvents.Toasting:
                    Debug.Print("\tHeating: TOASTING signal!");
                    TransitionState(toasting);
                    return null;
                case (Signal)ProfilerEvents.Baking:
                    Debug.Print("\tHeating: BAKING signal!");
                    TransitionState(baking);
                    return null;
            }
            return oven;
        }

        State toasting(Event e)
        {
            switch (e._signal)
            {
                case Signal.Entry:
                    Debug.Print("\t\tEntering Toasting State");
                    return null;
                case Signal.Init:
                    Debug.Print("\t\tInitializing Toasting State");
                    return null;
                case Signal.Exit:
                    Debug.Print("\t\tExiting Toasting State");
                    return null;
            }
            return heating;
        }

        State baking(Event e)
        {
            switch (e._signal)
            {
                case Signal.Entry:
                    Debug.Print("\t\tEntering Baking State");
                    return null;
                case Signal.Init:
                    return null;
                case Signal.Exit:
                    Debug.Print("\t\tExiting Baking State");
                    return null;
            }
            return heating;
        }

        State doorOpen(Event e)
        {
            switch (e._signal)
            {
                case Signal.Entry:
                    Debug.Print("Entering Door Open State");
                    return null;
                case Signal.Init:
                    return null;
                case Signal.Exit:
                    Debug.Print("Exiting Door Open State");
                    return null;
                case (Signal)ProfilerEvents.CloseDoor:
                    Debug.Print("Door Open: CLOSE_DOOR signal!");
                    TransitionState(heating, true);
                    return null;
            }
            return oven;
        }
    }
}

