示例#1
0
    void Update()
    {
        var now = Time.time;

        _currentValue = _bleManager.GetCharacteristic <IRCharacteristic>().Value;

        if (_prevValue != _currentValue && _currentValue)
        {
            _duration = now - _prevTime;
            RPM       = 60.0f / _duration;
            _prevTime = now;
            Speed     = Mathf.PI * Diameter * (RPM / 60.0f);
        }
        else if (now - _prevTime > 2.0f)
        {
            RPM = 0f;
        }

        if (Speed > 0.0f)
        {
            Speed = Mathf.Max(0.0f, Speed - Resistance);
        }

        _prevValue = _currentValue;
    }
 // Update is called once per frame
 void Update()
 {
     if (_bleManager.GetCharacteristic <IRCharacteristic>().Value)
     {
         _cubeRenderer.material.color = Color.green;
     }
     else
     {
         _cubeRenderer.material.color = Color.red;
     }
 }
示例#3
0
    void Update()
    {
        var now = Time.time;

        _currentValue = _bleManager.GetCharacteristic <IRCharacteristic>().Value;

        if (_currentValue > _prevValue)
        {
            _deltaTime = now - _prevTime;
            _prevTime  = now;
            _revolutionCount++;

            if (_revolutionCount == 1)
            {
                _timer     = 0;
                _lastSpeed = Speed;
                _state     = States.ACC;
            }
            else if (_revolutionCount > _minimalRevolutionCount && Speed == _minimalSpeed)
            {
                _state = States.PED;
            }
        }


        if (now - _prevTime > _resetTime && (_state == States.PED || _state == States.ACC))
        {
            // no sensor value within last _resetTime seconds
            _revolutionCount = 0;
            _state           = States.DEC;
            _timer           = 0;
            _lastSpeed       = Speed;
        }

        switch (_state)
        {
        case States.ACC:
        {
            _timer += Time.deltaTime;
            if (_timer > _accTime)
            {
                _timer = _accTime;
            }
            Speed = Mathf.Lerp(_lastSpeed, _minimalSpeed, _timer / _accTime);
            break;
        }

        case States.PED:
        {
            Speed = _minimalSpeed + AddBonusSpeed(_deltaTime);
            break;
        }

        case States.DEC:
        {
            _timer += Time.deltaTime;
            if (_timer > _decTime)
            {
                _timer = _decTime;
            }
            Speed = Mathf.Lerp(_lastSpeed, 0f, _timer / _decTime);

            if (Speed < 0.01)
            {
                _state = States.STILL;
                _timer = 0;
            }

            break;
        }

        case States.STILL:
        {
            Speed = 0f;
            break;
        }
        }

        _prevValue = _currentValue;
    }