Esempio n. 1
0
        public void RunCompiledSequence(byte[] sequence)
        {
            switchState   = true;
            currentAction = null;
            int index = 0;

            while (index < sequence.Length)
            {
                switch (sequence[index] & 0x0f)
                {
                case (byte)SequenceAction.ActionType.DelayAction:
                {
                    int duration = sequence[++index] | (sequence[++index] << 8);
                    ActionsQueue.Enqueue(delayAction(duration));
                    System.Console.WriteLine("delayAction({0})", duration);
                    index++;
                }
                break;

                case (byte)SequenceAction.ActionType.LidAction:
                {
                    int fromPos  = sequence[++index] * 10;
                    int toPos    = sequence[++index] * 10;
                    int duration = sequence[++index] | (sequence[++index] << 8);
                    ActionsQueue.Enqueue(lidAction(fromPos, toPos, duration));
                    System.Console.WriteLine("lidAction({0},{1},{2})", fromPos, toPos, duration);
                    index++;
                }
                break;

                case (byte)SequenceAction.ActionType.SwitchAction:
                {
                    int fromPos  = sequence[++index] * 10;
                    int toPos    = sequence[++index] * 10;
                    int duration = sequence[++index] | (sequence[++index] << 8);
                    ActionsQueue.Enqueue(switchAction(fromPos, toPos, duration));
                    System.Console.WriteLine("switchAction({0},{1},{2})", fromPos, toPos, duration);
                    index++;
                }
                break;
                }
            }
        }
Esempio n. 2
0
        public void Sequence0()
        {
            switchState   = true;
            currentAction = null;
            ActionsQueue.Enqueue(lidAction(900, 1300, 4000));
            ActionsQueue.Enqueue(delayAction(1000));
            ActionsQueue.Enqueue(lidAction(1300, 1400, 500));
            ActionsQueue.Enqueue(delayAction(1000));
            ActionsQueue.Enqueue(switchAction(1050, 1900, 2000));
            ActionsQueue.Enqueue(delayAction(300));
            ActionsQueue.Enqueue(switchAction(1900, 2200, 500));
            ActionsQueue.Enqueue(delayAction(100));
            ActionsQueue.Enqueue(switchAction(2200, 1050, 2000));
            ActionsQueue.Enqueue(delayAction(100));
            ActionsQueue.Enqueue(lidAction(1400, 900, 2000));
#if usingLidTicker
            lidTicker.Start();
#endif
        }
Esempio n. 3
0
        public void lidTicker_Tick(object sender, ElapsedEventArgs e)
        {
            float resolution = 3f;

            if (currentAction != null)
            {
                if (currentAction.Action == SequenceAction.actionType.LidAction)
                {
                    if (lidRotateAngle == lidTargetAngle && lidMoveDirection > 0)
                    {
                        currentAction = null;
                    }
                    else if (lidRotateAngle == lidTargetAngle && lidMoveDirection < 0)
                    {
                        currentAction = null;
                    }
                    else
                    {
                        lidRotateAngle += (float)lidMoveDirection / resolution;
                        if (lidMoveDirection > 0 && lidRotateAngle > lidTargetAngle)
                        {
                            lidRotateAngle = lidTargetAngle;
                        }
                        else if (lidMoveDirection < 0 && lidRotateAngle < lidTargetAngle)
                        {
                            lidRotateAngle = lidTargetAngle;
                        }
                    }
                }
                else if (currentAction.Action == SequenceAction.actionType.DelayAction)
                {
                    currentAction = null;
                    return;
                }
                else if (currentAction.Action == SequenceAction.actionType.SwitchAction)
                {
                    if (switchRotateAngle == switchTargetAngle && switchOnOffMoveDirection < 0)
                    {
                        currentAction = null;
                    }
                    else if (switchRotateAngle == switchTargetAngle && switchOnOffMoveDirection > 0)
                    {
                        currentAction = null;
                    }
                    else
                    {
                        switchRotateAngle += (float)switchOnOffMoveDirection / resolution;
                        if (switchOnOffMoveDirection < 0 && switchRotateAngle < switchTargetAngle)
                        {
                            switchRotateAngle = switchTargetAngle;
                        }
                        else if (switchOnOffMoveDirection > 0 && switchRotateAngle > switchTargetAngle)
                        {
                            switchRotateAngle = switchTargetAngle;
                        }

                        if (switchRotateAngle < 7)
                        {
                            switchState = false;
                        }
                    }
                }
            }
            else
            {
                lidTicker.Stop();
                if (ActionsQueue.Count > 0)
                {
                    currentAction = ActionsQueue.Dequeue();
                    System.Console.WriteLine("Dequeing {0}", currentAction.Action);
                    if (currentAction.Action == SequenceAction.actionType.LidAction)
                    {
                        lidStartAngle = currentAction.StartMs;
                        lidEndAngle   = currentAction.EndMs;
                        if (lidStartAngle < lidEndAngle)
                        {
                            lidMoveDirection = 1;
                        }
                        else
                        {
                            lidMoveDirection = -1;
                        }
                        lidRotateAngle = lidStartAngle;
                        lidTargetAngle = lidEndAngle;
                        var numSteps     = Math.Abs((lidEndAngle - lidStartAngle) * resolution);
                        int tickInterval = (int)(currentAction.Duration / numSteps);
                        if (tickInterval == 0)
                        {
                            tickInterval = 1;
                        }
                        lidTicker.Interval = tickInterval;
                    }
                    else if (currentAction.Action == SequenceAction.actionType.DelayAction)
                    {
                        lidTicker.Interval = currentAction.Duration;
                    }
                    else if (currentAction.Action == SequenceAction.actionType.SwitchAction)
                    {
                        switchOnOffStartAngle = currentAction.StartMs;
                        switchOnOffEndAngle   = currentAction.EndMs;
                        switchRotateAngle     = switchOnOffStartAngle;
                        if (switchOnOffStartAngle > switchOnOffEndAngle)
                        {
                            switchOnOffMoveDirection = -1;
                        }
                        else
                        {
                            switchOnOffMoveDirection = 1;
                        }
                        switchTargetAngle = switchOnOffEndAngle;
                        var numSteps     = Math.Abs((switchOnOffEndAngle - switchOnOffStartAngle) * resolution);
                        int tickInterval = (int)(currentAction.Duration / numSteps);
                        if (tickInterval == 0)
                        {
                            tickInterval = 1;
                        }

                        lidTicker.Interval = tickInterval;
                    }
                    System.Console.WriteLine("TickInterval {0}", lidTicker.Interval);
                    lidTicker.Start();
                }
            }


            Refresh();
        }
Esempio n. 4
0
        public void Ticker_Thread()
        {
            bool repaintNeeded = false;

            while (true)
            {
                Thread.Sleep(0);
                if (currentAction != null)
                {
                    if (currentAction.Action == SequenceAction.ActionType.LidAction)
                    {
                        if (lidCurrentPos == lidTargetPos && lidMoveDirection > 0)
                        {
                            currentAction = null;
                        }
                        else if (lidCurrentPos == lidTargetPos && lidMoveDirection < 0)
                        {
                            currentAction = null;
                        }
                        else
                        {
                            lidCurrentPos += lidMoveDirection;
                            if (lidMoveDirection > 0 && lidCurrentPos > lidTargetPos)
                            {
                                lidCurrentPos = lidTargetPos;
                            }
                            else if (lidMoveDirection < 0 && lidCurrentPos < lidTargetPos)
                            {
                                lidCurrentPos = lidTargetPos;
                            }
                        }
                    }
                    else if (currentAction.Action == SequenceAction.ActionType.SwitchAction)
                    {
                        if (switchCurrentPos == switchOnOffTargetPos && switchOnOffMoveDirection < 0)
                        {
                            currentAction = null;
                        }
                        else if (switchCurrentPos == switchOnOffTargetPos && switchOnOffMoveDirection > 0)
                        {
                            currentAction = null;
                        }
                        else
                        {
                            switchCurrentPos += switchOnOffMoveDirection;
                            if (switchOnOffMoveDirection < 0 && switchCurrentPos < switchOnOffTargetPos)
                            {
                                switchCurrentPos = switchOnOffTargetPos;
                            }
                            else if (switchOnOffMoveDirection > 0 && switchCurrentPos > switchOnOffTargetPos)
                            {
                                switchCurrentPos = switchOnOffTargetPos;
                            }

                            if (switchCurrentPos > 2000)
                            {
                                switchState = false;
                            }
                        }
                    }
                    if (currentAction != null)
                    {
                        μTimer.uSleep(currentAction.Duration);
                    }
                }
                else
                {
                    if (ActionsQueue.Count > 0)
                    {
                        currentAction = ActionsQueue.Dequeue();
                        //System.Console.WriteLine("Dequeing {0}", currentAction.Action);
                        if (currentAction.Action == SequenceAction.ActionType.LidAction)
                        {
                            lidStartPos = currentAction.StartMs;
                            lidEndPos   = currentAction.EndMs;
                            if (lidStartPos < lidEndPos)
                            {
                                lidMoveDirection = 1;
                            }
                            else
                            {
                                lidMoveDirection = -1;
                            }
                            lidCurrentPos = lidStartPos;
                            lidTargetPos  = lidEndPos;
                        }
                        else if (currentAction.Action == SequenceAction.ActionType.DelayAction)
                        {
                            //System.Console.Write("Delaying {0}", currentAction.Duration);
                            Thread.Sleep(currentAction.Duration);
                            //System.Console.WriteLine("done");
                            currentAction = null;
                        }
                        else if (currentAction.Action == SequenceAction.ActionType.SwitchAction)
                        {
                            switchOnOffStartPos = currentAction.StartMs;
                            switchOnOffEndPos   = currentAction.EndMs;
                            switchCurrentPos    = switchOnOffStartPos;
                            if (switchOnOffStartPos > switchOnOffEndPos)
                            {
                                switchOnOffMoveDirection = -1;
                            }
                            else
                            {
                                switchOnOffMoveDirection = 1;
                            }
                            switchOnOffTargetPos = switchOnOffEndPos;
                        }
                    }
                }
                repaintNeeded = currentAction != null;
                if (repaintNeeded)
                {
                    Refresh();
                }
            }
        }