Skip to content

Commit 8665d44

Browse files
authored
Use int16 for ADXL345 readings (#656)
ADXL345: fix: use int16 for ADXL345 readings
1 parent c344e5d commit 8665d44

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

adxl345/adxl345.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,16 @@ func (d *Device) Restart() {
9595
func (d *Device) ReadAcceleration() (x int32, y int32, z int32, err error) {
9696
rx, ry, rz := d.ReadRawAcceleration()
9797

98-
x = d.dataFormat.convertToIS(rx)
99-
y = d.dataFormat.convertToIS(ry)
100-
z = d.dataFormat.convertToIS(rz)
98+
x = int32(d.dataFormat.convertToIS(rx))
99+
y = int32(d.dataFormat.convertToIS(ry))
100+
z = int32(d.dataFormat.convertToIS(rz))
101101

102102
return
103103
}
104104

105105
// ReadRawAcceleration reads the sensor values and returns the raw x, y and z axis
106106
// from the adxl345.
107-
func (d *Device) ReadRawAcceleration() (x int32, y int32, z int32) {
107+
func (d *Device) ReadRawAcceleration() (x int16, y int16, z int16) {
108108
data := []byte{0, 0, 0, 0, 0, 0}
109109
legacy.ReadRegister(d.bus, uint8(d.Address), REG_DATAX0, data)
110110

@@ -140,7 +140,7 @@ func (d *Device) SetRange(sensorRange Range) bool {
140140
}
141141

142142
// convertToIS adjusts the raw values from the adxl345 with the range configuration
143-
func (d *dataFormat) convertToIS(rawValue int32) int32 {
143+
func (d *dataFormat) convertToIS(rawValue int16) int16 {
144144
switch d.sensorRange {
145145
case RANGE_2G:
146146
return rawValue * 4 // rawValue * 2 * 1000 / 512
@@ -190,6 +190,6 @@ func (b *bwRate) toByte() (bits uint8) {
190190
}
191191

192192
// readInt converts two bytes to int16
193-
func readIntLE(msb byte, lsb byte) int32 {
194-
return int32(uint16(msb) | uint16(lsb)<<8)
193+
func readIntLE(msb byte, lsb byte) int16 {
194+
return int16(uint16(msb) | uint16(lsb)<<8)
195195
}

0 commit comments

Comments
 (0)