本文整理汇总了Golang中gobot/io/x/gobot.NewEventer函数的典型用法代码示例。如果您正苦于以下问题:Golang NewEventer函数的具体用法?Golang NewEventer怎么用?Golang NewEventer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewEventer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewWiichuckDriver
// NewWiichuckDriver creates a WiichuckDriver with specified i2c interface.
//
// It adds the following events:
// "z"- Gets triggered every interval amount of time if the z button is pressed
// "c" - Gets triggered every interval amount of time if the c button is pressed
// "joystick" - Gets triggered every "interval" amount of time if a joystick event occurred, you can access values x, y
// "error" - Gets triggered whenever the WiichuckDriver encounters an error
func NewWiichuckDriver(a I2c, v ...time.Duration) *WiichuckDriver {
w := &WiichuckDriver{
name: "Wiichuck",
connection: a,
interval: 10 * time.Millisecond,
pauseTime: 1 * time.Millisecond,
Eventer: gobot.NewEventer(),
joystick: map[string]float64{
"sy_origin": -1,
"sx_origin": -1,
},
data: map[string]float64{
"sx": 0,
"sy": 0,
"z": 0,
"c": 0,
},
}
if len(v) > 0 {
w.interval = v[0]
}
w.AddEvent(Z)
w.AddEvent(C)
w.AddEvent(Joystick)
w.AddEvent(Error)
return w
}
示例2: NewAnalogSensorDriver
// NewAnalogSensorDriver returns a new AnalogSensorDriver with a polling interval of
// 10 Milliseconds given an AnalogReader and pin.
//
// Optionally accepts:
// time.Duration: Interval at which the AnalogSensor is polled for new information
//
// Adds the following API Commands:
// "Read" - See AnalogSensor.Read
func NewAnalogSensorDriver(a AnalogReader, pin string, v ...time.Duration) *AnalogSensorDriver {
d := &AnalogSensorDriver{
name: "AnalogSensor",
connection: a,
pin: pin,
Eventer: gobot.NewEventer(),
Commander: gobot.NewCommander(),
interval: 10 * time.Millisecond,
halt: make(chan bool),
}
if len(v) > 0 {
d.interval = v[0]
}
d.AddEvent(Data)
d.AddEvent(Error)
d.AddCommand("Read", func(params map[string]interface{}) interface{} {
val, err := d.Read()
return map[string]interface{}{"val": val, "err": err}
})
return d
}
示例3: NewDriver
// NewDriver creates a new pebble driver
// Adds following events:
// button - Sent when a pebble button is pressed
// accel - Pebble watch acceleromenter data
// tab - When a pebble watch tap event is detected
// And the following API commands:
// "publish_event"
// "send_notification"
// "pending_message"
func NewDriver(adaptor *Adaptor) *Driver {
p := &Driver{
name: "Pebble",
connection: adaptor,
Messages: []string{},
Eventer: gobot.NewEventer(),
Commander: gobot.NewCommander(),
}
p.AddEvent("button")
p.AddEvent("accel")
p.AddEvent("tap")
p.AddCommand("publish_event", func(params map[string]interface{}) interface{} {
p.PublishEvent(params["name"].(string), params["data"].(string))
return nil
})
p.AddCommand("send_notification", func(params map[string]interface{}) interface{} {
p.SendNotification(params["message"].(string))
return nil
})
p.AddCommand("pending_message", func(params map[string]interface{}) interface{} {
return p.PendingMessage()
})
return p
}
示例4: New
// New returns a new Client
func New() *Client {
c := &Client{
ProtocolVersion: "",
FirmwareName: "",
connection: nil,
pins: []Pin{},
analogPins: []int{},
connected: false,
Eventer: gobot.NewEventer(),
}
for _, s := range []string{
"FirmwareQuery",
"CapabilityQuery",
"AnalogMappingQuery",
"ProtocolVersion",
"I2cReply",
"StringData",
"Error",
} {
c.AddEvent(s)
}
return c
}
示例5: NewDriver
// NewDriver creates a Parrot Minidrone Driver
func NewDriver(a *ble.ClientAdaptor) *Driver {
n := &Driver{
name: "Minidrone",
connection: a,
Pcmd: Pcmd{
Flag: 0,
Roll: 0,
Pitch: 0,
Yaw: 0,
Gaz: 0,
Psi: 0,
},
Eventer: gobot.NewEventer(),
}
n.AddEvent(Battery)
n.AddEvent(FlightStatus)
n.AddEvent(Takeoff)
n.AddEvent(Flying)
n.AddEvent(Hovering)
n.AddEvent(Landing)
n.AddEvent(Landed)
n.AddEvent(Emergency)
n.AddEvent(Rolling)
return n
}
示例6: NewMCP23017Driver
// NewMCP23017Driver creates a new driver with specified i2c interface.
func NewMCP23017Driver(a I2c, conf MCP23017Config, deviceAddress int, v ...time.Duration) *MCP23017Driver {
m := &MCP23017Driver{
name: "MCP23017",
connection: a,
conf: conf,
mcp23017Address: deviceAddress,
Commander: gobot.NewCommander(),
Eventer: gobot.NewEventer(),
}
m.AddCommand("WriteGPIO", func(params map[string]interface{}) interface{} {
pin := params["pin"].(uint8)
val := params["val"].(uint8)
port := params["port"].(string)
err := m.WriteGPIO(pin, val, port)
return map[string]interface{}{"err": err}
})
m.AddCommand("ReadGPIO", func(params map[string]interface{}) interface{} {
pin := params["pin"].(uint8)
port := params["port"].(string)
val, err := m.ReadGPIO(pin, port)
return map[string]interface{}{"val": val, "err": err}
})
return m
}
示例7: NewCameraDriver
// NewCameraDriver creates a new driver with specified source.
// It also creates a start function to either set camera as a File or Camera capture.
func NewCameraDriver(source interface{}, v ...time.Duration) *CameraDriver {
c := &CameraDriver{
name: "Camera",
Eventer: gobot.NewEventer(),
Source: source,
interval: 10 * time.Millisecond,
start: func(c *CameraDriver) (err error) {
switch v := c.Source.(type) {
case string:
c.camera = cv.NewFileCapture(v)
case int:
c.camera = cv.NewCameraCapture(v)
default:
return errors.New("Unknown camera source")
}
return
},
}
if len(v) > 0 {
c.interval = v[0]
}
c.AddEvent(Frame)
return c
}
示例8: NewDriver
// NewDriver creates an Driver for the ARDrone.
//
// It add the following events:
// 'flying' - Sent when the device has taken off.
func NewDriver(connection *Adaptor) *Driver {
d := &Driver{
name: "ARDrone",
connection: connection,
Eventer: gobot.NewEventer(),
}
d.AddEvent(Flying)
return d
}
示例9: NewGenericAccessDriver
// NewGenericAccessDriver creates a GenericAccessDriver
func NewGenericAccessDriver(a *ClientAdaptor) *GenericAccessDriver {
n := &GenericAccessDriver{
name: "GenericAccess",
connection: a,
Eventer: gobot.NewEventer(),
}
return n
}
示例10: NewDeviceInformationDriver
// NewDeviceInformationDriver creates a DeviceInformationDriver
func NewDeviceInformationDriver(a *ClientAdaptor) *DeviceInformationDriver {
n := &DeviceInformationDriver{
name: "DeviceInformation",
connection: a,
Eventer: gobot.NewEventer(),
}
return n
}
示例11: NewBatteryDriver
// NewBatteryDriver creates a BatteryDriver
func NewBatteryDriver(a *ClientAdaptor) *BatteryDriver {
n := &BatteryDriver{
name: "Battery",
connection: a,
Eventer: gobot.NewEventer(),
}
return n
}
示例12: NewAdaptor
// NewAdaptor creates new Photon adaptor with deviceId and accessToken
// using api.particle.io server as default
func NewAdaptor(deviceID string, accessToken string) *Adaptor {
return &Adaptor{
name: "Particle",
DeviceID: deviceID,
AccessToken: accessToken,
servoPins: make(map[string]bool),
APIServer: "https://api.particle.io",
Eventer: gobot.NewEventer(),
}
}
示例13: NewDriver
// NewDriver creates a Driver for a Sphero Ollie
func NewDriver(a *ble.ClientAdaptor) *Driver {
n := &Driver{
name: "Ollie",
connection: a,
Eventer: gobot.NewEventer(),
packetChannel: make(chan *packet, 1024),
}
return n
}
示例14: NewDriver
// NewDriver returns a new audio Driver. It accepts:
//
// *Adaptor: The audio adaptor to use for the driver
// string: The filename of the audio to start playing
//
func NewDriver(a *Adaptor, filename string) *Driver {
return &Driver{
name: "Audio",
connection: a,
interval: 500 * time.Millisecond,
filename: filename,
halt: make(chan bool, 0),
Eventer: gobot.NewEventer(),
Commander: gobot.NewCommander(),
}
}
示例15: NewDriver
// NewDriver creates a new leap motion driver
//
// Adds the following events:
// "message" - Gets triggered when receiving a message from leap motion
// "hand" - Gets triggered per-message when leap motion detects a hand
// "gesture" - Gets triggered per-message when leap motion detects a hand
func NewDriver(a *Adaptor) *Driver {
l := &Driver{
name: "LeapMotion",
connection: a,
Eventer: gobot.NewEventer(),
}
l.AddEvent(MessageEvent)
l.AddEvent(HandEvent)
l.AddEvent(GestureEvent)
return l
}