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

Constant Pattern generator function definition More...

#include "hapticLib.h"

Go to the source code of this file.

Functions

uint8_t constantContinuator (pattern_desc *pattern)
 Pattern generator continuator
uint8_t constantPatternGenerator (pattern_desc *pattern)
 Pattern generator initiator

Detailed Description

Constant Pattern generator function definition

Introduction

Constant Pattern can be used to shake haptors providing the shaking magnitude.

Theory

Simply a on/off pattern.

Link to optional tools used on pattern development.

No other tools needed.

Optional Parameters

User must provide a constant value from 0 to 65000:

  • 1 to 65000 means set an haptor in busy mode and shake it at provided value.

Usage Examples

   ...
   //start one haptor shaking @ 35000
   haptor_desc *myHaptor = hl_configure(24000000,15,1);

   user_param myParams; // param must use struct of user_param_t type
   myParams.constant.constant = 35000;

   pattern_desc *myConstantPattern = hl_initPattern(Constant,&myParams);

   hl_addHaptor(myHaptor,myConstantPattern);

   hl_startPattern(myConstantPattern);
   ...
   hl_stopPattern(myConstantPattern);
   ...

Debugging Details

Parameters can't be NULL. It NULL is passed return an error. If HL_DEBUG symbol defined a "NULL found" string will sent to UART.

Additional Notes

The constant parameter can be used to change the duty-cycle even after the pattern has started! At ever continuator pass, it will poll the actual value of the user parameter constant and update the duty-cycle accordingly.

Warning:
When use Constant Pattern remember to free an haptor that was previously started using this pattern.
Note:
To stop this pattern and free its active haptor, use hl_stopPattern() with the right pattern descriptor passed as argument.
Authors:
Leonardo Guardati
Silvio Vallorani
Version:
v0.7
Date:
2012

Definition in file constant.c.


Function Documentation

uint8_t constantContinuator ( pattern_desc pattern)

Pattern generator continuator

This function is called back from the patternScheduler() every SystemDesc.samples_delay ms.

At every call, this continuator will decide what to do.

For a simple and static pattern, the action could be to simply point to the next element of an array of samples, or to generate it on the fly through a certain formula.

For more complex scenarios, this pattern continuator callback should be able to deliver a good degree of flexibility.

Warning:
The continuator must implement an exit strategy to decide when the pattern is finished an remove itself from the scheduling patterns. If this is not done right, the pattern will never free the haptor to other patterns.
Parameters:
[out]patternA pattern_desc* holding the reference to the running pattern instance to work with. Through this reference, the continuator can extract the user and status parameters in order to execute the haptic pattern.
Returns:
uint8_t The result is returned to indicate success or error.
Return values:
0Success
1Error

Definition at line 127 of file constant.c.

uint8_t constantPatternGenerator ( pattern_desc pattern)

Pattern generator initiator

This function is called by the User API Module of HapticLib, when the library user calls hl_startPattern().

The first task for the pattern generator initiator is to validate the user provided inputs, this cannot be done anywhere else.

This pattern initiator then sets up all the status parameters.

If the pattern accept user parameters, the status setting can be based on the user provided parameters.

The last duty of this function is to put the pattern continuator up for scheduling ( setting pattern->continuator =&constantContinuator;), so the next time patternScheduler() will check for active patterns, it will find this pattern.

Warning:
If the initiator doesn't set the continuator up for scheduling, the pattern will never start, and for HapticLib, the haptor is free to receive other patterns.
Parameters:
[out]patternA pattern_desc* holding the running instance of the pattern being started.
Returns:
uint8_t The result is returned to indicate success or error.
Return values:
0Success
1Error

Definition at line 184 of file constant.c.