Exemplo n.º 1
0
        private void Service_HeartRateUpdated(
            ContactSensorStatus status,
            int bpm)
        {
            try
            {
                if (_leaktest)
                {
                    for (var i = 0; i < 4000; ++i)
                    {
                        Service_HeartRateUpdatedCore(status, bpm);
                    }

                    return;
                }

                Service_HeartRateUpdatedCore(status, bpm);
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Exception in Service_HeartRateUpdated {ex}");

                Debugger.Break();
            }
        }
Exemplo n.º 2
0
 private void _service_HeartRateUpdated(
     ContactSensorStatus status, int bpm)
 {
     lock (_sync)
     {
         _lastUpdateTimer.Restart();
     }
 }
Exemplo n.º 3
0
        internal static void SendData(int bpm, ContactSensorStatus status)
        {
            byte[] dataBytes = Encoding.UTF8.GetBytes(bpm.ToString());

            var isDisconnected = status == ContactSensorStatus.Contact;

            int connection = Convert.ToInt32(isDisconnected);

            Debug.WriteLine($"NeosVR - {bpm}.00000000.0000.{connection}");
        }
Exemplo n.º 4
0
        private void Service_HeartRateUpdated(
            ContactSensorStatus status,
            int bpm)
        {
            try
            {
                Service_HeartRateUpdatedCore(status, bpm);
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Exception in Service_HeartRateUpdated {ex}");

                Debugger.Break();
            }
        }
Exemplo n.º 5
0
        private void Service_HeartRateUpdatedCore(
            ContactSensorStatus status,
            int bpm)
        {
            var isDisconnected = bpm == 0 ||
                                 status == ContactSensorStatus.NoContact;

            var iconText = bpm.ToString();
            // <= 0 implies disabled.
            var isWarn = bpm >= 40 && bpm < 180;

            lock (_updateSync)
            {
                var color = isWarn ? Color.Red : Color.Blue;

                Invoke(new Action(() => {
                    labelHR.Text      = iconText;
                    labelHR.ForeColor = color;
                }));
            }
        }
Exemplo n.º 6
0
        private void Service_HeartRateUpdatedCore(
            ContactSensorStatus status,
            int bpm)
        {
            var isDisconnected = bpm == 0 ||
                                 status == ContactSensorStatus.NoContact;

            var iconText = bpm.ToString();

            var warnLevel  = _settings.WarnLevel;
            var alertLevel = _settings.AlertLevel;
            // <= 0 implies disabled.
            var isWarn  = warnLevel > 0 && bpm >= warnLevel;
            var isAlert = alertLevel > 0 && bpm >= alertLevel;

            lock (_updateSync)
            {
                if (isDisconnected)
                {
                    uxBpmNotifyIcon.Text = $"Disconnected {status} ({bpm})";

                    if (!_disconnectedTimeout.IsRunning)
                    {
                        _disconnectedTimeout.Start();
                    }

                    if (_disconnectedTimeout.Elapsed >
                        _settings.DisconnectedTimeout)
                    {
                        // Originally this used " ⃠" (U+20E0, "Prohibition Symbol")
                        // but MeasureString was only returning ~half of the
                        // width.
                        iconText = "X";
                    }
                }
                else
                {
                    uxBpmNotifyIcon.Text = null;
                    _disconnectedTimeout.Stop();
                }

                _iconGraphics.Clear(Color.Transparent);

                var sizingMeasurement = _iconGraphics
                                        .MeasureString(iconText, _measurementFont);

                var color = isWarn ? _settings.WarnColor : _settings.Color;

                using (var brush = new SolidBrush(color))
                    using (var font = new Font(_settings.FontName,
                                               _iconHeight * (_iconWidth / sizingMeasurement.Width),
                                               GraphicsUnit.Pixel))
                    {
                        _iconGraphics.DrawString(
                            iconText, font, brush,
                            new RectangleF(0, 0, _iconWidth, _iconHeight),
                            _iconStringFormat);
                    }

                _iconText = iconText;

                Invoke(new Action(() => {
                    uxBpmLabel.Text      = _iconText;
                    uxBpmLabel.ForeColor = isWarn
                        ? _settings.UIWarnColor
                        : _settings.UIColor;
                    uxBpmLabel.BackColor = _settings.UIBackgroundColor;

                    var fontx = _settings.UIFontName;

                    if (uxBpmLabel.Font.FontFamily.Name != fontx)
                    {
                        UpdateLabelFontLocked();
                    }
                }));

                var iconHandle = _iconBitmap.GetHicon();

                using (var icon = Icon.FromHandle(iconHandle))
                {
                    uxBpmNotifyIcon.Icon = icon;

                    if (isAlert && (!_alertTimeout.IsRunning ||
                                    _alertTimeout.Elapsed >= _settings.AlertTimeout))
                    {
                        _alertTimeout.Restart();

                        var alertText = $"BPMs @ {bpm}";

                        uxBpmNotifyIcon.ShowBalloonTip(
                            (int)_settings.AlertTimeout.TotalMilliseconds,
                            alertText, alertText, ToolTipIcon.Warning);
                    }
                }

                if (_oldIconHandle != IntPtr.Zero)
                {
                    DestroyIcon(_oldIconHandle);
                }

                _oldIconHandle = iconHandle;

                if (_logfilename != null)
                {
                    string data = null;

                    var dateString = DateTimeFormatter.Format(
                        _settings.LogDateFormat,
                        DateTime.Now,
                        DateTimeFormatter.DefaultColumn);

                    switch ((_settings.LogFormat ?? "").ToLower())
                    {
                    case "csv":
                        data = $"{dateString},{bpm},{status}\r\n";
                        break;
                    }

                    if (data != null)
                    {
                        File.AppendAllText(_settings.LogFile, data);
                    }
                }
            }
        }
Exemplo n.º 7
0
        private void Service_HeartRateUpdatedCore(
            ContactSensorStatus status,
            int bpm)
        {
            var isDisconnected = bpm == 0 ||
                                 status == ContactSensorStatus.NoContact;

            var iconText = bpm.ToString();

            var warnLevel  = _settings.WarnLevel;
            var alertLevel = _settings.AlertLevel;
            // <= 0 implies disabled.
            var isWarn  = warnLevel > 0 && bpm >= warnLevel;
            var isAlert = alertLevel > 0 && bpm >= alertLevel;

            lock (_updateSync)
            {
                if (isDisconnected)
                {
                    uxBpmNotifyIcon.Text = $"Disconnected {status} ({bpm})";

                    if (!_disconnectedTimeout.IsRunning)
                    {
                        _disconnectedTimeout.Start();
                    }

                    if (_disconnectedTimeout.Elapsed >
                        _settings.DisconnectedTimeout)
                    {
                        // Originally this used " ⃠" (U+20E0, "Prohibition Symbol")
                        // but MeasureString was only returning ~half of the
                        // width.
                        iconText = "X";
                    }
                }
                else
                {
                    uxBpmNotifyIcon.Text = null;
                    _disconnectedTimeout.Stop();
                }

                _iconGraphics.Clear(Color.Transparent);

                var sizingMeasurement = _iconGraphics
                                        .MeasureString(iconText, _measurementFont);

                var color = isWarn ? _settings.WarnColor : _settings.Color;

                using (var brush = new SolidBrush(color))
                    using (var font = new Font(_settings.FontName,
                                               _iconHeight * (_iconWidth / sizingMeasurement.Width),
                                               GraphicsUnit.Pixel))
                    {
                        _iconGraphics.DrawString(
                            iconText, font, brush,
                            new RectangleF(0, 0, _iconWidth, _iconHeight),
                            _iconStringFormat);
                    }

                _iconText = iconText;

                Invoke(new Action(() => {
                    uxBpmLabel.Text      = _iconText;
                    uxBpmLabel.ForeColor = isWarn
                        ? _settings.UIWarnColor
                        : _settings.UIColor;
                    uxBpmLabel.BackColor = _settings.UIBackgroundColor;

                    // EB:
                    if (this.sendToExobrainCheckBox.Checked && int.TryParse(_iconText, out int rateValue) && DateTime.Now.Second % Properties.Settings.Default.Interval == 0)
                    {
                        this.neuronApplicationService.CreateNeuron(
                            Properties.Settings.Default.AvatarUrl,
                            Guid.NewGuid().ToString(),
                            cleanForJSON(JObject.FromObject(new
                        {
                            Timestamp = DateTime.Now.ToString(),
                            HeartRate = rateValue.ToString(),
                        }).ToString()),
                            new Terminal[] {
                            // Instantiates, Heart Rate
                            new Terminal()
                            {
                                Strength = 1, Effect = NeurotransmitterEffect.Excite, TargetId = Properties.Settings.Default.HeartRateId
                            }
                        },
                            Properties.Settings.Default.AuthorId
                            );
                    }

                    var fontx = _settings.UIFontName;

                    if (uxBpmLabel.Font.FontFamily.Name != fontx)
                    {
                        UpdateLabelFontLocked();
                    }
                }));

                var iconHandle = _iconBitmap.GetHicon();

                using (var icon = Icon.FromHandle(iconHandle))
                {
                    uxBpmNotifyIcon.Icon = icon;

                    if (isAlert && (!_alertTimeout.IsRunning ||
                                    _alertTimeout.Elapsed >= _settings.AlertTimeout))
                    {
                        _alertTimeout.Restart();

                        var alertText = $"BPMs @ {bpm}";

                        uxBpmNotifyIcon.ShowBalloonTip(
                            (int)_settings.AlertTimeout.TotalMilliseconds,
                            alertText, alertText, ToolTipIcon.Warning);
                    }
                }

                if (_oldIconHandle != IntPtr.Zero)
                {
                    DestroyIcon(_oldIconHandle);
                }

                _oldIconHandle = iconHandle;

                if (_logfilename != null)
                {
                    string data = null;

                    var dateString = DateTimeFormatter.Format(
                        _settings.LogDateFormat,
                        DateTime.Now,
                        DateTimeFormatter.DefaultColumn);

                    switch ((_settings.LogFormat ?? "").ToLower())
                    {
                    case "csv":
                        data = $"{dateString},{bpm},{status}\r\n";
                        break;
                    }

                    if (data != null)
                    {
                        File.AppendAllText(_settings.LogFile, data);
                    }
                }
            }
        }