From e7fe989d5d1269dfb94734478b1e56de0ad10e41 Mon Sep 17 00:00:00 2001 From: sshikhare Date: Sun, 30 Aug 2015 22:09:05 -0700 Subject: [PATCH] Added Airwheel feature to Hover Library and modified example code to demonstrate Airwheel functionality --- Hover/Hover.cpp | 12 +++++++++++- Hover/Hover.h | 15 ++++++++++++--- Hover/examples/HoverDemo/HoverDemo.ino | 12 +++++++++++- Hover/keywords.txt | 3 ++- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/Hover/Hover.cpp b/Hover/Hover.cpp index adabdce..8b2f5fc 100644 --- a/Hover/Hover.cpp +++ b/Hover/Hover.cpp @@ -109,8 +109,19 @@ Gesture Hover::getGesture(void) { return Gesture(gtype, gid, gval); } +Airwheel::Airwheel (uint16_t value){ + wheelValue = value; +} + +Airwheel Hover::getAirWheelData(void){ + uint16_t value; + value = _dat[19] << 8 | _dat[18]; + return Airwheel(value); +} + void Hover::readGestureData(char * gtype, uint8_t * gid, uint8_t * gval) { + switch (_dat[10]){ case 2: strcpy(gtype, "Right Swipe"); @@ -141,7 +152,6 @@ void Hover::readGestureData(char * gtype, uint8_t * gid, uint8_t * gval) { } - Touch::Touch(){ strcpy(touchType, "none"); touchID = 0; diff --git a/Hover/Hover.h b/Hover/Hover.h index 21b8efc..7d42038 100644 --- a/Hover/Hover.h +++ b/Hover/Hover.h @@ -36,6 +36,12 @@ class Gesture { uint8_t gestureValue; }; +class Airwheel { + public: + Airwheel(uint16_t wheelValue); + uint16_t wheelValue; +}; + class Touch { public: Touch(); @@ -51,15 +57,19 @@ class Position { uint16_t x, y, z; }; + + class Hover { public: Hover(uint8_t ts, uint8_t rst, uint8_t gestmode, uint8_t touchmode, uint8_t tapmode, uint8_t posmode); void begin(); Position getPosition(void); Gesture getGesture(void); + Airwheel getAirWheelData(void); Touch getTouch(void); void readI2CData(void); - + + private: boolean _valid; uint8_t _dat[26], _i2caddr, _ts, _rst, _gestmode, _touchmode, _tapmode, _posmode; @@ -68,8 +78,7 @@ class Hover { void readPositionData(uint16_t *x, uint16_t *y, uint16_t *z); void readGestureData(char * gtype, uint8_t * gid, uint8_t * gval); void readTouchData(char * ttype, uint8_t * tid, uint8_t * tval); - }; -#endif \ No newline at end of file +#endif diff --git a/Hover/examples/HoverDemo/HoverDemo.ino b/Hover/examples/HoverDemo/HoverDemo.ino index 34e24fa..3bf133f 100644 --- a/Hover/examples/HoverDemo/HoverDemo.ino +++ b/Hover/examples/HoverDemo/HoverDemo.ino @@ -69,11 +69,15 @@ | 3D Position | 0 to 100 | 0 to 100 | 0 to 100 | ------------------------------------------------------------- + ============================================================= + | Airwheel Data - 2 bytes + ============================================================= # HISTORY v1.0 - Initial Release v2.0 - Standardized Output Definition, On Github v2.1 - Fixed Count Issue, Update Output String with examples v3.0 - Major library update -- added 3D Position, Touch, Double Tap + v3.1 - Added Airwheel detection data output feature # INSTALLATION The 3 library files (Hover.cpp, Hover.h and keywords.txt) in the Hover folder should be placed in your Arduino Library folder. @@ -123,7 +127,13 @@ void loop(void) { Gesture g = hover.getGesture(); Touch t = hover.getTouch(); Position p = hover.getPosition(); - + Airwheel a = hover.getAirWheelData(); + + //Read Airwheel gesture value + if(a.wheelValue) + { + Serial.print("Airwheel: "); Serial.print(a.wheelValue); Serial.print("\r\n"); + } // print Gesture data if ( g.gestureID != 0){ Serial.print("Event: "); Serial.print(g.gestureType); Serial.print("\t"); diff --git a/Hover/keywords.txt b/Hover/keywords.txt index 600e75f..d430f65 100644 --- a/Hover/keywords.txt +++ b/Hover/keywords.txt @@ -11,4 +11,5 @@ readI2CData KEYWORD2 getGesture KEYWORD2 readGestureData KEYWORD2 getTouch KEYWORD2 -readTouchData KEYWORD2 \ No newline at end of file +readTouchData KEYWORD2 +getAirWheelData KEYWORD2