1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
/*
* DriverWithCallbackExample.c
*
* Created on: 11 march 2018
* Author: shlomo
*/
#include "include.h"
#include "control.h"
uint32_t KeepParameter = 0;
callback_fptr ModuleCallback = 0;
bool isValid (uint32_t deviceID);
uint32_t ControlCallBackFunction(uint32_t deviceID, uint32_t ReadValue);
uint32_t DriverActionWithCallback (uint32_t deviceId, uint32_t parameter, callback_fptr callback)
{
assert (callback);
assert (isValid(deviceId));
//call driver action to device id with the parameter
//SetMotorSpeed (deviceId, parameter);
KeepParameter = parameter;
ModuleCallback = callback;
//start control:
uint32_t ControlId = AddControlCallback(NULL, callback, eOneMillisecond, NULL, (IfTypeNone*0x100+deviceId),deviceId, parameter );
return ControlId;
}
uint32_t ControlCallBackFunction(uint32_t deviceId, uint32_t ReadValue)
{
if (ReadValue == KeepParameter)
{
//stop this control loop
RemoveControlCallback(deviceId, ControlCallBackFunction );
//possibly: start regular control (speed etc)
//uint32_t ControlId = AddControlCallback(NULL,ControlCBFunction Callback, eOneMillisecond, NULL, deviceId, Parameter );
//call the module callback
ModuleCallback(deviceId,ReadValue);
}
return OK;
}
bool isValid (uint32_t deviceID)
{
return true;
}
|