Hover!( Microchip MGC3130 ) library. Now, it is development version. http://www.hoverlabs.co/#hover https://www.switch-science.com/catalog/2124/

Dependents:   MjHover_Hello

Revision:
2:46cf70365584
Parent:
1:8e9c00c59101
Child:
3:b03009537d66
--- a/MjHover.cpp	Sat Feb 28 07:45:07 2015 +0000
+++ b/MjHover.cpp	Thu Apr 02 13:02:52 2015 +0000
@@ -2,7 +2,7 @@
 
 namespace matsujirushi {
 
-MjHover::MjHover(I2C* i2c, uint8_t address, DigitalInOut* ts, DigitalOut* reset_n)
+MjHover::MjHover(I2C* i2c, uint8_t address, DigitalInOut* ts, DigitalInOut* reset_n)
 {
     this->i2c = i2c;
     this->address = address;
@@ -13,14 +13,15 @@
 void MjHover::begin()
 {
     this->ts->input();
+    this->reset_n->output();
     this->reset_n->write(0);
-    this->reset_n->write(1);
+    wait_ms(1);
+    this->reset_n->input();
     wait_ms(3000);
 }
 
 void MjHover::setRelease()
 {
-    this->ts->write(1);
     this->ts->input();
 }
 
@@ -37,13 +38,24 @@
 
 uint8_t MjHover::getEvent()
 {
+    this->i2c->start();
+    this->i2c->write(this->address | 1);
+    uint8_t size = this->i2c->read(1);
+    uint8_t buffer[255];
+    buffer[0] = size;
+    for (int i = 1; i < size; i++)
+    {
+        buffer[i] = this->i2c->read(i < size - 1 ? 1 : 0);
+    }
+    this->i2c->stop();
+    wait_us(100);
+    
     uint8_t data;
     uint8_t event;
-    
-    this->i2c->read(this->address, NULL, 0, true);
     for (int c = 0; c < 18; c++)
     {
-        data = (uint8_t)this->i2c->read(1);
+        data = buffer[c];
+        
         if (c == 10 && data > 1)
         {
             event = (0x01 << (data - 1)) | 0x20;
@@ -94,3 +106,4 @@
 } // namespace matsujirushi
 
 
+