From 140f3fed2458ab0712ee13a4d50f72dbb966052f Mon Sep 17 00:00:00 2001 From: soypat Date: Sat, 27 May 2023 14:44:16 -0300 Subject: [PATCH] make zero value useful for configuration --- examples/mpu6050/main.go | 6 ++---- mpu6050/mpu6050.go | 13 ++----------- mpu6050/registers.go | 6 ++++-- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/examples/mpu6050/main.go b/examples/mpu6050/main.go index b64fe3be6..a80c2aa27 100644 --- a/examples/mpu6050/main.go +++ b/examples/mpu6050/main.go @@ -13,10 +13,8 @@ func main() { mpuDevice := mpu6050.New(machine.I2C0, mpu6050.DefaultAddress) - err := mpuDevice.Configure(mpu6050.Config{ - AccelRange: mpu6050.ACCEL_RANGE_16, - GyroRange: mpu6050.GYRO_RANGE_2000, - }) + // Configure the device with default configuration. + err := mpuDevice.Configure(mpu6050.Config{}) if err != nil { panic(err.Error()) } diff --git a/mpu6050/mpu6050.go b/mpu6050/mpu6050.go index b7f9d3698..df7fdde8c 100644 --- a/mpu6050/mpu6050.go +++ b/mpu6050/mpu6050.go @@ -167,7 +167,7 @@ func (p *Device) setRangeGyro(gyroRange RangeGyro) (err error) { p.gRange = 500 case RangeGyro1000: p.gRange = 1000 - case RangeGyro2000: + case RangeGyro2000, rangeGyroDefault: p.gRange = 2000 default: return errInvalidRangeGyro @@ -187,7 +187,7 @@ func (p *Device) setRangeAccel(accRange RangeAccel) (err error) { p.aRange = 4 case RangeAccel8: p.aRange = 8 - case RangeAccel16: + case RangeAccel16, rangeGyroDefault: p.aRange = 16 default: return errInvalidRangeAccel @@ -218,12 +218,3 @@ func b2u8(b bool) byte { } return 0 } - -func DefaultConfig() Config { - return Config{ - AccelRange: RangeAccel16, - GyroRange: RangeGyro2000, - sampleRatio: 0, // TODO add const values. - clkSel: 0, - } -} diff --git a/mpu6050/registers.go b/mpu6050/registers.go index e06bf36b6..ca6c5e0ae 100644 --- a/mpu6050/registers.go +++ b/mpu6050/registers.go @@ -41,8 +41,9 @@ const ( // Gyroscope ranges for Init configuration const ( + rangeGyroDefault = iota // 250°/s - RangeGyro250 RangeGyro = iota + RangeGyro250 // 500°/s RangeGyro500 // 1000°/s @@ -53,8 +54,9 @@ const ( // Accelerometer ranges for Init configuration const ( + rangeAccelDefault RangeAccel = iota // 2g - RangeAccel2 RangeAccel = iota + RangeAccel2 // 4g RangeAccel4 // 8g