new state machine description
This commit is contained in:
parent
980f41afc6
commit
e0467fcda6
@ -73,9 +73,6 @@ int pos_air_closed;
|
|||||||
int precharge_closed;
|
int precharge_closed;
|
||||||
int pre_and_air_open; // used to be:int precharge_opened = 0; now we read if PC is open from the pin -> high if open
|
int pre_and_air_open; // used to be:int precharge_opened = 0; now we read if PC is open from the pin -> high if open
|
||||||
|
|
||||||
#warning just a fix to make the code compile
|
|
||||||
int precharge_opened = 0;
|
|
||||||
|
|
||||||
/* USER CODE END PV */
|
/* USER CODE END PV */
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
@ -222,7 +219,7 @@ int main(void)
|
|||||||
}
|
}
|
||||||
if (count % 4 == 0) {
|
if (count % 4 == 0) {
|
||||||
print_battery_info();
|
print_battery_info();
|
||||||
debug_log(LOG_LEVEL_INFO, " Time since last update: %lu ms", HAL_GetTick() - lastTimestamp);
|
print_master_status();
|
||||||
}
|
}
|
||||||
shunt_check();
|
shunt_check();
|
||||||
ts_sm_update();
|
ts_sm_update();
|
||||||
|
@ -53,7 +53,7 @@ void ts_sm_update() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ts_state.current_state != old_state) {
|
if (ts_state.current_state != old_state) {
|
||||||
debug_log(LOG_LEVEL_DEBUG,
|
debug_log(LOG_LEVEL_DEBUG,
|
||||||
"Transitioned from %s to %s", TSStateToString(old_state),
|
"Transitioned from %s to %s", TSStateToString(old_state),
|
||||||
TSStateToString(ts_state.current_state));
|
TSStateToString(ts_state.current_state));
|
||||||
@ -93,7 +93,7 @@ TSState ts_sm_update_active() {
|
|||||||
precharge_opened_timestamp = HAL_GetTick();
|
precharge_opened_timestamp = HAL_GetTick();
|
||||||
} else if (precharge_opened_timestamp != 0 &&
|
} else if (precharge_opened_timestamp != 0 &&
|
||||||
HAL_GetTick() - precharge_opened_timestamp > 100) {
|
HAL_GetTick() - precharge_opened_timestamp > 100) {
|
||||||
precharge_opened = 1;
|
//precharge_opened = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TS_ACTIVE;
|
return TS_ACTIVE;
|
||||||
@ -113,7 +113,7 @@ TSState ts_sm_update_precharge() {
|
|||||||
PRECHARGE_95_DURATION) {
|
PRECHARGE_95_DURATION) {
|
||||||
precharge_95_reached_timestamp = 0;
|
precharge_95_reached_timestamp = 0;
|
||||||
precharge_opened_timestamp = 0;
|
precharge_opened_timestamp = 0;
|
||||||
precharge_opened = 0;
|
//precharge_opened = 0;
|
||||||
return TS_ACTIVE;
|
return TS_ACTIVE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -188,7 +188,7 @@ void ts_sm_set_relay_positions(TSState state) {
|
|||||||
case TS_CHARGING:
|
case TS_CHARGING:
|
||||||
ts_sm_set_relay_position(RELAY_NEG, 1);
|
ts_sm_set_relay_position(RELAY_NEG, 1);
|
||||||
ts_sm_set_relay_position(RELAY_POS, 1);
|
ts_sm_set_relay_position(RELAY_POS, 1);
|
||||||
ts_sm_set_relay_position(RELAY_PRECHARGE, !precharge_opened);
|
ts_sm_set_relay_position(RELAY_PRECHARGE, 0);
|
||||||
// TODO: Open precharge relay after a while
|
// TODO: Open precharge relay after a while
|
||||||
break;
|
break;
|
||||||
case TS_PRECHARGE:
|
case TS_PRECHARGE:
|
||||||
@ -203,7 +203,7 @@ void ts_sm_set_relay_positions(TSState state) {
|
|||||||
void ts_sm_set_relay_position(Relay relay, int closed) {
|
void ts_sm_set_relay_position(Relay relay, int closed) {
|
||||||
static int neg_closed = 0;
|
static int neg_closed = 0;
|
||||||
static int pos_closed = 0;
|
static int pos_closed = 0;
|
||||||
static int precharge_closed = 0;
|
static int pre_closed = 0;
|
||||||
|
|
||||||
GPIO_PinState state = closed ? GPIO_PIN_SET : GPIO_PIN_RESET;
|
GPIO_PinState state = closed ? GPIO_PIN_SET : GPIO_PIN_RESET;
|
||||||
switch (relay) {
|
switch (relay) {
|
||||||
@ -216,7 +216,7 @@ void ts_sm_set_relay_position(Relay relay, int closed) {
|
|||||||
HAL_GPIO_WritePin(POS_AIR_CTRL_GPIO_Port, POS_AIR_CTRL_Pin, state);
|
HAL_GPIO_WritePin(POS_AIR_CTRL_GPIO_Port, POS_AIR_CTRL_Pin, state);
|
||||||
break;
|
break;
|
||||||
case RELAY_PRECHARGE:
|
case RELAY_PRECHARGE:
|
||||||
ts_sm_check_close_wait(&precharge_closed, closed);
|
ts_sm_check_close_wait(&pre_closed, closed);
|
||||||
HAL_GPIO_WritePin(PRECHARGE_CTRL_GPIO_Port, PRECHARGE_CTRL_Pin, state);
|
HAL_GPIO_WritePin(PRECHARGE_CTRL_GPIO_Port, PRECHARGE_CTRL_Pin, state);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user