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* 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_;
|
|
|
|
}
|
|
|
|
|
2023-08-25 12:13:51 +00:00
|
|
|
WATCHDOG* WDcontroller(){
|
|
|
|
return &theFactory.WDcontroller_;
|
|
|
|
}
|
|
|
|
|
2023-08-25 16:23:36 +00:00
|
|
|
ALIVE_CHECKER* ACjoy() {
|
|
|
|
return &theFactory.ACjoy_;
|
|
|
|
}
|
|
|
|
|
2023-08-23 11:45:34 +00:00
|
|
|
|
|
|
|
//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();
|
2023-08-24 15:28:30 +00:00
|
|
|
CAN_setSender(1);
|
|
|
|
LED_off(l1());
|
2023-08-25 12:13:51 +00:00
|
|
|
|
|
|
|
// TODO init EPROM interface
|
|
|
|
|
|
|
|
// TODO init watchdog with EPROM CST
|
|
|
|
WATCHDOG_init(WDcontroller());
|
2023-08-25 16:23:36 +00:00
|
|
|
CAR_CST.CONTROL_ALIVE_TIME = 100;
|
2023-08-25 12:13:51 +00:00
|
|
|
WATCHDOG_setTime(WDcontroller(), CAR_CST.CONTROL_ALIVE_TIME);
|
2023-08-25 16:23:36 +00:00
|
|
|
|
|
|
|
// TODO init ALIVE CHECKER with EPROM CST
|
|
|
|
CAR_CST.JOYSTICK_MODE = 0;
|
|
|
|
CAR_CST.JOYSTICK_PARAM1 = 100;
|
|
|
|
CAR_CST.JOYSTICK_PARAM2 = 1;
|
|
|
|
CAR_CST.JOYSTICK_ALIVE_TIME = 10;
|
|
|
|
ALIVE_CHECKER_init(ACjoy());
|
2023-08-23 11:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void foo(uint8_t a, uint8_t b, uint32_t c){
|
2023-08-24 18:31:40 +00:00
|
|
|
if(b){
|
|
|
|
LED_on(l1());
|
|
|
|
} else {
|
|
|
|
LED_off(l1());
|
|
|
|
}
|
|
|
|
CAN_Send(a, b, c);
|
2023-08-23 11:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//connect objects if required
|
|
|
|
void Factory_build() {
|
|
|
|
ECAN_SetRXBnInterruptHandler(CAN_newMsg);
|
|
|
|
CAN_onReceiveCan(foo);
|
2023-08-25 12:13:51 +00:00
|
|
|
|
2023-08-25 16:23:36 +00:00
|
|
|
WATCHDOG_onAlive(WDcontroller(), CM_CONTROLLER_ALIVE, NULL);
|
|
|
|
ALIVE_CHECKER_onSetup(ACjoy(), CM_JOY_SETUP, NULL);
|
|
|
|
ALIVE_CHECKER_setAliveTime(ACjoy(), CAR_CST.JOYSTICK_ALIVE_TIME);
|
|
|
|
|
2023-08-23 11:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//start all state machines
|
|
|
|
void Factory_start() {
|
|
|
|
CAN_startBehaviour();
|
2023-08-25 12:13:51 +00:00
|
|
|
WATCHDOG_startBehaviour(WDcontroller());
|
2023-08-25 16:23:36 +00:00
|
|
|
ALIVE_CHECKER_startBehaviour(ACjoy());
|
|
|
|
ALIVE_CHECKER_emitBorn(ACjoy(), 100, 0);
|
|
|
|
ALIVE_CHECKER_emitReady(ACjoy(), 200, 0);
|
|
|
|
|
2023-08-23 11:45:34 +00:00
|
|
|
}
|