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-30 18:22:44 +00:00
|
|
|
BLINKER* b1() {
|
|
|
|
return &theFactory.b1_;
|
|
|
|
}
|
|
|
|
|
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 15:02:23 +00:00
|
|
|
ALIVE* ALdrive(){
|
|
|
|
return &theFactory.ALdrive_;
|
|
|
|
}
|
|
|
|
|
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());
|
2023-08-30 18:22:44 +00:00
|
|
|
|
|
|
|
BLINKER_init(b1());
|
2023-08-23 11:45:34 +00:00
|
|
|
|
|
|
|
CAN_init();
|
2023-08-24 15:28:30 +00:00
|
|
|
CAN_setSender(1);
|
|
|
|
LED_off(l1());
|
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-08-29 12:11:48 +00:00
|
|
|
ALIVE_init(ALcontroller());
|
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-08-29 12:11:48 +00:00
|
|
|
ALIVE_init(ALjoy());
|
2023-08-31 15:02:23 +00:00
|
|
|
ALIVE_init(ALdrive());
|
|
|
|
}
|
|
|
|
|
|
|
|
void foo(void* p){
|
|
|
|
static int16_t speed = 0;
|
|
|
|
static bool up = true;
|
|
|
|
if(up) {
|
|
|
|
speed += 3;
|
|
|
|
if(speed >100) up = false;
|
|
|
|
} else {
|
|
|
|
speed -= 3;
|
|
|
|
if(speed < -100) up = true;
|
|
|
|
}
|
|
|
|
CM_DRIVE_POWER(&speed);
|
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);
|
|
|
|
|
2023-08-31 15:02:23 +00:00
|
|
|
//BLINKER_onOn(b1(), LED_on, l6());
|
|
|
|
//BLINKER_onOff(b1(), LED_off, l6());
|
2023-08-30 18:22:44 +00:00
|
|
|
|
2023-08-29 12:11:48 +00:00
|
|
|
ALIVE_onSetup(ALjoy(), CM_JOY_SETUP, NULL);
|
2023-08-30 13:37:53 +00:00
|
|
|
ALIVE_setAliveTime(ALjoy(), KART_CST.JOYSTICK_ALIVE_TIME);
|
2023-08-29 12:11:48 +00:00
|
|
|
ALIVE_onBorn(ALjoy(), LED_on, l1());
|
|
|
|
ALIVE_onDead(ALjoy(), LED_off, l1());
|
2023-08-25 16:23:36 +00:00
|
|
|
|
2023-08-31 15:02:23 +00:00
|
|
|
ALIVE_onSetup(ALdrive(), CM_DRIVE_SETUP, NULL);
|
|
|
|
ALIVE_setAliveTime(ALdrive(), KART_CST.DRIVE_ALIVE_TIME);
|
|
|
|
ALIVE_onBorn(ALdrive(), LED_on, l2());
|
|
|
|
ALIVE_onDead(ALdrive(), LED_off, l2());
|
|
|
|
|
|
|
|
BLINKER_setTimeOn(b1(), (KART_CST.DRIVE_STOP_TIME*9)/2);
|
|
|
|
BLINKER_setTimeOff(b1(), (KART_CST.DRIVE_STOP_TIME*9)/2);
|
|
|
|
BLINKER_onOn(b1(), foo, NULL);
|
2023-08-23 11:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//start all state machines
|
|
|
|
void Factory_start() {
|
|
|
|
CAN_startBehaviour();
|
2023-08-30 18:22:44 +00:00
|
|
|
|
2023-08-29 12:11:48 +00:00
|
|
|
|
|
|
|
ALIVE_startBehaviourSender(ALcontroller());
|
|
|
|
ALIVE_startBehaviourChecker(ALjoy());
|
|
|
|
ALIVE_emitBorn(ALjoy(), 100, 0);
|
|
|
|
ALIVE_emitReady(ALjoy(), 200, 0);
|
2023-08-31 15:02:23 +00:00
|
|
|
ALIVE_startBehaviourChecker(ALdrive());
|
|
|
|
ALIVE_emitBorn(ALdrive(), 100, 0);
|
|
|
|
ALIVE_emitReady(ALdrive(), 200, 0);
|
|
|
|
|
|
|
|
BLINKER_startBehaviour(b1());
|
|
|
|
BLINKER_emitBlink(b1(), 300);
|
|
|
|
|
2023-08-25 16:23:36 +00:00
|
|
|
|
2023-08-23 11:45:34 +00:00
|
|
|
}
|