Hover!( Microchip MGC3130 ) library. Now, it is development version. http://www.hoverlabs.co/#hover https://www.switch-science.com/catalog/2124/
MjHover.cpp
- Committer:
- matsujirushi
- Date:
- 2015-02-28
- Revision:
- 1:8e9c00c59101
- Parent:
- 0:051e1e753af5
- Child:
- 2:46cf70365584
File content as of revision 1:8e9c00c59101:
#include "MjHover.h" namespace matsujirushi { MjHover::MjHover(I2C* i2c, uint8_t address, DigitalInOut* ts, DigitalOut* reset_n) { this->i2c = i2c; this->address = address; this->ts = ts; this->reset_n = reset_n; } void MjHover::begin() { this->ts->input(); this->reset_n->write(0); this->reset_n->write(1); wait_ms(3000); } void MjHover::setRelease() { this->ts->write(1); this->ts->input(); } bool MjHover::getStatus() { if (this->ts->read() == 0) { this->ts->output(); this->ts->write(0); return false; } return true; } uint8_t MjHover::getEvent() { 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); if (c == 10 && data > 1) { event = (0x01 << (data - 1)) | 0x20; return event; } if (c == 14 && data > 0x1f) { event = ((data & 0xe0) >> 5) | 0x40; return event; } if (c == 15 && data > 0) { event = ((data & 0x03) << 3) | 0x40; return event; } } return 0x00; } const char* MjHover::getEventString(uint8_t eventByte) { switch (eventByte) { case 0x22: return "Right Swipe"; case 0x24: return "Left Swipe"; case 0x28: return "Up Swipe"; case 0x30: return "Down Swipe"; case 0x41: return "Tap South"; case 0x42: return "Tap West"; case 0x50: return "Tap Center"; case 0x48: return "Tap East"; case 0x44: return "Tap North"; default: return ""; } } } // namespace matsujirushi