Home | History | Annotate | Download | only in mllite
      1 /*
      2  $License:
      3    Copyright 2011 InvenSense, Inc.
      4 
      5  Licensed under the Apache License, Version 2.0 (the "License");
      6  you may not use this file except in compliance with the License.
      7  You may obtain a copy of the License at
      8 
      9  http://www.apache.org/licenses/LICENSE-2.0
     10 
     11  Unless required by applicable law or agreed to in writing, software
     12  distributed under the License is distributed on an "AS IS" BASIS,
     13  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  See the License for the specific language governing permissions and
     15  limitations under the License.
     16   $
     17  */
     18 /*******************************************************************************
     19  *
     20  * $RCSfile: mlcontrol.h,v $
     21  *
     22  * $Date: 2011-06-10 20:13:08 -0700 (Fri, 10 Jun 2011) $
     23  *
     24  * $Revision: 5629 $
     25  *
     26  *******************************************************************************/
     27 
     28 /*******************************************************************************/
     29 /** @defgroup INV_CONTROL
     30 
     31     The Control processes gyroscopes and accelerometers to provide control
     32     signals that can be used in user interfaces to manipulate objects such as
     33     documents, images, cursors, menus, etc.
     34 
     35     @{
     36         @file mlcontrol.h
     37         @brief Header file for the Control Library.
     38 */
     39 /******************************************************************************/
     40 #ifndef MLCONTROL_H
     41 #define MLCONTROL_H
     42 
     43 #ifdef __cplusplus
     44 extern "C" {
     45 #endif
     46 
     47 #include "mltypes.h"
     48 #include "ml.h"
     49 #ifdef INV_INCLUDE_LEGACY_HEADERS
     50 #include "mlcontrol_legacy.h"
     51 #endif
     52 
     53     /* ------------ */
     54     /* - Defines. - */
     55     /* ------------ */
     56 
     57     /*******************************************************************************/
     58     /* Control Signals.                                                            */
     59     /*******************************************************************************/
     60 
     61 #define INV_CONTROL_1                    0x0001
     62 #define INV_CONTROL_2                    0x0002
     63 #define INV_CONTROL_3                    0x0004
     64 #define INV_CONTROL_4                    0x0008
     65 
     66     /*******************************************************************************/
     67     /* Control Functions.                                                          */
     68     /*******************************************************************************/
     69 
     70 #define INV_GRID                         0x0001 // Indicates that the user will be controlling a system that
     71     //   has discrete steps, such as icons, menu entries, pixels, etc.
     72 #define INV_SMOOTH                       0x0002 // Indicates that noise from unintentional motion should be filtered out.
     73 #define INV_DEAD_ZONE                    0x0004 // Indicates that a dead zone should be used, below which sensor data is set to zero.
     74 #define INV_HYSTERESIS                   0x0008 // Indicates that, when INV_GRID is selected, hysteresis should be used to prevent
     75     //   the control signal from switching rapidly across elements of the grid.</dd>
     76 
     77     /*******************************************************************************/
     78     /* Integral reset options.                                                     */
     79     /*******************************************************************************/
     80 
     81 #define INV_NO_RESET                     0x0000
     82 #define INV_RESET                        0x0001
     83 
     84     /*******************************************************************************/
     85     /* Data select options.                                                        */
     86     /*******************************************************************************/
     87 
     88 #define INV_CTRL_SIGNAL                  0x0000
     89 #define INV_CTRL_GRID_NUM                0x0001
     90 
     91     /*******************************************************************************/
     92     /* Control Axis.                                                               */
     93     /*******************************************************************************/
     94 #define INV_CTRL_PITCH                   0x0000 // (INV_PITCH >> 1)
     95 #define INV_CTRL_ROLL                    0x0001 // (INV_ROLL  >> 1)
     96 #define INV_CTRL_YAW                     0x0002 // (INV_YAW   >> 1)
     97 
     98     /*******************************************************************************/
     99     /* control_params structure default values.                                   */
    100     /*******************************************************************************/
    101 
    102 #define MLCTRL_SENSITIVITY_0_DEFAULT           128
    103 #define MLCTRL_SENSITIVITY_1_DEFAULT           128
    104 #define MLCTRL_SENSITIVITY_2_DEFAULT           128
    105 #define MLCTRL_SENSITIVITY_3_DEFAULT           128
    106 #define MLCTRL_FUNCTIONS_DEFAULT                 0
    107 #define MLCTRL_CONTROL_SIGNALS_DEFAULT           0
    108 #define MLCTRL_PARAMETER_ARRAY_0_DEFAULT         0
    109 #define MLCTRL_PARAMETER_ARRAY_1_DEFAULT         0
    110 #define MLCTRL_PARAMETER_ARRAY_2_DEFAULT         0
    111 #define MLCTRL_PARAMETER_ARRAY_3_DEFAULT         0
    112 #define MLCTRL_PARAMETER_AXIS_0_DEFAULT          0
    113 #define MLCTRL_PARAMETER_AXIS_1_DEFAULT          0
    114 #define MLCTRL_PARAMETER_AXIS_2_DEFAULT          0
    115 #define MLCTRL_PARAMETER_AXIS_3_DEFAULT          0
    116 #define MLCTRL_GRID_THRESHOLD_0_DEFAULT          1
    117 #define MLCTRL_GRID_THRESHOLD_1_DEFAULT          1
    118 #define MLCTRL_GRID_THRESHOLD_2_DEFAULT          1
    119 #define MLCTRL_GRID_THRESHOLD_3_DEFAULT          1
    120 #define MLCTRL_GRID_MAXIMUM_0_DEFAULT            0
    121 #define MLCTRL_GRID_MAXIMUM_1_DEFAULT            0
    122 #define MLCTRL_GRID_MAXIMUM_2_DEFAULT            0
    123 #define MLCTRL_GRID_MAXIMUM_3_DEFAULT            0
    124 #define MLCTRL_GRID_CALLBACK_DEFAULT             0
    125 
    126     /* --------------- */
    127     /* - Structures. - */
    128     /* --------------- */
    129 
    130     /**************************************************************************/
    131     /* Control Parameters Structure.                                          */
    132     /**************************************************************************/
    133 
    134     struct control_params {
    135         // Sensitivity of control signal 1, 2, 3, and 4.
    136         unsigned short sensitivity[4];
    137         // Indicates what functions will be used. Can be a bitwise OR of INV_GRID,
    138         // ML_SMOOT, INV_DEAD_ZONE, and INV_HYSTERISIS.
    139         unsigned short functions;
    140         // Indicates which parameter array is being assigned to a control signal.
    141         // Must be one of INV_GYROS, INV_ANGULAR_VELOCITY, or
    142         // INV_ANGULAR_VELOCITY_WORLD.
    143         unsigned short parameterArray[4];
    144         // Indicates which axis of the parameter array will be used. Must be
    145         // INV_ROLL, INV_PITCH, or INV_YAW.
    146         unsigned short parameterAxis[4];
    147         // Threshold of the control signal at which the grid number will be
    148         // incremented or decremented.
    149         long gridThreshold[4];
    150         // Maximum grid number for the control signal.
    151         long gridMaximum[4];
    152         // User defined callback that will trigger when the grid location changes.
    153         void (*gridCallback) (
    154                                  // Indicates which control signal crossed a grid threshold. Must be
    155                                  // one of INV_CONTROL_1, INV_CONTROL_2, INV_CONTROL_3 or INV_CONTROL_4.
    156                                  unsigned short controlSignal,
    157                                  // An array of four numbers representing the grid number for each
    158                                  // control signal.
    159                                  long *gridNum,
    160                                  // An array of four numbers representing the change in grid number
    161                                  // for each control signal.
    162                                  long *gridChange);
    163     };
    164 
    165     struct control_obj {
    166 
    167         long gridNum[4];        // Current grid number for each control signal.
    168         long controlInt[4];     // Current data for each control signal.
    169         long lastGridNum[4];    // Previous grid number
    170         unsigned char controlDir[4];    // Direction of control signal
    171         long gridChange[4];     // Change in grid number
    172 
    173         long mlGridNumDMP[4];
    174         long gridNumOffset[4];
    175         long prevDMPGridNum[4];
    176 
    177     };
    178 
    179     /* --------------------- */
    180     /* - Function p-types. - */
    181     /* --------------------- */
    182 
    183     /**************************************************************************/
    184     /* ML Control Functions.                                                  */
    185     /**************************************************************************/
    186 
    187     unsigned short inv_get_control_params(struct control_params *params);
    188     unsigned short inv_set_control_params(struct control_params *params);
    189 
    190     /*API for handling control signals */
    191     inv_error_t inv_set_control_sensitivity(unsigned short controlSignal,
    192                                             long sensitivity);
    193     inv_error_t inv_set_control_func(unsigned short function);
    194     inv_error_t inv_get_control_signal(unsigned short controlSignal,
    195                                        unsigned short reset, long *data);
    196     inv_error_t inv_get_grid_num(unsigned short controlSignal,
    197                                  unsigned short reset, long *data);
    198     inv_error_t inv_set_grid_thresh(unsigned short controlSignal,
    199                                     long threshold);
    200     inv_error_t inv_set_grid_max(unsigned short controlSignal, long maximum);
    201     inv_error_t
    202         inv_set_grid_callback(void (*func)
    203                               (unsigned short controlSignal, long *gridNum,
    204                                long *gridChange));
    205     inv_error_t inv_set_control_data(unsigned short controlSignal,
    206                                      unsigned short parameterArray,
    207                                      unsigned short parameterNum);
    208     inv_error_t inv_get_control_data(long *controlSignal, long *gridNum,
    209                                      long *gridChange);
    210     inv_error_t inv_update_control(struct inv_obj_t *inv_obj);
    211     inv_error_t inv_enable_control(void);
    212     inv_error_t inv_disable_control(void);
    213 
    214 #ifdef __cplusplus
    215 }
    216 #endif
    217 #endif                          /* MLCONTROL_H */
    218