ISSDK  1.7
IoT Sensing Software Development Kit
pedometer.h
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
4  * Copyright 2016-2017 NXP
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted (subject to the limitations in the disclaimer below) provided
9  * that the following conditions are met:
10  *
11  * o Redistributions of source code must retain the above copyright notice, this list
12  * of conditions and the following disclaimer.
13  *
14  * o Redistributions in binary form must reproduce the above copyright notice, this
15  * list of conditions and the following disclaimer in the documentation and/or
16  * other materials provided with the distribution.
17  *
18  * o Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /**
36 * @file pedometer.h
37 * @brief The pedometer.h file contains the interface and structure definitions for
38 * pedometer application.
39 */
40 
41 #ifndef PEDOMETER_H_
42 #define PEDOMETER_H_
43 
44 #include <stddef.h>
45 #include <stdint.h>
46 #include <stdbool.h>
47 #include "KeynetikPedometer.h"
48 /******************************************************************************
49  * Public Datatypes
50  *****************************************************************************/
51 
52 typedef KeynetikActivityLevel activitylevel_t; /* alias to a shorter name for readability */
53 typedef uint16_t debounce_count_t;
54 #define PEDO_ONEG_8G 4096 /* One G value for 8G mode.*/
55 #define PEDO_ONEG_4G 8192 /* One G value for 4G mode.*/
56 #define PEDO_ONEG_2G 16384 /* One G value for 2G mode.*/
57 #define PEDO_FREQHZ_DEFAULT 50 /* Default frequency*/
58 #define PEDO_STEP_THRESHOLD_DEFAULT 130
59 #define PEDO_SPEED_PERIOD_DEFAULT 5
60 #define PEDO_FILTER_TIME_DEFAULT 3
61 #define PEDO_FILTER_STEPS_DEFAULT 4
62 /*!
63  * @brief This defines the acceleration input data for the pedometer.
64  */
65 typedef struct
66 {
67  int16_t accel[3];
68 } ped_accel_t;
69 /*!
70  * @brief This defines the configuration structure of the pedometer.
71  */
72 typedef struct
73 {
74  uint16_t sleepminimum; /* Sleep vector magnitude minimum */
75  uint16_t sleepmaximum; /* Sleep vector magnitude maximum */
76  debounce_count_t sleepcount_threshold; /* Sleep debounce counter threshold */
77  struct
78  {
79  uint8_t : 5; /* Reserved */
80  bool sleep_dbcntm : 1; /* Sleep debounce counter mode. Set to 1 to clear the debounce counter when the test
81  condition fails, otherwise decrement. */
82  bool activity_dbcntm : 1; /* Activity debounce counter mode. Set to 1 to clear the debounce counter when the
83  test condition fails, otherwise decrement. */
84  bool config : 1; /* Set to 1 to initialize the pedometer and configure it with the other configuration
85  variables. */
86  } bits;
87  KeynetikConfig keynetik; /* Keynetik parameters (step length, height, weight, etc) */
88  debounce_count_t activitycount_threshold; /* Activity debounce counter threshold */
89  uint8_t stepcoalesce; /* Number of steps to coalesce for step interrupt */
90  uint16_t oneG; /* One G value for the range at accelerometer is running. refer the data sheet of the accelerometer
91  and compute this value.
92  eg. 2G Mode, 1G is 4096.*/
93  uint16_t frequency; /* The frequency at which accelerometer runs in HZ. best set frequencies are 25HZ or 50HZ. It
94  can run at higher too.*/
96 /*!
97  * @brief This defines the pedometer instance.
98  */
99 typedef struct
100 {
102  {
103  union
104  {
105  struct
106  {
107  activitylevel_t activity : 3; /* Activity level. */
108  bool suspend : 1; /* Pedometer autonomously suspended. */
109  bool activitychange : 1; /* Change in activity level. */
110  bool stepchange : 1; /* Change in step count. */
111  bool suspendchange : 1; /* Change in suspend state .*/
112  bool mergedflags : 1; /* Merged status flags. */
113  } bits;
114  uint8_t byte;
115  } status;
116  uint8_t version; /* Pedometer version number. */
117  uint16_t stepcount; /* Step count. */
118  uint16_t distance; /* Total distance in meters or activity state. */
119  uint16_t speed; /* Average speed in meters per hour. The value is updated on the completion of each step. */
120  uint16_t calories; /* Calorie count expended. */
121  debounce_count_t sleepcount; /* Sleep debounce counter. */
122  } status;
123  pedometer_config_t config; /* Pedometer configuration.*/
125  {
126  debounce_count_t activitycount; /* Activity debounce counter. */
127  uint16_t stepchg_stepcount; /* Step count at last stepchange interrupt (for step coalesing) */
128  } private;
129 } pedometer_t;
130 
131 /******************************************************************************
132  * Public Function Declarations
133  ******************************************************************************/
134 /*******************************************************************************
135  * API
136  ******************************************************************************/
137 /*! @brief The interface function initialize the pedometer.
138  * @details This function initialize the pedometer structure and return the handle.
139 
140  * @param[in] pPedometer handle to the pedometer.
141  *
142  * @return void.
143  *
144  * @Constraints None
145  *
146  * @Reentrant Yes
147  */
148 void pedometer_init(pedometer_t *pPedometer);
149 
150 /*! @brief The interface function to configure the pedometer.
151  *
152  * @param[in] pedometer_t handle to the pedometer.
153  * @param[in] config configuration value.
154  *
155  * @return void.
156  *
157  * @Constraints None
158  *
159  * @Reentrant Yes
160  */
161 void pedometer_configure(pedometer_t *pPedometer, const pedometer_config_t *pConfig);
162 /*! @brief The interface function excutes the pedometer algorithm.
163  * @details Call this function the rate at which accelerometer runs.
164 
165  * @param[in] pPedometer handle to the pedometer.
166  * @param[in] accel_data acceleration data.
167  * @return ::pedometer_run() returns the status .
168  *
169  * @Constraints None
170  *
171  * @Reentrant Yes
172  */
173 int32_t pedometer_run(pedometer_t *pPedometer, ped_accel_t *pData);
174 
175 #endif // PEDOMETER_H_
int32_t pedometer_run(pedometer_t *pPedometer, ped_accel_t *pData)
The interface function excutes the pedometer algorithm.
Definition: pedometer.c:151
pedometer_config_t config
Definition: pedometer.h:123
This defines the configuration structure of the pedometer.
Definition: pedometer.h:72
uint16_t sleepmaximum
Definition: pedometer.h:75
int32_t status
This defines the acceleration input data for the pedometer.
Definition: pedometer.h:65
uint16_t sleepminimum
Definition: pedometer.h:74
This defines the pedometer instance.
Definition: pedometer.h:99
KeynetikActivityLevel activitylevel_t
Definition: pedometer.h:52
debounce_count_t sleepcount_threshold
Definition: pedometer.h:76
KeynetikConfig keynetik
Definition: pedometer.h:87
void pedometer_init(pedometer_t *pPedometer)
The interface function initialize the pedometer.
Definition: pedometer.c:123
debounce_count_t activitycount_threshold
Definition: pedometer.h:88
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
void pedometer_configure(pedometer_t *pPedometer, const pedometer_config_t *pConfig)
The interface function to configure the pedometer.
Definition: pedometer.c:137
uint16_t frequency
Definition: pedometer.h:93
uint16_t debounce_count_t
Definition: pedometer.h:53
uint8_t stepcoalesce
Definition: pedometer.h:89