1 #ifndef KEYNETIKPEDOMETER_H
2 #define KEYNETIKPEDOMETER_H
3 /*
4 ============================================================================
5  Name        : KeynetikPedometer.h
6  Author      : KEYnetik, Inc.
7  Version     :
8  Copyright   : Copyright 2011 by KEYnetik, Inc.
9  Description : Pedometry interface for Freescale MMA9553L Pedometer project
10 ============================================================================
11 */
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 #include <stdint.h>
18 
19 typedef struct KeynetikConfig
20 {
21     uint8_t steplength; /* Step length in centimeters. If the value is 0 it will automatically calculate the user's step
22                            length from their gender and height. */
23     uint8_t height;     /* Height in centimeters. This is used to estimate the step length if steplength is set to 0. */
24     uint8_t weight;     /* Weight in kilograms. This is used to estimate the calories burned. */
25     uint8_t filtersteps; /* Number of steps that must occur within the filtertime in order to decide that the user is
26                             making steps. If this is set to 0, then the step filtering is disabled. */
27     struct
28     {
29         uint8_t
30             filtertime : 7; /* Number of seconds in which filtersteps occur to decide that the user is making steps. If
31                                this is set to 0, then the step filtering is disabled. */
32         uint8_t male : 1;   /* Set to 1 for a male user, or 0 for a female user. */
33     } bits;
34     uint8_t
35         speedperiod; /* Length of the time window for speed calculation, in seconds. The allowable range is from 1 to 5.
36                         If the value specified is greater than 5, it will be reset to 5, 0 will be reset to 1 */
37     uint8_t stepthreshold; /* Step threshold value, in 1000ths of G. Set to 0 to use the default of 130 (0.13G). */
38     /* Higher values will make the pedometer less sensitive, lower values may lead to false positives. */
39 } KeynetikConfig;
40 
41 /*
42 * Pedometry staistcics (since last KeynetikInitialize), populated by the latest call to KeynetikHandleIncomingEvent:
43 */
44 /*
45 * Step count
46 */
47 extern unsigned int keynetikStepCount;
48 /*
49 * Distance covered (in meters)
50 */
51 extern unsigned int keynetikDistance;
52 /*
53 * Average speed (in meters per hour).
54 */
55 extern unsigned short keynetikSpeed;
56 /*
57 * Calories buirned (since last KeynetikInitialize), populated by the latest call to KeynetikHandleIncomingEvent.
58 */
59 extern unsigned int keynetikCalories;
60 
61 /*
62 * Current activity level, updated with every call to KeynetikHandleIncomingEvent
63 */
64 typedef enum
65 {
66     KeynetikActivityUnknown = 0,
67     KeynetikActivityRest = 1,
68     KeynetikActivityWalking = 2,
69     KeynetikActivityJogging = 3,
70     KeynetikActivityRunning = 4
71 } KeynetikActivityLevel;
72 extern KeynetikActivityLevel keynetikActivityLevel;
73 
74 /**
75 * Initialize the Keynetik library.
76 * \param oneG Value of 1G
77 * \param frequencyHz Accelerometer polling frequency, in readings per second
78 * \param isMale User's gender: 0 for female, non-0 for male
79 * \param heightCm User's height in centimeters. May be 0 if a custom stride length is to be used
80 * \param weightCm User's weight in kilograms
81 * \param strideCm Custom stride length in centimeters, or 0 for a standard stride length based on gender and height
82 * \param stepDelay Number of steps to expect before counting any steps (0 to turn off step filtering)
83 * \param delayWindow Amount of time within which these steps must be detected (in seconds; 0 to turn off step filtering)
84 */
85 void KeynetikInitialize(unsigned short oneG, unsigned short frequencyHz, KeynetikConfig *config);
86 
87 #define KEYNETIK_STEP 1
88 #define KEYNETIK_ACTIVITYCHANGED 2
89 /**
90 * Process an accelerometer reading and report detected events if any.
91 * \param x X axis reading
92 * \param y Y axis reading
93 * \param z Z axis reading
94 * \return combination of flags KEYNETIK_STEP and KEYNETIK_ACTIVITYCHANGED
95 */
96 unsigned int KeynetikHandleIncomingEvent(int x, int y, int z);
97 
98 /**
99 * Clear the collected data. Can be used after a period of skipped readings to re-initialize processing.
100 */
101 void KeynetikReset();
102 
103 /**
104 * Finalize the Keynetik library.
105 */
106 void KeynetikTerminate();
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif
113