mirror of
http://172.16.0.230/r/SIF/TowerOptoSifAndSpectral.git
synced 2025-10-19 19:49:42 +08:00
138 lines
3.3 KiB
C++
138 lines
3.3 KiB
C++
//
|
|
// Created by xin on 25-4-2.
|
|
//
|
|
|
|
#include "TemperatureRegulator.h"
|
|
#include "logout.h"
|
|
TemperatureRegulator *g_tempretureRegulator;
|
|
TemperatureRegulator::TemperatureRegulator(){
|
|
|
|
g_tempretureRegulator=this;
|
|
}
|
|
/*
|
|
"PortName": "ttyS2",
|
|
"BaudRate": 115200,
|
|
"Pin": {
|
|
"TG": {
|
|
"Pin_H": 7,
|
|
"Pin_L": 10
|
|
},
|
|
"Fan": {
|
|
"Pin": 11
|
|
},
|
|
"HOT": {
|
|
"Pin": 12
|
|
}
|
|
},
|
|
"Constant_Temperature": {
|
|
"MaxTemp": 30,
|
|
"MinTemp": 0
|
|
},
|
|
"Temperature": {
|
|
"index_x": 0,
|
|
"index_y": 0,
|
|
}
|
|
|
|
**/
|
|
void TemperatureRegulator::setconfig(json jconfig) {
|
|
QString Port_Name="ttyS2";
|
|
int BaudRate=115200;
|
|
|
|
if (jconfig.contains("PortName")) {
|
|
Port_Name=QString::fromStdString(jconfig["PortName"]);
|
|
}
|
|
if (jconfig.contains("BaudRate")) {
|
|
BaudRate=jconfig["BaudRate"];
|
|
}
|
|
m_TemperaTureWoker=new TemperaTureWoker();
|
|
m_TemperaTureWoker->OpenCom(Port_Name,BaudRate);
|
|
int pin1_H=7;
|
|
int pin1_L=10;
|
|
int pin2_H=2;
|
|
int pin2_L=4;
|
|
if (jconfig.contains("Pin")) {
|
|
if (jconfig["Pin"].contains("TG")) {
|
|
if (jconfig["Pin"]["TG"].contains("Pin_H")) {
|
|
pin1_H=jconfig["Pin"]["TG"]["Pin_H"];
|
|
}
|
|
if (jconfig["Pin"]["TG"].contains("Pin_L")) {
|
|
pin1_L=jconfig["Pin"]["TG"]["Pin_L"];
|
|
}
|
|
}
|
|
if (jconfig["Pin"].contains("Fan")) {
|
|
if (jconfig["Pin"]["Fan"].contains("Pin")) {
|
|
pin2_H=jconfig["Pin"]["Fan"]["Pin"];
|
|
}
|
|
}
|
|
if (jconfig["Pin"].contains("HOT")) {
|
|
if (jconfig["Pin"]["HOT"].contains("Pin")) {
|
|
pin2_L=jconfig["Pin"]["HOT"]["Pin"];
|
|
}
|
|
}
|
|
}
|
|
|
|
m_TG_Manager=new TG_Manager();
|
|
m_TG_Manager->SetPin(pin1_H,pin1_L,pin2_H,pin2_L);
|
|
|
|
if (jconfig.contains("Constant_Temperature")) {
|
|
if (jconfig["Constant_Temperature"].contains("MaxTemp")) {
|
|
M_Targert_Max_Tempreature=jconfig["Constant_Temperature"]["MaxTemp"];
|
|
}
|
|
if (jconfig["Constant_Temperature"].contains("MinTemp")) {
|
|
M_Targert_Min_Tempreature=jconfig["Constant_Temperature"]["MinTemp"];
|
|
}
|
|
}
|
|
if (jconfig.contains("Temperature")) {
|
|
if (jconfig["Temperature"].contains("index_x")) {
|
|
m_target_index=jconfig["Temperature"]["index_x"];
|
|
}
|
|
if (jconfig["Temperature"].contains("index_y")) {
|
|
m_target_indey=jconfig["Temperature"]["index_y"];
|
|
}
|
|
}
|
|
|
|
|
|
isinit=true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
void TemperatureRegulator::SetTartGetX_Y(int x,int y){
|
|
m_target_index=x;
|
|
m_target_indey=y;
|
|
}
|
|
void TemperatureRegulator::init(){
|
|
|
|
|
|
|
|
|
|
}
|
|
void TemperatureRegulator::loop(){
|
|
if (!isinit) return;
|
|
m_TemperaTureWoker->ReadTempreature();
|
|
float tempreture=m_TemperaTureWoker->m_Tempreaturegroups[m_target_index].tempera[m_target_indey];
|
|
//printf("current tempreture is %f\n",tempreture);
|
|
logout("Temp","current tempreture is "+QString::number(tempreture),6);
|
|
// qDebug()<< "current tempreture is " << tempreture;
|
|
if (tempreture>M_Targert_Max_Tempreature)
|
|
{
|
|
m_TG_Manager->Cooling();
|
|
}
|
|
else if (tempreture<M_Targert_Min_Tempreature)
|
|
{
|
|
m_TG_Manager->Heating();
|
|
}
|
|
else
|
|
{
|
|
m_TG_Manager->Stop();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
bool TemperatureRegulator::looptask() {
|
|
g_tempretureRegulator->loop();
|
|
}
|