[riot-notifications] [RIOT-OS/RIOT] drivers: add driver for FXOS8700 3-axis accelerometer/magnetometer (#8978)

Joakim NohlgÄrd notifications at github.com
Mon Apr 23 12:18:21 CEST 2018


gebart commented on this pull request.



> +    }
+
+    /* Read all data at once */
+    if (fxos8700_read_regs(dev, FXOS8700_REG_OUT_X_MSB, &data[0], 12)) {
+        return FXOS8700_BUSERR;
+    }
+
+    if (fxos8700_set_idle(dev)) {
+        return FXOS8700_BUSERR;
+    }
+
+    /* Read accelerometer */
+    if (acc) {
+        int32_t acc_raw_x = (int32_t) ((data[0] << 6) | (data[1] >> 2));
+        int32_t acc_raw_y = (int32_t) ((data[2] << 6) | (data[3] >> 2));
+        int32_t acc_raw_z = (int32_t) ((data[4] << 6) | (data[5] >> 2));

This gives reasonable results for negative numbers:
```c
        int32_t acc_raw_x = (int16_t) ((data[0] << 8) | data[1]) >> 2;
        int32_t acc_raw_y = (int16_t) ((data[2] << 8) | data[3]) >> 2;
        int32_t acc_raw_z = (int16_t) ((data[4] << 8) | data[5]) >> 2;
        acc->x = (int16_t) ((acc_raw_x * 244) / 1000);
        acc->y = (int16_t) ((acc_raw_y * 244) / 1000);
        acc->z = (int16_t) ((acc_raw_z * 244) / 1000);
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/8978#discussion_r183343071
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20180423/bfe54a37/attachment.html>


More information about the notifications mailing list