#include <EasyNextionLibrary.h>
#include <trigger.h>
#include "config.h"
#include "config_setup.h"
#include "nextion_hmi.h"
#include "clock_counter.h"
#include "mc_interface.h"
#include "VescUart.h"
#include "global_pas.h"
#ifdef PAS_MODULE_ENABLE
PAS_Module pas(PAS_INTERRUPT_PIN);
#endif
#ifdef EASY_NEXTION_ENABLE
// EasyNex myNex(Serial1);
#endif
//#include "sim_def.h"
//NextionHMI hmi;
#ifdef PAS_SIMULATION_ENABLE
pas_simulator sim;
#endif
clock_counter clock;
void update_hmi_sm() {
static int prev_state = 0;
int state = sim.get_state();
static bool new_start = true;
// if (state == 0 && new_start == true) {
update_state_machine(state, 1);
// new_start = false;
// } else if (state != prev_state && new_start == false) {
//
update_state_machine(state, 1);
//update_state_machine(prev_state, 0);
prev_state = state;
// }
}
void update_sm_counter() {
unsigned long currentMillis = millis();
static unsigned long previousMillis = 0;
int wait_duration = 900;
if (currentMillis - previousMillis >= wait_duration) {
update_hmi_sm();
previousMillis = currentMillis;
}
}
int get_pulse_count() {
int pulse_count = pas.get_pulse_counter();
return pulse_count;
}
void setup() {
// put your setup code here, to run once:
config_setup();
setup_uart_vesc();
}
void loop() {
static double duty_cycle = 0.0;
// main_loop();
clock.tick();
pulse_generator(10, SIM_PULSE_PIN);
//sim.pas_sim_state_machine();
update_sm_counter();
//pulse_counter();
pas_interface();
vesc_set_duty_cycle(duty_cycle++);
}