Example #1
0
 private void Stop()
 {
     if (ChannelList.isRunning)
     {
         ChannelList.Stop();
     }
 }
        protected virtual void ApplyStimulation()
        {
            if (payload.direction <= 0)
            {
                int width = (int)Mathf.Round(
                    getPulseWidth(
                        payload.direction,
                        payload.side == Side.Left ? maxWidthWristL : maxWidthWristR
                        )
                    );

                ArmStimulation.StimulateArm(
                    Part.Wrist,
                    payload.side,
                    width,
                    payload.side == Side.Left ? currentWristL : currentWristR
                    );
            }
            else
            {
                ChannelList.Stop();
                // normally apply to frist flexor
            }

            //stopTime = DateTime.Now.AddMilliseconds(500);
        }
Example #3
0
    protected override void processMessage(string raw)
    {
        //if (!isActiveAndEnabled)
        //    return;

        if (printDebug)
        {
            Debug.Log("Got message: " + raw);
        }

        try
        {
            Message msg = JsonUtility.FromJson <Message>(raw);
            AbstractMessageHandler handler;
            switch (msg.type)
            {
            // Room1
            case MessageType.ElectroWall:
            case MessageType.ButtonUpdate:
            case MessageType.ElectroProjectile:

            // Room2
            case MessageType.SolidWall:
            case MessageType.RockerButton:
            case MessageType.Slider:
            case MessageType.Water:
            case MessageType.SolidObject:

            //Room3
            case MessageType.Cube:
            case MessageType.CubeGrab:
            case MessageType.PunchCube:
                if (handlers.TryGetValue(msg.type, out handler) &&
                    handler.isActiveAndEnabled)
                {
                    handler.HandleMessage(msg);
                }
                else
                {
                    print("no handler " + msg.type);
                }
                break;

            case MessageType.Stop:
                ChannelList.Stop();
                break;

            default:
                print("Unknown Message: " + raw);
                break;
            }
        }
        catch (Exception e) { }
    }
Example #4
0
    protected void close()
    {
        ChannelList.Stop();
#if UNITY_EDITOR
        if (RehaStimInterface.Port != null)
        {
            RehaStimInterface.Port.Close();
            RehaStimInterface.Port.Dispose();
            //print("Closed Serial Port " + RehaStimInterface.Port.PortName);
            RehaStimInterface.Port = null;
        }
#endif
    }
Example #5
0
    private void OnValidate()
    {
        if (Application.isPlaying)
        {
            if (!enableEMS)
            {
                ChannelList.Stop();
            }

            init();

            enable = enableEMS;
        }
    }
        protected override void processMessage(string raw)
        {
            if (printDebug)
            {
                Debug.Log("Got message: " + raw);
            }

            try
            {
                Message msg = JsonUtility.FromJson <Message>(raw);
                AbstractMessageHandler handler;
                switch (msg.type)
                {
                case MessageType.Solid:
                case MessageType.Electro:
                case MessageType.SliderEnd:
                //case MessageType.Bump:
                //case MessageType.Hole:
                case MessageType.DetentSlider:
                case MessageType.Tracking:
                case MessageType.Push:
                case MessageType.ButtonContact:
                case MessageType.ButtonUpdate:
                case MessageType.DetentDial:
                    if (handlers.TryGetValue(msg.type, out handler))
                    {
                        handler.HandleMessage(msg);
                    }
                    else
                    {
                        print("no handler " + msg.type);
                    }
                    break;

                case MessageType.Stop:
                    ChannelList.Stop();
                    break;

                case MessageType.Bump:
                case MessageType.Hole:
                    break;

                //Pilot Stuff
                //case MessageType.ButtonGridCode:
                //    print(msg.payload.ToString());
                //    break;

                case MessageType.GridButtonUpdate:
                case MessageType.GridButtonCodeUpdate:
                case MessageType.GridButtonContact:
                case MessageType.GridButtonCodeContact:
                    //case MessageType.PullSlider:
                    if (handlers.TryGetValue(msg.type, out handler))
                    {
                        handler.HandleMessage(msg);
                    }
                    else
                    {
                        print("no handler " + msg.type);
                    }
                    break;

                // Catapult
                case MessageType.CatapultArm:
                case MessageType.CatapultRelease:
                case MessageType.CatapultTarget:
                    if (handlers.TryGetValue(MessageType.CatapultArm, out handler))
                    {
                        handler.HandleMessage(msg);
                    }
                    else
                    {
                        print("no handler " + msg.type);
                    }
                    break;

                // Box Game
                case MessageType.BoxTouching:
                case MessageType.BoxMoving:
                case MessageType.BoxLedge:
                    if (handlers.TryGetValue(MessageType.BoxTouching, out handler))
                    {
                        handler.HandleMessage(msg);
                    }
                    else
                    {
                        print("no handler " + msg.type);
                    }
                    break;

                // Marble Game
                case MessageType.MarbleImpact:
                case MessageType.MarblePosition:
                case MessageType.MarbleSuccess:
                case MessageType.MarbleWallCollision:
                    if (handlers.TryGetValue(MessageType.MarbleImpact, out handler))
                    {
                        handler.HandleMessage(msg);
                    }
                    else
                    {
                        print("no handler " + msg.type);
                    }
                    break;

                // Walkthrough
                case MessageType.WalkthroughDial:
                case MessageType.WalkthroughDialDetent:
                case MessageType.WalkthroughDialStatus:
                case MessageType.WalkthroughButton:
                case MessageType.WalkthroughButtonContact:
                case MessageType.WalkthroughButtonPosition:
                case MessageType.EscapeElectro:
                case MessageType.EscapeDetent:
                    if (handlers.TryGetValue(MessageType.WalkthroughDial, out handler))
                    {
                        handler.HandleMessage(msg);
                    }
                    else
                    {
                        print("no handler " + msg.type);
                    }
                    break;

                default:
                    print("Unknown Message: " + raw);
                    break;
                }
            }
            catch (Exception e) { }
        }
 public virtual void Stop()
 {
     //Debug.Log("Stopping");
     ChannelList.Stop();
 }
Example #8
0
    // Update is called once per frame
    private void Update()
    {
        if (Input.GetKeyDown("space"))
        {
            TestSinglePulse();
        }

        else if (Input.GetKeyDown(startKey))
        {
            if (Input.GetKey(KeyCode.LeftControl))
            {
                startPulseThread();
            }
            else
            {
                ChannelMask channels = new ChannelMask();
                channels.setChannel((int)channel);
                channels.setChannel((int)channel2);

                ChannelList.InitCM(0
                                   , channels
                                   , new ChannelMask()
                                   , groupFrequency
                                   , channelFrequency);
            }
        }
        else if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            if (channel1Active)
            {
                print("Stop Channel 1");
                ChannelList.StopChannel((int)channel);
            }
            else
            {
                print("Start Channel 1");
                ChannelList.UpdateChannel((int)channel, new UpdateInfo(UpdateInfo.MODE_SINGLE
                                                                       , pulseWidth
                                                                       , milliAmps));
            }

            channel1Active = !channel1Active;
        }
        else if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            if (channel2Active)
            {
                print("Stop Channel 2");
                ChannelList.StopChannel((int)channel2);
            }
            else
            {
                print("Start Channel 2");
                ChannelList.UpdateChannel((int)channel2, new UpdateInfo(UpdateInfo.MODE_SINGLE
                                                                        , pulseWidth2
                                                                        , milliAmps2));
            }

            channel2Active = !channel2Active;
            //ChannelList.StopChannel((int)channel);
            //ChannelList.UpdateChannel((int)channel2, new UpdateInfo(0, pulseWidth2, milliAmps2));
        }
        else if (Input.GetKeyDown(stopKey))
        {
            if (Input.GetKey(KeyCode.LeftControl))
            {
                stopPulseThread();
            }
            else
            {
                channel1Active = false;
                channel2Active = false;
                ChannelList.Stop();
            }

            //RehaStimInterface.sendMessage(ChannelList.GetStopCommand());
        }
        else if (Input.GetKeyDown(KeyCode.KeypadPlus))
        {
            if (channel1Active)
            {
                pulseWidth += 5;
                ChannelList.UpdateChannel((int)channel, new UpdateInfo(UpdateInfo.MODE_SINGLE, pulseWidth, milliAmps));
            }
        }
        else if (Input.GetKeyDown(KeyCode.KeypadMinus))
        {
            if (channel1Active)
            {
                pulseWidth -= 5;
                ChannelList.UpdateChannel((int)channel, new UpdateInfo(UpdateInfo.MODE_SINGLE, pulseWidth, milliAmps));
            }
            //RehaStimInterface.sendMessage(ChannelList.GetStopCommand());
        }
        else if (Input.GetKeyDown(KeyCode.Keypad8))
        {
            if (channel1Active)
            {
                milliAmps += 1;
                ChannelList.UpdateChannel((int)channel, new UpdateInfo(UpdateInfo.MODE_SINGLE, pulseWidth, milliAmps));
            }
        }
        else if (Input.GetKeyDown(KeyCode.Keypad2))
        {
            if (channel1Active)
            {
                milliAmps -= 1;
                ChannelList.UpdateChannel((int)channel, new UpdateInfo(UpdateInfo.MODE_SINGLE, pulseWidth, milliAmps));
            }
            //RehaStimInterface.sendMessage(ChannelList.GetStopCommand());
        }
        //StopCoroutine("ContinuousPulse");
    }
        protected void HandleDialDetent(Message msg)
        {
            VectorPayload payload = JsonUtility.FromJson <VectorPayload>(msg.payload);


            Debug.Log(payload.source + (payload.vector.x < 0).ToString());

            switch (payload.source)
            {
            case "Thermo":
                if (!activeThermo)
                {
                    break;
                }

                if (activeTimeThermo < DateTime.Now)
                {
                    if (payload.vector.x < 0)
                    {
                        ArmStimulation.StimulateArmBurst(
                            new StimulationInfo(
                                Part.InwardsWrist,
                                Side.Right,
                                inDetentR,
                                current
                                ),
                            detentDuration
                            );
                    }
                    else
                    {
                        ArmStimulation.StimulateArmBurst(
                            new StimulationInfo(
                                Part.OutwardsWrist,
                                Side.Right,
                                outDetentsR,
                                current
                                ),
                            detentDuration
                            );
                    }

                    activeTimeThermo = DateTime.Now.AddMilliseconds(cooldown);
                }
                break;

            case "Intensity":
                currentIntensity = (int)payload.vector.y;

                if (targetIntensity == currentIntensity)
                {
                    ChannelList.Stop();
                    targetIntensity = -1;
                    Debug.Log("Snapped to last Intensity");
                }

                if (changing && !invalidCombination())
                {
                    ChannelList.Stop();

                    Debug.Log("Changed To Valid Combination");
                    changing = false;
                }
                else if (invalidCombination())
                {
                    Debug.Log("Invalid Combination");
                    changing = true;
                }

                if (!activeIntensity)
                {
                    break;
                }

                if (activeTimeIntensity < DateTime.Now)
                {
                    if (payload.vector.x < 0)
                    {
                        ArmStimulation.StimulateArmBurst(
                            new StimulationInfo(
                                Part.InwardsWrist,
                                Side.Right,
                                inDetentR,
                                current
                                ),
                            detentDuration
                            );
                    }
                    else
                    {
                        ArmStimulation.StimulateArmBurst(
                            new StimulationInfo(
                                Part.OutwardsWrist,
                                Side.Right,
                                outDetentsR,
                                current
                                ),
                            detentDuration
                            );
                    }

                    activeTimeIntensity = DateTime.Now.AddMilliseconds(cooldown);
                }
                break;

            case "Color":
                if (!activeColor)
                {
                    break;
                }

                currentColor = (int)payload.vector.y;

                // snap to intensity 2
                if (invalidCombination())
                {
                    Debug.Log("Invalid Combination");
                    changing = true;
                }

                if (activeTimeColor < DateTime.Now)
                {
                    if (payload.vector.x < 0)
                    {
                        ArmStimulation.StimulateArmBurst(
                            new StimulationInfo(
                                Part.InwardsWrist,
                                Side.Left,
                                outDetentL,
                                current
                                ),
                            detentDuration
                            );
                    }
                    else
                    {
                        ArmStimulation.StimulateArmBurst(
                            new StimulationInfo(
                                Part.OutwardsWrist,
                                Side.Left,
                                inDetentL,
                                current
                                ),
                            detentDuration
                            );
                    }

                    activeTimeColor = DateTime.Now.AddMilliseconds(cooldown);
                }
                break;
            }
        }