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/factory/factory.c
2023-09-07 10:31:26 +02:00

89 lines
1.8 KiB
C

#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_;
}
ALIVE* ALcontroller(){
return &theFactory.ALcontroller_;
}
ALIVE* ALjoy(){
return &theFactory.ALjoy_;
}
DRIVE* drive(){
return &theFactory.drive_;
}
STEERING* steering(){
return &theFactory.steering_;
}
//initialize all objects
void Factory_init() {
LED_init(l7(), 7);
LED_init(l8(), 8);
LED_initHW(l7());
LED_initHW(l8());
CAN_init();
CAN_setSender(1);
MEM_init();
initRamp();
ALIVE_init(ALcontroller(), 6);
ALIVE_setAliveTime(ALcontroller(), KART_CST.CONTROL_ALIVE_TIME);
ALIVE_init(ALjoy(), 1);
DRIVE_init(drive());
STEERING_init(steering());
}
//connect objects if required
void Factory_build() {
ECAN_SetRXBnInterruptHandler(CAN_newMsg);
CAN_onReceiveCan(CM_processIncome);
ALIVE_onAlive(ALcontroller(), CM_CONTROLLER_ALIVE, NULL);
ALIVE_onSetup(ALjoy(), CM_JOY_SETUP, NULL);
ALIVE_setAliveTime(ALjoy(), KART_CST.JOYSTICK_ALIVE_TIME);
//ALIVE_onBorn(ALjoy(), LED_on, l1());
ALIVE_onDead(ALjoy(), deadJoystick, NULL);
//DRIVE_onRun(drive(), LED_on, l2());
//DRIVE_onDead(drive(), LED_off, l2());
//STEERING_onRun(steering(), LED_on, l3());
//STEERING_onDead(steering(), LED_off, l3());
}
//start all state machines
void Factory_start() {
CAN_startBehaviour();
ALIVE_startBehaviourSender(ALcontroller());
/*
DRIVE_startBehaviour(drive());
STEERING_startBehaviour(steering());
ALIVE_startBehaviourChecker(ALjoy());
ALIVE_emitBorn(ALjoy(), 100, 0);
ALIVE_emitReady(ALjoy(), 200, 0);
*/
}