Merge remote-tracking branch 'origin/master' into ahrs_dev_protocolfun

adsbexchange
Christopher Young 2017-05-24 21:44:28 -04:00
commit 5bb15527f4
1 zmienionych plików z 13 dodań i 20 usunięć

Wyświetl plik

@ -21,19 +21,16 @@ const (
defaultTempTarget = 50.
hysteresis = float32(1.)
/* This puts our PWM frequency at 19.2 MHz / 128 =
/* 150kHz. Higher frequencies will reduce audible switching
/* noise but will be less efficient */
pwmClockDivisor = 128
pwmClockDivisor = 100
/* Minimum duty cycle is the point below which the fan does
/* not spin. This depends on both your fan and the switching
/* transistor used. */
defaultPwmDutyMin = 20
pwmDutyMax = 256
defaultPwmDutyMin = 1
pwmDutyMax = 10
// how often to update
delaySeconds = 2
delaySeconds = 30
// GPIO-1/BCM "18"/Pin 12 on a Raspberry PI 3
defaultPin = 1
@ -50,8 +47,16 @@ var stdlog, errlog *log.Logger
func fanControl(pwmDutyMin int, pin int, tempTarget float32) {
cPin := C.int(pin)
C.wiringPiSetup()
C.pwmSetMode(C.PWM_MODE_BAL)
// Power on "test". Allows the user to verify that their fan is working.
C.pinMode(cPin, C.OUTPUT)
C.digitalWrite(cPin, C.HIGH)
time.Sleep(5 * time.Second)
C.digitalWrite(cPin, C.LOW)
C.pwmSetMode(C.PWM_MODE_MS)
C.pinMode(cPin, C.PWM_OUTPUT)
C.pwmSetRange(pwmDutyMax)
C.pwmSetClock(pwmClockDivisor)
@ -64,21 +69,9 @@ func fanControl(pwmDutyMin int, pin int, tempTarget float32) {
})
pwmDuty := 0
tempWhenRampStarted := float32(0.)
for {
if temp > (tempTarget + hysteresis) {
if tempWhenRampStarted < 1. {
tempWhenRampStarted = temp
}
pwmDuty = iMax(iMin(pwmDutyMax, pwmDuty+1), pwmDutyMin)
if pwmDuty == pwmDutyMax {
// At the maximum duty cycle currently.
// Has the temperature increased "substantially" since the ramp-up started?
if temp > (tempWhenRampStarted + hysteresis) {
// Give up. The fan does not like the PWM control.
break
}
}
} else if temp < (tempTarget - hysteresis) {
pwmDuty = iMax(pwmDuty-1, 0)
if pwmDuty < pwmDutyMin {