summaryrefslogtreecommitdiff
path: root/drivers/bma150.h
blob: 2e043ff3b9a0649eab7e5857df19cfc991941768 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifndef BMA150_H
#define BMA150_H

#include "i2c.h"

class BMA150 {
	private:
		I2C& i2c;
	
	public:
		int16_t x, y, z;
		
		BMA150(I2C& i2c_bus) : i2c(i2c_bus) {
			
		}
		
		void init() {
			uint8_t temp;
			i2c.read_reg(0x38, 0x14, 1, &temp);
			i2c.write_reg(0x38, 0x14, (temp & 0xe0) | 0x00 | 0x00); // 2g range, 25 Hz bandwidth
		}
		
		void update() {
			uint8_t buf[6];
			i2c.read_reg(0x38, 0x02, 6, buf);
			
			x = (buf[1] << 8 | buf[0]) - 0;
			y = (buf[3] << 8 | buf[2]) - 0;
			z = (buf[5] << 8 | buf[4]) - 0;
		}
};

#endif