// NewPIRMotionDriver returns a new PIRMotionDriver with a polling interval of
// 10 Milliseconds given a DigitalReader and pin.
//
// Optionally accepts:
//  time.Duration: Interval at which the PIRMotionDriver is polled for new information
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
}
538132
func NewReplicationWatcher(se *schema.Engine, config tabletenv.TabletConfig) *ReplicationWatcher {
	rpw := &ReplicationWatcher{
		watchReplication: config.WatchReplication,
		se:               se,
	}
	replOnce.Do(func() {
		stats.Publish("EventTokenPosition", stats.StringFunc(func() string {
			if e := rpw.EventToken(); e != nil {
				return e.Position
			}
			return ""
		}))
		stats.NewGaugeFunc(
			"EventTokenTimestamp",
			"Replication watcher event token timestamp",
			func() int64 {
				if e := rpw.EventToken(); e != nil {
					return e.Timestamp
				}
				return 0
			})
	})
	return rpw
}
944257
func NewIDGenerator(opts ...IDGeneratorOp) *IDGenerator {
	gen := &IDGenerator{}
	for _, f := range opts {
		f(gen)
	}
	if gen.Generator == nil {
		gen.Generator = snowflake.New(rand.Intn(1023))
	}
	return gen
}
577751
func newDynamicTimeout(timeout, minimum time.Duration) *dynamicTimeout {
	return &dynamicTimeout{timeout: int64(timeout), minimum: int64(minimum)}
}
1306567
func NewDriver(tcpaddress string, udpaddress string) *Driver {
	command := []byte{
		0xff, // 2 byte header
		0x04,

		// Left joystick
		0x7e, // throttle 0x00 - 0xff(?)
		0x3f, // rotate left/right

		// Right joystick
		0xc0, // forward / backward 0x80 - 0xfe(?)
		0x3f, // left / right 0x00 - 0x7e(?)

		// Trim
		0x90, // ? yaw (used as a setting to trim the yaw of the uav)
		0x10, // ? pitch (used as a setting to trim the pitch of the uav)
		0x10, // ? roll (used as a setting to trim the roll of the uav)

		0x00, // flags/buttons
		0x00, // checksum; 255 - ((sum of flight controls from index 1 to 9) % 256)
	}
	command[10] = checksum(command)

	return &Driver{name: gobot.DefaultName("HS200"), stopc: make(chan struct{}),
		tcpaddress: tcpaddress, udpaddress: udpaddress, cmd: command, mutex: &sync.RWMutex{}}
}
275791
func NewPiFaceDigital(hardware_addr byte, bus int, chip_select int) *PiFaceDigital {
	pfd := new(PiFaceDigital)
	pfd.mcp = MCP23S17.NewMCP23S17(hardware_addr, bus, chip_select)
	// pfd.device = interrupts.NewGPIOInterruptDevice()

	pfd.InputPins = make([]*MCP23S17.MCP23S17RegisterBitNeg, 8)
	for i := range pfd.InputPins {
		pfd.InputPins[i] = MCP23S17.NewMCP23S17RegisterBitNeg(uint(i), MCP23S17.GPIOB, pfd.mcp)
	}

	pfd.InputPort = MCP23S17.NewMCP23S17RegisterNeg(MCP23S17.GPIOB, pfd.mcp)

	pfd.OutputPins = make([]*MCP23S17.MCP23S17RegisterBit, 8)
	for i := range pfd.OutputPins {
		pfd.OutputPins[i] = MCP23S17.NewMCP23S17RegisterBit(uint(i), MCP23S17.GPIOA, pfd.mcp)
	}

	pfd.OutputPort = MCP23S17.NewMCP23S17Register(MCP23S17.GPIOA, pfd.mcp)

	pfd.Leds = make([]*MCP23S17.MCP23S17RegisterBit, 8)
	for i := range pfd.Leds {
		pfd.Leds[i] = MCP23S17.NewMCP23S17RegisterBit(uint(i), MCP23S17.GPIOA, pfd.mcp)
	}

	pfd.Relays = make([]*MCP23S17.MCP23S17RegisterBit, 2)
	for i := range pfd.Relays {
		pfd.Relays[i] = MCP23S17.NewMCP23S17RegisterBit(uint(i), MCP23S17.GPIOA, pfd.mcp)
	}

	pfd.Switches = make([]*MCP23S17.MCP23S17RegisterBit, 4)
	for i := range pfd.Switches {
		pfd.Switches[i] = MCP23S17.NewMCP23S17RegisterBit(uint(i), MCP23S17.GPIOB, pfd.mcp)
	}

	return pfd
}
1116028
func (agent *Agent) initTimer() {
	if agent.HTTPTimer == nil {
		agent.HTTPTimer = metrics.NewTimer()
	}
}
935370
func NewLEDDriver(a ble.BLEConnector) *LEDDriver {
	n := &LEDDriver{
		name:       gobot.DefaultName("Microbit LED"),
		connection: a,
		Eventer:    gobot.NewEventer(),
	}

	return n
}
1326914
func NewGPIODriver(pinMap PinMap, dpf digitalPinFactory, apf analogPinFactory, ppf pwmPinFactory) GPIODriver {
	return &gpioDriver{
		pinMap: pinMap,
		dpf:    dpf,
		apf:    apf,
		ppf:    ppf,

		initializedPins: map[string]pin{},
	}
}
978926
func NewIntegrationDriverManager(
	d types.IntegrationDriver) types.IntegrationDriver {
	return &idm{IntegrationDriver: d, used: map[string]int{}}
}
73891
func NewTM1638Driver(a gobot.Connection, clockPin string, dataPin string, strobePin string) *TM1638Driver {
	t := &TM1638Driver{
		name:       gobot.DefaultName("TM1638"),
		pinClock:  NewDirectPinDriver(a, clockPin),
		pinData:    NewDirectPinDriver(a, dataPin),
		pinStrobe:  NewDirectPinDriver(a, strobePin),
		fonts:      NewTM1638Fonts(),
		connection: a,
		Commander:  gobot.NewCommander(),
	}

	/* TODO : Add commands */

	return t
}
1355497
func NewDriver(dconfig *DriverConfig, config *SSHConfig, vmName string) (Driver, error) {
	drivers := []Driver{}

	if dconfig.RemoteType != "" {
		drivers = []Driver{
			&ESX5Driver{
				Host:           dconfig.RemoteHost,
				Port:           dconfig.RemotePort,
				Username:       dconfig.RemoteUser,
				Password:       dconfig.RemotePassword,
				PrivateKeyFile: dconfig.RemotePrivateKey,
				Datastore:      dconfig.RemoteDatastore,
				CacheDatastore: dconfig.RemoteCacheDatastore,
				CacheDirectory: dconfig.RemoteCacheDirectory,
				VMName:         vmName,
				CommConfig:     config.Comm,
			},
		}

	} else {
		switch runtime.GOOS {
		case "darwin":
			drivers = []Driver{
				&Fusion6Driver{
					Fusion5Driver: Fusion5Driver{
						AppPath:   dconfig.FusionAppPath,
						SSHConfig: config,
					},
				},
				&Fusion5Driver{
					AppPath:   dconfig.FusionAppPath,
					SSHConfig: config,
				},
			}
		case "linux":
			fallthrough
		case "windows":
			drivers = []Driver{
				&Workstation10Driver{
					Workstation9Driver: Workstation9Driver{
						SSHConfig: config,
					},
				},
				&Workstation9Driver{
					SSHConfig: config,
				},
				&Player6Driver{
					Player5Driver: Player5Driver{
						SSHConfig: config,
					},
				},
				&Player5Driver{
					SSHConfig: config,
				},
			}
		default:
			return nil, fmt.Errorf("can't find driver for OS: %s", runtime.GOOS)
		}
	}

	errs := ""
	for _, driver := range drivers {
		err := driver.Verify()
		log.Printf("Testing vmware driver %T. Success: %t",
			driver, err == nil)

		if err == nil {
			return driver, nil
		}
		errs += "* " + err.Error() + "\n"
	}

	return nil, fmt.Errorf(
		"Unable to initialize any driver for this platform. The errors\n"+
			"from each driver are shown below. Please fix at least one driver\n"+
			"to continue:\n%s", errs)
}
825239
func NewGenerator(seed int64) *Generator {
	r := rand.New(rand.NewSource(seed))
	return &Generator{
		r:     r,
		zs:    make(map[int]*rand.Zipf),
		times: make(map[time.Time]time.Duration),
		hsh:   sha1.New(),
	}
}
738173
func NewDriver(a *Adaptor, filename string) *Driver {
	return &Driver{
		name:       gobot.DefaultName("Audio"),
		connection: a,
		interval:   500 * time.Millisecond,
		filename:   filename,
		halt:       make(chan bool, 0),
		Eventer:    gobot.NewEventer(),
		Commander:  gobot.NewCommander(),
	}
}
27373
func (c *pidCollector) pidStats() (map[string]*drivers.ResourceUsage, error) {
	stats := make(map[string]*drivers.ResourceUsage)
	c.pidLock.RLock()
	pids := make(map[int]*nomadPid, len(c.pids))
	for k, v := range c.pids {
		pids[k] = v
	}
	c.pidLock.RUnlock()
	for pid, np := range pids {
		p, err := process.NewProcess(int32(pid))
		if err != nil {
			c.logger.Trace("unable to create new process", "pid", pid, "error", err)
			continue
		}
		ms := &drivers.MemoryStats{}
		if memInfo, err := p.MemoryInfo(); err == nil {
			ms.RSS = memInfo.RSS
			ms.Swap = memInfo.Swap
			ms.Measured = ExecutorBasicMeasuredMemStats
		}

		cs := &drivers.CpuStats{}
		if cpuStats, err := p.Times(); err == nil {
			cs.SystemMode = np.cpuStatsSys.Percent(cpuStats.System * float64(time.Second))
			cs.UserMode = np.cpuStatsUser.Percent(cpuStats.User * float64(time.Second))
			cs.Measured = ExecutorBasicMeasuredCpuStats

			// calculate cpu usage percent
			cs.Percent = np.cpuStatsTotal.Percent(cpuStats.Total() * float64(time.Second))
		}
		stats[strconv.Itoa(pid)] = &drivers.ResourceUsage{MemoryStats: ms, CpuStats: cs}
	}

	return stats, nil
}
594179
func NewDriverPool(connStr string, max int) (DriverPool, error) {
	return createDriverPool(connStr, max)
}
147558
func NewCustomTimer(h Histogram, m Meter) Timer {
	if !Enabled {
		return NilTimer{}
	}
	return &StandardTimer{
		histogram: h,
		meter:     m,
	}
}