private void SampleTimer_Tick(object sender, object e)
        {
            if (_fezhat != null)
            {
                // KeyUp
                if (!_fezhat.IsDIO22Pressed() && _buttonPressed)
                {
                    _buttonPressed = false;

                    var now = DateTime.Now;
                    if (previousBeat != default(DateTime))
                    {
                        var t = now - previousBeat;

                        _currentHeartRate         = (int)(60000 / t.TotalMilliseconds);
                        CurrentHeartRateText.Text = _currentHeartRate.ToString();
                    }

                    previousBeat = now;
                    _fezhat.D2.TurnOff();
                }
                // KeyDown
                else if (_fezhat.IsDIO22Pressed() && !_buttonPressed)
                {
                    _buttonPressed   = true;
                    _fezhat.D2.Color = new FEZHAT.Color(255, 0, 0);
                }
            }

            Debug.WriteLine("current heartrate = " + _currentHeartRate);
        }
Exemple #2
0
        public void Process()
        {
            DIO18Pressed = _hat.IsDIO18Pressed();
            DIO22Pressed = _hat.IsDIO22Pressed();
            Ain1         = _hat.ReadAnalog(FEZHAT.AnalogPin.Ain1);
            Ain2         = _hat.ReadAnalog(FEZHAT.AnalogPin.Ain2);
            Ain3         = _hat.ReadAnalog(FEZHAT.AnalogPin.Ain3);

            _hat.GetAcceleration(out var x, out var y, out var z);
            AccelerationX = x;
            AccelerationY = y;
            AccelerationZ = z;
        }
        /// <summary>
        /// Tick every 100 milliseconds to retrieve the button's state
        /// but blink only every 1/2 second.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnTick(object sender, object e)
        {
            double x, y, z;

            hat.GetAcceleration(out x, out y, out z);

            LightTextBox.Text    = hat.GetLightLevel().ToString("P2");
            TempTextBox.Text     = hat.GetTemperature().ToString("N2");
            AccelTextBox.Text    = $"({x:N2}, {y:N2}, {z:N2})";
            Button18TextBox.Text = hat.IsDIO18Pressed().ToString();
            Button22TextBox.Text = hat.IsDIO22Pressed().ToString();

            if ((i++ % 5) == 0)
            {
                LedsTextBox.Text = next.ToString();

                hat.DIO24On  = next;
                hat.D2.Color = next ? FEZHAT.Color.White : FEZHAT.Color.Black;
                hat.D3.Color = next ? FEZHAT.Color.White : FEZHAT.Color.Black;

                next = !next;
            }
        }
Exemple #4
0
        private async void M_t_Tick(object sender, object e)
        {
            if (m_msgCount >= MaxMsgCount && MaxMsgCount != -1)
            {
                //No more than MaxMsgCount messages / run
                m_t.Stop(); return;
            }

            MAll m = new MAll();

            if (m_hat != null)
            {
                m.Light       = m_hat.GetLightLevel();
                m.Temperature = m_hat.GetTemperature();
                m.DIO18       = m_hat.IsDIO18Pressed();
                m.DIO22       = m_hat.IsDIO22Pressed();
            }
            m.MsgType = "FEZHATALL";
            m.Dt      = DateTime.UtcNow;
            var obj = JsonConvert.SerializeObject(m);

            try
            {
                if (m_clt != null)
                {
                    await m_clt.SendEventAsync(new Message(System.Text.Encoding.UTF8.GetBytes(obj)));

                    m_msgCount++;
                }
                txtState.Text = obj + $", MSG:{m_msgCount}";
            }
            catch (Exception ex)
            {
                txtState.Text = ex.ToString();
            }
            Debug.WriteLine(txtState.Text);
        }