Beispiel #1
0
        unsafe void UpdateHeartRate(NSData hr)
        {
            var now = DateTime.Now;

            var    data = (byte *)hr.Bytes;
            ushort bpm  = 0;

            if ((data [0] & 0x01) == 0)
            {
                bpm = data [1];
            }
            else
            {
                bpm = (ushort)data [1];
                bpm = (ushort)(((bpm >> 8) & 0xFF) | ((bpm << 8) & 0xFF00));
            }

            PreviousHeartBeat = CurrentHeartBeat;
            CurrentHeartBeat  = new HeartBeat {
                Time = now, Rate = bpm
            };

            OnHeartRateUpdated();

            if (PreviousHeartBeat.Rate == 0 && CurrentHeartBeat.Rate != 0)
            {
                OnHeartBeat();
                ScheduleBeatTimer();
            }
        }
        /* to use the unsafe version of this method,
         * 'tick' **Project > Options > Build > General > Allow 'unsafe' code** */
        /*unsafe*/ void UpdateHeartRate(NSData hr)
        {
            var now = DateTime.Now;

            // unsafe line
//			var data = (byte *)hr.Bytes;

            // replaced by safe lines
            byte[] data = new byte[hr.Length];
            System.Runtime.InteropServices.Marshal.Copy(hr.Bytes, data, 0, Convert.ToInt32(hr.Length));
            // end safe lines

            ushort bpm = 0;

            if ((data [0] & 0x01) == 0)
            {
                bpm = data [1];
            }
            else
            {
                bpm = (ushort)data [1];
                bpm = (ushort)(((bpm >> 8) & 0xFF) | ((bpm << 8) & 0xFF00));
            }

            PreviousHeartBeat = CurrentHeartBeat;
            CurrentHeartBeat  = new HeartBeat {
                Time = now, Rate = bpm
            };

            OnHeartRateUpdated();

            if (PreviousHeartBeat.Rate == 0 && CurrentHeartBeat.Rate != 0)
            {
                OnHeartBeat();
                ScheduleBeatTimer();
            }
        }
		public HeartBeatEventArgs (HeartBeat previous, HeartBeat current)
		{
			PreviousHeartBeat = previous;
			CurrentHeartBeat = current;
		}
		unsafe void UpdateHeartRate (NSData hr)
		{
			var now = DateTime.Now;
		
			var data = (byte *)hr.Bytes;
			ushort bpm = 0;
			if ((data [0] & 0x01) == 0) {
				bpm = data [1];
			} else {
				bpm = (ushort)data [1];
				bpm = (ushort)(((bpm >> 8) & 0xFF) | ((bpm << 8) & 0xFF00));
			}
						
			PreviousHeartBeat = CurrentHeartBeat;
			CurrentHeartBeat = new HeartBeat { Time = now, Rate = bpm };

			OnHeartRateUpdated ();

			if (PreviousHeartBeat.Rate == 0 && CurrentHeartBeat.Rate != 0) {			
				OnHeartBeat ();
				ScheduleBeatTimer ();
			}
		}
		/* to use the unsafe version of this method, 
		 * 'tick' **Project > Options > Build > General > Allow 'unsafe' code** */
		/*unsafe*/ void UpdateHeartRate (NSData hr)
		{
			var now = DateTime.Now;

			// unsafe line
//			var data = (byte *)hr.Bytes;

			// replaced by safe lines
			byte[] data = new byte[hr.Length];
			System.Runtime.InteropServices.Marshal.Copy(hr.Bytes, data, 0, Convert.ToInt32(hr.Length));
			// end safe lines

			ushort bpm = 0;
			if ((data [0] & 0x01) == 0) {
				bpm = data [1];
			} else {
				bpm = (ushort)data [1];
				bpm = (ushort)(((bpm >> 8) & 0xFF) | ((bpm << 8) & 0xFF00));
			}

			PreviousHeartBeat = CurrentHeartBeat;
			CurrentHeartBeat = new HeartBeat { Time = now, Rate = bpm };

			OnHeartRateUpdated ();

			if (PreviousHeartBeat.Rate == 0 && CurrentHeartBeat.Rate != 0) {			
				OnHeartBeat ();
				ScheduleBeatTimer ();
			}
		}
Beispiel #6
0
 public HeartBeatEventArgs(HeartBeat previous, HeartBeat current)
 {
     PreviousHeartBeat = previous;
     CurrentHeartBeat  = current;
 }
Beispiel #7
0
 protected virtual void OnHeartBeat()
 => HeartBeat?.Invoke(this, EventArgs.Empty);