コード例 #1
0
        private void PollSensors(ThreadPoolTimer timer)
        {
            float?angle1    = AccP1?.GetAngle();
            float?pressure1 = BarP1?.GetPressure();

            float?angle2    = AccP2?.GetAngle();
            float?pressure2 = BarP2?.GetPressure();

            if (currTest != null)
            {
                if (angle1 == null)
                {
                    // Alert user
                }
                else
                {
                    float volume = AngleToVolumeConversion * (float)angle1;
                    currTest.VolumeDataP1.Add(volume);
                }
                if (angle2 == null)
                {
                    // Alert user
                }
                else
                {
                    float volume = AngleToVolumeConversion * (float)angle2;
                    currTest.VolumeDataP2.Add(volume);
                }
                if (pressure1 == null)
                {
                    // Alert user
                }
                else
                {
                    currTest.PressureDataP1.Add((float)pressure1);
                }
                if (pressure2 == null)
                {
                    // Alert user
                }
                else
                {
                    currTest.PressureDataP2.Add((float)pressure2);
                }
            }

            if ((Application.Current as App).ComService != null)
            {
                angle1 = angle1 == null ? 0 : angle1;
                (Application.Current as App).ComService.SendVolumeUpdate(AngleToVolumeConversion * (float)angle1, Enums.Patient.A);
                angle2 = angle2 == null ? 0 : angle2;
                (Application.Current as App).ComService.SendVolumeUpdate(AngleToVolumeConversion * (float)angle2, Enums.Patient.B);
                pressure1 = pressure1 == null ? 0 : pressure1;
                (Application.Current as App).ComService.SendPressureUpdate((float)pressure1, Enums.Patient.A);
                pressure2 = pressure2 == null ? 0 : pressure2;
                (Application.Current as App).ComService.SendPressureUpdate((float)pressure2, Enums.Patient.B);
            }

            if (pressure1 < NextPeep1)
            {
                NextPeep1 = (float)pressure1;
            }

            if (pressure2 < NextPeep2)
            {
                NextPeep2 = (float)pressure2;
            }

            if (angle1 != null)
            {
                float volume = AngleToVolumeConversion * (float)angle1;
                float deriv  = volume - PrevVolume1;
                PrevVolume1 = volume;
                VolDeriv1   = (VolDeriv1 + deriv) / 2;

                if (volume < CurrMinVol1)
                {
                    CurrMinVol1 = volume;
                }
                if (volume > CurrMaxVol1)
                {
                    CurrMaxVol1 = volume;
                }

                if (InhaleExhale) // Inhaling
                {
                    if (VolDeriv1 < -0.001)
                    {
                        InhaleExhale = false;
                        MaxVol1      = CurrMaxVol1;
                        CurrMinVol1  = float.MaxValue;
                        var lastChange = LastChange1;
                        LastChange1 = PollCounter;
                        var currDiff = PollCounter - lastChange; // Time to inhale
                        var ie       = currDiff / ((float)LastDiff1);
                        LastDiff1 = currDiff;
                        (Application.Current as App)?.ComService?.SendIEUpdate(ie, Enums.Patient.A);
                        (Application.Current as App)?.ComService?.SendTVUpdate(MaxVol1 - MinVol1, Enums.Patient.A);
                    }
                }
                else // Exhaling
                {
                    if (VolDeriv1 > 0.001)
                    {
                        InhaleExhale = true;
                        MinVol1      = CurrMinVol1;
                        CurrMaxVol1  = float.MinValue;
                        var lastChange = LastChange1;
                        LastChange1 = PollCounter;
                        var currDiff = PollCounter - lastChange; // Time to inhale
                        var ie       = ((float)LastDiff1) / currDiff;
                        LastDiff1 = currDiff;
                        (Application.Current as App)?.ComService?.SendIEUpdate(ie, Enums.Patient.A);
                        (Application.Current as App)?.ComService?.SendTVUpdate(MaxVol1 - MinVol1, Enums.Patient.A);
                    }
                }
            }

            if (angle2 != null)
            {
                float volume = AngleToVolumeConversion * (float)angle2;
                float deriv  = volume - PrevVolume2;
                PrevVolume2 = volume;
                VolDeriv2   = (VolDeriv2 + deriv) / 2;

                if (volume < CurrMinVol2)
                {
                    CurrMinVol2 = volume;
                }
                if (volume > CurrMaxVol2)
                {
                    CurrMaxVol2 = volume;
                }

                if (InhaleExhale) // Inhaling
                {
                    if (VolDeriv2 < -0.001)
                    {
                        InhaleExhale = false;
                        MaxVol2      = CurrMaxVol2;
                        CurrMinVol2  = float.MaxValue;
                        var lastChange = LastChange2;
                        LastChange2 = PollCounter;
                        var currDiff = PollCounter - lastChange; // Time to inhale
                        var ie       = currDiff / ((float)LastDiff2);
                        LastDiff2 = currDiff;
                        (Application.Current as App)?.ComService?.SendIEUpdate(ie, Enums.Patient.B);
                        (Application.Current as App)?.ComService?.SendTVUpdate(MaxVol2 - MinVol2, Enums.Patient.B);
                    }
                }
                else // Exhaling
                {
                    if (VolDeriv2 > 0.001)
                    {
                        InhaleExhale = true;
                        MinVol2      = CurrMinVol2;
                        CurrMaxVol2  = float.MinValue;
                        var lastChange = LastChange2;
                        LastChange2 = PollCounter;
                        var currDiff = PollCounter - lastChange; // Time to inhale
                        var ie       = ((float)LastDiff2) / currDiff;
                        LastDiff2 = currDiff;
                        (Application.Current as App)?.ComService?.SendIEUpdate(ie, Enums.Patient.B);
                        (Application.Current as App)?.ComService?.SendTVUpdate(MaxVol2 - MinVol2, Enums.Patient.B);
                    }
                }
            }

            if (PollCounter % NextValueBecomesCurrValue == 0)
            {
                CurrPeep1 = NextPeep1;
                CurrPeep2 = NextPeep2;

                (Application.Current as App)?.ComService?.SendPeepUpdate(CurrPeep1, Enums.Patient.A);
                (Application.Current as App)?.ComService?.SendPeepUpdate(CurrPeep2, Enums.Patient.B);

                NextPeep1 = float.MaxValue;
                NextPeep2 = float.MaxValue;
            }

            PollCounter++;
        }