//[SerializeField]
    //string eventNameToListenFor = "New Layer Penetrated";
    //
    //private void Start()
    //{
    //    EventManager.StartListening(eventNameToListenFor, OnNewLayerPenetrated);
    //}

    public void OnLayerChange()
    {
        if (HapticNativePlugin.isPatientPenetrated())
        {
            PenetrableMaterial lastLayerPenetrated = PenetrableMaterial.GetLayer(HapticNativePlugin.getLastLayerPenetratedID());
            arduino.SetResistance((float)lastLayerPenetrated.m_fluidResistance);
        }
        else
        {
            lastLayerPenetrated = null;

            arduino.SetResistance(0.0f);
            //Debug.Log ("not resisting");
        }
    }
    //sets attempt details and returns true if success
    bool EndAttempt()
    {
        isTestRunning = false;

        ProcedureAttempt currentAttempt = attempts[attemptNum];

        if (currentAttempt != null)
        {
            currentAttempt.timeEnded = Time.realtimeSinceStartup;
            var currentLayer = PenetrableMaterial.GetLayer(HapticNativePlugin.getLastLayerPenetratedID());
            currentAttempt.notes = "ended in: " + currentLayer.m_name;
            if (duraPunctured)
            {
                currentAttempt.notes += ", Dura punctured";
            }

            currentAttempt.success = (currentLayer == targetLayer);

            string result;

            if (currentAttempt.success)
            {
                result = "success";
            }
            else
            {
                result = "failure, ";
            }

            currentAttempt.summaryText = "Attempt # " + attemptNum + ": " + result + ", Duration: " + (currentAttempt.timeEnded - currentAttempt.timeStarted) + ", " + currentAttempt.notes;;
            return(currentAttempt.success);
        }
        else
        {
            return(false);
        }
    }
Ejemplo n.º 3
0
    void CheckForNewPuncture()
    {
        //if (HapticNativePlugin.isPatientPenetrated())
        //{
        PenetrableMaterial currentLayer = PenetrableMaterial.GetLayer(HapticNativePlugin.getLastLayerPenetratedID());
        int currentLayerDepth           = HapticNativePlugin.getCurrentLayerDepth();

        if (currentLayer != lastLayer)
        {
            // send layer change event
            OnLayerChange.Invoke();
            EventManager.TriggerEvent(newLayerMessage);

            // leaving a layer i.e. needle moving outwards
            if (currentLayerDepth < lastLayerDepth)
            {
                // send last layer event
                EventManager.TriggerEvent(leftLayerKey + lastLayer.m_name);
                OnLeaveLayer.Invoke();

                if (currentLayer != null)
                {
                    /////////////////   !!!!!!!!   /////////////////
                    // unlock rotation if entering an unlocked layer
                    // POTENTIAL BUG here, because this check does not cover all possible cases!
                    // e.g. if you go from a layer that is locked to a new layer further in that is not locked. In that case you should still be locked, but this code will unlock you
                    /////////////////   !!!!!!!!   /////////////////
                    if (lastLayer.m_locksRotation && !currentLayer.m_locksRotation)
                    {
                        // last layer should never be null because you cannot go lower than -1 current layer depth
                        EventManager.TriggerEvent(unlockRotationEvent);
                        OnUnlockRotation.Invoke();
                    }
                }
                else
                {
                    // entered air therefore unlock
                    OnUnlockRotation.Invoke();
                    OnNoPunctures.Invoke();
                }
            }
            else
            {
                // entering a further layer i.e. needle moving inwards
                if (currentLayer != null)
                {
                    if (lastLayer == null)
                    {
                        // if going from nothing to something then that is a puncture. Send the event
                        OnFirstPuncture.Invoke();
                    }


                    // send new layer event
                    EventManager.TriggerEvent(penetratedLayerKey + currentLayer.m_name);
                    OnEnterLayer.Invoke();

                    // send lock rotation event
                    if (currentLayer.m_locksRotation)
                    {
                        EventManager.TriggerEvent(lockRotationEvent);
                        OnLockRotation.Invoke();
                    }
                }
            }


            // update info UI
            if (LayerInfoUI != null)
            {
                if (currentLayer != null)
                {
                    LayerInfoUI.text = currentLayer.m_name;
                }
                else
                {
                    LayerInfoUI.text = "";
                }
            }

            lastLayerDepth = currentLayerDepth;
            lastLayer      = currentLayer;
        } // if (currentLayer != lastLayer)
    }     // CheckForNewPuncture