Ejemplo n.º 1
0
func checkDevice(dev *evdev.Device) (string, bool) {
	if !correctDevice(dev) {
		return "", false
	}

	return dev.Name(), true
}
Ejemplo n.º 2
0
func OpenFLIRC(grab bool) {
	i := 0
	var dev *evdev.Device
	var err error
	for {
		node := fmt.Sprintf("/dev/input/event%d", i)
		dev, err = evdev.Open(node)
		i++
		if err != nil {
			if os.IsNotExist(err) {
				log.Fatalln("could not find FLIRC device")
			}
			log.Fatalln(err)
		}
		if strings.TrimRight(dev.Name(), "\x00") != FLIRCName {
			dev.Close()
			continue
		}
		break
	}

	if grab && !dev.Grab() {
		log.Warnln("failed to grab device")
	}
	log.Infoln("using device:", strings.TrimRight(dev.Path(), "\x00"))
	for event := range dev.Inbox {
		if event.Type != evdev.EvKeys {
			continue
		}
		if event.Value != 0 {
			continue
		}

		log.Infoln("FLIRC event", event.Code)
		for i, code := range flircMap {
			if int(event.Code) == code {
				setState(i)
				break
			}
		}
	}
}