LEDExcute.cs 3.38 KB
using HHECS.Model.Entities;
using LEDhelp;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Threading.Tasks;

namespace HHECS.Bll
{
    public class LEDExcute
    {
        LEDHelper Led;
        //LEDHelper BatteriesLED;
        //LEDHelper PartsStation1LED;
        //LEDHelper PartsStation2LED;
        public Queue<string> LedQueue { get; set; } = new Queue<string>();
        //public Queue<string> BatteriesQueue { get; set; } = new Queue<string>();
        //public Queue<string> PartsStation1Queue { get; set; } = new Queue<string>();
        //public Queue<string> PartsStation2Queue { get; set; } = new Queue<string>();

        public LEDExcute()
        {
            string LedIP = ConfigurationManager.AppSettings["LedIP"];
            //string batteriesLedIP = ConfigurationManager.AppSettings["BatteriesLedIP"];
            //string partsStation1LedIP = ConfigurationManager.AppSettings["PartsStation1LedIP"];
            //string partsStation2LedIP = ConfigurationManager.AppSettings["PartsStation2LedIP"];
            int ledPort = Convert.ToInt32(ConfigurationManager.AppSettings["ledPort"]);
            Led = new LEDhelp.LEDHelper(LedIP, (uint)ledPort, 1);
            //BatteriesLED = new LEDhelp.LEDHelper(batteriesLedIP, (uint)ledPort, 1);
            //PartsStation1LED = new LEDhelp.LEDHelper(partsStation1LedIP, (uint)ledPort, 1);
            //PartsStation2LED = new LEDhelp.LEDHelper(partsStation2LedIP, (uint)ledPort, 1);
        }

        public void BeginSendInfo()
        {
            Task.Run(async () =>
            {
                while (true)
                {
                    await Task.Delay(2000);

                    if (Led != null && LedQueue != null && LedQueue.Count > 0)
                    {
                        SCREEN_ForceOnOff(LEDHelper.Produce, LEDHelper.OPEN);
                        SCREEN_DelDynamicArea(LEDHelper.Produce, 0);
                        sendLedInfo(LEDHelper.Produce, LEDHelper.GREEN, LedQueue.Dequeue());
                        setBrightness(LEDHelper.Produce, 5);
                    }
                }
            });
        }

        private void sendLedInfo(int direction, int color, String sendText)
        {
            if (color == LEDhelp.LEDHelper.GREEN)
            {
                sendText = "\\C2" + sendText;
            }
            else if (color == LEDhelp.LEDHelper.YELLOW)
            {
                sendText = "\\C3" + sendText;
            }
            else
            {
                sendText = "\\C1" + sendText;
            }
            if (direction == LEDhelp.LEDHelper.Produce)
            {
                Led.SendLedInfo(sendText);
            }

        }

        private void SCREEN_ForceOnOff(int direction, byte status)
        {
            if (direction == LEDhelp.LEDHelper.Produce)
            {
                Led.SCREEN_ForceOnOff(status);
            }
        }

        // value 0-15 值越大亮度越大
        public void setBrightness(int direction, byte value)
        {
            if (direction == LEDhelp.LEDHelper.Produce)
            {
                Led.setBrightness(1, value, null);
            }

        }

        public void SCREEN_DelDynamicArea(int direction, byte DeleteAreaId)
        {
            if (direction == LEDhelp.LEDHelper.Produce)
            {
                Led.SCREEN_DelDynamicArea(DeleteAreaId);
            }
        }
    }
}