131 lines
2.4 KiB
C
131 lines
2.4 KiB
C
/**
|
|
* @author Rémi Heredero
|
|
* @version 1.0.0
|
|
* @date August 2023
|
|
* @file drive.h
|
|
*/
|
|
#ifndef DRIVE_H
|
|
#define DRIVE_H
|
|
|
|
#include "../xf/xf.h"
|
|
#include "../middleware/alive.h"
|
|
|
|
typedef enum {
|
|
STDR_INIT,
|
|
STDR_WAIT,
|
|
STDR_RUN,
|
|
STDR_DEAD
|
|
} DRIVE_STATES;
|
|
|
|
typedef enum {
|
|
evDRinit = 100,
|
|
evDRstart,
|
|
evDRstop,
|
|
evDRresurrect,
|
|
evDRpollSpeed,
|
|
evDRpollTorque
|
|
} DRIVE_EVENTS;
|
|
|
|
typedef void (*DRIVE_CALLBACK_FUNCTION)(void*);
|
|
typedef struct {
|
|
DRIVE_CALLBACK_FUNCTION f; // function
|
|
void* p; // param(s)
|
|
} DRIVE_CALLBACK;
|
|
|
|
typedef struct {
|
|
DRIVE_STATES state;
|
|
ALIVE myChecker;
|
|
DRIVE_CALLBACK wait;
|
|
DRIVE_CALLBACK run;
|
|
DRIVE_CALLBACK dead;
|
|
} DRIVE;
|
|
|
|
/**
|
|
* Initialize the DRIVE
|
|
* @param me the DRIVE itself
|
|
*/
|
|
void DRIVE_init(DRIVE* me);
|
|
|
|
/**
|
|
* Start the DRIVE state machine
|
|
* @param me the DRIVE itself
|
|
*/
|
|
void DRIVE_startBehaviour(DRIVE* me);
|
|
|
|
/**
|
|
* Process the event
|
|
* @param ev the event to process
|
|
* @return true if the event is processed
|
|
*/
|
|
bool DRIVE_processEvent(Event* ev);
|
|
|
|
/*************
|
|
* Callbacks *
|
|
*************/
|
|
|
|
/**
|
|
* Set the callback function to call when the DRIVE is entering state wait
|
|
* @param me the DRIVE itself
|
|
* @param f the function to call
|
|
* @param p the param(s) to pass to the function
|
|
*/
|
|
void DRIVE_onWait(DRIVE* me, DRIVE_CALLBACK_FUNCTION f, void* p);
|
|
|
|
/**
|
|
* Set the callback function to call when the DRIVE is entering state run
|
|
* @param me the DRIVE itself
|
|
* @param f the function to call
|
|
* @param p the param(s) to pass to the function
|
|
*/
|
|
void DRIVE_onRun(DRIVE* me, DRIVE_CALLBACK_FUNCTION f, void* p);
|
|
|
|
/**
|
|
* Set the callback function to call when the DRIVE is entering state dead
|
|
* @param me the DRIVE itself
|
|
* @param f the function to call
|
|
* @param p the param(s) to pass to the function
|
|
*/
|
|
void DRIVE_onDead(DRIVE* me, DRIVE_CALLBACK_FUNCTION f, void* p);
|
|
|
|
/************
|
|
* EMITTERS *
|
|
************/
|
|
|
|
/**
|
|
* Emit the start event
|
|
* @param p the DRIVE itself
|
|
*/
|
|
void DRIVE_emitStart(void* p);
|
|
|
|
/**
|
|
* Emit the stop event
|
|
* @param p the DRIVE itself
|
|
*/
|
|
void DRIVE_emitStop(void* p);
|
|
|
|
/**
|
|
* Emit the resurrect event
|
|
* @param p the DRIVE itself
|
|
*/
|
|
void DRIVE_emitResurrect(void* p);
|
|
|
|
/**
|
|
* Emit the pollSpeed event
|
|
* @param p the DRIVE itself
|
|
*/
|
|
void DRIVE_emitPollSpeed(void* p);
|
|
|
|
/**
|
|
* Emit the pollTorque event
|
|
* @param p the DRIVE itself
|
|
*/
|
|
void DRIVE_emitPollTorque(DRIVE* me, uint16_t t, int64_t data);
|
|
|
|
/***********
|
|
* SETTERS *
|
|
***********/
|
|
|
|
|
|
|
|
#endif
|