2020-09-19 02:49:20 -07:00
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
|
|
|
|
2020-09-19 16:51:02 -07:00
|
|
|
#include "can.h"
|
2020-12-10 18:32:41 -08:00
|
|
|
#include "fault.h"
|
2020-10-30 01:53:54 -07:00
|
|
|
#include "heater_control.h"
|
2020-10-31 16:59:35 -07:00
|
|
|
#include "pump_control.h"
|
2020-10-27 16:33:32 -07:00
|
|
|
#include "pump_dac.h"
|
2020-10-29 02:55:55 -07:00
|
|
|
#include "sampling.h"
|
2020-12-10 23:48:47 -08:00
|
|
|
#include "uart.h"
|
2020-09-19 15:44:10 -07:00
|
|
|
|
2020-10-26 17:25:05 -07:00
|
|
|
|
2020-09-19 02:49:20 -07:00
|
|
|
/*
|
|
|
|
* Application entry point.
|
|
|
|
*/
|
2020-09-19 21:39:29 -07:00
|
|
|
int main() {
|
2020-09-19 16:51:02 -07:00
|
|
|
halInit();
|
|
|
|
chSysInit();
|
2020-09-19 02:49:20 -07:00
|
|
|
|
2020-10-31 16:59:35 -07:00
|
|
|
// Fire up all of our threads
|
2020-10-29 02:55:55 -07:00
|
|
|
StartSampling();
|
2020-10-27 16:33:32 -07:00
|
|
|
InitPumpDac();
|
2020-10-31 16:59:35 -07:00
|
|
|
StartHeaterControl();
|
|
|
|
StartPumpControl();
|
2020-09-19 15:44:10 -07:00
|
|
|
|
2020-10-31 16:59:35 -07:00
|
|
|
InitCan();
|
2021-01-15 19:21:27 -08:00
|
|
|
//InitUart();
|
2020-09-19 21:39:29 -07:00
|
|
|
|
2020-12-10 18:08:06 -08:00
|
|
|
while(true)
|
|
|
|
{
|
2021-11-03 23:02:11 -07:00
|
|
|
auto fault = GetCurrentFault();
|
2020-12-10 21:58:59 -08:00
|
|
|
|
|
|
|
if (fault == Fault::None)
|
2020-12-10 21:46:41 -08:00
|
|
|
{
|
|
|
|
// blue is off
|
|
|
|
palClearPad(GPIOB, 5);
|
|
|
|
|
|
|
|
// Green is blinking
|
|
|
|
palTogglePad(GPIOB, 6);
|
|
|
|
|
2020-12-19 16:06:35 -08:00
|
|
|
// Slow blink if closed loop, fast if not
|
|
|
|
chThdSleepMilliseconds(IsRunningClosedLoop() ? 700 : 50);
|
2020-12-10 21:46:41 -08:00
|
|
|
}
|
2020-12-10 21:58:59 -08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// green is off
|
|
|
|
palClearPad(GPIOB, 6);
|
2020-12-10 21:46:41 -08:00
|
|
|
|
2020-12-10 21:58:59 -08:00
|
|
|
// Blink out the error code
|
|
|
|
for (int i = 0; i < 2 * static_cast<int>(fault); i++)
|
|
|
|
{
|
|
|
|
// Blue is blinking
|
|
|
|
palTogglePad(GPIOB, 5);
|
2020-12-10 21:58:09 -08:00
|
|
|
|
2020-12-10 21:58:59 -08:00
|
|
|
// fast blink
|
|
|
|
chThdSleepMilliseconds(300);
|
|
|
|
}
|
2020-12-10 21:58:09 -08:00
|
|
|
|
2020-12-10 21:58:59 -08:00
|
|
|
chThdSleepMilliseconds(2000);
|
2020-12-10 18:32:41 -08:00
|
|
|
}
|
2020-09-19 16:51:02 -07:00
|
|
|
}
|
2020-09-19 02:49:20 -07:00
|
|
|
}
|