This repository has been archived on 2024-01-25. You can view files and clone it, but cannot push or open issues or pull requests.
SummerSchool2-Controller/306-controller_interface.X/app/drive.h

131 lines
2.4 KiB
C
Raw Normal View History

2023-08-31 18:02:41 +00:00
/**
* @author R<EFBFBD>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 {
2023-09-04 13:22:45 +00:00
STDR_INIT = 100,
2023-08-31 18:02:41 +00:00
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