mirror of
http://172.16.0.230/r/SIF/TowerOptoSifAndSpectral.git
synced 2025-12-20 05:13:31 +08:00
138 lines
3.5 KiB
C++
138 lines
3.5 KiB
C++
//
|
|
// Created by xin on 25-3-31.
|
|
//
|
|
|
|
#include "TG_Manager.h"
|
|
#include "string"
|
|
void TG_Manager::SetPin(int pin1_H, int pin1_L, int pin2_H, int pin2_L)
|
|
{
|
|
this->pin1_H = pin1_H;
|
|
this->pin1_L = pin1_L;
|
|
this->pin2_H = pin2_H;
|
|
this->pin2_L = pin2_L;
|
|
}
|
|
|
|
bool TG_Manager::SetTuiGan(int IS_High)
|
|
{
|
|
|
|
switch (IS_High)
|
|
{
|
|
case 2:
|
|
{std::string comand1 = "gpio write " + std::to_string(pin1_H) + " 0";
|
|
std::string comand2 = "gpio write " + std::to_string(pin1_L) + " 0";
|
|
system(comand1.c_str());
|
|
system(comand2.c_str());
|
|
break;}
|
|
case 1:
|
|
{std::string comand3 = "gpio write " + std::to_string(pin1_H) + " 1";
|
|
std::string comand4 = "gpio write " + std::to_string(pin1_L) + " 0";
|
|
system(comand3.c_str());
|
|
system(comand4.c_str());
|
|
break;}
|
|
case 0:
|
|
{std::string comand3 = "gpio write " + std::to_string(pin1_H) + " 0";
|
|
std::string comand4 = "gpio write " + std::to_string(pin1_L) + " 1";
|
|
system(comand3.c_str());
|
|
system(comand4.c_str());
|
|
break;}
|
|
default:
|
|
{std::string comand1 = "gpio write " + std::to_string(pin1_H) + " 0";
|
|
std::string comand2 = "gpio write " + std::to_string(pin1_L) + " 0";
|
|
system(comand1.c_str());
|
|
system(comand2.c_str());
|
|
break;}
|
|
}
|
|
|
|
if (IS_High)
|
|
{
|
|
std::string comand1 = "gpio write " + std::to_string(pin1_H) + " 1";
|
|
std::string comand2 = "gpio write " + std::to_string(pin1_L) + " 0";
|
|
system(comand1.c_str());
|
|
system(comand2.c_str());
|
|
}
|
|
else
|
|
{
|
|
std::string comand1 = "gpio write " + std::to_string(pin1_H) + " 0";
|
|
std::string comand2 = "gpio write " + std::to_string(pin1_L) + " 1";
|
|
system(comand1.c_str());
|
|
system(comand2.c_str());
|
|
}
|
|
return IS_High;
|
|
}
|
|
void TG_Manager::InitManger()
|
|
{
|
|
std::string comand1 = "gpio mode " + std::to_string(pin1_H) + " out";
|
|
std::string comand2 = "gpio mode " + std::to_string(pin1_L) + " out";
|
|
std::string comand3 = "gpio mode " + std::to_string(pin2_H) + " out";
|
|
std::string comand4 = "gpio mode " + std::to_string(pin2_L) + " out";
|
|
system(comand1.c_str());
|
|
system(comand2.c_str());
|
|
system(comand3.c_str());
|
|
system(comand4.c_str());
|
|
SetTuiGan(0);
|
|
SetSwitch1Status(0);
|
|
SetSwitch2Status(0);
|
|
}
|
|
bool TG_Manager::SetSwitch1Status(bool status)
|
|
{
|
|
if (status)
|
|
{
|
|
std::string comand1 = "gpio write " + std::to_string(pin2_H) + " 1";
|
|
system(comand1.c_str());
|
|
}
|
|
else
|
|
{
|
|
std::string comand1 = "gpio write " + std::to_string(pin2_H) + " 0";
|
|
system(comand1.c_str());
|
|
}
|
|
|
|
return status;
|
|
}
|
|
bool TG_Manager::SetSwitch2Status(bool status)
|
|
{
|
|
if (status)
|
|
{
|
|
std::string comand1 = "gpio write " + std::to_string(pin2_L) + " 1";
|
|
system(comand1.c_str());
|
|
}
|
|
else
|
|
{
|
|
std::string comand1 = "gpio write " + std::to_string(pin2_L) + " 0";
|
|
system(comand1.c_str());
|
|
}
|
|
return status;
|
|
}
|
|
|
|
bool TG_Manager::Heating()
|
|
{
|
|
printf("Heating\n");
|
|
SetTuiGan(true);
|
|
SetSwitch1Status(true);
|
|
SetSwitch2Status(false);
|
|
WorkingStatus = HEATING;
|
|
return true;
|
|
}
|
|
bool TG_Manager::Cooling()
|
|
{
|
|
printf("Cooling\n");
|
|
SetTuiGan(false);
|
|
SetSwitch1Status(false);
|
|
SetSwitch2Status(true);
|
|
WorkingStatus = COOLING;
|
|
return true;
|
|
}
|
|
|
|
bool TG_Manager::Stop(){
|
|
SetTuiGan(2);
|
|
SetSwitch1Status(false);
|
|
SetSwitch2Status(false);
|
|
WorkingStatus = NotWroking;
|
|
return true;
|
|
|
|
}
|
|
|
|
int TG_Manager::GetManagerStatus(){
|
|
return WorkingStatus;
|
|
}
|
|
|