HapticLib  0.7
Haptic Feedback Library for embedded systems
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
hl_patterns.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  */
57 #define HL_SYSTEM_FILE
58 
59 #include "hapticLib.h"
60 
61 extern system_desc SystemDesc;
62 
63 extern uint8_t genericPatternGenerator( pattern_desc * );
64 extern uint8_t testPatternGenerator( pattern_desc * );
65 extern uint8_t impactPatternGenerator( pattern_desc * );
66 extern uint8_t constantPatternGenerator( pattern_desc * );
67 
80  { NULL, \
81  genericPatternGenerator, \
82  testPatternGenerator, \
83  impactPatternGenerator, \
84  constantPatternGenerator };
85 
101 {
102  uint8_t i=0;
103 
104  for( i=0; i < SystemDesc.num_haptors ; i++ )
105  {
106  if( SystemDesc.patterns[i].continuator )
107  {
108  if( SystemDesc.patterns[i].continuator( &SystemDesc.patterns[i] ) )
109  {
110 #ifdef HL_DEBUG
111  send_string("patternScheduler(): Problem invoking continuator \0");
112  send_int( i );
113  send_string("\r\n\0");
114 #endif
115  }
116  }
117  }
118 
119 }
120 
131 void cleanList(haptor_desc *haptor)
132 {
133  haptor_desc *tmp = NULL;
134 
135  while( haptor )
136  {
137  tmp = haptor->nextHaptor;
138 
139  haptor->nextHaptor = NULL;
140  haptor->activePattern = NULL;
141 
142  haptor = tmp;
143  }
144 }
145 
163 uint16_t dutyConverter(uint16_t duty, haptor_desc *haptor)
164 {
165  return duty*(haptor->max_duty - haptor->min_duty)/65535 + haptor->min_duty;
166 }