The MGC3130 is the world’s first electrical-field (E-field) based three-dimensional (3D) tracking and gesture controller
Dependents: NucleoMGC3130 i2c_master
Diff: MGC3130.cpp
- Revision:
- 0:92f17b057d6b
- Child:
- 1:621c4e9238ef
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MGC3130.cpp Tue Oct 06 22:35:38 2015 +0000 @@ -0,0 +1,50 @@ +#include "MGC3130.h" + +// IS2 true->High, false->Low +MGC3130::MGC3130(PinName sda, PinName scl, PinName EI0, bool IS2) + :TS_Line(EI0), _i2c_bus(sda,scl), msg(255), sensor() +{ + TS_Line.output(); + TS_Line.write(1); + _i2c_bus.frequency(FREQUENCY_FULL); + + if (IS2) + _addr = 0x86; + else + _addr = 0x84; +} + +GestICMsg * MGC3130::readMsg() +{ + TS_Line.input(); + if (TS_Line.read() == 0) + return NULL; + + msg.reset(); + + TS_Line.output(); + TS_Line.write(0); + + _i2c_bus.start(); + _i2c_bus.write(_addr | 0x01); + + int size = _i2c_bus.read(1); + msg.set(size); + + for (int i = 1; i < size - 1; i++) + msg.set(_i2c_bus.read(1)); + + msg.set(_i2c_bus.read(0)); + + _i2c_bus.stop(); + TS_Line.write(1); + + return &msg; +} + +SensorData * MGC3130::readSensorData() +{ + if (readMsg() != NULL && sensor.convert(&msg)) + return &sensor; + else return NULL; +} \ No newline at end of file