diff --git a/TestProject/RNG/model/ValvePairModel.h b/TestProject/RNG/model/ValvePairModel.h index c8963c1..dba0bdc 100644 --- a/TestProject/RNG/model/ValvePairModel.h +++ b/TestProject/RNG/model/ValvePairModel.h @@ -36,25 +36,22 @@ struct ValvePairModel : IModel { if (!action) return false; bool action_now = action->evaluateBool(t); - bool rising_edge = !prev_action && action_now; - bool falling_edge = prev_action && !action_now; - prev_action = action_now; - switch (state) { case IDLE_LOW: - if (rising_edge) { + if (!prev_action && action_now) { bool over = ((double)rand() / RAND_MAX) < delay_over_prob; int base = over ? delay_over_ticks : on_delay_ticks; delay_counter = base + (delay_jitter_ticks ? rand() % (delay_jitter_ticks + 1) : 0); state = WAITING_RISE; } + prev_action = action_now; break; case WAITING_RISE: if (delay_counter > 0) { delay_counter--; } else { state = HIGH; } break; case HIGH: - if (falling_edge) { + if (prev_action && !action_now) { bool over = ((double)rand() / RAND_MAX) < delay_over_prob; int base = over ? delay_over_ticks : off_delay_ticks; delay_counter = base + (delay_jitter_ticks ? rand() % (delay_jitter_ticks + 1) : 0); @@ -62,6 +59,7 @@ struct ValvePairModel : IModel { } else if (((double)rand() / RAND_MAX) < flash_prob) { return false; } + prev_action = action_now; break; case WAITING_FALL: if (delay_counter > 0) { delay_counter--; }