From 418831ebfec9034e1a83b4f8400d4eee8724e7f9 Mon Sep 17 00:00:00 2001 From: Daniel Ledda Date: Sat, 31 Oct 2020 15:18:13 +0100 Subject: [PATCH] Proper calibration addd --- main.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 0b80d1d..6639c7e 100644 --- a/main.go +++ b/main.go @@ -15,16 +15,25 @@ const Timeout = math.MaxInt32 const TimeoutErrInitial string = "Timed out waiting for sensor's initial %s reading!" var oneSecondInCycles = (func() int { + result := cyclesInAMillisecond() + for i := 0; i < 100; i++ { + result += cyclesInAMillisecond() + } + fmt.Println(result / 100) + return result / 100 +})() + +func cyclesInAMillisecond() int { count := 0 - start := time.Now().Nanosecond() + start := time.Now().UnixNano() for { count++ - if time.Now().Nanosecond() - start >= 1000000 { + if time.Now().UnixNano() - start >= 1000000 { break } } return count -})() +} func main() { err := gpio.Open()