From 02085518d805ab20d8ca41db8911a56ca7913a3d Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sun, 29 Oct 2023 20:30:26 +0800 Subject: [PATCH] update --- components/algorithm/pid_module.cpp | 1 + components/zcancmder/zcan_board_module.cpp | 74 ++++++++++++++++++++++++++++++ components/zcancmder/zcan_board_module.hpp | 63 +++++++++++++++++++++++++ components/zprotocols/zcancmder_v2 | 2 +- 4 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 components/zcancmder/zcan_board_module.cpp create mode 100644 components/zcancmder/zcan_board_module.hpp diff --git a/components/algorithm/pid_module.cpp b/components/algorithm/pid_module.cpp index a50db2e..c48d200 100644 --- a/components/algorithm/pid_module.cpp +++ b/components/algorithm/pid_module.cpp @@ -21,6 +21,7 @@ int32_t PidModule::reset() { m_previous_err1 = 0; m_previous_err2 = 0; m_integral_err = 0; + return 0; } float PidModule::pid_calc_incremental(float error) { float output = 0; diff --git a/components/zcancmder/zcan_board_module.cpp b/components/zcancmder/zcan_board_module.cpp new file mode 100644 index 0000000..6e1592d --- /dev/null +++ b/components/zcancmder/zcan_board_module.cpp @@ -0,0 +1,74 @@ +#include "zcan_board_module.hpp" + +using namespace iflytop; +using namespace std; +void ZCanBoardModule::initialize(int32_t moduleId, hardware_config_t *hcfg) { + module_id = moduleId; + m_cfg = *hcfg; + + for (int i = 0; i < ZARRAY_SIZE(hcfg->input); i++) { + if (hcfg->input[i].pin == PinNull) { + break; + } + ZGPIO::InputGpioCfg_t *cfg = &hcfg->input[i]; + m_input[i].initAsInput(cfg->pin, cfg->mode, cfg->irqtype, cfg->mirror); + m_input_num++; + } + + for (int i = 0; i < ZARRAY_SIZE(hcfg->output); i++) { + if (hcfg->output[i].pin == PinNull) { + break; + } + ZGPIO::OutputGpioCfg_t *cfg = &hcfg->output[i]; + m_output[i].initAsOutput(cfg->pin, cfg->mode, cfg->mirror, cfg->initLevel); + m_output_num++; + } +} +int32_t ZCanBoardModule::getid(int32_t *id) { *id = module_id; }; +int32_t ZCanBoardModule::module_readio(int32_t *io) { + *io = readinput(); + return 0; +}; +int32_t ZCanBoardModule::module_writeio(int32_t idindex, int32_t io) { + if (idindex < 0 || idindex >= ZARRAY_SIZE(m_output)) { + return err::kparam_out_of_range; + } + m_output[idindex].setState(io); + return 0; +}; + +int32_t ZCanBoardModule::module_xxx_reg(int32_t param_id, bool read, int32_t &val) { + switch (param_id) { + PROCESS_REG(kreg_module_version, /* */ val = 0x0001, ACTION_NONE); + PROCESS_REG(kreg_module_type, /* */ val = 0, ACTION_NONE); + PROCESS_REG(kreg_module_initflag, /* */ val = module_get_inited_flag(), module_set_inited_flag(val)); + PROCESS_REG(kreg_module_output_state, /* */ val = readoutput(), ACTION_NONE); + PROCESS_REG(kreg_module_input_state, /* */ val = readinput(), ACTION_NONE); + default: + return err::kmodule_not_find_config_index; + break; + } + return 0; +} + +int32_t ZCanBoardModule::module_set_reg(int32_t param_id, int32_t param_value) { return module_xxx_reg(param_id, false, param_value); } +int32_t ZCanBoardModule::module_get_reg(int32_t param_id, int32_t *param_value) { return module_xxx_reg(param_id, true, *param_value); } + +int32_t ZCanBoardModule::readinput() { + int32_t inputval = 0; + for (int i = 0; i < m_input_num; i++) { + if (m_input[i].getStateUint32()) { + inputval |= (1 << i); + } + } + return inputval; +} +int32_t ZCanBoardModule::readoutput() { + int32_t outputval = 0; + for (int i = 0; i < m_output_num; i++) { + if (m_output[i].getStateUint32()) { + outputval |= (1 << i); + } + } + return outputval; +} \ No newline at end of file diff --git a/components/zcancmder/zcan_board_module.hpp b/components/zcancmder/zcan_board_module.hpp new file mode 100644 index 0000000..3e88ece --- /dev/null +++ b/components/zcancmder/zcan_board_module.hpp @@ -0,0 +1,63 @@ +// +// Created by zwsd +// + +#pragma once +#include "sdk/os/zos.hpp" +#include "sdk\components\zprotocols\zcancmder_v2\api\api.hpp" + +/** + * @brief + * + * service: M3078 + * + * 监听事件: + * 依赖状态: + * 依赖服务: + * 作用: + * + * 推荐配置: + * 1. 识读模式:按键保持 + * 2. 波特率:9600 + * 3. 单次扫码时长:无限时 + * + */ + +namespace iflytop { +using namespace std; + +class ZCanBoardModule : public ZIModule { + public: + typedef struct { + ZGPIO::InputGpioCfg_t input[10]; + ZGPIO::OutputGpioCfg_t output[10]; + } hardware_config_t; + + hardware_config_t m_cfg; + int32_t module_id; + + ZGPIO m_input[10]; + ZGPIO m_output[10]; + + int32_t m_input_num = 0; + int32_t m_output_num = 0; + + public: + virtual ~ZCanBoardModule() {} + + void initialize(int32_t moduleId, hardware_config_t *cfg); + + virtual int32_t getid(int32_t *id) override; + virtual int32_t module_readio(int32_t *io) override; + virtual int32_t module_writeio(int32_t idindex, int32_t io) override; + + virtual int32_t module_set_reg(int32_t param_id, int32_t param_value); + virtual int32_t module_get_reg(int32_t param_id, int32_t *param_value); + + private: + int32_t module_xxx_reg(int32_t param_id, bool read, int32_t ¶m_value); + int32_t readinput(); + int32_t readoutput(); +}; + +} // namespace iflytop \ No newline at end of file diff --git a/components/zprotocols/zcancmder_v2 b/components/zprotocols/zcancmder_v2 index fb17dcb..7c37ecd 160000 --- a/components/zprotocols/zcancmder_v2 +++ b/components/zprotocols/zcancmder_v2 @@ -1 +1 @@ -Subproject commit fb17dcb55250a0d7230051ca725149928905aa25 +Subproject commit 7c37ecd0941426c01b0cf57db89da5943925dbd9