// setPWM sets the start (on) and end (off) of the high-segment of the PWM pulse
// on the specific channel (pin).
176127
func (a *AdafruitMotorHatDriver) setPWM(conn Connection, pin byte, on, off int32) (err error) {
	// register and values to be written to that register
	regVals := make(map[int][]byte)
	regVals[0] = []byte{byte(_LedZeroOnL + 4*pin), byte(on & 0xff)}
	regVals[1] = []byte{byte(_LedZeroOnH + 4*pin), byte(on >> 8)}
	regVals[2] = []byte{byte(_LedZeroOffL + 4*pin), byte(off & 0xff)}
	regVals[3] = []byte{byte(_LedZeroOffH + 4*pin), byte(off >> 8)}
	for i := 0; i < len(regVals); i++ {
		if _, err = conn.Write(regVals[i]); err != nil {
			return
		}
	}
	return
}
1108370
func (l *Language) SetParam(k string, v interface{}) {
	l.params[strings.ToLower(k)] = v
}
1301754
func (b *Client) SetPinMode(pin int, mode int) error {
	b.pins[byte(pin)].Mode = mode
	return b.write([]byte{PinMode, byte(pin), byte(mode)})
}
263453
func (p *PCA9685Driver) SetPWMFreq(freq float32) error {
	// IC oscillator frequency is 25 MHz
	var prescalevel float32 = 25000000
	// Find frequency of PWM waveform
	prescalevel /= 4096
	// Ratio between desired frequency and maximum
	prescalevel /= freq
	prescalevel -= 1
	// Round value to nearest whole
	prescale := byte(prescalevel + 0.5)

	if _, err := p.connection.Write([]byte{byte(PCA9685_MODE1)}); err != nil {
		return err
	}
	data := make([]byte, 1)
	oldmode, err := p.connection.Read(data)
	if err != nil {
		return err
	}

	// Put oscillator in sleep mode, clear bit 7 here to avoid overwriting
	// previous setting
	newmode := (oldmode & 0x7F) | 0x10
	if _, err := p.connection.Write([]byte{byte(PCA9685_MODE1), byte(newmode)}); err != nil {
		return err
	}
	// Write prescaler value
	if _, err := p.connection.Write([]byte{byte(PCA9685_PRESCALE), prescale}); err != nil {
		return err
	}
	// Put back to old settings
	if _, err := p.connection.Write([]byte{byte(PCA9685_MODE1), byte(oldmode)}); err != nil {
		return err
	}

	time.Sleep(100 * time.Millisecond)
	// Enable response to All Call address, enable auto-increment, clear restart
	if _, err := p.connection.Write([]byte{byte(PCA9685_MODE1), byte(oldmode | 0xa1)}); err != nil {
		return err
	}

	return nil
}
648958
func (e *Adaptor) PWMPin(pin string) (sysfsPin sysfs.PWMPinner, err error) {
	e.mutex.Lock()
	defer e.mutex.Unlock()

	sysPin, ok := sysfsPinMap[pin]
	if !ok {
		err = errors.New("Not a valid pin")
		return
	}
	if sysPin.pwmPin != -1 {
		if e.pwmPins[sysPin.pwmPin] == nil {
			e.pwmPins[sysPin.pwmPin] = sysfs.NewPWMPin(sysPin.pwmPin)
			if err = e.pwmPins[sysPin.pwmPin].Export(); err != nil {
				return
			}
			if err = e.pwmPins[sysPin.pwmPin].SetPeriod(10000000); err != nil {
				return
			}
			if err = e.pwmPins[sysPin.pwmPin].Enable(true); err != nil {
				return
			}
		}

		sysfsPin = e.pwmPins[sysPin.pwmPin]
		return
	}
	err = errors.New("Not a PWM pin")
	return
}
1197797
func (module *BBPWMModule) SetDuty(pin Pin, ns int64) error {
	openPin := module.openPins[pin]
	if openPin == nil {
		return fmt.Errorf("PWM pin is being written but is not enabled. Have you called EnablePin?")
	}

	return openPin.setDuty(ns)
}
3482
func (g *Driver) SetMotorPower(motor Motor, power int8) error {
	return g.writeBytes([]byte{
		goPiGo3Address,
		SET_MOTOR_PWM,
		byte(motor),
		byte(power),
	})
}
728877
func (c *CertAuthorityV2) SetRoleMap(m RoleMap) {
	c.Spec.RoleMap = []RoleMapping(m)
}
73718
func (module *BBPWMModule) SetOptions(options map[string]interface{}) error {
	v := options["pins"]
	if v == nil {
		return fmt.Errorf("Module '%s' SetOptions() did not get 'pins' values", module.GetName())
	}

	module.definedPins = v.(BBPWMModulePinDefMap)
	return nil
}
802980
func NewPWMPin(pin int) *PWMPin {
	return &PWMPin{
		pin:     strconv.Itoa(pin),
		enabled: false,
		Path:    "/sys/class/pwm/pwmchip0",
		read:    readPwmFile,
		write:   writePwmFile}
}
507514
func (p *pwmChannel) SetAnalog(value byte) error {
	offTime := util.Map(int64(value), 0, 255, 0, pwmControlPoints-1)
	return p.d.SetPwm(p.channel, 0, int(offTime))
}
584090
func (s *rowSegment) SetBit(i uint64) (changed bool) {
	s.ensureWritable()
	changed, _ = s.data.Add(i)
	if changed {
		s.n++
	}
	return changed
}
1309408
func (s *ScheduledAction) SetStartTime(v time.Time) *ScheduledAction {
	s.StartTime = &v
	return s
}
1196951
func (g *Driver) SetPWMFreq(port Grove, freq uint16) error {
	if freq < 3 {
		freq = 3
	}
	if freq > 48000 {
		freq = 48000
	}
	return g.writeBytes([]byte{
		goPiGo3Address,
		SET_GROVE_PWM_FREQUENCY,
		byte(port),
		byte((freq >> 8) & 0xFF),
		byte(freq & 0xFF),
	})
}
297397
func (p *PWMPin) Enable(enable bool) (err error) {
	if p.enabled != enable {
		p.enabled = enable
		enableVal := 0
		if enable {
			enableVal = 1
		}
		_, err = p.write(p.pwmEnablePath(), []byte(fmt.Sprintf("%v", enableVal)))
	}
	return
}
722330
func (c *PIDController) Set(setpoint float64) *PIDController {
	c.setpoint = setpoint
	return c
}
574991
func (s *PutScheduledActionInput) SetStartTime(v time.Time) *PutScheduledActionInput {
	s.StartTime = &v
	return s
}