Browse Source

update

master
zhaohe 2 years ago
parent
commit
735df75f69
  1. 44
      app/MDK-ARM/app.uvguix.h_zha
  2. 33
      src/board/hardware.cpp
  3. 27
      src/board/hardware.hpp
  4. 27
      src/umain.cpp

44
app/MDK-ARM/app.uvguix.h_zha
File diff suppressed because it is too large
View File

33
src/board/hardware.cpp

@ -64,6 +64,7 @@ void Hardware::temperature_init() {
m_temperature.tmp117[2].initializate(&hi2c1, TMP117::ID2);
m_temperature.tmp117[3].initializate(&hi2c1, TMP117::ID3);
}
TMP117 *Hardware::temperature_get_tmp117(int off) {
if (off < 0 || off > 3) {
ZASSERT(0);
@ -71,6 +72,14 @@ TMP117 *Hardware::temperature_get_tmp117(int off) {
}
return &m_temperature.tmp117[off];
}
float Hardware::temperature_get_temp(int off) {
if (off < 0 || off > 3) {
ZASSERT(0);
return 0;
}
return m_temperature.tmp117[off].getTemperature();
}
void Hardware::temperature_periodicJob() {
if (testHardwareFlag) {
/**
@ -171,9 +180,22 @@ bool *Hardware::fanGetPowerState(int fanIndex) {
}
return &m_fan.m_fanState[fanIndex];
}
void Hardware::fanSetState0to3(uint16_t dutyCycle) { fanSetDutyCycle(0, dutyCycle); }
void Hardware::fanSetState4(uint16_t dutyCycle) { fanSetDutyCycle(4, dutyCycle); }
void Hardware::fanSetState5(uint16_t dutyCycle) { fanSetDutyCycle(5, dutyCycle); }
void Hardware::fanSetState0to3(uint16_t dutyCycle) {
fanSetDutyCycle(0, dutyCycle);
m_fan.fan0_3duty = dutyCycle;
}
void Hardware::fanSetState4(uint16_t dutyCycle) {
fanSetDutyCycle(4, dutyCycle);
m_fan.fan4duty = dutyCycle;
}
void Hardware::fanSetState5(uint16_t dutyCycle) {
fanSetDutyCycle(5, dutyCycle);
m_fan.fan5duty = dutyCycle;
}
uint16_t Hardware::fanReadState0to3() { return m_fan.fan0_3duty; }
uint16_t Hardware::fanReadState4() { return m_fan.fan4duty; }
uint16_t Hardware::fanReadState5() { return m_fan.fan5duty; }
void Hardware::fan_periodicJob() {
/**
* @brief
@ -230,6 +252,8 @@ void Hardware::peltier_init() { //
STM32_HAL::gpioInit(GPIOB, GPIO_PIN_1, GPIO_MODE_AF_PP, GPIO_PULLUP, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET);
STM32_HAL::gpioInit(GPIOE, GPIO_PIN_10, GPIO_MODE_AF_PP, GPIO_PULLUP, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET);
}
int Hardware::peltier_get_pwm() { return m_peltier.pwm; }
void Hardware::peltier_set_pwm(int pwm) {
/**
* @brief
@ -250,7 +274,8 @@ void Hardware::peltier_set_pwm(int pwm) {
* COLD_CTR_PWM0(BL) = 1(PWM)
* COLD_CTR(BH) = 0
*/
pwm = pwm * 1000;
m_peltier.pwm = pwm;
pwm = pwm * 1000;
if (pwm == 0) {
peltier_hot_ctr_pwm(0); /*HOT_CTR_PWM0*/
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET); /*HOT_CTR*/

27
src/board/hardware.hpp

@ -35,14 +35,20 @@ class Hardware : public TMC4361APort, //
struct fan_res_t {
FanStateMonitor fanStateMonitor[6];
bool m_fanState[6];
uint16_t fan0_3duty;
uint16_t fan4duty;
uint16_t fan5duty;
};
struct temperature_res_t {
TMP117 tmp117[4];
};
struct peltier_res_t {};
struct peltier_res_t {
int32_t pwm;
};
tmc_res_t m_tmc;
fan_res_t m_fan;
temperature_res_t m_temperature;
peltier_res_t m_peltier;
HardwareListener *m_listener[MAX_HARDWARE_LISTENER_NUM];
int m_listenerNum;
bool testHardwareFlag;
@ -77,18 +83,22 @@ class Hardware : public TMC4361APort, //
*******************************************************************************/
void temperature_init();
TMP117 *temperature_get_tmp117(int off);
float temperature_get_temp(int off);
void temperature_periodicJob();
/*******************************************************************************
* *
*******************************************************************************/
void fan_init(int freq);
void fanSetDutyCycle(int fanIndex, uint16_t dutyCycle);
void fanSetState0to3(uint16_t dutyCycle);
void fanSetState4(uint16_t dutyCycle);
void fanSetState5(uint16_t dutyCycle);
bool *fanGetPowerState(int fanIndex);
void fan_periodicJob();
void fan_init(int freq);
void fanSetDutyCycle(int fanIndex, uint16_t dutyCycle);
void fanSetState0to3(uint16_t dutyCycle);
void fanSetState4(uint16_t dutyCycle);
void fanSetState5(uint16_t dutyCycle);
uint16_t fanReadState0to3();
uint16_t fanReadState4();
uint16_t fanReadState5();
bool *fanGetPowerState(int fanIndex);
void fan_periodicJob();
/*******************************************************************************
* *
*******************************************************************************/
@ -96,6 +106,7 @@ class Hardware : public TMC4361APort, //
void peltier_cold_ctr_pwm(int pwm);
void peltier_hot_ctr_pwm(int pwm);
void peltier_set_pwm(int pwm);
int peltier_get_pwm();
void peltier_periodicJob();
/*******************************************************************************
* TMC *

27
src/umain.cpp

@ -34,6 +34,7 @@ class Main : public HardwareListener, //
void main(int argc, char const *argv[]);
void initializeIflytopCanProtocolStackProcesser();
void updateRegList();
/*******************************************************************************
* override HardwareListener *
@ -127,12 +128,12 @@ icps::error_t Main::IflytopCanProtocolStack_onHostRegisterWriteEvent( //
}
icps::error_t Main::IflytopCanProtocolStack_onHostRegisterReadEvent( //
icps::Reg_t *reg, int32_t &value) { //
icps::Reg_t *reg, int32_t &value) { //
return icps::kSuccess;
}
void Main::IflytopCanProtocolStack_onRegisterValueAutoReportEvent( //
icps::Reg_t *reg, int32_t &value) { //
icps::Reg_t *reg, int32_t &value) { //
}
void Main::initializeIflytopCanProtocolStackProcesser() {
@ -169,6 +170,27 @@ void Main::initializeIflytopCanProtocolStackProcesser() {
ACTIVE_REG(REG_TEMPERATURE_CTRL_SENSOR4_TEMPERATURE /* */, icps::kr, 0);
}
#define UPDATE_REG(reg, value, periodms) \
{ \
static uint32_t lastReportTicket = 0; \
if (m_hardware.hasPassedMS(lastReportTicket) > periodms) { \
lastReportTicket = m_hardware.getTicket(); \
m_protocolStack.writeRegValue(reg, value, false); \
} \
}
void Main::updateRegList() { //
UPDATE_REG(REG_TEMPERATURE_CTRL_MAIN_FAN_SPEED, m_hardware.fanReadState4(), 1000);
UPDATE_REG(REG_TEMPERATURE_CTRL_SUB_FAN_SPEED, m_hardware.fanReadState0to3(), 1000);
UPDATE_REG(REG_TEMPERATURE_CTRL_HEAT_TEMPERATURE, 0, 1000);
UPDATE_REG(REG_TEMPERATURE_CTRL_REAL_OUTPUT, m_hardware.peltier_get_pwm(), 33);
UPDATE_REG(REG_TEMPERATURE_CTRL_FILTERED_TEMPERATURE, m_tempCtrl.getTemperature(), 1000);
UPDATE_REG(REG_TEMPERATURE_CTRL_SENSOR1_TEMPERATURE, m_hardware.temperature_get_temp(0) * 100, 1000);
UPDATE_REG(REG_TEMPERATURE_CTRL_SENSOR2_TEMPERATURE, m_hardware.temperature_get_temp(1) * 100, 1000);
UPDATE_REG(REG_TEMPERATURE_CTRL_SENSOR3_TEMPERATURE, m_hardware.temperature_get_temp(2) * 100, 1000);
UPDATE_REG(REG_TEMPERATURE_CTRL_SENSOR4_TEMPERATURE, m_hardware.temperature_get_temp(3) * 100, 1000);
}
void Main::main(int argc, char const *argv[]) {
sys_loggger_enable(true);
ZLOGI(TAG, "VERSION:%s", VERSION);
@ -187,6 +209,7 @@ void Main::main(int argc, char const *argv[]) {
while (true) {
m_hardware.periodicJob();
updateRegList();
}
}
static Main mainObject;

Loading…
Cancel
Save