Ejemplo n.º 1
0
func NewLedDriver(a PwmDigitalWriter, name string, pin string) *LedDriver {

	l := &LedDriver{
		Driver: *gobot.NewDriver(
			name,
			"LedDriver",
			pin,
			a.(gobot.AdaptorInterface),
		),
		High: false,
	}

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

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

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

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

	return l
}
Ejemplo n.º 2
0
func NewJoystickDriver(a *JoystickAdaptor, name string, config string) *JoystickDriver {
	d := &JoystickDriver{
		Driver: *gobot.NewDriver(
			name,
			"JoystickDriver",
			a,
		),
	}

	file, e := ioutil.ReadFile(config)
	if e != nil {
		panic(fmt.Sprintf("File error: %v\n", e))
	}
	var jsontype joystickConfig
	json.Unmarshal(file, &jsontype)
	d.config = jsontype
	for _, value := range d.config.Buttons {
		d.AddEvent(fmt.Sprintf("%s_press", value.Name))
		d.AddEvent(fmt.Sprintf("%s_release", value.Name))
	}
	for _, value := range d.config.Axis {
		d.AddEvent(value.Name)
	}
	for _, value := range d.config.Hats {
		d.AddEvent(value.Name)
	}
	return d
}
Ejemplo n.º 3
0
func NewServoDriver(a Servo, name string, pin string) *ServoDriver {
	s := &ServoDriver{
		Driver: *gobot.NewDriver(
			name,
			"ServoDriver",
			a.(gobot.AdaptorInterface),
			pin,
		),
		CurrentAngle: 0,
	}

	s.AddCommand("Move", func(params map[string]interface{}) interface{} {
		angle := byte(params["angle"].(float64))
		s.Move(angle)
		return nil
	})
	s.AddCommand("Min", func(params map[string]interface{}) interface{} {
		s.Min()
		return nil
	})
	s.AddCommand("Center", func(params map[string]interface{}) interface{} {
		s.Center()
		return nil
	})
	s.AddCommand("Max", func(params map[string]interface{}) interface{} {
		s.Max()
		return nil
	})

	return s

}
Ejemplo n.º 4
0
func NewPebbleDriver(adaptor *PebbleAdaptor, name string) *PebbleDriver {
	p := &PebbleDriver{
		Driver: *gobot.NewDriver(
			name,
			"PebbleDriver",
			adaptor,
		),
		Messages: []string{},
	}

	p.AddEvent("button")
	p.AddEvent("accel")
	p.AddEvent("tap")

	p.AddCommand("PublishEvent", func(params map[string]interface{}) interface{} {
		p.PublishEvent(params["name"].(string), params["data"].(string))
		return nil
	})

	p.AddCommand("SendNotification", func(params map[string]interface{}) interface{} {
		p.SendNotification(params["message"].(string))
		return nil
	})

	p.AddCommand("PendingMessage", func(params map[string]interface{}) interface{} {
		m := make(map[string]string)
		m["result"] = p.PendingMessage()
		return m
	})

	return p
}
Ejemplo n.º 5
0
func NewBlinkMDriver(a I2cInterface, name string) *BlinkMDriver {
	b := &BlinkMDriver{
		Driver: *gobot.NewDriver(
			name,
			"BlinkMDriver",
			a.(gobot.AdaptorInterface),
		),
	}

	b.AddCommand("FirmwareVersion", func(params map[string]interface{}) interface{} {
		return b.FirmwareVersion()
	})
	b.AddCommand("Color", func(params map[string]interface{}) interface{} {
		return b.Color()
	})
	b.AddCommand("Rgb", func(params map[string]interface{}) interface{} {
		red := byte(params["red"].(float64))
		green := byte(params["green"].(float64))
		blue := byte(params["blue"].(float64))
		b.Rgb(red, green, blue)
		return nil
	})
	b.AddCommand("Fade", func(params map[string]interface{}) interface{} {
		red := byte(params["red"].(float64))
		green := byte(params["green"].(float64))
		blue := byte(params["blue"].(float64))
		b.Fade(red, green, blue)
		return nil
	})

	return b
}
Ejemplo n.º 6
0
func NewWindowDriver(name string) *WindowDriver {
	return &WindowDriver{
		Driver: *gobot.NewDriver(
			name,
			"WindowDriver",
		),
	}
}
Ejemplo n.º 7
0
func NewHMC6352Driver(a I2cInterface, name string) *HMC6352Driver {
	return &HMC6352Driver{
		Driver: *gobot.NewDriver(
			name,
			"HMC6352Driver",
			a.(gobot.AdaptorInterface),
		),
	}
}
Ejemplo n.º 8
0
func NewSpheroDriver(a *SpheroAdaptor, name string) *SpheroDriver {
	s := &SpheroDriver{
		Driver: *gobot.NewDriver(
			name,
			"SpheroDriver",
			a,
		),
		packetChannel:   make(chan *packet, 1024),
		responseChannel: make(chan []uint8, 1024),
	}

	s.AddEvent("collision")
	s.AddCommand("SetRGB", func(params map[string]interface{}) interface{} {
		r := uint8(params["r"].(float64))
		g := uint8(params["g"].(float64))
		b := uint8(params["b"].(float64))
		s.SetRGB(r, g, b)
		return nil
	})

	s.AddCommand("Roll", func(params map[string]interface{}) interface{} {
		speed := uint8(params["speed"].(float64))
		heading := uint16(params["heading"].(float64))
		s.Roll(speed, heading)
		return nil
	})

	s.AddCommand("Stop", func(params map[string]interface{}) interface{} {
		s.Stop()
		return nil
	})

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

	s.AddCommand("SetBackLED", func(params map[string]interface{}) interface{} {
		level := uint8(params["level"].(float64))
		s.SetBackLED(level)
		return nil
	})

	s.AddCommand("SetHeading", func(params map[string]interface{}) interface{} {
		heading := uint16(params["heading"].(float64))
		s.SetHeading(heading)
		return nil
	})
	s.AddCommand("SetStabilization", func(params map[string]interface{}) interface{} {
		on := params["heading"].(bool)
		s.SetStabilization(on)
		return nil
	})

	return s
}
Ejemplo n.º 9
0
func NewArdroneDriver(adaptor *ArdroneAdaptor, name string) *ArdroneDriver {
	d := &ArdroneDriver{
		Driver: *gobot.NewDriver(
			name,
			"ArdroneDriver",
			adaptor,
		),
	}
	d.AddEvent("flying")
	return d
}
Ejemplo n.º 10
0
func NewLeapMotionDriver(a *LeapMotionAdaptor, name string) *LeapMotionDriver {
	l := &LeapMotionDriver{
		Driver: *gobot.NewDriver(
			name,
			"LeapMotionDriver",
			a,
		),
	}

	l.AddEvent("Message")
	return l
}
Ejemplo n.º 11
0
func NewCameraDriver(name string, source interface{}) *CameraDriver {
	c := &CameraDriver{
		Driver: *gobot.NewDriver(
			name,
			"CameraDriver",
		),
		Source: source,
	}

	c.AddEvent("frame")

	return c
}
Ejemplo n.º 12
0
func NewMotorDriver(a PwmDigitalWriter, name string, pin string) *MotorDriver {
	return &MotorDriver{
		Driver: *gobot.NewDriver(
			name,
			"MotorDriver",
			a.(gobot.AdaptorInterface),
		),
		CurrentState:     0,
		CurrentSpeed:     0,
		CurrentMode:      "digital",
		CurrentDirection: "forward",
	}
}
Ejemplo n.º 13
0
func NewButtonDriver(a DigitalReader, name string, pin string) *ButtonDriver {
	b := &ButtonDriver{
		Driver: *gobot.NewDriver(
			name,
			"ButtonDriver",
			a.(gobot.AdaptorInterface),
			pin,
		),
		Active: false,
	}

	b.AddEvent("push")
	b.AddEvent("release")

	return b
}
Ejemplo n.º 14
0
func NewMakeyButtonDriver(a DigitalReader, name string, pin string) *MakeyButtonDriver {
	m := &MakeyButtonDriver{
		Driver: *gobot.NewDriver(
			name,
			"MakeyButtonDriver",
			a.(gobot.AdaptorInterface),
			pin,
		),
		Active: false,
	}

	m.AddEvent("push")
	m.AddEvent("release")

	return m
}
Ejemplo n.º 15
0
func NewAnalogSensorDriver(a AnalogReader, name string, pin string) *AnalogSensorDriver {
	d := &AnalogSensorDriver{
		Driver: *gobot.NewDriver(
			name,
			"AnalogSensorDriver",
			a.(gobot.AdaptorInterface),
			pin,
		),
	}

	d.AddEvent("data")
	d.AddCommand("Read", func(params map[string]interface{}) interface{} {
		return d.Read()
	})

	return d
}
Ejemplo n.º 16
0
func NewNeuroskyDriver(a *NeuroskyAdaptor, name string) *NeuroskyDriver {
	n := &NeuroskyDriver{
		Driver: *gobot.NewDriver(
			name,
			"NeuroskyDriver",
			a,
		),
	}

	n.AddEvent("extended")
	n.AddEvent("signal")
	n.AddEvent("attention")
	n.AddEvent("meditation")
	n.AddEvent("blink")
	n.AddEvent("wave")
	n.AddEvent("eeg")

	return n
}
Ejemplo n.º 17
0
func NewDirectPinDriver(a DirectPin, name string, pin string) *DirectPinDriver {
	d := &DirectPinDriver{
		Driver: *gobot.NewDriver(
			name,
			"DirectPinDriver",
			a.(gobot.AdaptorInterface),
			pin,
		),
	}

	d.AddCommand("DigitalRead", func(params map[string]interface{}) interface{} {
		return d.DigitalRead()
	})
	d.AddCommand("DigitalWrite", func(params map[string]interface{}) interface{} {
		level, _ := strconv.Atoi(params["level"].(string))
		d.DigitalWrite(byte(level))
		return nil
	})
	d.AddCommand("AnalogRead", func(params map[string]interface{}) interface{} {
		return d.AnalogRead()
	})
	d.AddCommand("AnalogWrite", func(params map[string]interface{}) interface{} {
		level, _ := strconv.Atoi(params["level"].(string))
		d.AnalogWrite(byte(level))
		return nil
	})
	d.AddCommand("PwmWrite", func(params map[string]interface{}) interface{} {
		level, _ := strconv.Atoi(params["level"].(string))
		d.PwmWrite(byte(level))
		return nil
	})
	d.AddCommand("ServoWrite", func(params map[string]interface{}) interface{} {
		level, _ := strconv.Atoi(params["level"].(string))
		d.ServoWrite(byte(level))
		return nil
	})

	return d
}
Ejemplo n.º 18
0
func NewWiichuckDriver(a I2cInterface, name string) *WiichuckDriver {
	w := &WiichuckDriver{
		Driver: *gobot.NewDriver(
			name,
			"WiichuckDriver",
			a.(gobot.AdaptorInterface),
		),
		joystick: map[string]float64{
			"sy_origin": -1,
			"sx_origin": -1,
		},
		data: map[string]float64{
			"sx": 0,
			"sy": 0,
			"z":  0,
			"c":  0,
		},
	}

	w.AddEvent("z")
	w.AddEvent("c")
	w.AddEvent("joystick")
	return w
}