#pragma once #include #include "json.hpp" using json= nlohmann::json; struct MotorSpeedParam { int finalPeriod; int Fmin; float stepnum; float a; float offset; float finalDelay; float acceleration_time; }; struct MotorSpeedParamEx { MotorSpeedParam mt_param; int speed; int colormode; int dpi; int sp; }; #ifndef WIN32 #define MT_DRV888_CUO_PATH "/usr/local/huago/drv888_cuo.json" #define MT_DRV888_ZOU_PATH "/usr/local/huago/drv888_zou.json" #define MT_TMC216_CUO_PATH "/usr/local/huago/tmc216_cuo.json" #define MT_TMC216_ZOU_PATH "/usr/local/huago/tmc216_zou.json" #else #define MT_DRV888_CUO_PATH "drv888_cuo.json" #define MT_DRV888_ZOU_PATH "drv888_zou.json" #define MT_TMC216_CUO_PATH "tmc216_cuo.json" #define MT_TMC216_ZOU_PATH "tmc216_zou.json" #endif class MotorConfig { private: std::vector m_cuoParams; std::vector m_zouParams; const std::vector m_jsonpaths={ MT_DRV888_CUO_PATH, MT_DRV888_ZOU_PATH, MT_TMC216_CUO_PATH, MT_TMC216_ZOU_PATH }; public: enum class MTBDType { MT_TMC, MT_DRV }; MotorConfig(/* args */); ~MotorConfig(); std::string GetParams(bool bzouzhi,MTBDType mttype); void SetParams(bool bzouzhi,MTBDType mttype,MotorSpeedParamEx& param); std::vector GetMotorSpeedParams(bool bzouzhi,MTBDType mttype); std::vector GetMotorSpeedParams(const std::string& json_str); private: void initconfigfile(); void to_json(MotorSpeedParamEx& param,json& j); void from_json(json& j,MotorSpeedParamEx& param); };