// NewLedDriver return a new LedDriver given a DigitalWriter and pin.
//
// Adds the following API Commands:
//	"Brightness" - See LedDriver.Brightness
//	"Toggle" - See LedDriver.Toggle
//	"On" - See LedDriver.On
//	"Off" - See LedDriver.Off
162718
func NewLedDriver(a DigitalWriter, pin string) *LedDriver {
	l := &LedDriver{
		name:       gobot.DefaultName("LED"),
		pin:        pin,
		connection: a,
		high:       false,
		Commander:  gobot.NewCommander(),
	}

	l.AddCommand("Brightness", func(params map[string]interface{}) interface{} {
		level := byte(params["level"].(float64))
		return l.Brightness(level)
	})

	l.AddCommand("Toggle", func(params map[string]interface{}) interface{} {
		return l.Toggle()
	})

	l.AddCommand("On", func(params map[string]interface{}) interface{} {
		return l.On()
	})

	l.AddCommand("Off", func(params map[string]interface{}) interface{} {
		return l.Off()
	})

	return l
}
294262
func NewWindowDriver() *WindowDriver {
	return &WindowDriver{
		name: "Window",
		start: func(w *WindowDriver) {
			w.window = gocv.NewWindow(w.Name())
		},
	}
}
805946
func New(host string, port uint16, index string) ElasticDriver {
	return newDriver(host, port, index)
}
575317
func NewCameraDriver(source interface{}) *CameraDriver {
	c := &CameraDriver{
		name:    "Camera",
		Eventer: gobot.NewEventer(),
		Source:  source,
		start: func(c *CameraDriver) (err error) {
			switch v := c.Source.(type) {
			case string:
				c.camera, _ = gocv.VideoCaptureFile(v)
			case int:
				c.camera, _ = gocv.VideoCaptureDevice(v)
			default:
				return errors.New("Unknown camera source")
			}
			return
		},
	}

	c.AddEvent(Frame)

	return c
}
1054277
func NewWriter(rc io.WriteCloser) io.WriteCloser {
	return bufWriteCloser{bufio.NewWriter(rc), rc}
}
472031
func NewIDGenerator(s string, t *testing.T) IDGenerator {
	return IDGenerator{
		IDFn: func() platform.ID {
			id, err := platform.IDFromString(s)
			if err != nil {
				t.Fatal(err)
			}
			return *id
		},
	}
}
1173964
func NewRelayDriver(a DigitalWriter, pin string) *RelayDriver {
	l := &RelayDriver{
		name:       gobot.DefaultName("Relay"),
		pin:        pin,
		connection: a,
		high:       false,
		Commander:  gobot.NewCommander(),
	}

	l.AddCommand("Toggle", func(params map[string]interface{}) interface{} {
		return l.Toggle()
	})

	l.AddCommand("On", func(params map[string]interface{}) interface{} {
		return l.On()
	})

	l.AddCommand("Off", func(params map[string]interface{}) interface{} {
		return l.Off()
	})

	return l
}
427742
func New(params DriverParameters) (*Driver, error) {

	client := oss.NewOSSClient(params.Region, params.Internal, params.AccessKeyID, params.AccessKeySecret, params.Secure)
	client.SetEndpoint(params.Endpoint)
	bucket := client.Bucket(params.Bucket)
	client.SetDebug(false)

	// Validate that the given credentials have at least read permissions in the
	// given bucket scope.
	if _, err := bucket.List(strings.TrimRight(params.RootDirectory, "/"), "", "", 1); err != nil {
		return nil, err
	}

	// TODO(tg123): Currently multipart uploads have no timestamps, so this would be unwise
	// if you initiated a new OSS client while another one is running on the same bucket.

	d := &driver{
		Client:          client,
		Bucket:          bucket,
		ChunkSize:       params.ChunkSize,
		Encrypt:         params.Encrypt,
		RootDirectory:   params.RootDirectory,
		EncryptionKeyID: params.EncryptionKeyID,
	}

	return &Driver{
		baseEmbed: baseEmbed{
			Base: base.Base{
				StorageDriver: d,
			},
		},
	}, nil
}
1253237
func NewMagnetometerDriver(a ble.BLEConnector) *MagnetometerDriver {
	n := &MagnetometerDriver{
		name:       gobot.DefaultName("Microbit Magnetometer"),
		connection: a,
		Eventer:    gobot.NewEventer(),
	}

	n.AddEvent(Magnetometer)

	return n
}
288263
func (r *DrvRegistry) AddDriver(ntype string, fn InitFunc, config map[string]interface{}) error {
	return fn(r, config)
}
653628
func NewMotorDriver(megaPi *Adaptor, port byte) *MotorDriver {
	return &MotorDriver{
		name:     "MegaPiMotor",
		megaPi:   megaPi,
		port:     port,
		halted:   true,
		syncRoot: &sync.Mutex{},
	}
}
276902
func NewButtonDriver(a ble.BLEConnector) *ButtonDriver {
	n := &ButtonDriver{
		name:       gobot.DefaultName("Microbit Button"),
		connection: a,
		Eventer:    gobot.NewEventer(),
	}

	n.AddEvent(ButtonA)
	n.AddEvent(ButtonB)

	return n
}
1093422
func NewDriver(a BaseAdaptor, v ...time.Duration) *Driver {
	m := &Driver{
		name:       "Mavlink",
		connection: a,
		Eventer:    gobot.NewEventer(),
		interval:   10 * time.Millisecond,
	}

	if len(v) > 0 {
		m.interval = v[0]
	}

	m.AddEvent(PacketEvent)
	m.AddEvent(MessageEvent)
	m.AddEvent(ErrorIOEvent)
	m.AddEvent(ErrorMAVLinkEvent)

	return m
}
335282
func NewPIRMotionDriver(a DigitalReader, pin string, v ...time.Duration) *PIRMotionDriver {
	b := &PIRMotionDriver{
		name:       gobot.DefaultName("PIRMotion"),
		connection: a,
		pin:        pin,
		Active:     false,
		Eventer:    gobot.NewEventer(),
		interval:   10 * time.Millisecond,
		halt:       make(chan bool),
	}

	if len(v) > 0 {
		b.interval = v[0]
	}

	b.AddEvent(MotionDetected)
	b.AddEvent(MotionStopped)
	b.AddEvent(Error)

	return b
}
1321185
func NewBatteryDriver(a BLEConnector) *BatteryDriver {
	n := &BatteryDriver{
		name:       gobot.DefaultName("Battery"),
		connection: a,
		Eventer:    gobot.NewEventer(),
	}

	return n
}
1114639
func New(name, root string, options []string) (graphdriver.Driver, error) {
	mutex.Lock()
	defer mutex.Unlock()

	if _, ok := instances[name]; ok {
		return nil, ErrExist
	}

	if initFunc, exists := drivers[name]; exists {
		driver, err := initFunc(root, options, nil, nil)
		if err != nil {
			return nil, err
		}
		instances[name] = driver
		return driver, err
	}
	return nil, ErrNotSupported
}
928194
func New(name string, pg plugingetter.PluginGetter, config Options) (Driver, error) {
	if name != "" {
		logrus.Debugf("[graphdriver] trying provided driver: %s", name) // so the logs show specified driver
		logDeprecatedWarning(name)
		return GetDriver(name, pg, config)
	}

	// Guess for prior driver
	driversMap := scanPriorDrivers(config.Root)
	list := strings.Split(priority, ",")
	logrus.Debugf("[graphdriver] priority list: %v", list)
	for _, name := range list {
		if name == "vfs" {
			// don't use vfs even if there is state present.
			continue
		}
		if _, prior := driversMap[name]; prior {
			// of the state found from prior drivers, check in order of our priority
			// which we would prefer
			driver, err := getBuiltinDriver(name, config.Root, config.DriverOptions, config.UIDMaps, config.GIDMaps)
			if err != nil {
				// unlike below, we will return error here, because there is prior
				// state, and now it is no longer supported/prereq/compatible, so
				// something changed and needs attention. Otherwise the daemon's
				// images would just "disappear".
				logrus.Errorf("[graphdriver] prior storage driver %s failed: %s", name, err)
				return nil, err
			}

			// abort starting when there are other prior configured drivers
			// to ensure the user explicitly selects the driver to load
			if len(driversMap)-1 > 0 {
				var driversSlice []string
				for name := range driversMap {
					driversSlice = append(driversSlice, name)
				}

				return nil, fmt.Errorf("%s contains several valid graphdrivers: %s; Please cleanup or explicitly choose storage driver (-s <DRIVER>)", config.Root, strings.Join(driversSlice, ", "))
			}

			logrus.Infof("[graphdriver] using prior storage driver: %s", name)
			logDeprecatedWarning(name)
			return driver, nil
		}
	}

	// Check for priority drivers first
	for _, name := range list {
		driver, err := getBuiltinDriver(name, config.Root, config.DriverOptions, config.UIDMaps, config.GIDMaps)
		if err != nil {
			if IsDriverNotSupported(err) {
				continue
			}
			return nil, err
		}
		logDeprecatedWarning(name)
		return driver, nil
	}

	// Check all registered drivers if no priority driver is found
	for name, initFunc := range drivers {
		if isDeprecated(name) {
			// Deprecated storage-drivers are skipped in automatic selection, but
			// can be selected through configuration.
			continue
		}
		driver, err := initFunc(filepath.Join(config.Root, name), config.DriverOptions, config.UIDMaps, config.GIDMaps)
		if err != nil {
			if IsDriverNotSupported(err) {
				continue
			}
			return nil, err
		}
		logDeprecatedWarning(name)
		return driver, nil
	}
	return nil, fmt.Errorf("No supported storage backend found")
}