Example #1
0
    protected override void waitEvent()
    {
        double timestamp = 0;
        bool   success   = false;

        bool ok;
        int  phase = 0;

        do
        {
            if (simulated)
            {
                ok = true;
            }
            else
            {
                ok = cp.Read_event(out timestamp, out platformState);
            }


            /*
             *           \()/            \()/
             *            \/              \/
             *   _()_     /\     _()_     /\     _()_
             *    \/              \/              \/
             * ___/\______________/\______________/\___
             *
             *  GraphA  graphB  graphC  graphD  graphE
             *  unused  jumps   lands   jumps   lands
             *
             *    ______start_______             end
             *
             *    DJ      DJ      SJ
             * hasFall  hasFall
             * fall -1
             *
             */

            //if (ok)
            if (ok && !cancel)
            {
                if (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF)
                {
                    //has landed
                    if (hasFall && tc == 0)
                    {
                        //**** graphC ****

                        if (fall == -1)
                        {
                            if (simulated)
                            {
                                timestamp = simulatedTimeLast * 1000;                                 //conversion to milliseconds
                            }
                            //calculate the fall height using flight time
                            double tvPreJump = timestamp / 1000.0;
                            fall = Convert.ToDouble(Util.GetHeightInCentimeters(tvPreJump.ToString()));
                        }

                        //jump with fall, landed first time
                        initializeTimer();

                        //app1.ProgressBarEventOrTimePreExecution(
                        //don't do it, put a boolean value and let the PulseGTK do it
                        updateProgressBar = new UpdateProgressBar(
                            true,                                     //isEvent
                            true,                                     //jumpsLimited: percentageMode
                            ++phase
                            );
                        needUpdateEventProgressBar = true;

                        feedbackMessage         = "";
                        needShowFeedbackMessage = true;
                    }
                    else
                    {
                        //**** graphE **** jump with fall: second landed; or without fall first landing

                        if (simulated)
                        {
                            timestamp = simulatedTimeLast * 1000;                             //conversion to milliseconds
                        }
                        LogB.Information(string.Format("t1:{0}", timestamp));

                        tv = timestamp / 1000.0;

                        jumpPhase = jumpPhases.PLATFORM_END;

                        write();

                        success = true;

                        //app1.ProgressBarEventOrTimePreExecution(
                        //don't do it, put a boolean value and let the PulseGTK do it
                        updateProgressBar = new UpdateProgressBar(
                            true,                                     //isEvent
                            true,                                     //percentageMode
                            ++phase
                            );
                        needUpdateEventProgressBar = true;
                    }
                    loggedState = States.ON;
                }
                else if (platformState == Chronopic.Plataforma.OFF && loggedState == States.ON)
                {
                    //it's out, was inside (= has jumped)

                    //fall != -1 because if it was == -1, it will change once touching floor for the first time
                    if (hasFall && fall != -1)
                    {
                        //**** graphD ****

                        if (simulated)
                        {
                            timestamp = simulatedTimeLast * 1000;                             //conversion to milliseconds
                        }
                        LogB.Information(string.Format("t2:{0}", timestamp));

                        //record the TC
                        tc = timestamp / 1000.0;

                        //takeOff jump (only one TC)
                        //if(fixedValue == 0.5)
                        if (type == Constants.TakeOffName || type == Constants.TakeOffWeightName)
                        {
                            tv = 0;

                            jumpPhase = jumpPhases.PLATFORM_END;

                            write();
                            success = true;
                        }

                        //update event progressbar
                        //app1.ProgressBarEventOrTimePreExecution(
                        //don't do it, put a boolean value and let the PulseGTK do it
                        updateProgressBar = new UpdateProgressBar(
                            true,                                     //isEvent
                            true,                                     //percentageMode
                            ++phase
                            );
                        needUpdateEventProgressBar = true;
                    }
                    else
                    {
                        //**** graphD (if normal jump) ****
                        //**** graphB (if hasFall and fall == -1) ****

                        initializeTimer();

                        //update event progressbar
                        //app1.ProgressBarEventOrTimePreExecution(
                        //don't do it, put a boolean value and let the PulseGTK do it
                        updateProgressBar = new UpdateProgressBar(
                            true,                                     //isEvent
                            true,                                     //percentageMode
                            ++phase
                            );
                        needUpdateEventProgressBar = true;

                        feedbackMessage         = "";
                        needShowFeedbackMessage = true;
                    }

                    //change the automata state
                    loggedState = States.OFF;
                }
            }
//Log.WriteLine("PREEXIT");
        } while (!success && !cancel);
//Log.WriteLine("EXIT");

        if (cancel)
        {
            //event will be raised, and managed in chronojump.cs
            fakeButtonFinished.Click();

            totallyCancelled = true;
        }
    }
Example #2
0
    public override void ManageFall()
    {
        //boolean to know if chronopic has been disconnected
        chronopicDisconnected = false;

        if (simulated)
        {
            if (fall != -1)
            {
                platformState = Chronopic.Plataforma.OFF;
            }
            else
            {
                platformState = Chronopic.Plataforma.ON;
            }
        }
        else
        {
            platformState = chronopicInitialValue(cp);
        }



        if (platformState != Chronopic.Plataforma.OFF &&
            platformState != Chronopic.Plataforma.ON)
        {
            //UNKNOW (Chronopic disconnected, port changed, ...)
            chronopicHasBeenDisconnected();
            return;
        }

        //if we are outside
        //or we are inside, but with fall == -1 (calculate fall using a previous jump (start inside))
        if (
            (platformState == Chronopic.Plataforma.OFF && fall != -1) ||
            (platformState == Chronopic.Plataforma.ON && fall == -1)
            )
        {
            if (fall != -1)
            {
                feedbackMessage = Catalog.GetString("You are OUT, JUMP when prepared!");
                loggedState     = States.OFF;
            }
            else
            {
                feedbackMessage = Catalog.GetString("You are IN, JUMP when prepared!");
                loggedState     = States.ON;
            }

            needShowFeedbackMessage = true;
            Util.PlaySound(Constants.SoundTypes.CAN_START, volumeOn);


            //useful also for tracking the jump phases
            tc = 0;

            //prepare jump for being cancelled if desired
            cancel           = false;
            totallyCancelled = false;

            jumpPhase = jumpPhases.PRE_OR_DOING;

            //in simulated mode, make the jump start just when we arrive to waitEvent at the first time
            if (simulated)
            {
                if (fall != -1)
                {
                    platformState = Chronopic.Plataforma.ON;                     //mark now that we have arrived:
                }
                else
                {
                    platformState = Chronopic.Plataforma.OFF;                     //mark now that we have jumped
                }
            }

            //start thread
            thread = new Thread(new ThreadStart(waitEvent));
            GLib.Idle.Add(new GLib.IdleHandler(PulseGTK));

            LogB.ThreadStart();
            thread.Start();
        }
        else
        {
            ConfirmWindow confirmWin;

            string message = Catalog.GetString("You are IN, please leave the platform, and press the 'accept' button");
            if (fall == -1)
            {
                message = Catalog.GetString("You are OUT, please enter the platform, prepare for jump and press the 'accept' button");
            }

            confirmWin = ConfirmWindow.Show(message, "", "");

            Util.PlaySound(Constants.SoundTypes.BAD, volumeOn);

            //we call again this function
            confirmWin.Button_accept.Clicked += new EventHandler(callAgainManageFall);

            //if confirmWin.Button_cancel is pressed return
            confirmWin.Button_cancel.Clicked += new EventHandler(cancel_event_before_start);
        }
    }
Example #3
0
    public override void Manage()
    {
        //boolean to know if chronopic has been disconnected
        chronopicDisconnected = false;

        if (simulated)
        {
            platformState = Chronopic.Plataforma.ON;
        }
        else
        {
            platformState = chronopicInitialValue(cp);
        }


        if (platformState == Chronopic.Plataforma.ON)
        {
            feedbackMessage         = Catalog.GetString("You are IN, JUMP when prepared!");
            needShowFeedbackMessage = true;
            Util.PlaySound(Constants.SoundTypes.CAN_START, volumeOn);

            loggedState = States.ON;

            //prepare jump for being cancelled if desired
            cancel           = false;
            totallyCancelled = false;

            jumpPhase = jumpPhases.PRE_OR_DOING;

            //in simulated mode, make the jump start just when we arrive to waitEvent at the first time
            //mark now that we have leaved platform:
            if (simulated)
            {
                platformState = Chronopic.Plataforma.OFF;
            }

            //start thread
            thread = new Thread(new ThreadStart(waitEvent));
            GLib.Idle.Add(new GLib.IdleHandler(PulseGTK));

            LogB.ThreadStart();
            thread.Start();
        }
        else if (platformState == Chronopic.Plataforma.OFF)
        {
            ConfirmWindow confirmWin;
            confirmWin = ConfirmWindow.Show(Catalog.GetString(
                                                "You are OUT, please enter the platform, prepare for jump and press the 'accept' button"), "", "");

            Util.PlaySound(Constants.SoundTypes.BAD, volumeOn);

            //we call again this function
            confirmWin.Button_accept.Clicked += new EventHandler(callAgainManage);

            //if confirmWin.Button_cancel is pressed return
            confirmWin.Button_cancel.Clicked += new EventHandler(cancel_event_before_start);
        }
        else           //UNKNOW (Chronopic disconnected, port changed, ...)
        {
            chronopicHasBeenDisconnected();
        }
    }
Example #4
0
    protected override void waitEvent()
    {
        double timestamp = 0;
        bool success = false;

        bool ok;
        int phase = 0;

        do {
            if(simulated)
                ok = true;
            else
            {
                LogB.Information("calling Read_event");
                ok = cp.Read_event(out timestamp, out platformState);
                LogB.Information("Read_event done!");
            }

            /*
             *           \()/            \()/
             *            \/              \/
             *   _()_     /\     _()_     /\     _()_
             *    \/              \/              \/
             * ___/\______________/\______________/\___
             *
             *  GraphA  graphB  graphC  graphD  graphE
             *  unused  jumps   lands   jumps   lands
             *
             *    ______start_______             end
             *
             *    DJ      DJ      SJ
             * hasFall  hasFall
             * fall -1
             *
             */

            //if (ok)
            if (ok && !cancel) {
                if (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF)
                {
                    //has landed
                    if(hasFall && tc == 0)
                    {
                        //**** graphC ****

                        if(fall == -1) {
                            if(simulated)
                                timestamp = simulatedTimeLast * 1000; //conversion to milliseconds

                            //calculate the fall height using flight time
                            double tvPreJump = timestamp / 1000.0;
                            fall = Convert.ToDouble(Util.GetHeightInCentimeters(tvPreJump.ToString()));
                        }

                        //jump with fall, landed first time
                        initializeTimer();

                        //app1.ProgressBarEventOrTimePreExecution(
                        //don't do it, put a boolean value and let the PulseGTK do it
                        updateProgressBar = new UpdateProgressBar (
                                true, //isEvent
                                true, //jumpsLimited: percentageMode
                                ++phase
                                );
                        needUpdateEventProgressBar = true;

                        feedbackMessage = "";
                        needShowFeedbackMessage = true;

                    } else {
                        //**** graphE **** jump with fall: second landed; or without fall first landing

                        if(simulated)
                            timestamp = simulatedTimeLast * 1000; //conversion to milliseconds

                        LogB.Information(string.Format("t1:{0}", timestamp));

                        tv = timestamp / 1000.0;

                        jumpPhase = jumpPhases.PLATFORM_END;

                        write();

                        success = true;

                        //app1.ProgressBarEventOrTimePreExecution(
                        //don't do it, put a boolean value and let the PulseGTK do it
                        updateProgressBar = new UpdateProgressBar (
                                true, //isEvent
                                true, //percentageMode
                                ++phase
                                );
                        needUpdateEventProgressBar = true;
                    }
                    loggedState = States.ON;
                }
                else if (platformState == Chronopic.Plataforma.OFF && loggedState == States.ON)
                {
                    //it's out, was inside (= has jumped)

                    //fall != -1 because if it was == -1, it will change once touching floor for the first time
                    if(hasFall && fall != -1) {
                        //**** graphD ****

                        if(simulated)
                            timestamp = simulatedTimeLast * 1000; //conversion to milliseconds

                        LogB.Information(string.Format("t2:{0}", timestamp));

                        //record the TC
                        tc = timestamp / 1000.0;

                        //takeOff jump (only one TC)
                        //if(fixedValue == 0.5)
                        if(type == Constants.TakeOffName || type == Constants.TakeOffWeightName) {
                            tv = 0;

                            jumpPhase = jumpPhases.PLATFORM_END;

                            write();
                            success = true;
                        }

                        //update event progressbar
                        //app1.ProgressBarEventOrTimePreExecution(
                        //don't do it, put a boolean value and let the PulseGTK do it
                        updateProgressBar = new UpdateProgressBar (
                                true, //isEvent
                                true, //percentageMode
                                ++phase
                                );
                        needUpdateEventProgressBar = true;
                    } else {
                        //**** graphD (if normal jump) ****
                        //**** graphB (if hasFall and fall == -1) ****

                        initializeTimer();

                        //update event progressbar
                        //app1.ProgressBarEventOrTimePreExecution(
                        //don't do it, put a boolean value and let the PulseGTK do it
                        updateProgressBar = new UpdateProgressBar (
                                true, //isEvent
                                true, //percentageMode
                                ++phase
                                );
                        needUpdateEventProgressBar = true;

                        feedbackMessage = "";
                        needShowFeedbackMessage = true;
                    }

                    //change the automata state
                    loggedState = States.OFF;
                }
            }
        } while ( ! success && ! cancel );

        LogB.Information("Exited waitEvent main bucle");

        if(cancel)
        {
            //event will be raised, and managed in chronojump.cs
            fakeButtonFinished.Click();

            totallyCancelled = true;
        }
    }
Example #5
0
    public override void ManageFall()
    {
        //boolean to know if chronopic has been disconnected
        chronopicDisconnected = false;

        if (simulated) {
            if(fall != -1)
                platformState = Chronopic.Plataforma.OFF;
            else
                platformState = Chronopic.Plataforma.ON;
        }
        else
            platformState = chronopicInitialValue(cp);

        if (platformState != Chronopic.Plataforma.OFF &&
                platformState != Chronopic.Plataforma.ON)
        {
            //UNKNOW (Chronopic disconnected, port changed, ...)
            chronopicHasBeenDisconnected();
            return;
        }

        //if we are outside
        //or we are inside, but with fall == -1 (calculate fall using a previous jump (start inside))
        if (
                ( platformState == Chronopic.Plataforma.OFF && fall != -1 ) ||
                ( platformState == Chronopic.Plataforma.ON  && fall == -1 )
                )
        {
            if(fall != -1) {
                feedbackMessage = Catalog.GetString("You are OUT, JUMP when prepared!");
                loggedState = States.OFF;
            } else {
                feedbackMessage = Catalog.GetString("You are IN, JUMP when prepared!");
                loggedState = States.ON;
            }

            needShowFeedbackMessage = true;
            Util.PlaySound(Constants.SoundTypes.CAN_START, volumeOn);

            //useful also for tracking the jump phases
            tc = 0;

            //prepare jump for being cancelled if desired
            cancel = false;
            totallyCancelled = false;

            jumpPhase = jumpPhases.PRE_OR_DOING;

            //in simulated mode, make the jump start just when we arrive to waitEvent at the first time
            if (simulated) {
                if(fall != -1)
                    platformState = Chronopic.Plataforma.ON; //mark now that we have arrived:
                else
                    platformState = Chronopic.Plataforma.OFF; //mark now that we have jumped
            }

            //start thread
            thread = new Thread(new ThreadStart(waitEvent));
            GLib.Idle.Add (new GLib.IdleHandler (PulseGTK));

            LogB.ThreadStart();
            thread.Start();
        }
        else
        {
            ConfirmWindow confirmWin;

            string message = Catalog.GetString("You are IN, please leave the platform, and press the 'accept' button");
            if(fall == -1)
                message = Catalog.GetString("You are OUT, please enter the platform, prepare for jump and press the 'accept' button");

            confirmWin = ConfirmWindow.Show(message, "", "");

            Util.PlaySound(Constants.SoundTypes.BAD, volumeOn);

            //we call again this function
            confirmWin.Button_accept.Clicked += new EventHandler(callAgainManageFall);

            //if confirmWin.Button_cancel is pressed return
            confirmWin.Button_cancel.Clicked += new EventHandler(cancel_event_before_start);
        }
    }
Example #6
0
    public override void Manage()
    {
        //boolean to know if chronopic has been disconnected
        chronopicDisconnected = false;

        if (simulated)
            platformState = Chronopic.Plataforma.ON;
        else
            platformState = chronopicInitialValue(cp);

        if (platformState==Chronopic.Plataforma.ON) {
            feedbackMessage = Catalog.GetString("You are IN, JUMP when prepared!");
            needShowFeedbackMessage = true;
            Util.PlaySound(Constants.SoundTypes.CAN_START, volumeOn);

            loggedState = States.ON;

            //prepare jump for being cancelled if desired
            cancel = false;
            totallyCancelled = false;

            jumpPhase = jumpPhases.PRE_OR_DOING;

            //in simulated mode, make the jump start just when we arrive to waitEvent at the first time
            //mark now that we have leaved platform:
            if (simulated)
                platformState = Chronopic.Plataforma.OFF;

            //start thread
            thread = new Thread(new ThreadStart(waitEvent));
            GLib.Idle.Add (new GLib.IdleHandler (PulseGTK));

            LogB.ThreadStart();
            thread.Start();
        }
        else if (platformState==Chronopic.Plataforma.OFF) {
            ConfirmWindow confirmWin;
            confirmWin = ConfirmWindow.Show(Catalog.GetString(
                        "You are OUT, please enter the platform, prepare for jump and press the 'accept' button"), "", "");

            Util.PlaySound(Constants.SoundTypes.BAD, volumeOn);

            //we call again this function
            confirmWin.Button_accept.Clicked += new EventHandler(callAgainManage);

            //if confirmWin.Button_cancel is pressed return
            confirmWin.Button_cancel.Clicked += new EventHandler(cancel_event_before_start);
        }
        else { //UNKNOW (Chronopic disconnected, port changed, ...)
            chronopicHasBeenDisconnected();
        }
    }