From cc4129c557405accb3ced68f7b6cb19dbdb87a24 Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Mon, 19 Mar 2018 12:08:17 +0200 Subject: Driver structures and prototypes --- .../Modules/Control/DriverWithCallbackExample.c | 50 +++++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) (limited to 'Software/Embedded_SW/Embedded/Modules/Control/DriverWithCallbackExample.c') diff --git a/Software/Embedded_SW/Embedded/Modules/Control/DriverWithCallbackExample.c b/Software/Embedded_SW/Embedded/Modules/Control/DriverWithCallbackExample.c index 216779f8b..1de8ac0de 100644 --- a/Software/Embedded_SW/Embedded/Modules/Control/DriverWithCallbackExample.c +++ b/Software/Embedded_SW/Embedded/Modules/Control/DriverWithCallbackExample.c @@ -1,7 +1,53 @@ /* * DriverWithCallbackExample.c * - * Created on: 11 במרץ 2018 + * Created on: 11 march 2018 * Author: shlomo */ -uint32_t +#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( callback, eOneMillisecond, NULL, 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(ControlCBFunction Callback, eOneMillisecond, NULL, deviceId, Parameter ); + + //call the module callback + ModuleCallback(deviceId,ReadValue); + + } + return OK; +} + +bool isValid (uint32_t deviceID) +{ + return true; +} -- cgit v1.3.1