125 lines
2.5 KiB
C
125 lines
2.5 KiB
C
/**
|
|
* @author Rémi Heredero
|
|
* @version 1.0.0
|
|
* @date September 2023
|
|
* @file steering.h
|
|
*/
|
|
#ifndef STEERING_H
|
|
#define STEERING_H
|
|
|
|
#include "../xf/xf.h"
|
|
#include "../middleware/alive.h"
|
|
|
|
typedef enum {
|
|
STST_INIT = 110,
|
|
STST_WAIT,
|
|
STST_RUN,
|
|
STST_DEAD
|
|
} STEERING_STATES;
|
|
|
|
typedef enum {
|
|
evSTinit = 110,
|
|
evSTstart,
|
|
evSTstop,
|
|
evSTresurrect,
|
|
evSTpollDir
|
|
} STEERING_EVENTS;
|
|
|
|
typedef void (*STEERING_CALLBACK_FUNCTION)(void*);
|
|
typedef struct {
|
|
STEERING_CALLBACK_FUNCTION f; // function
|
|
void* p; // param(s)
|
|
} STEERING_CALLBACK;
|
|
|
|
typedef struct {
|
|
STEERING_STATES state;
|
|
ALIVE myChecker;
|
|
STEERING_CALLBACK wait;
|
|
STEERING_CALLBACK run;
|
|
STEERING_CALLBACK dead;
|
|
} STEERING;
|
|
|
|
/**
|
|
* Initialize the STEERING
|
|
* @param me the STEERING itself
|
|
*/
|
|
void STEERING_init(STEERING* me);
|
|
|
|
/**
|
|
* Start the STEERING state machine
|
|
* @param me the STEERING itself
|
|
*/
|
|
void STEERING_startBehaviour(STEERING* me);
|
|
|
|
/**
|
|
* Process the event
|
|
* @param ev the event to process
|
|
* @return true if the event is processed
|
|
*/
|
|
bool STEERING_processEvent(Event* ev);
|
|
|
|
/*************
|
|
* Callbacks *
|
|
*************/
|
|
|
|
/**
|
|
* Set the callback function to call when the STEERING is entering state wait
|
|
* @param me the STEERING itself
|
|
* @param f the function to call
|
|
* @param p the param(s) to pass to the function
|
|
*/
|
|
void STEERING_onWait(STEERING* me, STEERING_CALLBACK_FUNCTION f, void* p);
|
|
|
|
/**
|
|
* Set the callback function to call when the STEERING is entering state run
|
|
* @param me the STEERING itself
|
|
* @param f the function to call
|
|
* @param p the param(s) to pass to the function
|
|
*/
|
|
void STEERING_onRun(STEERING* me, STEERING_CALLBACK_FUNCTION f, void* p);
|
|
|
|
/**
|
|
* Set the callback function to call when the STEERING is entering state dead
|
|
* @param me the STEERING itself
|
|
* @param f the function to call
|
|
* @param p the param(s) to pass to the function
|
|
*/
|
|
void STEERING_onDead(STEERING* me, STEERING_CALLBACK_FUNCTION f, void* p);
|
|
|
|
/************
|
|
* EMITTERS *
|
|
************/
|
|
|
|
/**
|
|
* Emit the start event
|
|
* @param p the STEERING itself
|
|
*/
|
|
void STEERING_emitStart(void* p);
|
|
|
|
/**
|
|
* Emit the stop event
|
|
* @param p the STEERING itself
|
|
*/
|
|
void STEERING_emitStop(void* p);
|
|
|
|
/**
|
|
* Emit the resurrect event
|
|
* @param p the STEERING itself
|
|
*/
|
|
void STEERING_emitResurrect(void* p);
|
|
|
|
/**
|
|
* Emit the pollDir event
|
|
* @param me the STEERING itself
|
|
* @param t time to wait in ms before triggering event
|
|
* @param data data to put on the event for XF
|
|
*/
|
|
void STEERING_emitPollDir(void* p);
|
|
|
|
/***********
|
|
* SETTERS *
|
|
***********/
|
|
|
|
|
|
#endif
|