private string FormatFilename(string inputFilename)
 {
     return(string.IsNullOrWhiteSpace(inputFilename)
         ? null
         : DateTimeFormatter.FormatStringTokens(
                inputFilename, _startedAt, forFilepath: true));
 }
Beispiel #2
0
        public void Reading(HeartRateReading reading)
        {
            if (!HasFileWriter)
            {
                return;
            }

            string data = null;

            var bpm     = reading.BeatsPerMinute;
            var status  = reading.BeatsPerMinute;
            var rrvalue = reading.RRIntervals == null
                ? ""
                : string.Join(",", reading.RRIntervals);

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

            switch ((_settings.LogFormat ?? "").ToLower())
            {
            case "csv":
                data = $"{dateString},{bpm},{status},{reading.EnergyExpended},{rrvalue}";
                break;
            }

            if (data != null)
            {
                WriteLine(data);
            }
        }
Beispiel #3
0
        private void LoadSettingsLocked()
        {
            _settings.Load();

            var logfile = _settings.LogFile;

            _logfilename = string.IsNullOrWhiteSpace(logfile)
                ? null
                : DateTimeFormatter.FormatStringTokens(logfile, _startedAt);
        }
Beispiel #4
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);
                    }
                }
            }
        }