HapticLib  0.7
Haptic Feedback Library for embedded systems
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
hl_patterns.h File Reference

Pattern Generator Module headers More...

#include <stdint.h>
#include <stdlib.h>
#include "test.h"
#include "generic.h"
#include "impact.h"
#include "constant.h"

Go to the source code of this file.

Data Structures

union  status_param
 Pattern specific status parameters container. More...
union  user_param
 Pattern specific optional user parameters container. More...
struct  pattern_desc
 Pattern descriptor. More...

Macros

#define MAX_PATTERNS   10
 Number of patterns known in the System.

Typedefs

typedef enum pattern_name pattern_name
 Index of pattern names.
typedef union status_param status_param
 Pattern specific status parameters container.
typedef union user_param user_param
 Pattern specific optional user parameters container.
typedef uint8_t(* pattern_continuator )(struct pattern_desc *)
 Pattern Generator Continuator callback function pointer.
typedef struct pattern_desc pattern_desc
 Pattern descriptor.
typedef uint8_t(* pattern_initiator )(pattern_desc *)
 Pattern Generation Initiator callback function pointer.

Enumerations

enum  pattern_name {
  Null, Generic, Test, Impact,
  Constant, Num_Patterns_Available
}
 Index of pattern names. More...

Functions

void patternScheduler (void)
 Updates all the active patterns' progress.
void cleanList (struct haptor_desc *)
 Utility function to clean the pattern list of haptors.
uint16_t dutyConverter (uint16_t, struct haptor_desc *)
 Utility function to convert duty-cycles.

Detailed Description

Pattern Generator Module headers

hl_patterns.h is part of the Pattern Generator Module of HapticLib.

In this file there are all the general definitions needed by HapticLib to call a pattern (the code specific to a particular pattern is in its pattern code module).

Todo:
Define Return values constants for pattern generators.
Authors:
Leonardo Guardati
Silvio Vallorani
Version:
0.7
Date:
2012

Definition in file hl_patterns.h.


Macro Definition Documentation

#define MAX_PATTERNS   10

Number of patterns known in the System.

This is the number of different pattern offered by the library.

There could be use cases where System resources (low memory) impose to lower this number; the result is that only the first MAX_PATTERNS patterns are available to the user.

Note:
MAX_PATTERNS does not refer to the maximum number of pattern running simultaneously, instead is the number of them that can be loaded in a running application and then called. ( MAX_HAPTORS is the maximum number of running pattern instances).
Todo:
Implement a re-mapping mechanism to easily allow the user the selection of some specific patterns discarding the others.

Definition at line 84 of file hl_patterns.h.


Typedef Documentation

typedef uint8_t(* pattern_continuator)(struct pattern_desc *)

Pattern Generator Continuator callback function pointer.

Before reading about this function pointer, please read HapticLib Architecture and Developer documentation pages.

This pointer is used by HapticLib code to transparently call the pattern continuator code of the right pattern.

A running pattern instance is active if its descriptor (pattern_desc) holds a valid pattern_continuator reference.

When hl_startPattern() is called by the user application, the right pattern initiator is called. The initiator, after some validation checks, sets the continuator callback function pointer for the passed pattern_desc.

Definition at line 202 of file hl_patterns.h.

typedef struct pattern_desc pattern_desc

Pattern descriptor.

The pattern descriptor holds all the relevant information about a pattern being run on a specific haptor.

typedef uint8_t(* pattern_initiator)(pattern_desc *)

Pattern Generation Initiator callback function pointer.

Before reading about this function pointer, please read HapticLib Architecture and Developer documentation pages.

This pointer is used by HapticLib code to transparently call the pattern initiator code of the right pattern.

HapticLib declares patternMap ; it is an array of pattern_initiators. The index of this array is a pattern_name element. Each element points to the right Pattern Generator's Initiator callback function.

Definition at line 251 of file hl_patterns.h.

typedef enum pattern_name pattern_name

Index of pattern names.

This enumeration makes it easy to index arrays with the name of a particular pattern.

Previous versions of HapticLib used #define directives for this purpose.

The advantage of using an enumeration type definition is code and debug readability.

typedef union status_param status_param

Pattern specific status parameters container.

This type definition is useful to increase the readability of the code and to enforce compiler type checking when passing arguments to functions.

The status parameters are intended only for the pattern developer. These parameters are not exposed outside the pattern module.

See also:
Please refer to the generic Pattern Template Generator ( generic.c ) for usage example of the status parameters.
typedef union user_param user_param

Pattern specific optional user parameters container.

This type definition is useful to increase the readability of the code and to enforce compiler type checking when passing parameters to patterns.

Usage example of the Impact Pattern:

                        ...
                        haptor_desc *myHaptor = hl_configure(24000000,10,1);

                        pattern_desc *myImpactPattern;

                        user_param myParams;

                        myParams.impact.velocity = Fast;
                        myParams.impact.material = Rubber;

                        myImpactPattern = hl_initPattern(Impact,&myParams);

                        hl_addHaptor(myHaptor,myImpactPattern);

                        hl_startPattern(myImpactPattern);
                        ...

Enumeration Type Documentation

Index of pattern names.

This enumeration makes it easy to index arrays with the name of a particular pattern.

Previous versions of HapticLib used #define directives for this purpose.

The advantage of using an enumeration type definition is code and debug readability.

Enumerator:
Null 
Generic 
Test 
Impact 
Constant 
Num_Patterns_Available 

Definition at line 99 of file hl_patterns.h.


Function Documentation

void cleanList ( haptor_desc haptor)

Utility function to clean the pattern list of haptors.

This function holds the frequently used code to free the haptor list form the attached pattern.

Parameters:
[out]haptorThe haptor_desc * hold by activeHaptorList inside pattern_desc structure.

Definition at line 131 of file hl_patterns.c.

uint16_t dutyConverter ( uint16_t  duty,
haptor_desc haptor 
)

Utility function to convert duty-cycles.

Given the absolute duty-cycle (0-65535) and the haptor this function will return the actual duty cycle honoring min_duty and max_duty values of the haptor.

Parameters:
[in]dutyA uint16_t value representing the absolute duty cycle.
[out]haptorA haptor_desc * holding the reference to the haptor for which the duty has to be scaled.
Returns:
uint16_t the scaled value of the duty cycle.

Definition at line 163 of file hl_patterns.c.

void patternScheduler ( void  )

Updates all the active patterns' progress.

patternScheduler() checks for all the patterns configured in the system. If the pattern is running, its continuator is called.

patternScheduler() is called by the Platform Specific Module ( for example in the STM32VLDISCOVERY platform, SysTick_Handler() is the caller).

See also:
Please refer to the Developer Guide page to know the internal details of how HapticLib multi-haptor technique works.

Definition at line 100 of file hl_patterns.c.