Skip to content

Commit

Permalink
fix the moduleclass usage issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AsiiaPine committed Jun 19, 2024
1 parent b6df20b commit 805a639
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "CircuitStatusModule.hpp"


bool CircuitStatus::instance_initialized = false;
Logger CircuitStatus::logger = Logger("CircuitStatus");

void CircuitStatus::init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class CircuitStatus : public Module {
protected:
void spin_once() override;

static bool instance_initialized;

private:
CircuitStatus_t circuit_status = {};
Temperature_t temperature_status = {};
Expand Down
18 changes: 8 additions & 10 deletions Src/dronecan_application/modules/pwm/PWMModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@ void PWMModule::init() {
void PWMModule::spin_once() {
uint32_t crnt_time_ms = HAL_GetTick();

static uint32_t next_update_ms = 0;
if (crnt_time_ms > next_update_ms) {
next_update_ms = crnt_time_ms + 1000;
update_params();
apply_params();
}

mode = Module::Mode::OPEARTIONAL;
for (auto& pwm : params) {
if (crnt_time_ms > pwm.cmd_end_time_ms) {
Expand Down Expand Up @@ -105,7 +98,9 @@ void PWMModule::update_params() {
params_error = true;
break;
}

if (health != Status::OK&& HAL_GetTick() %1000 == 0) {
logger.log_info("102");
}
static uint32_t last_warn_pub_time_ms = 0;
for (int i = 0; i < static_cast<uint8_t>(PwmPin::PWM_AMOUNT); i++) {
params[i].fb = paramsGetIntegerValue(params[i].names.fb);
Expand All @@ -129,11 +124,14 @@ void PWMModule::update_params() {
logger.log_debug("check parameters");
}
}
if (health != Status::OK && HAL_GetTick() %1000 == 0) {
logger.log_info("128");
}
apply_params();
mode = Mode::OPEARTIONAL;
}

void PWMModule::apply_params() {
mode = Mode::MAINTENANCE;

for (int i = 0; i < static_cast<uint8_t>(PwmPin::PWM_AMOUNT); i++) {
if (PwmPeriphery::get_frequency(params[i].pin) != pwm_freq) {
PwmPeriphery::set_frequency(params[i].pin, pwm_freq);
Expand Down
11 changes: 6 additions & 5 deletions Src/dronecan_application/modules/pwm/PWMModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,19 @@ struct PwmChannelInfo {

class PWMModule : public Module {
public:
PWMModule() : Module(2) {}
void init() override;

inline PWMModule() : Module(50) {}

protected:
void update_params() override;
void spin_once() override;

static std::array<PwmChannelInfo, static_cast<uint8_t>(PwmPin::PWM_AMOUNT)> params;

private:
void (*callback)(CanardRxTransfer*);
void (*publish_state)();
void (*callback)(CanardRxTransfer*) = {};
void (*publish_state)() = {};

void update_pwm();
void apply_params();
Expand All @@ -78,8 +79,8 @@ class PWMModule : public Module {
static CommandType pwm_cmd_type;

static uint16_t ttl_cmd;
uint16_t status_pub_timeout_ms;
bool verbose;
uint16_t status_pub_timeout_ms = 0;
bool verbose = false;

static bool publish_error;
static Logger logger;
Expand Down

0 comments on commit 805a639

Please sign in to comment.