Esempio n. 1
0
        private void PeriodicTimerCallback(ThreadPoolTimer timer)
        {
            if (ValueChangeCompleted == null)
            {
                return;
            }

            if (_simulatorGoingUp)
            {
                _startSimulatorValue = (ushort)(_startSimulatorValue + _stepSimulatorValue);
                if (_startSimulatorValue > _maxSimulatorValue)
                {
                    _startSimulatorValue = _maxSimulatorValue;
                    _simulatorGoingUp    = false;
                }
            }
            else
            {
                _startSimulatorValue = (ushort)(_startSimulatorValue - _stepSimulatorValue);
                if (_startSimulatorValue < _minSimulatorValue)
                {
                    _startSimulatorValue = _minSimulatorValue;
                    _simulatorGoingUp    = true;
                }
            }

            ValueChangeCompleted(HeartbeatMeasurement.GetHeartbeatMeasurementFromData(_startSimulatorValue, DateTimeOffset.Now));
        }
Esempio n. 2
0
        private void Oncharacteristic_ValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args)
        {
            var data = new byte[args.CharacteristicValue.Length];

            DataReader.FromBuffer(args.CharacteristicValue).ReadBytes(data);

            if (ValueChangeCompleted != null)
            {
                ValueChangeCompleted(HeartbeatMeasurement.GetHeartbeatMeasurementFromData(data, args.Timestamp));
            }
        }
        //find where in graph image each values would correspond to and add this info to a new array
        private List<DataPoint> FillOffsetList(HeartbeatMeasurement[] dataSet, RenderingOptions options, float Width, float Height)
        {
            if (dataSet == null || dataSet.Length <= 0)
            {
                return null;
            }

            var valueDiff = options.MaxValue - options.MinValue;
            float tickOffset = (Width / dataSet.Length);

            List<DataPoint> offsetList = new List<DataPoint>();

            float currentOffset = 0;

            for (int i = 0; i < dataSet.Length; i++)
            {
                var currentDiff = options.MaxValue - dataSet[i].HeartbeatValue;

                offsetList.Add(new DataPoint
                {
                    OffsetX = currentOffset,
                    OffsetY = (currentDiff / valueDiff) * Height,
                    Value = dataSet[i].HeartbeatValue //just in case we would have functionality to show the actual value, we'll store  it here
                });
                currentOffset += tickOffset;
            }

            return offsetList;
        }
        private void DrawCharData(CanvasDevice device, RenderingOptions options, HeartbeatMeasurement[] data)
        {
            //Size restrictions descriped in : http://microsoft.github.io/Win2D/html/P_Microsoft_Graphics_Canvas_CanvasDevice_MaximumBitmapSizeInPixels.htm
            float useHeight = (float)ChartWin2DCanvas.Size.Height > device.MaximumBitmapSizeInPixels ? device.MaximumBitmapSizeInPixels : (float)ChartWin2DCanvas.Size.Height;
            float useWidth = data.Length > device.MaximumBitmapSizeInPixels ? device.MaximumBitmapSizeInPixels : data.Length;

            //this will change the values array to array with drawing-line-points for the graph
            List<DataPoint> dataList = FillOffsetList(data, options, useWidth, useHeight);

            //reset zoom & moving values
            _zoomFactor = 100;
            _graphDrawingPoint = new Point(0, 0);
            _graphDrawingSource = new Size(useWidth, useHeight);
            //create the graph image
            _offscreenChartImage = new CanvasRenderTarget(device, useWidth, useHeight, 96);

            using (CanvasDrawingSession ds = _offscreenChartImage.CreateDrawingSession())
            {
                //This creates drawing geometry from the drawing-line-points
                CanvasGeometry chart = getDrawChartGeometry(device, dataList);
                //and then we simply draw it with defined color
                ds.DrawGeometry(chart, 0, 0, GRAPG_COLOR);
            }
        }
        private RenderingOptions CreateRenderingOptions(HeartbeatMeasurement[] dataSet)
        {
            RenderingOptions renderingOptions = null;
            if (dataSet != null)
            {
                renderingOptions = new RenderingOptions();
                //set initial end-of-range values
                renderingOptions.MinValue = double.MaxValue;
                renderingOptions.MaxValue = double.MinValue;

                //find if we have bigger or smaller than what we have with current values
                for (int i = 0; i < dataSet.Length; i++)
                {
                    renderingOptions.MinValue = Math.Min(dataSet[i].HeartbeatValue, renderingOptions.MinValue);
                    renderingOptions.MaxValue = Math.Max(dataSet[i].HeartbeatValue, renderingOptions.MaxValue);
                }

                //and see if default values are more suitable
                if (renderingOptions.MinValue > MIN_VALUE_DEFAULT)
                {
                    renderingOptions.MinValue = MIN_VALUE_DEFAULT;
                }

                if (renderingOptions.MaxValue < MAX_VALUE_DEFAULT)
                {
                    renderingOptions.MaxValue = MAX_VALUE_DEFAULT;
                }

                var valueDiff = renderingOptions.MaxValue - renderingOptions.MinValue;
                var diffBuffer = (valueDiff > 0) ? (valueDiff * 0.1) : 2;
                //values used with value texts
                renderingOptions.MaxValueBuffered = renderingOptions.MaxValue + diffBuffer;
                renderingOptions.MinValueBuffered = renderingOptions.MinValue - diffBuffer;
                renderingOptions.MinValueBuffered = (renderingOptions.MinValueBuffered > 0) ? renderingOptions.MinValueBuffered : 0;
            }

            return renderingOptions;
        }
 // this is called externally to give us the data for the graph
 public void PlotChart(HeartbeatMeasurement[] data)
 {
     _data = data;
     DrawChart();
 }
        private async void Instance_ValueChangeCompleted(HeartbeatMeasurement HeartbeatMeasurementValue)
        {
            System.Diagnostics.Debug.WriteLine("got heartbeat : " + HeartbeatMeasurementValue.HeartbeatValue);

            // Serialize UI update to the the main UI thread.
            await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                if (progressGrid.Visibility == Visibility.Visible)
                {
                    SetWaitVisibility(false);
                }

                chartControlOne.AddChartData(HeartbeatMeasurementValue);
            });
        }
        public void AddChartData(HeartbeatMeasurement HeartbeatMeasurementValue)
        {
            // lets put the value into the UI control
            HeartbeatValueBox.Text = "" + HeartbeatMeasurementValue.HeartbeatValue;

            //we need to store it in an array in order to visualize the values with graph
            _data.Add(HeartbeatMeasurementValue);

            ReDrawChart();
        }
        public void PlotChart(HeartbeatMeasurement[] data)
        {
            // First set the data points that we are going to render
            // The functions will use this data to plot the chart
            _data = data;

            //then do the full drawing
            DrawAll();
        }