示例#1
0
func main() {

	panicChan := make(chan interface{})
	go func() {
		select {
		case m := <-panicChan:
			log.Fatal("Received a panic error - exiting: %v", m)
		}
	}()

	////////////////////////////////////////
	// a nice and delicate alarm
	////////////////////////////////////////
	alarmPwm := func(pin byte, pwmId byte) *pwm.Pwm {

		// kill the process (via log.Fatal) in case we can't create the PWM
		pwm, err := pwm.New(pwmId, pin)
		if err != nil {
			log.Fatal(err)
		}

		if !pwm.IsExported() {
			err = pwm.Export()
			if err != nil {
				log.Fatal(err)
			}
		}

		pwm.Disable()

		if err = pwm.SetPeriodAndDutyCycle(200*time.Millisecond, 0.5); err != nil {
			log.Fatal(err)
		}

		return pwm
	}(conf.AlarmGpioPin, conf.AlarmGpioPWM)
	// defer alarmPwm.Unexport() // Don't do that it can disable the alarms for the autopilot program

	theAlarm := alarm.New(alarmPwm)
	alarmChan := make(chan interface{})
	theAlarm.SetInputChan(alarmChan)
	theAlarm.SetPanicChan(panicChan)

	theAlarm.Start()

	alarmChan <- alarm.NewMessage(true)

	for !theAlarm.Enabled() {
		log.Info("Waiting for the alarm to come")
		time.Sleep(10 * time.Millisecond)
	}

	theAlarm.Shutdown()

}
示例#2
0
func (p Pilot) tellTheWorld() {
	// Keep the alarm first - so at least we get notified something is wrong
	p.alarmChan <- alarm.NewMessage(bool(p.alarm))
	p.dashboardChan <- dashboard.NewMessage(p.leds)
}