/// <summary> /// Initializes the Illuminance Click with user defined Gain and IntegrationTime. /// </summary> /// <param name="gain">The user defined Gain. See <see cref="GainControl"/> for more information.</param> /// <param name="intergrationTime">The IntegrationTimePeriod. See <see cref="IntegrationTimePeriod"/> for more information.</param> /// <example>Example usage: /// <code language = "C#"> /// illuminance.Initialize(IlluminanceClick.GainControl.x1, IlluminanceClick.IntegrationTimePeriod._101MS); /// </code> /// <code language = "VB"> /// illuminance.Initialize(IlluminanceClick.GainControl.x1, IlluminanceClick.IntegrationTimePeriod._101MS) /// </code> /// </example> public void Initialize(GainControl gain, IntegrationTimePeriod intergrationTime) { Gain = gain; IntegrationTime = intergrationTime; }
/// <summary> /// Gets the fullSpectrum (mixed lighting) and IR only values from the Illuminance Click, adjusting GainControl if the <see cref="AutoGainControl"/> property is enabled. /// </summary> /// <param name="fullSpectrum">The reference to the <see cref="UInt16"/> to hold the value of the FullsSectrum Light (Mixed Lighting - Visible and Infrared combined).</param> /// <param name="visible">The reference to the <see cref="UInt16"/> to hold the value of the Visible Light (Visible only).</param> /// <param name="ir">The reference to the <see cref="UInt16"/> to hold the value of the Infrared Light (Infrared only).</param> /// <example>Example usage: /// <code language = "C#"> /// UInt16 visible; /// UInt16 ir; /// UInt16 fullSpectrum; /// /// illuminance.ReadLuminosity(out fullSpectrum, out visible, out ir); /// /// Debug.Print("FullSpectrum Light - " + fullSpectrum); /// Debug.Print("Visible Light - " + visible); /// Debug.Print("Infrared Light - " + ir + "\n"); /// </code> /// <code language = "VB"> /// Dim visible As UInt16 /// Dim ir As UInt16 /// Dim fullSpectrum As UInt16 /// /// illuminance.ReadLuminosity(fullSpectrum, visible, ir) /// /// Debug.Print("FullSpectrum Light - " <![CDATA[&]]> fullSpectrum) /// Debug.Print("Visible Light - " <![CDATA[&]]> visible) /// Debug.Print("Infrared Light - " <![CDATA[&]]> ir) /// </code> /// </example> public void ReadLuminosity(out UInt16 fullSpectrum, out UInt16 visible, out UInt16 ir) { var valid = false; UInt16 _b; UInt16 _ir; IntegrationTimePeriod _it = _integrationTime; var _agcCheck = false; if (!AutoGainControl) { fullSpectrum = GetChannelData(Channels.Channel0); ir = GetChannelData(Channels.Channel1); visible = (UInt16)(fullSpectrum - ir); return; } GainControl oldGain = Gain; IntegrationTimePeriod oldIntegrationTime = IntegrationTime; do { UInt16 _hi; UInt16 _lo; switch (_it) { case IntegrationTimePeriod._13MS: { _hi = (UInt16)IntegrationTimePeriod._13MS; _lo = (UInt16)IntegrationTimePeriod._13MS; break; } case IntegrationTimePeriod._101MS: { _hi = (UInt16)IntegrationTimePeriod._101MS; _lo = (UInt16)IntegrationTimePeriod._101MS; break; } default: { _hi = (UInt16)IntegrationTimePeriod._402MS; _lo = (UInt16)IntegrationTimePeriod._402MS; break; } } _b = GetChannelData(Channels.Channel0); /* Run an auto-GainControl check if we haven't already done so ... */ if (!_agcCheck) { if ((_b < _lo) && (_gainControl == GainControl.Low)) { /* Increase the GainControl and try again */ Gain = GainControl.High; /* Drop the previous conversion results */ _b = GetChannelData(Channels.Channel0); _ir = GetChannelData(Channels.Channel1); /* Set a flag to indicate we've adjusted the GainControl */ _agcCheck = true; } else if ((_b > _hi) && (_gainControl == GainControl.High)) { /* Drop GainControl to 1x and try again */ Gain = GainControl.Low; /* Drop the previous conversion results */ _b = GetChannelData(Channels.Channel0); _ir = GetChannelData(Channels.Channel1); /* Set a flag to indicate we've adjusted the GainControl */ _agcCheck = true; } else { /* Nothing to look at here, keep moving .... * Reading is either valid, or we're already at the chips limits */ _b = GetChannelData(Channels.Channel0); _ir = GetChannelData(Channels.Channel1); valid = true; } } else { /* If we've already adjusted the GainControl once, just return the new results. * This avoids endless loops where a value is at one extreme pre-GainControl, * and the other extreme post-GainControl */ _b = GetChannelData(Channels.Channel0); _ir = GetChannelData(Channels.Channel1); valid = true; } } while (!valid); fullSpectrum = _b; ir = _ir; visible = (UInt16)(_b - ir); Gain = oldGain; IntegrationTime = oldIntegrationTime; }