diff --git a/AutoPID.cpp b/AutoPID.cpp index 64a5f49..94e2d87 100644 --- a/AutoPID.cpp +++ b/AutoPID.cpp @@ -1,4 +1,26 @@ #include "AutoPID.h" +#ifdef ESP_PLATFORM +#include +#include "esp_timer.h" +#endif + +#ifdef ESP_PLATFORM +unsigned long millis() { + return (unsigned long)esp_timer_get_time()/1000; +} + +template +const T& constrain(const T& x, const T& a, const T& b) { + if(x < a) { + return a; + } + else if(b < x) { + return b; + } + else + return x; +} +#endif AutoPID::AutoPID(double *input, double *setpoint, double *output, double outputMin, double outputMax, double Kp, double Ki, double Kd) { @@ -100,5 +122,3 @@ void AutoPIDRelay::run() { double AutoPIDRelay::getPulseValue(){ return (isStopped()?0:_pulseValue); } - - diff --git a/AutoPID.h b/AutoPID.h index efe85f2..13b0d86 100644 --- a/AutoPID.h +++ b/AutoPID.h @@ -1,6 +1,8 @@ #ifndef AUTOPID_H #define AUTOPID_H +#ifndef ESP_PLATFORM #include +#endif class AutoPID { diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..4e276ee --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "AutoPID.cpp" + INCLUDE_DIRS "." + REQUIRES esp_common)