kopia lustrzana https://github.com/cyoung/stratux
Merge pull request #531 from jamez70/move_timer_calls
Move timer calls to bottom of routinespull/533/head
commit
8bf9347878
|
@ -676,7 +676,6 @@ func isCPUTempValid() bool {
|
||||||
func cpuTempMonitor() {
|
func cpuTempMonitor() {
|
||||||
timer := time.NewTicker(1 * time.Second)
|
timer := time.NewTicker(1 * time.Second)
|
||||||
for {
|
for {
|
||||||
<-timer.C
|
|
||||||
|
|
||||||
// Update CPUTemp.
|
// Update CPUTemp.
|
||||||
temp, err := ioutil.ReadFile("/sys/class/thermal/thermal_zone0/temp")
|
temp, err := ioutil.ReadFile("/sys/class/thermal/thermal_zone0/temp")
|
||||||
|
@ -695,6 +694,7 @@ func cpuTempMonitor() {
|
||||||
if t >= -99.0 { // Only update if valid value was obtained.
|
if t >= -99.0 { // Only update if valid value was obtained.
|
||||||
globalStatus.CPUTemp = t
|
globalStatus.CPUTemp = t
|
||||||
}
|
}
|
||||||
|
<-timer.C
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,7 +159,6 @@ func handleStatusWS(conn *websocket.Conn) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Send status.
|
// Send status.
|
||||||
<-timer.C
|
|
||||||
update, _ := json.Marshal(&globalStatus)
|
update, _ := json.Marshal(&globalStatus)
|
||||||
_, err := conn.Write(update)
|
_, err := conn.Write(update)
|
||||||
|
|
||||||
|
@ -167,19 +166,20 @@ func handleStatusWS(conn *websocket.Conn) {
|
||||||
// log.Printf("Web client disconnected.\n")
|
// log.Printf("Web client disconnected.\n")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
<-timer.C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleSituationWS(conn *websocket.Conn) {
|
func handleSituationWS(conn *websocket.Conn) {
|
||||||
timer := time.NewTicker(100 * time.Millisecond)
|
timer := time.NewTicker(100 * time.Millisecond)
|
||||||
for {
|
for {
|
||||||
<-timer.C
|
|
||||||
situationJSON, _ := json.Marshal(&mySituation)
|
situationJSON, _ := json.Marshal(&mySituation)
|
||||||
_, err := conn.Write(situationJSON)
|
_, err := conn.Write(situationJSON)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
<-timer.C
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -536,7 +536,6 @@ func networkStatsCounter() {
|
||||||
var previousNetworkMessagesSent, previousNetworkBytesSent, previousNetworkMessagesSentNonqueueable, previousNetworkBytesSentNonqueueable uint64
|
var previousNetworkMessagesSent, previousNetworkBytesSent, previousNetworkMessagesSentNonqueueable, previousNetworkBytesSentNonqueueable uint64
|
||||||
|
|
||||||
for {
|
for {
|
||||||
<-timer.C
|
|
||||||
globalStatus.NetworkDataMessagesSentLastSec = globalStatus.NetworkDataMessagesSent - previousNetworkMessagesSent
|
globalStatus.NetworkDataMessagesSentLastSec = globalStatus.NetworkDataMessagesSent - previousNetworkMessagesSent
|
||||||
globalStatus.NetworkDataBytesSentLastSec = globalStatus.NetworkDataBytesSent - previousNetworkBytesSent
|
globalStatus.NetworkDataBytesSentLastSec = globalStatus.NetworkDataBytesSent - previousNetworkBytesSent
|
||||||
globalStatus.NetworkDataMessagesSentNonqueueableLastSec = globalStatus.NetworkDataMessagesSentNonqueueable - previousNetworkMessagesSentNonqueueable
|
globalStatus.NetworkDataMessagesSentNonqueueableLastSec = globalStatus.NetworkDataMessagesSentNonqueueable - previousNetworkMessagesSentNonqueueable
|
||||||
|
@ -549,6 +548,7 @@ func networkStatsCounter() {
|
||||||
previousNetworkBytesSent = globalStatus.NetworkDataBytesSent
|
previousNetworkBytesSent = globalStatus.NetworkDataBytesSent
|
||||||
previousNetworkMessagesSentNonqueueable = globalStatus.NetworkDataMessagesSentNonqueueable
|
previousNetworkMessagesSentNonqueueable = globalStatus.NetworkDataMessagesSentNonqueueable
|
||||||
previousNetworkBytesSentNonqueueable = globalStatus.NetworkDataBytesSentNonqueueable
|
previousNetworkBytesSentNonqueueable = globalStatus.NetworkDataBytesSentNonqueueable
|
||||||
|
<-timer.C
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1398,7 +1398,6 @@ func initI2C() error {
|
||||||
func tempAndPressureReader() {
|
func tempAndPressureReader() {
|
||||||
timer := time.NewTicker(5 * time.Second)
|
timer := time.NewTicker(5 * time.Second)
|
||||||
for globalStatus.RY835AI_connected && globalSettings.AHRS_Enabled {
|
for globalStatus.RY835AI_connected && globalSettings.AHRS_Enabled {
|
||||||
<-timer.C
|
|
||||||
// Read temperature and pressure altitude.
|
// Read temperature and pressure altitude.
|
||||||
temp, alt, err_bmp180 := readBMP180()
|
temp, alt, err_bmp180 := readBMP180()
|
||||||
// Process.
|
// Process.
|
||||||
|
@ -1410,6 +1409,7 @@ func tempAndPressureReader() {
|
||||||
mySituation.Pressure_alt = alt
|
mySituation.Pressure_alt = alt
|
||||||
mySituation.LastTempPressTime = stratuxClock.Time
|
mySituation.LastTempPressTime = stratuxClock.Time
|
||||||
}
|
}
|
||||||
|
<-timer.C
|
||||||
}
|
}
|
||||||
globalStatus.RY835AI_connected = false
|
globalStatus.RY835AI_connected = false
|
||||||
}
|
}
|
||||||
|
@ -1464,7 +1464,6 @@ func makeAHRSGDL90Report() {
|
||||||
func attitudeReaderSender() {
|
func attitudeReaderSender() {
|
||||||
timer := time.NewTicker(100 * time.Millisecond) // ~10Hz update.
|
timer := time.NewTicker(100 * time.Millisecond) // ~10Hz update.
|
||||||
for globalStatus.RY835AI_connected && globalSettings.AHRS_Enabled {
|
for globalStatus.RY835AI_connected && globalSettings.AHRS_Enabled {
|
||||||
<-timer.C
|
|
||||||
// Read pitch and roll.
|
// Read pitch and roll.
|
||||||
pitch, roll, err_mpu6050 := readMPU6050()
|
pitch, roll, err_mpu6050 := readMPU6050()
|
||||||
|
|
||||||
|
@ -1488,6 +1487,7 @@ func attitudeReaderSender() {
|
||||||
makeAHRSGDL90Report()
|
makeAHRSGDL90Report()
|
||||||
|
|
||||||
mySituation.mu_Attitude.Unlock()
|
mySituation.mu_Attitude.Unlock()
|
||||||
|
<-timer.C
|
||||||
}
|
}
|
||||||
globalStatus.RY835AI_connected = false
|
globalStatus.RY835AI_connected = false
|
||||||
}
|
}
|
||||||
|
@ -1587,7 +1587,6 @@ func pollRY835AI() {
|
||||||
readyToInitGPS = true //TO-DO: Implement more robust method (channel control) to kill zombie serial readers
|
readyToInitGPS = true //TO-DO: Implement more robust method (channel control) to kill zombie serial readers
|
||||||
timer := time.NewTicker(4 * time.Second)
|
timer := time.NewTicker(4 * time.Second)
|
||||||
for {
|
for {
|
||||||
<-timer.C
|
|
||||||
// GPS enabled, was not connected previously?
|
// GPS enabled, was not connected previously?
|
||||||
if globalSettings.GPS_Enabled && !globalStatus.GPS_connected && readyToInitGPS { //TO-DO: Implement more robust method (channel control) to kill zombie serial readers
|
if globalSettings.GPS_Enabled && !globalStatus.GPS_connected && readyToInitGPS { //TO-DO: Implement more robust method (channel control) to kill zombie serial readers
|
||||||
globalStatus.GPS_connected = initGPSSerial()
|
globalStatus.GPS_connected = initGPSSerial()
|
||||||
|
@ -1603,6 +1602,7 @@ func pollRY835AI() {
|
||||||
globalStatus.RY835AI_connected = false
|
globalStatus.RY835AI_connected = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
<-timer.C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue