2023-08-23 11:45:34 +00:00
|
|
|
#include "factory.h"
|
|
|
|
|
|
|
|
|
|
|
|
//the factory object containing all objects of our system
|
|
|
|
static Factory theFactory;
|
|
|
|
|
|
|
|
//all the getters
|
|
|
|
LED* l7() {
|
|
|
|
return &theFactory.l7_;
|
|
|
|
}
|
|
|
|
LED* l8() {
|
|
|
|
return &theFactory.l8_;
|
|
|
|
}
|
|
|
|
|
2023-08-29 12:11:48 +00:00
|
|
|
ALIVE* ALcontroller(){
|
|
|
|
return &theFactory.ALcontroller_;
|
2023-08-25 12:13:51 +00:00
|
|
|
}
|
|
|
|
|
2023-08-29 12:11:48 +00:00
|
|
|
ALIVE* ALjoy(){
|
|
|
|
return &theFactory.ALjoy_;
|
2023-08-25 16:23:36 +00:00
|
|
|
}
|
|
|
|
|
2023-08-31 18:02:41 +00:00
|
|
|
DRIVE* drive(){
|
|
|
|
return &theFactory.drive_;
|
2023-08-31 15:02:23 +00:00
|
|
|
}
|
|
|
|
|
2023-09-04 13:20:54 +00:00
|
|
|
STEERING* steering(){
|
|
|
|
return &theFactory.steering_;
|
|
|
|
}
|
|
|
|
|
2023-08-23 11:45:34 +00:00
|
|
|
|
|
|
|
//initialize all objects
|
|
|
|
void Factory_init() {
|
|
|
|
LED_init(l7(), 7);
|
|
|
|
LED_init(l8(), 8);
|
|
|
|
LED_initHW(l7());
|
|
|
|
LED_initHW(l8());
|
|
|
|
|
|
|
|
CAN_init();
|
2023-08-24 15:28:30 +00:00
|
|
|
CAN_setSender(1);
|
2023-08-25 12:13:51 +00:00
|
|
|
|
2023-08-28 10:57:16 +00:00
|
|
|
MEM_init();
|
2023-08-25 12:13:51 +00:00
|
|
|
|
2023-09-05 06:52:27 +00:00
|
|
|
ALIVE_init(ALcontroller(), 6);
|
2023-08-30 13:37:53 +00:00
|
|
|
ALIVE_setAliveTime(ALcontroller(), KART_CST.CONTROL_ALIVE_TIME);
|
2023-08-25 16:23:36 +00:00
|
|
|
|
2023-09-05 06:52:27 +00:00
|
|
|
ALIVE_init(ALjoy(), 1);
|
2023-08-31 18:02:41 +00:00
|
|
|
DRIVE_init(drive());
|
2023-09-04 13:20:54 +00:00
|
|
|
STEERING_init(steering());
|
2023-08-23 11:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//connect objects if required
|
|
|
|
void Factory_build() {
|
|
|
|
ECAN_SetRXBnInterruptHandler(CAN_newMsg);
|
2023-08-25 16:35:01 +00:00
|
|
|
CAN_onReceiveCan(CM_processIncome);
|
2023-08-25 12:13:51 +00:00
|
|
|
|
2023-08-29 12:11:48 +00:00
|
|
|
ALIVE_onAlive(ALcontroller(), CM_CONTROLLER_ALIVE, NULL);
|
|
|
|
|
|
|
|
ALIVE_onSetup(ALjoy(), CM_JOY_SETUP, NULL);
|
2023-08-30 13:37:53 +00:00
|
|
|
ALIVE_setAliveTime(ALjoy(), KART_CST.JOYSTICK_ALIVE_TIME);
|
2023-09-05 06:52:27 +00:00
|
|
|
//ALIVE_onBorn(ALjoy(), LED_on, l1());
|
|
|
|
//ALIVE_onDead(ALjoy(), LED_off, l1());
|
2023-08-25 16:23:36 +00:00
|
|
|
|
2023-09-05 06:52:27 +00:00
|
|
|
//DRIVE_onRun(drive(), LED_on, l2());
|
|
|
|
//DRIVE_onDead(drive(), LED_off, l2());
|
2023-08-31 15:02:23 +00:00
|
|
|
|
2023-09-05 06:52:27 +00:00
|
|
|
//STEERING_onRun(steering(), LED_on, l3());
|
|
|
|
//STEERING_onDead(steering(), LED_off, l3());
|
2023-09-04 13:20:54 +00:00
|
|
|
|
2023-08-23 11:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//start all state machines
|
|
|
|
void Factory_start() {
|
|
|
|
CAN_startBehaviour();
|
2023-08-29 12:11:48 +00:00
|
|
|
|
2023-09-01 11:22:35 +00:00
|
|
|
DRIVE_startBehaviour(drive());
|
2023-09-04 13:44:36 +00:00
|
|
|
STEERING_startBehaviour(steering());
|
2023-09-01 11:22:35 +00:00
|
|
|
|
|
|
|
ALIVE_startBehaviourSender(ALcontroller());
|
2023-09-04 17:51:19 +00:00
|
|
|
|
2023-09-01 11:22:35 +00:00
|
|
|
ALIVE_startBehaviourChecker(ALjoy());
|
2023-08-29 12:11:48 +00:00
|
|
|
ALIVE_emitBorn(ALjoy(), 100, 0);
|
|
|
|
ALIVE_emitReady(ALjoy(), 200, 0);
|
2023-08-31 15:02:23 +00:00
|
|
|
|
|
|
|
|
2023-08-25 16:23:36 +00:00
|
|
|
|
2023-08-23 11:45:34 +00:00
|
|
|
}
|