示例#1
0
func main() {
	gbot := gobot.NewGobot()

	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	led := gpio.NewDirectPinDriver(beagleboneAdaptor, "led", "P8_10")
	button := gpio.NewDirectPinDriver(beagleboneAdaptor, "button", "P8_9")

	work := func() {
		gobot.Every(500*time.Millisecond, func() {
			if button.DigitalRead() == 1 {
				led.DigitalWrite(1)
			} else {
				led.DigitalWrite(0)
			}
		})
	}

	robot := gobot.NewRobot("pinBot",
		[]gobot.Connection{beagleboneAdaptor},
		[]gobot.Device{led},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
示例#2
0
func main() {
	gbot := gobot.NewGobot()

	firmataAdaptor := firmata.NewFirmataAdaptor("myFirmata", "/dev/ttyACM0")
	pin := gpio.NewDirectPinDriver(firmataAdaptor, "pin", "13")

	work := func() {
		level := byte(1)

		gobot.Every(1*time.Second, func() {
			pin.DigitalWrite(level)
			if level == 1 {
				level = 0
			} else {
				level = 1
			}
		})
	}

	robot := gobot.NewRobot("pinBot",
		[]gobot.Connection{firmataAdaptor},
		[]gobot.Device{pin},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
示例#3
0
func main() {
	gbot := gobot.NewGobot()

	e := edison.NewEdisonAdaptor("edison")
	m := mqtt.NewMqttAdaptor("mqtt", "tcp://192.168.0.90:1883", "pump")

	lever := gpio.NewButtonDriver(e, "lever", "2")
	fault := gpio.NewButtonDriver(e, "fault", "4")
	pump := gpio.NewDirectPinDriver(e, "pump", "13")

	work := func() {
		dgram := url.Values{
			"name":         {"Four"},
			"dispenser_id": {"4"},
			"drink_id":     {"0"},
			"event":        {"online"},
			"details":      {"dispenser"},
		}
		pumping := false
		served := byte(0)

		m.On("startPump", func(data []byte) {
			if !pumping {
				pumping = true
				pump.DigitalWrite(1)
				served++
				dgram.Set("event", "online")
				dgram.Set("drink_id", fmt.Sprintf("%v", served))
				m.Publish("pumped", []byte(dgram.Encode()))
				gobot.After(2*time.Second, func() {
					pump.DigitalWrite(0)
					pumping = false
				})
			}
		})

		gobot.On(lever.Event("push"), func(data interface{}) {
			m.Publish("pump", []byte{})
		})

		m.On("startFault", func(data []byte) {
			dgram.Set("event", "error")
			m.Publish("fault", []byte(dgram.Encode()))
		})

		gobot.On(fault.Event("push"), func(data interface{}) {
			m.Publish("startFault", []byte{})
		})
	}

	gbot.AddRobot(gobot.NewRobot("brewmachine",
		[]gobot.Connection{e, m},
		[]gobot.Device{lever, fault, pump},
		work,
	))

	gbot.Start()
}
示例#4
0
// Run some simple GPIO interactions
// by taking control of the Direct Pin abstraction
func setDirectPin(state int) {
	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	gpioPin := gpio.NewDirectPinDriver(beagleboneAdaptor, "myDevice", "P9_12")

	// Initialize the internal representation of the pinout
	beagleboneAdaptor.Connect()

	// Cast to byte because we are returning an int from a function
	// and not passing in an int literal.
	gpioPin.DigitalWrite(byte(state))
}
func main() {

	// Use Gobot to control BeagleBone's digital pins directly

	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	gpioPin := gpio.NewDirectPinDriver(beagleboneAdaptor, "myDevice", "P9_12")

	// Initialize the internal representation of the pinout
	beagleboneAdaptor.Connect()

	// Cast to byte because we are returning an int from a function
	// and not passing in an int literal.
	gpioPin.DigitalWrite(byte(myStateFunction()))
}
示例#6
0
文件: main.go 项目: mbrumlow/dartbot
func main() {

	flag.Parse()

	gbot := gobot.NewGobot()

	e := edison.NewEdisonAdaptor("edison")

	pwmA := gpio.NewDirectPinDriver(e, "pwmA", "3")
	breakA := gpio.NewDirectPinDriver(e, "breakA", "9")
	dirA := gpio.NewDirectPinDriver(e, "dirA", "12")

	pwmB := gpio.NewDirectPinDriver(e, "pwmB", "5")
	breakB := gpio.NewDirectPinDriver(e, "breakB", "8")
	dirB := gpio.NewDirectPinDriver(e, "dirB", "13")

	work := func() {
		tank := tank.NewTank(pwmA, breakA, dirA, pwmB, breakB, dirB, *maxspeed, *maxrotate)

		go func() {

			wb := webbot.New(*host, *video, *pass, tank)

			for {
				if err := wb.Run(); err != nil {
					log.Printf("RUN ERROR: %v\n", err.Error())
				}
				time.Sleep(1 * time.Second)
			}

		}()

	}

	robot := gobot.NewRobot("dartBot",
		[]gobot.Connection{e},
		[]gobot.Device{pwmA},
		[]gobot.Device{breakA},
		[]gobot.Device{dirA},
		[]gobot.Device{pwmB},
		[]gobot.Device{dirB},
		[]gobot.Device{breakB},
		work,
	)

	gbot.AddRobot(robot)
	gbot.Start()

}
示例#7
0
文件: main.go 项目: iiie/ps1rfid
func main() {
	var code string
	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	//NewDirectPinDriver returns a pointer - this wasn't immediately obvious to me
	splate := gpio.NewDirectPinDriver(beagleboneAdaptor, "splate", "P9_11")
	c := &serial.Config{Name: "/dev/ttyUSB0", Baud: 9600}
	u, err := serial.OpenPort(c)
	if err != nil {
		fmt.Print(err)
		os.Exit(1)
	}
	//Configure ZMQ publisher
	publisher, err := zmq.NewSocket(zmq.PUB)
	if err != nil {
		fmt.Print(err)
		os.Exit(1)
	}
	publisher.Bind("tcp://*:5556")
	//Configure ZMQ publisher
	go http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Code: "))
		w.Write([]byte(code))
	})
	// the anonymous function here allows us to call openDoor with splate remaining in scope
	go http.HandleFunc("/open", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Okay"))
		openDoor(*splate, publisher)
	})
	go http.ListenAndServe(":8080", nil)
	buf := make([]byte, 16)
	for {
		n, err := io.ReadFull(u, buf)
		if err != nil {
			fmt.Print(err)
			os.Exit(1)
		}
		// We need to strip the stop and start bytes from the tag, so we only assign a certain range of the slice
		code = string(buf[1 : n-3])
		var request bytes.Buffer
		request.WriteString("https://members.pumpingstationone.org/rfid/check/FrontDoor/")
		request.WriteString(code)
		resp, err := http.Get(request.String())
		if err != nil {
			fmt.Printf("Whoops!")
			publisher.SendMessage("door.rfid.error", fmt.Sprintf("Auth Server Error: %s", err))
			os.Exit(1)
		}
		if resp.StatusCode == 200 {
			fmt.Println("Success!")
			publisher.SendMessage("door.rfid.accept", "RFID Accepted")
			code = ""
			openDoor(*splate, publisher)
		} else if resp.StatusCode == 403 {
			fmt.Println("Membership status: Expired")
			publisher.SendMessage("door.rfid.deny", "RFID Denied")
		} else {
			fmt.Println("Code not found")
			publisher.SendMessage("door.rfid.deny", "RFID not found")
		}
	}

}
示例#8
0
func main() {
	var code string
	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	//NewDirectPinDriver returns a pointer - this wasn't immediately obvious to me
	splate := gpio.NewDirectPinDriver(beagleboneAdaptor, "splate", "P9_11")
	c := &serial.Config{Name: "/dev/ttyUSB0", Baud: 9600}
	u, err := serial.OpenPort(c)
	if err != nil {
		fmt.Print(err)
		os.Exit(1)
	}
	//Configure ZMQ publisher
	publisher, err := zmq.NewSocket(zmq.PUB)
	if err != nil {
		fmt.Print(err)
		os.Exit(1)
	}
	publisher.Bind("tcp://*:5556")
	//Configure ZMQ publisher
	go http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Code: "))
		w.Write([]byte(code))
	})
	// the anonymous function here allows us to call openDoor with splate remaining in scope
	go http.HandleFunc("/open", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Okay"))
		openDoor(*splate, publisher)
	})
	go http.ListenAndServe(":8080", nil)
	buf := make([]byte, 16)
	for {
		n, err := io.ReadFull(u, buf)
		if err != nil {
			fmt.Print(err)
			os.Exit(1)
		}
		// We need to strip the stop and start bytes from the tag, so we only assign a certain range of the slice
		code = string(buf[1 : n-3])

		// Now open the cache db to check if it's already here
		cacheDB, err = bolt.Open("rfid-tags.db", 0600, nil)
		if err != nil {
			fmt.Println(err)
		}

		cacheDB.Update(func(tx *bolt.Tx) error {
			_, err := tx.CreateBucketIfNotExists([]byte("RFIDBucket"))
			if err != nil {
				return fmt.Errorf("create bucket: %s", err)
			}
			return nil
		})

		// Before checking the site for the code, let's check our cache
		if checkCacheDBForTag(code) == false {
			var request bytes.Buffer
			request.WriteString("https://members.pumpingstationone.org/rfid/check/FrontDoor/")
			request.WriteString(code)
			resp, err := http.Get(request.String())
			if err != nil {
				fmt.Printf("Whoops!")
				publisher.SendMessage("door.rfid.error", fmt.Sprintf("Auth Server Error: %s", err))
				os.Exit(1)
			}
			if resp.StatusCode == 200 {

				// We got 200 back, so we're good to add this
				// tag to the cache
				addTagToCacheDB(code)

				fmt.Println("Success!")
				publisher.SendMessage("door.rfid.accept", "RFID Accepted")
				code = ""
				openDoor(*splate, publisher)
			} else if resp.StatusCode == 403 {
				fmt.Println("Membership status: Expired")
				publisher.SendMessage("door.rfid.deny", "RFID Denied")
			} else {
				fmt.Println("Code not found")
				publisher.SendMessage("door.rfid.deny", "RFID not found")
			}
		} else {
			// If we're here, we found the tag in the cache, so
			// let's just go and open the door for 'em
			fmt.Println("Success!")
			publisher.SendMessage("door.rfid.accept", "RFID Accepted")
			code = ""
			openDoor(*splate, publisher)
		}

		cacheDB.Close()
	}
}