Exemple #1
0
func getStatus(dev *gorfxtrx.Device) {
	log.Println("Setting mode")
	pkt, _ := gorfxtrx.NewSetMode()
	err := dev.Send(pkt)
	if err != nil {
		log.Println("Error sending packet:", err)
	}

	log.Println("Getting status")
	pkt2, _ := gorfxtrx.NewStatus()
	err = dev.Send(pkt2)
	if err != nil {
		log.Println("Error sending packet:", err)
	}
}
Exemple #2
0
// Read events from the rfxtrx
func readEvents(dev *gorfxtrx.Device) {
	for {
		packet, err := dev.Read()
		if err != nil {
			log.Println("Error reading:", err)
			continue
		}
		if packet == nil {
			continue
		}

		ev := translatePacket(packet)

		if ev != nil {
			services.Publisher.Emit(ev)
		}

	}
}
Exemple #3
0
func repeatSend(dev *gorfxtrx.Device, device string, pkt gorfxtrx.OutPacket, repeat int64) error {
	// cancel any existing timer
	if t, ok := repeats[device]; ok {
		delete(repeats, device)
		t.Stop()
	}

	err := dev.Send(pkt)
	if err != nil {
		return err
	}

	if repeat > 1 {
		repeats[device] = time.AfterFunc(RepeatInterval, func() {
			repeatSend(dev, device, pkt, repeat-1)
		})
	}
	return nil
}