HapticLib
0.7
Haptic Feedback Library for embedded systems
Main Page
Related Pages
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
generic.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2012, Leonardo Guardati <leonardo@guardati.it>
3
*
4
* Permission to use, copy, modify, and/or distribute this
5
* software for any purpose with or without fee is hereby
6
* granted, provided that the above copyright notice and this
7
* permission notice appear in all copies.
8
*
9
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS
10
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
11
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
12
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
15
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
17
* USE OR PERFORMANCE OF THIS SOFTWARE.
18
*
19
*/
117
/*
118
* The following 4 preprocessor directives, are useless; they
119
* do nothing. They are here to let doxygen generate documentation
120
* about HL_DEBUG symbol behavior.
121
* When implementing a new pattern from this file, it is recommended
122
* to remove :
123
* - the doxygen comment above
124
* - this comment
125
* - the following 4 directives.
126
*
127
*/
128
#ifndef HL_DEBUG
129
#define HL_DEBUG
130
#undef HL_DEBUG
131
#endif
132
133
#include "
hapticLib.h
"
134
170
uint8_t
genericContinuator
(
pattern_desc
*pattern)
171
{
172
haptor_desc
* tmp = NULL;
173
/*
174
* Create a handy reference for userParameters and statusParameters
175
* Note:
176
* - userParams data reside on the user program module. (main.c)
177
* - statusParams data reside on SystemDesc variable.
178
*/
179
genericUserParameters
*userParams = &pattern->
userParams
->
generic
;
180
genericStatusParameters
*statusParams = &pattern->
statusParams
.
generic
;
181
182
uint16_t increment = 0;
183
184
if
( userParams->
increment
==
smallIncrement
)
185
increment = 650;
186
else
if
( userParams->
increment
==
bigIncrement
)
187
increment = 1300;
188
else
189
increment = 1000;
190
191
if
( statusParams->
flag
== 0 )
192
{
193
statusParams->
duty
+= increment;
194
195
if
( statusParams->
duty
> 63000 )
196
statusParams->
flag
= 1;
197
}
198
else
199
{
200
statusParams->
duty
-= increment;
201
202
if
( statusParams->
duty
< 2000 )
203
{
204
// Ensure finish without vibrations (multi-haptor)
205
tmp = pattern->
activeHaptorList
;
206
while
( tmp )
207
{
208
TIM_Channel_DutyChanger
( 0, tmp->
id
);
209
tmp = tmp->
nextHaptor
;
210
}
211
212
// Removing pattern from scheduling
213
// and freeing all the haptors
214
215
cleanList
(pattern->
activeHaptorList
);
216
pattern->
name
=
Null
;
217
pattern->
userParams
= NULL;
218
pattern->
continuator
= NULL;
219
pattern->
activeHaptorList
= NULL;
220
221
return
0;
222
}
223
}
224
225
// multi-haptor
226
tmp = pattern->
activeHaptorList
;
227
while
( tmp )
228
{
229
TIM_Channel_DutyChanger
( statusParams->
duty
, tmp->
id
);
230
tmp = tmp->
nextHaptor
;
231
}
232
233
return
0;
234
}
235
272
uint8_t
genericPatternGenerator
(
pattern_desc
*pattern)
273
{
274
/*
275
* Create a handy reference for userParameters
276
* and statusParameters
277
* Note:
278
* - userParams data reside on the user
279
* program module. (main.c)
280
* - statusParams data reside on SystemDesc
281
* variable.
282
*/
283
genericUserParameters
*userParams = &pattern->
userParams
->
generic
;
284
genericStatusParameters
*statusParams = &pattern->
statusParams
.
generic
;
285
286
287
// User Parameters Validation:
288
// Input validation must be made before attempting
289
// to use the provided parameters.
290
if
( userParams == NULL )
291
{
292
#ifdef HL_DEBUG
293
send_string
(
"genericPatternGenerator(): expecting optional Parameters, NULL found.\r\n\0"
);
294
#endif
295
return
1;
296
}
297
if
( userParams->
checkParam
!=
rightValue
)
298
{
299
#ifdef HL_DEBUG
300
send_string
(
"Wrong parameter value: checkParam must be \0"
);
301
send_int
(
rightValue
);
302
send_string
(
"\r\n\0"
);
303
#endif
304
return
1;
305
}
306
307
308
// Status initialization based on user provided parameters...
309
if
( userParams->
increment
!=
bigIncrement
)
310
{
311
statusParams->
duty
= 555;
312
}
313
314
315
// ...or static status initialization
316
statusParams->
flag
= 0;
317
statusParams->
duty
= 0;
318
319
320
// Set up for scheduling.
321
pattern->
continuator
= &
genericContinuator
;
322
323
return
0;
324
}
HapticLib
patterns
generic
generic.c
Generated on Thu Jan 31 2013 02:03:32 for HapticLib by
1.8.1.1