code: func (d *TSL2561Driver) GetLuminocity() (broadband uint16, ir uint16, err error) {
  	// if auto gain disabled get a single reading and continue
  	if !d.autoGain {
  		broadband, ir, err = d.getData()
  		return
  	}
  
  	agcCheck := false
  	hi, lo := d.getHiLo()
  
  	// Read data until we find a valid range
  	valid := false
  	for {
  		broadband, ir, err = d.getData()
  		if err != nil {
  			return
  		}
  
  		// Run an auto-gain check if we haven't already done so
  		if !agcCheck {
  			if (broadband < lo) && (d.gain == TSL2561Gain1X) {
  				// increase gain and try again
  				err = d.SetGain(TSL2561Gain16X)
  				if err != nil {
  					return
  				}
  				agcCheck = true
  			} else if (broadband > hi) && (d.gain == TSL2561Gain16X) {
  				// drop gain and try again
  				err = d.SetGain(TSL2561Gain1X)
  				if err != nil {
  					return
  				}
  				agcCheck = true
  			} else {
  				// Reading is either valid, or we're already at the chips
  				// limits
  				valid = true
  			}
  		} else {
  			// If we've already adjusted the gain once, just return the new results.
  			// This avoids endless loops where a value is at one extreme pre-gain,
  			// and the the other extreme post-gain
  			valid = true
  		}
  
  		if valid {
  			break
  		}
  	}
  
  	return
  }
docs: // GetLuminocity gets the broadband and IR only values from the TSL2561,
  // adjusting gain if auto-gain is enabled