コード例 #1
0
ファイル: main.go プロジェクト: cassava/pillr
func main() {
	pinnr := flag.Int("pin", -1, "gpio pin number of LED")
	flag.Parse()

	if *pinnr < 0 {
		fmt.Println("Please specify pin which LED is on! Be careful!")
		os.Exit(1)
	}

	panicIf(embd.InitGPIO())
	defer embd.CloseGPIO()

	l := led.New(*pinnr)
	if flag.NArg() <= 0 {
		fmt.Println("Blinking Heartbeat1000 pattern till you quit...")
		l.Blink(led.Heartbeat1000...)
	} else {
		pattern := make([]time.Duration, flag.NArg())
		for i, s := range flag.Args() {
			d, err := time.ParseDuration(s)
			if err != nil {
				fmt.Println("Error parsing duration:", err)
				os.Exit(1)
			}
			pattern[i] = d
		}

		fmt.Printf("Blinking your pattern %v till you quit...\n", pattern)
		l.Blink(pattern...)
	}

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	<-c

	fmt.Println("\nBye-bye.")
	go func() {
		// This we do in case l.Stop() doesn't work.
		// It's a way to force quit.
		<-c
		os.Exit(1)
	}()
	l.Stop()
}
コード例 #2
0
ファイル: main.go プロジェクト: cassava/pillr
  It will also store any measurements in XDG_DATA_HOME/pimon/th.csv.
`,
	Run: func(cmd *cobra.Command, args []string) {
		Conf.Assert()

		exitIf(pimonLock())
		defer pimonUnlock()

		exitIf(embd.InitGPIO())
		defer embd.CloseGPIO()

		done := make(chan struct{})
		c := make(chan os.Signal, 1)
		signal.Notify(c, os.Interrupt)

		nl := &WarningLED{led.New(Conf.PinWarningLED), guitar.Low}
		csv, err := NewCSVPersister(xdg.UserData(databaseSuffix))
		if err != nil {
			log.Error("error persisting: ", err)
			return
		}
		m, err := NewMonitor(csv, 0.1)
		if err != nil {
			log.Error("error reading persistent file: ", err)
			return
		}
		g := guitar.Larrivee

		go Serve(Conf.Listen, m)
		go WatchSensor(Conf.PinSensor, done, func(x Measurement) {
			m.Update(x)