The MGC3130 is the world’s first electrical-field (E-field) based three-dimensional (3D) tracking and gesture controller

Dependencies:   BufferedArray

Dependents:   NucleoMGC3130 i2c_master

Files at this revision

API Documentation at this revision

Comitter:
yangcq88517
Date:
Thu Oct 08 17:37:33 2015 +0000
Parent:
2:c7d984193741
Child:
4:6d639fd23628
Commit message:
bug fix, add some runtime message

Changed in this revision

MGC3130.cpp Show annotated file Show diff for this revision Revisions of this file
MGC3130.h Show annotated file Show diff for this revision Revisions of this file
RuntimeParameter/CalibrationMode.h Show annotated file Show diff for this revision Revisions of this file
RuntimeParameter/GestureProcessing.h Show annotated file Show diff for this revision Revisions of this file
RuntimeParameter/MakePersistent.h Show annotated file Show diff for this revision Revisions of this file
RuntimeParameter/Trigger.h Show annotated file Show diff for this revision Revisions of this file
--- a/MGC3130.cpp	Thu Oct 08 11:14:18 2015 +0000
+++ b/MGC3130.cpp	Thu Oct 08 17:37:33 2015 +0000
@@ -15,10 +15,16 @@
 
 GestICMsg * MGC3130::readMsg()
 {
+    int count = 0;
     TS_Line.input();
-    while (TS_Line.read() == 0)
+    while (TS_Line.read() == 0) {
         wait_us(200);
+        count++;
 
+        // time out after 20 ms
+        if (count > 100)
+            return NULL;
+    }
     msg.reset();
 
     TS_Line.output();
@@ -62,8 +68,7 @@
 
     _i2c_bus.stop();
 
-    if (readMsg() == NULL || msg.getID() != GestICMsg::System_Status)
-        return -1;
+    while (readMsg() == NULL || msg.getID() != GestICMsg::System_Status);
 
     return msg.get(6) | (msg.get(7) << 8);
 }
\ No newline at end of file
--- a/MGC3130.h	Thu Oct 08 11:14:18 2015 +0000
+++ b/MGC3130.h	Thu Oct 08 17:37:33 2015 +0000
@@ -10,6 +10,10 @@
 #include "ApproachDetection.h"
 #include "TouchInfo.h"
 #include "OutputEnable.h"
+#include "Trigger.h"
+#include "MakePersistent.h"
+#include "CalibrationMode.h"
+#include "GestureProcessing.h"
 
 /**
 * Outlines the function of the Library’s I2C message interface, and contains the complete message reference to control and operate the MGC3X30 system.
@@ -47,7 +51,7 @@
     *
     * @param sda I2C sda signal
     * @param scl I2C scl signal
-    * @param ET0
+    * @param EI0 transfer status line
     * @param IS2 High->true, Low->false
     *
     */
@@ -68,7 +72,7 @@
     *0x0000 NoError OK
     *0x0001 UnknownCommand Message ID is unknown
     *0x0002 InvalidSessionId Session ID is invalid or does not match (0x0 is not allowed) (message Fw_Update_Start, Fw_Update_Completed)
-    *0x003 InvalidCrc CRC is invalid thrown by messages: Fw_Update_Block, Fw_Update_Start, Fw_Update_Completed
+    *0x0003 InvalidCrc CRC is invalid thrown by messages: Fw_Update_Block, Fw_Update_Start, Fw_Update_Completed
     *0x0004 InvalidLength Length is invalid (message Fw_Update_Block)
     *0x0005 InvalidAddress Address is invalid (message Fw_Update_Block)
     *0x0006 InvalidFunction Function-Id is invalid (message Fw_Update_Start, Fw_Update_Block, Fw_Update_Completed)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RuntimeParameter/CalibrationMode.h	Thu Oct 08 17:37:33 2015 +0000
@@ -0,0 +1,58 @@
+#ifndef UK_AC_HERTS_SMARTLAB_MGC3130_CalibrationMode
+#define UK_AC_HERTS_SMARTLAB_MGC3130_CalibrationMode
+
+#include "Parameter.h"
+
+/** This parameter enables/disables the selected auto-calibration feature.
+*If a bit in Argument0 is set to ‘0’, the respective auto-calibration feature will be enabled.
+*If a bit in Argument0 is set to ‘1’ the respective auto-calibration feature will be disabled.
+*/
+class CalibrationMode: public Parameter
+{
+public:
+    CalibrationMode() {
+        setRuntimeParameterID(0x80);
+    }
+
+    /// Enable/disable gesture-triggered calibration.
+    void enableGestureTriggered(bool enable) {
+        if (enable)
+            value[4] |= 0xFE;
+        else value[4] &= 0x01;
+        value[8] |= 0x01;
+    }
+
+    /// Enable/disable negative calibration.
+    void enableNegative(bool enable) {
+        if (enable)
+            value[4] |= 0xFD;
+        else value[4] &= 0x02;
+        value[8] |= 0x02;
+    }
+
+    /// Enable/disable idle calibration.
+    void enableIdle(bool enable) {
+        if (enable)
+            value[4] |= 0xFB;
+        else value[4] &= 0x04;
+        value[8] |= 0x04;
+    }
+
+    /// Enable/disable invalidity value calibration, if values are completely out of range.
+    void enableInvalidityValue(bool enable) {
+        if (enable)
+            value[4] |= 0xF7;
+        else value[4] &= 0x08;
+        value[8] |= 0x08;
+    }
+
+    /// Enable/disable calibration triggered by AFA
+    void enableTriggeredAFA(bool enable) {
+        if (enable)
+            value[4] |= 0xEF;
+        else value[4] &= 0x10;
+        value[8] |= 0x10;
+    }
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RuntimeParameter/GestureProcessing.h	Thu Oct 08 17:37:33 2015 +0000
@@ -0,0 +1,153 @@
+#ifndef UK_AC_HERTS_SMARTLAB_MGC3130_GestureProcessing
+#define UK_AC_HERTS_SMARTLAB_MGC3130_GestureProcessing
+
+#include "Parameter.h"
+
+/**
+*This parameter enables the in-built gestures. Disabling one gesture will increase the
+*recognition probability of the others.
+*If a bit in Argument0 is set To ‘1’, the respective Gesture will be enabled. If a bit in
+*Argument0 is set To ‘0’, the respective Gesture will be disabled.
+*/
+class GestureProcessing: public Parameter
+{
+public:
+    GestureProcessing() {
+        setRuntimeParameterID(0x85);
+    }
+
+    void enableGarbageModel(bool enable) {
+        if (enable)
+            value[4] |= 0x01;
+        else value[4] &= 0xFE;
+        value[8] |= 0x01;
+    }
+
+    void enableFlickWesToEast(bool enable) {
+        if (enable)
+            value[4] |= 0x02;
+        else value[4] &= 0xFD;
+        value[8] |= 0x02;
+    }
+
+    void enableFlickEastToWest(bool enable) {
+        if (enable)
+            value[4] |= 0x04;
+        else value[4] &= 0xFB;
+        value[8] |= 0x04;
+    }
+
+    void enableFlickSouthToNorth(bool enable) {
+        if (enable)
+            value[4] |= 0x08;
+        else value[4] &= 0xF7;
+        value[8] |= 0x08;
+    }
+
+    void enableFlickNorthToSouth(bool enable) {
+        if (enable)
+            value[4] |= 0x10;
+        else value[4] &= 0xEF;
+        value[8] |= 0x10;
+    }
+
+    void enableCircleClockwise(bool enable) {
+        if (enable)
+            value[4] |= 0x20;
+        else value[4] &= 0xDF;
+        value[8] |= 0x20;
+    }
+
+    void enableCircleCounterclockwise(bool enable) {
+        if (enable)
+            value[4] |= 0x40;
+        else value[4] &= 0xBF;
+        value[8] |= 0x40;
+    }
+
+    void enableWaveX(bool enable) {
+        if (enable)
+            value[4] |= 0x80;
+        else value[4] &= 0x7F;
+        value[8] |= 0x80;
+    }
+
+    void enableWaveY(bool enable) {
+        if (enable)
+            value[5] |= 0x01;
+        else value[5] &= 0xFE;
+        value[9] |= 0x01;
+    }
+
+    void enableHoldGesture(bool enable) {
+        if (enable)
+            value[6] |= 0x40;
+        else value[6] &= 0xBF;
+        value[10] |= 0x40;
+    }
+
+    void enablePresenceGesture(bool enable) {
+        if (enable)
+            value[6] |= 0x80;
+        else value[6] &= 0x7F;
+        value[10] |= 0x80;
+    }
+
+    void enableEdgeFlickWestToEast(bool enable) {
+        if (enable)
+            value[7] |= 0x01;
+        else value[7] &= 0xFE;
+        value[11] |= 0x01;
+    }
+
+    void enableEdgeFlickEastToWest(bool enable) {
+        if (enable)
+            value[7] |= 0x02;
+        else value[7] &= 0xFD;
+        value[11] |= 0x02;
+    }
+
+    void enableEdgeFlickSouthToNorth(bool enable) {
+        if (enable)
+            value[7] |= 0x04;
+        else value[7] &= 0xFB;
+        value[11] |= 0x04;
+    }
+
+    void enableEdgeFlickNorthToSouth(bool enable) {
+        if (enable)
+            value[7] |= 0x08;
+        else value[7] &= 0xF7;
+        value[11] |= 0x08;
+    }
+
+    void enableDoubleFlickWestToEast(bool enable) {
+        if (enable)
+            value[7] |= 0x10;
+        else value[7] &= 0xEF;
+        value[11] |= 0x10;
+    }
+
+    void enableDoubleFlickEastToWest(bool enable) {
+        if (enable)
+            value[7] |= 0x20;
+        else value[7] &= 0xDF;
+        value[11] |= 0x20;
+    }
+
+    void enableDoubleFlickSouthToNorth(bool enable) {
+        if (enable)
+            value[7] |= 0x40;
+        else value[7] &= 0xBF;
+        value[11] |= 0x40;
+    }
+
+    void enableDoubleFlickNorthToSouth(bool enable) {
+        if (enable)
+            value[7] |= 0x80;
+        else value[7] &= 0x7F;
+        value[11] |= 0x80;
+    }
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RuntimeParameter/MakePersistent.h	Thu Oct 08 17:37:33 2015 +0000
@@ -0,0 +1,31 @@
+#ifndef UK_AC_HERTS_SMARTLAB_MGC3130_MakePersistent
+#define UK_AC_HERTS_SMARTLAB_MGC3130_MakePersistent
+
+#include "Parameter.h"
+
+/// Make the parameter set defined in Argument0 persistent (store to Flash memory).
+class MakePersistent: public Parameter
+{
+public:
+    /// The default setting will be Store RTPs for AFE Category.
+    MakePersistent() {
+        setRuntimeParameterID(0xFF00);
+    }
+
+    /// Store RTPs for AFE Category.
+    void StoreRTPsAFECategory() {
+        setArgument0(0x00000000);
+    }
+
+    /// Store RTPs for DSP Category.
+    void StoreRTPsDSPCategory() {
+        setArgument0(0x00000001);
+    }
+
+    /// Store RTPs for System Category.
+    void StoreRTPsSystemCategory() {
+        setArgument0(0x00000002);
+    }
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RuntimeParameter/Trigger.h	Thu Oct 08 17:37:33 2015 +0000
@@ -0,0 +1,44 @@
+#ifndef UK_AC_HERTS_SMARTLAB_MGC3130_Trigger
+#define UK_AC_HERTS_SMARTLAB_MGC3130_Trigger
+
+#include "Parameter.h"
+
+class Trigger: public Parameter
+{
+public:
+    /// The default setting will be force re-calibration.
+    Trigger() {
+        setRuntimeParameterID(0x1000);
+    }
+
+    /// Force re-calibration.
+    void ForceRecalibration() {
+        setArgument0(0x00);
+    }
+
+    /**
+    *Enter Deep Sleep 1: The wake-up sources from
+    *Deep Sleep 1 are I2C0 Start bit detection or
+    *MCLR Reset.
+    *The system will resume from Deep Sleep on any
+    *I2C messages sent on the bus, and the first I2C
+    *message will be lost.
+    */
+    void EnterDeepSleep1() {
+        setArgument0(0x00000002);
+    }
+
+    /**
+    *Enter Deep Sleep 2: The wake-up source from
+    *Deep Sleep 2 is a falling edge on External Interrupt
+    *(IRQ0) or MCLR Reset.
+    *The IRQ0 (EIO2) should be tied to High when this
+    *command is sent unless the MGC3X30 resumes
+    *directly after receiving it.
+    */
+    void EnterDeepSleep2() {
+        setArgument0(0x00000003);
+    }
+};
+
+#endif
\ No newline at end of file