using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DeviceLibrary
{
    public class Led
    {
        public static Dictionary<string, List<Led>> LedGroup = new Dictionary<string, List<Led>>();
        public LedState LedState = LedState.off;
        ushort ledio;
        public Led(ushort io, string devicename)
        {
            ledio = io;
            if (!LedGroup.ContainsKey(devicename)) {
                LedGroup.Add(devicename, new List<Led>());
            }
            LedGroup[devicename].Add(this);
        }
        IO_VALUE iovalue;
        IO_VALUE lastiovalue;
        public void run()
        {
            if (this.LedState == LedState.on)
            {
                iovalue = IO_VALUE.HIGH;
            }
            if (this.LedState == LedState.off)
            {
                iovalue = IO_VALUE.LOW;
            }
            if (this.LedState == LedState.blink)
            {
                if (iovalue == IO_VALUE.LOW)
                {
                    iovalue = IO_VALUE.HIGH;
                }
                else
                {
                    iovalue = IO_VALUE.LOW;
                }
            }
            //if (iovalue != lastiovalue)
            //{
                lastiovalue = iovalue;
                IOManager.WriteSingleDO("", 0x00, ledio, iovalue);
            //}
        }
    }
    public enum LedState
    {
        off,
        on,
        blink
    }
}