Esempio n. 1
0
// Demos the Gobot Every function, which provides a way
// to trigger recurring functionality.
func blinkLedOverAndOver(gbot *gobot.Gobot) {

	// Create an instance of our chosen adapter type
	// and pass it to the LED driver. The names given here
	// are used in the management functionality.
	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_15")

	// Robots in the Gobot colletion run a "work" function
	// when they fire
	work := func() {
		gobot.Every(1*time.Second, func() {
			led.Toggle()
		})
	}

	// A Robot is a board or device, and is one of the things managed by a Gobot.
	// Here we make one with the adaptor and led objects we made above.
	// The constructor creates a new named robot, provided a connection and a device
	// which will map to something like a GPIO pin.

	// A Robot can be composed of as many Connections and Devices as you like,
	// meaning that you can create something out of a group of supported hardware pieces
	// and treat it in code as a single logical unit.
	robot := gobot.NewRobot("blinkBot",
		[]gobot.Connection{beagleboneAdaptor},
		[]gobot.Device{led},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
Esempio n. 2
0
		gbot    *gobot.Gobot
	)

	BeforeEach(func() {
		// Remove line below to get more debug info
		log.SetOutput(&testutils.NullReadWriteCloser{})

		gbot = gobot.NewGobot()
		adapter := newMockAdapter("mock adapter")
		broker = newMockBroker()
		service = sensors.Initialize(gbot, adapter, broker)
	})

	It("publishes sensor name to sensor list", func() {
		service.NewTouchSensor("4")
		go gbot.Start()
		broker.IsConnectedOutput.ret0 <- true
		Eventually(broker.PublishCalled).Should(Receive(BeTrue()))
		Eventually(broker.PublishInput.arg0).Should(Receive(Equal(sensors.SENSORS_LIST_KEY)))
		Eventually(broker.PublishInput.arg1).Should(Receive(MatchJSON(`{"sensors":["/wff/v1/sp1/touchsensor4"]}`)))
	})

	Context("Touch", func() {

		It("adds touch robot to gobot", func() {
			service.NewTouchSensor("2")
			Eventually(gbot.Robots().Len()).Should(Equal(1))
			Expect(gbot.Robot("touchsensor2")).ToNot(BeNil())
		})

		It("publishes alert on touch push event", func() {