zynq_7010/MotorConfig.h

49 lines
1.5 KiB
C++

#pragma once
#include <vector>
#include "json.hpp"
#include "Motordef.h"
using json= nlohmann::json;
#ifndef WIN32
#define MT_DRV888_CUO_PATH "/mnt/conf-disk/huago/drv888_cuo.json"
#define MT_DRV888_ZOU_PATH "/mnt/conf-disk/huago/drv888_zou.json"
#define MT_TMC216_CUO_PATH "/mnt/conf-disk/huago/tmc216_cuo.json"
#define MT_TMC216_ZOU_PATH "/mnt/conf-disk/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:
const std::vector<std::string> 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
};
public:
MotorConfig(/* args */);
~MotorConfig();
std::string GetParams(bool bzouzhi,MTBDType mttype);
void SetParams(bool bzouzhi,MTBDType mttype,MotorSpeedParamEx& param);
std::vector<MotorSpeedParamEx> GetMotorSpeedParams(bool bzouzhi,MTBDType mttype);
std::vector<MotorSpeedParamEx> GetMotorSpeedParams(const std::string& json_str);
MotorSpeedParamEx GetMotorSpeedParam(bool bzouzhi,MTBDType mttype,int speed,int colormmode,int dpi);
private:
void initconfigfile();
void to_json(MotorSpeedParamEx& param,json& j);
void from_json(json& j,MotorSpeedParamEx& param);
};