using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FLY.Simulation.Flyad7
{
    public class DriveManage
    {
        ISimDrive mSimDrive;
        private void Init(ISimDrive simDrive) 
        {
            mSimDrive = simDrive;
        }

        public void OnPoll()
        {
            
        }

        class ORDER_Runto 
        {
            ISimDrive mSimDrive;
            enum STATE 
            {
                Init,
                Forw,
                Backw,
                Idle
            }
            STATE State;
            public void Start(int targetpos) 
            {
                State = STATE.Init;
            }
            public int TargetPos;
            public void OnPoll() 
            {
                if (mSimDrive is SimDrive_VF0)
                {
                    SimDrive_VF0 vf0 = mSimDrive as SimDrive_VF0;
                    switch (State)
                    {
                        case STATE.Init:
                            {
                                if (TargetPos > mSimDrive.Pos)
                                {
                                    vf0.PIN_OUT_FORW = false;
                                    vf0.PIN_OUT_BACKW = true;
                                    State = STATE.Forw;
                                }
                                else if (TargetPos < mSimDrive.Pos)
                                {
                                    vf0.PIN_OUT_FORW = true;
                                    vf0.PIN_OUT_BACKW = false;
                                    State = STATE.Backw;
                                }
                                else
                                {
                                    vf0.PIN_OUT_FORW = true;
                                    vf0.PIN_OUT_BACKW = true;
                                    State = STATE.Idle;
                                }

                            } break;
                        case STATE.Forw:
                            {
                                if (vf0.Pos >= TargetPos)
                                {
                                    vf0.PIN_OUT_FORW = true;
                                    vf0.PIN_OUT_BACKW = true;
                                    State = STATE.Idle;
                                }
                            } break;
                        case STATE.Backw:
                            {
                                if (vf0.Pos <= TargetPos)
                                {
                                    vf0.PIN_OUT_FORW = true;
                                    vf0.PIN_OUT_BACKW = true;
                                    State = STATE.Idle;
                                }
                            } break;
                        case STATE.Idle:
                            break;
                    }
                }
            }
        } 
    }
}
