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

100 lines
1.9 KiB
C

#include "factory.h"
//the factory object containing all objects of our system
static Factory theFactory;
//all the getters
LED* l1() {
return &theFactory.l1_;
}
LED* l2() {
return &theFactory.l2_;
}
LED* l3() {
return &theFactory.l3_;
}
LED* l4() {
return &theFactory.l4_;
}
LED* l5() {
return &theFactory.l5_;
}
LED* l6() {
return &theFactory.l6_;
}
LED* l7() {
return &theFactory.l7_;
}
LED* l8() {
return &theFactory.l8_;
}
ALIVE* ALcontroller(){
return &theFactory.ALcontroller_;
}
ALIVE* ALjoy(){
return &theFactory.ALjoy_;
}
//initialize all objects
void Factory_init() {
LED_init(l1(), 1);
LED_init(l2(), 2);
LED_init(l3(), 3);
LED_init(l4(), 4);
LED_init(l5(), 5);
LED_init(l6(), 6);
LED_init(l7(), 7);
LED_init(l8(), 8);
LED_initHW(l1());
LED_initHW(l2());
LED_initHW(l3());
LED_initHW(l4());
LED_initHW(l5());
LED_initHW(l6());
LED_initHW(l7());
LED_initHW(l8());
CAN_init();
CAN_setSender(1);
LED_off(l1());
// TODO init EPROM interface
MEM_init();
// TODO init watchdog with EPROM CST
ALIVE_init(ALcontroller());
ALIVE_setAliveTime(ALcontroller(), CAR_CST.CONTROL_ALIVE_TIME);
ALIVE_init(ALjoy());
}
//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(), CAR_CST.JOYSTICK_ALIVE_TIME);
ALIVE_onBorn(ALjoy(), LED_on, l1());
ALIVE_onDead(ALjoy(), LED_off, l1());
}
//start all state machines
void Factory_start() {
CAN_startBehaviour();
ALIVE_startBehaviourSender(ALcontroller());
ALIVE_startBehaviourChecker(ALjoy());
ALIVE_emitBorn(ALjoy(), 100, 0);
ALIVE_emitReady(ALjoy(), 200, 0);
}