Skip to content

Commit 140f3fe

Browse files
committed
make zero value useful for configuration
1 parent d675bd4 commit 140f3fe

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

examples/mpu6050/main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ func main() {
1313

1414
mpuDevice := mpu6050.New(machine.I2C0, mpu6050.DefaultAddress)
1515

16-
err := mpuDevice.Configure(mpu6050.Config{
17-
AccelRange: mpu6050.ACCEL_RANGE_16,
18-
GyroRange: mpu6050.GYRO_RANGE_2000,
19-
})
16+
// Configure the device with default configuration.
17+
err := mpuDevice.Configure(mpu6050.Config{})
2018
if err != nil {
2119
panic(err.Error())
2220
}

mpu6050/mpu6050.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (p *Device) setRangeGyro(gyroRange RangeGyro) (err error) {
167167
p.gRange = 500
168168
case RangeGyro1000:
169169
p.gRange = 1000
170-
case RangeGyro2000:
170+
case RangeGyro2000, rangeGyroDefault:
171171
p.gRange = 2000
172172
default:
173173
return errInvalidRangeGyro
@@ -187,7 +187,7 @@ func (p *Device) setRangeAccel(accRange RangeAccel) (err error) {
187187
p.aRange = 4
188188
case RangeAccel8:
189189
p.aRange = 8
190-
case RangeAccel16:
190+
case RangeAccel16, rangeGyroDefault:
191191
p.aRange = 16
192192
default:
193193
return errInvalidRangeAccel
@@ -218,12 +218,3 @@ func b2u8(b bool) byte {
218218
}
219219
return 0
220220
}
221-
222-
func DefaultConfig() Config {
223-
return Config{
224-
AccelRange: RangeAccel16,
225-
GyroRange: RangeGyro2000,
226-
sampleRatio: 0, // TODO add const values.
227-
clkSel: 0,
228-
}
229-
}

mpu6050/registers.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ const (
4141

4242
// Gyroscope ranges for Init configuration
4343
const (
44+
rangeGyroDefault = iota
4445
// 250°/s
45-
RangeGyro250 RangeGyro = iota
46+
RangeGyro250
4647
// 500°/s
4748
RangeGyro500
4849
// 1000°/s
@@ -53,8 +54,9 @@ const (
5354

5455
// Accelerometer ranges for Init configuration
5556
const (
57+
rangeAccelDefault RangeAccel = iota
5658
// 2g
57-
RangeAccel2 RangeAccel = iota
59+
RangeAccel2
5860
// 4g
5961
RangeAccel4
6062
// 8g

0 commit comments

Comments
 (0)