COSA
An Object-Oriented Platform for Arduino Programming
L3G4200D.cpp
Go to the documentation of this file.
1 
21 #include "L3G4200D.hh"
22 
23 bool
25 {
26  ctrl_reg1_t reg;
27  reg.Xen = 1;
28  reg.Yen = 1;
29  reg.Zen = 1;
30  reg.PD = 1;
31  write(CTRL_REG1, reg);
32  return (true);
33 }
34 
35 bool
37 {
38  write(CTRL_REG1, 0);
39  return (true);
40 }
41 
42 void
43 L3G4200D::write(Register reg, uint8_t value)
44 {
45  twi.acquire(this);
46  twi.write((uint8_t) reg, &value, sizeof(value));
47  twi.release();
48 }
49 
50 void
51 L3G4200D::write(Register reg, void* buffer, uint8_t count)
52 {
53  twi.acquire(this);
54  twi.write((uint8_t) (reg | AUTO_INC), buffer, count);
55  twi.release();
56 }
57 
58 uint8_t
60 {
61  uint8_t res;
62  twi.acquire(this);
63  twi.write((uint8_t) reg);
64  twi.read(&res, sizeof(res));
65  twi.release();
66  return (res);
67 }
68 
69 void
70 L3G4200D::read(Register reg, void* buffer, uint8_t count)
71 {
72  twi.acquire(this);
73  twi.write((uint8_t) (reg | AUTO_INC));
74  twi.read(buffer, count);
75  twi.release();
76 }
77 
78 IOStream&
79 operator<<(IOStream& outs, L3G4200D& gyroscope)
80 {
81  L3G4200D::sample_t value;
82  gyroscope.sample(value);
83  outs << PSTR("L3G4200D(x = ") << value.x
84  << PSTR(", y = ") << value.y
85  << PSTR(", z = ") << value.z
86  << PSTR(")");
87  return (outs);
88 }
89 
TWI twi
Definition: TWI.cpp:27
uint8_t Xen
< As bitfields.
Definition: L3G4200D.hh:143
IOStream & operator<<(IOStream &outs, L3G4200D &gyroscope)
Definition: L3G4200D.cpp:79
uint8_t read(Register reg)
Definition: L3G4200D.cpp:59
#define PSTR(s)
Definition: Types.h:202
static const uint8_t AUTO_INC
Definition: L3G4200D.hh:135
void release()
Definition: TWI.cpp:58
bool end()
Definition: L3G4200D.cpp:36
int read(void *buf, size_t size)
Definition: TWI.hh:326
uint8_t PD
Power down enable.
Definition: L3G4200D.hh:146
void sample(sample_t &s)
Definition: L3G4200D.hh:90
int write(void *buf, size_t size)
Definition: TWI.hh:282
uint8_t Yen
Y axis enable.
Definition: L3G4200D.hh:144
uint8_t Zen
Z axis enable.
Definition: L3G4200D.hh:145
void acquire(TWI::Driver *dev)
Definition: TWI.cpp:36
bool begin()
Definition: L3G4200D.cpp:24
Control register#1.
Definition: L3G4200D.hh:102
void write(Register reg, uint8_t value)
Definition: L3G4200D.cpp:43