示例#1
0
文件: main.go 项目: qmsk/onewire
func main() {
	flag.Parse()

	if hidrawList, err := hidraw.List(deviceConfig); err != nil {
		log.Fatalf("hidraw.List %v: %v\n", deviceConfig, err)
	} else {
		log.Printf("hidraw.List...\n")
		for _, deviceInfo := range hidrawList {
			if hidrawDevice, err := hidraw.Open(deviceInfo); err != nil {
				log.Printf("hidraw.Open: %v\n", deviceInfo, err)
			} else if avrtempDevice, err := avrtemp.Open(hidrawDevice); err != nil {
				log.Printf("avrtemp.Open: %v\n", deviceInfo, err)
			} else {
				log.Printf("%#v\n", deviceInfo, avrtempDevice)

				log.Printf("avrtempDevice %v: Read...\n", avrtempDevice)
				for {
					if report, err := avrtempDevice.Read(); err != nil {
						log.Fatalf("avrtemp.Device %v: Read: %v\n", avrtempDevice, err)
					} else {
						log.Printf("%v\n", report)
					}
				}
			}
		}
	}
}
示例#2
0
文件: main.go 项目: qmsk/onewire
func main() {
	flag.Parse()

	s, err := server.New()
	if err != nil {
		log.Fatalf("server.New: %v\n", err)
	}

	http.Handle("/api/", http.StripPrefix("/api", s))

	// config
	if configPath == "" {

	} else if err := s.LoadConfig(configPath); err != nil {
		log.Fatalf("server.LoadConfig %v: %v\n", configPath, err)
	} else {
		log.Printf("server.LoadConfig %v\n", configPath)
	}

	// influx
	if influxOptions.Empty() {

	} else if err := s.InfluxWriter(influxOptions); err != nil {
		log.Fatalf("server.InfluxWriter %v: %v\n", influxOptions, err)
	} else {
		log.Printf("server.InfluxWriter %v\n", influxOptions)
	}

	// devices
	if hidrawList, err := hidraw.List(deviceConfig); err != nil {
		log.Fatalf("hidraw.List %v: %v\n", deviceConfig, err)
	} else {
		log.Printf("hidraw.List...\n")
		for _, deviceInfo := range hidrawList {
			go s.AddHidrawDevice(deviceInfo)
		}
	}

	if monitorChan, err := hidraw.Monitor(deviceConfig); err != nil {
		log.Fatalf("hidraw.Monitor %v: %v\n", deviceConfig, err)
	} else {
		log.Printf("hidraw.Monitor...\n")

		go s.MonitorHidraw(monitorChan)
	}

	// run
	log.Printf("http.ListenAndServe %v...\n", httpListen)

	if err := http.ListenAndServe(httpListen, nil); err != nil {
		log.Fatalf("http.ListenAndServe %v: %v\n", httpListen, err)
	}
}