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

Dependents:   MjHover_Hello

Committer:
matsujirushi
Date:
Sat Apr 04 14:51:27 2015 +0000
Revision:
7:a3b72910732d
Added MjHover2 class.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
matsujirushi 7:a3b72910732d 1 #include "MjHover.h"
matsujirushi 7:a3b72910732d 2
matsujirushi 7:a3b72910732d 3 namespace matsujirushi {
matsujirushi 7:a3b72910732d 4
matsujirushi 7:a3b72910732d 5 MjHover2::MjHover2(I2C* i2c, uint8_t address, DigitalInOut* ts_n, DigitalInOut* reset_n) : MjHoverBase(i2c, address, ts_n, reset_n)
matsujirushi 7:a3b72910732d 6 {
matsujirushi 7:a3b72910732d 7 }
matsujirushi 7:a3b72910732d 8
matsujirushi 7:a3b72910732d 9 void MjHover2::Reset()
matsujirushi 7:a3b72910732d 10 {
matsujirushi 7:a3b72910732d 11 MjHoverBase::Reset();
matsujirushi 7:a3b72910732d 12
matsujirushi 7:a3b72910732d 13 while (!MjHoverBase::DataAvailable())
matsujirushi 7:a3b72910732d 14 {
matsujirushi 7:a3b72910732d 15 }
matsujirushi 7:a3b72910732d 16
matsujirushi 7:a3b72910732d 17 uint8_t id;
matsujirushi 7:a3b72910732d 18 uint8_t payload[255 - 4];
matsujirushi 7:a3b72910732d 19 uint8_t readPayloadSize;
matsujirushi 7:a3b72910732d 20 ReadMessage(&id, payload, sizeof (payload), &readPayloadSize);
matsujirushi 7:a3b72910732d 21 }
matsujirushi 7:a3b72910732d 22
matsujirushi 7:a3b72910732d 23 void MjHover2::Task()
matsujirushi 7:a3b72910732d 24 {
matsujirushi 7:a3b72910732d 25 uint8_t id;
matsujirushi 7:a3b72910732d 26 uint8_t payload[255 - 4];
matsujirushi 7:a3b72910732d 27 uint8_t readPayloadSize;
matsujirushi 7:a3b72910732d 28 if (MjHoverBase::ReadMessage(&id, payload, sizeof (payload), &readPayloadSize))
matsujirushi 7:a3b72910732d 29 {
matsujirushi 7:a3b72910732d 30 if (id == 0x91) // SENSOR_DATA_OUTPUT
matsujirushi 7:a3b72910732d 31 {
matsujirushi 7:a3b72910732d 32 this->SensorData.GestureInfoValid = false;
matsujirushi 7:a3b72910732d 33 this->SensorData.TouchInfoValid = false;
matsujirushi 7:a3b72910732d 34 this->SensorData.XyzPositionValid = false;
matsujirushi 7:a3b72910732d 35
matsujirushi 7:a3b72910732d 36 uint16_t dataOutputConfigMask = payload[0] | payload[1] << 8;
matsujirushi 7:a3b72910732d 37 uint8_t systemInfo = payload[3];
matsujirushi 7:a3b72910732d 38 uint8_t* data = &payload[4];
matsujirushi 7:a3b72910732d 39 if (dataOutputConfigMask & 0x0001) // DSPStatus
matsujirushi 7:a3b72910732d 40 {
matsujirushi 7:a3b72910732d 41 data += 2;
matsujirushi 7:a3b72910732d 42 }
matsujirushi 7:a3b72910732d 43 if (dataOutputConfigMask & 0x0002) // GestureInfo
matsujirushi 7:a3b72910732d 44 {
matsujirushi 7:a3b72910732d 45 uint32_t gestureInfo = data[0] | data[1] << 8 | data[2] << 16 | data[3] << 24;
matsujirushi 7:a3b72910732d 46 uint8_t gesture = gestureInfo & 0x0000003f;
matsujirushi 7:a3b72910732d 47 uint8_t gestureClass = (gestureInfo & 0x0000f000) >> 12;
matsujirushi 7:a3b72910732d 48 bool edgeFlick = gestureInfo & 0x00010000 ? true : false;
matsujirushi 7:a3b72910732d 49
matsujirushi 7:a3b72910732d 50 if (gestureClass == 1) // Flick gesture
matsujirushi 7:a3b72910732d 51 {
matsujirushi 7:a3b72910732d 52 if (gesture == 2)
matsujirushi 7:a3b72910732d 53 {
matsujirushi 7:a3b72910732d 54 this->SensorData.GestureInfo = edgeFlick ? EDGE_FLICK_WEST_TO_EAST : FLICK_WEST_TO_EAST;
matsujirushi 7:a3b72910732d 55 this->SensorData.GestureInfoValid = true;
matsujirushi 7:a3b72910732d 56 }
matsujirushi 7:a3b72910732d 57 else if (gesture == 3)
matsujirushi 7:a3b72910732d 58 {
matsujirushi 7:a3b72910732d 59 this->SensorData.GestureInfo = edgeFlick ? EDGE_FLICK_EAST_TO_WEST : FLICK_EAST_TO_WEST;
matsujirushi 7:a3b72910732d 60 this->SensorData.GestureInfoValid = true;
matsujirushi 7:a3b72910732d 61 }
matsujirushi 7:a3b72910732d 62 else if (gesture == 4)
matsujirushi 7:a3b72910732d 63 {
matsujirushi 7:a3b72910732d 64 this->SensorData.GestureInfo = edgeFlick ? EDGE_FLICK_SOUTH_TO_NORTH : FLICK_SOUTH_TO_NORTH;
matsujirushi 7:a3b72910732d 65 this->SensorData.GestureInfoValid = true;
matsujirushi 7:a3b72910732d 66 }
matsujirushi 7:a3b72910732d 67 else if (gesture == 5)
matsujirushi 7:a3b72910732d 68 {
matsujirushi 7:a3b72910732d 69 this->SensorData.GestureInfo = edgeFlick ? EDGE_FLICK_NORTH_TO_SOUTH : FLICK_NORTH_TO_SOUTH;
matsujirushi 7:a3b72910732d 70 this->SensorData.GestureInfoValid = true;
matsujirushi 7:a3b72910732d 71 }
matsujirushi 7:a3b72910732d 72 }
matsujirushi 7:a3b72910732d 73 data += 4;
matsujirushi 7:a3b72910732d 74 }
matsujirushi 7:a3b72910732d 75 if (dataOutputConfigMask & 0x0004) // TouchInfo
matsujirushi 7:a3b72910732d 76 {
matsujirushi 7:a3b72910732d 77 TouchInfoType touchInfo = (TouchInfoType)((data[0] | data[1] << 8) & 0x7fff);
matsujirushi 7:a3b72910732d 78 if (touchInfo != 0)
matsujirushi 7:a3b72910732d 79 {
matsujirushi 7:a3b72910732d 80 this->SensorData.TouchInfo = touchInfo;
matsujirushi 7:a3b72910732d 81 this->SensorData.TouchInfoValid = true;
matsujirushi 7:a3b72910732d 82 }
matsujirushi 7:a3b72910732d 83 data += 4;
matsujirushi 7:a3b72910732d 84 }
matsujirushi 7:a3b72910732d 85 if (dataOutputConfigMask & 0x0008) // AirWheelInfo
matsujirushi 7:a3b72910732d 86 {
matsujirushi 7:a3b72910732d 87 data += 2;
matsujirushi 7:a3b72910732d 88 }
matsujirushi 7:a3b72910732d 89 if (dataOutputConfigMask & 0x0010) // xyzPosition
matsujirushi 7:a3b72910732d 90 {
matsujirushi 7:a3b72910732d 91 if (systemInfo & 0x01)
matsujirushi 7:a3b72910732d 92 {
matsujirushi 7:a3b72910732d 93 this->SensorData.XyzPosition.X = data[0] | data[1] << 8;
matsujirushi 7:a3b72910732d 94 this->SensorData.XyzPosition.Y = data[2] | data[3] << 8;
matsujirushi 7:a3b72910732d 95 this->SensorData.XyzPosition.Z = data[4] | data[5] << 8;
matsujirushi 7:a3b72910732d 96 this->SensorData.XyzPositionValid = true;
matsujirushi 7:a3b72910732d 97 }
matsujirushi 7:a3b72910732d 98 data += 6;
matsujirushi 7:a3b72910732d 99 }
matsujirushi 7:a3b72910732d 100 }
matsujirushi 7:a3b72910732d 101 }
matsujirushi 7:a3b72910732d 102 }
matsujirushi 7:a3b72910732d 103
matsujirushi 7:a3b72910732d 104 } // namespace matsujirushi