Example #1
0
File: ir.go Project: gordyf/golirc
func main() {
	/*
	 *  MQTT setup
	 */

	opts := MQTT.NewClientOptions().AddBroker("tcp://localhost:1883")
	opts.SetClientID("golirc")

	mc := MQTT.NewClient(opts)
	if token := mc.Connect(); token.Wait() && token.Error() != nil {
		panic(token.Error())
	}

	/*
	 *  LIRC setup
	 */

	ir, err := lirc.Init("/var/run/lirc/lircd")
	if err != nil {
		panic(err)
	}

	ir.Handle("", "BTN_0", makeHandler(mc, "0"))
	ir.Handle("", "BTN_1", makeHandler(mc, "1"))
	ir.Handle("", "BTN_2", makeHandler(mc, "2"))
	ir.Handle("", "BTN_3", makeHandler(mc, "3"))

	go ir.Run()

	select {}
}
Example #2
0
func NewLirc() *Lirc {
	l := &Lirc{
		Events: make(chan string, 5),
	}
	if configuration.LircConf.PidFile == "" {
		glog.Error("Lirc not configured")
		return l
	}

	var err error
	l.ir, err = lirc.Init(configuration.LircConf.PidFile)
	if err != nil {
		return l
	}

	remote := configuration.LircConf.Remote
	if remote == "" {
		remote = "*"
	}

	l.ir.Handle(remote, "*", l.handler)

	go l.ir.Run()

	return l
}
Example #3
0
func main() {

	// Open memory range for GPIO access in /dev/mem
	err := rpio.Open()
	if err != nil {
		log.Println(err)
	}
	defer rpio.Close()

	burglarm := &Burglarm{
		action: make(chan uint8),
		stop:   make(chan bool),
	}
	// Init GPIO Pins
	burglarm.buzzerPin = rpio.Pin(22)
	burglarm.buzzerPin.Mode(rpio.Output)

	burglarm.pirPin = rpio.Pin(23)
	burglarm.pirPin.Mode(rpio.Input)

	// Init IR
	ir, err := lirc.Init("/var/run/lirc/lircd")
	if err != nil {
		log.Println("LIRC Error", err)
	}
	ir.Handle("", "KEY_POWER", burglarm.remoteKey)
	go ir.Run()

	// Start Service
	log.Println("Starting Service")
	go burglarm.start()
	burglarm.action <- ARMED // Arm alarm on start

	// Stop Service
	// Handle SIGINT and SIGTERM
	ch := make(chan os.Signal)
	signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
	log.Println(<-ch) // blocks main

	burglarm.terminate()

}