Usage Examples

On this page:

 

Polling sensor data


private GliaBehaviour _gliaBehaviour = null;
private GliaBehaviour gliaBehaviour
{
    get
    {
        if (_gliaBehaviour == null)
        {
            _gliaBehaviour = FindObjectOfType<GliaBehaviour>();
        }

        return _gliaBehaviour;
    }
}

public void Update()
{
    gliaBehaviour.GetLastHeartRate();
}

 

Subscribing to sensors data

// Lazy cache of GliaBehaviour 
private GliaBehaviour _gliaBehaviour = null;
private GliaBehaviour gliaBehaviour 
{
    get
    {
        if(_gliaBehaviour == null)
        {
            _gliaBehaviour = FindObjectOfType<GliaBehaviour>();
        }

        return _gliaBehaviour;
    }
}

// Subscribe to Heart Rate messages
public void StartListeningToHeartRate()
{
    gliaBehaviour.OnHeartRate.AddListener(AccumulateHeartRate);
}


// Unsubscribe to Heart Rate messages 
public void StopListeningToHeartRate()
{ 
    gliaBehaviour.OnHeartRate.RemoveListener(AccumulateHeartRate); 
}


// Your code using heart rate messages
private void AccumulateHeartRate(HeartRate heartRate)
{
   
}

 

Using Face Camera

  public class FaceCameraDisplay : Graphic {
        private GliaBehaviour _gliaBehaviour;
        protected GliaBehaviour gliaBehaviour{
            get{
                if(_gliaBehaviour == null){
                    _gliaBehaviour = FindObjectOfType();
                }

                return _gliaBehaviour;
            }
        }

        public override Texture mainTexture
        {
            get
            {
                return cameraTexture;
            }
        }

        private Texture2D cameraTexture;

        public void Start()
        {
            base.Start();

            gliaBehaviour.OnCameraImage.AddListener(OnCameraImage);
            cameraTexture  =  new Texture2D(400, 400, TextureFormat.R8, false);
        }

        private void OnCameraImage(CameraImage cameraImage)
        {
            if(cameraImage != null)
            {
                // Load data into the texture and upload it to the GPU.
                cameraTexture.LoadRawTextureData(cameraImage.ImageData);
                cameraTexture.Apply();
            }
        }
    }