codespaces-blank icon indicating copy to clipboard operation
codespaces-blank copied to clipboard

Create main

Open liaowentao520 opened this issue 6 months ago • 0 comments

#include "sys.h"

static uint8_t InterFace=0;//页面显示标志位 自动模式下,一页显示不完所有信息,所以分两页显示,0显示第一页,1显示第二页 uint8_t OperateMode=0;//运行模式标志位 uint8_t IndexFlag1=1;//选项索引 uint8_t CursorFlag1=1;//光标索引 uint8_t IndexFlag=1;//选项索引 uint8_t CursorFlag=1;//光标索引 /******************
功能:模式选择及控制界面 参数:无 返回值:无 ******************/ void Mode_Decide(void)//模式判定 {

   Manual_Mode();
//按键判定
if(isKey1)//若按键1按下
{
    isKey1=isKey2=isKey3=isKey4=0;//清除按键按下标志
    oled_Clear();
    OperateMode++;
}
else if(isKey2&&(!OperateMode))//若按键2按下,且当前模式为自动模式
{
    isKey1=isKey2=isKey3=isKey4=0;//清除按键按下标志
    oled_Clear();
    InterFace=!InterFace;
}
//标志位限制
if(OperateMode>=4) OperateMode=0;
/**根据模式选择显示界面**/
switch(OperateMode)
{
    case 0:
        Inform_Show();//显示信息
        AutoContrl();//自动控制
    break;
    
			case 1: 
        Anti_theft_mode();//防盗
			    AutoContrl();//自动控制
    break;
			
    case 2: 
				  AutoContrl();//自动控制
        ThresholdSet();//阈值设置1        
    break;
    
    case 3: 
				 Manual_Contrl();//手动模式
    break;
}

}

/******************
功能:显示界面 参数:无 返回值:无 ******/ void Inform_Show(void) { if(!InterFace)//自动模式页面1 { oled_ShowCHinese(161,20,48); oled_ShowCHinese(162,20,49); oled_ShowCHinese(163,20,50); oled_ShowCHinese(164,20,51); oled_ShowCHinese(165,20,52); oled_ShowCHinese(166,20,53);

			oled_ShowCHinese(16*0,2*1,0);
			oled_ShowCHinese(16*1,2*1,1);	
			oled_ShowCHinese(16*2,2*1,2);	
			oled_ShowCHinese(16*3,2*1,3);
			oled_ShowString(16*4,2*1,":",16);
			oled_ShowNum(16*5,2*1,SensorData.Fumes,2,16);	
			oled_ShowString(16*7,2*1,"%",16);		
			//第二行	光照
			oled_ShowCHinese(16*0,2*2,4);
			oled_ShowCHinese(16*1,2*2,5);	
			oled_ShowCHinese(16*2,2*2,6);	
			oled_ShowCHinese(16*3,2*2,7);	
			oled_ShowString(16*4,2*2,":",16);
			oled_ShowNum(16*5,2*2,SensorData.Lllumination,2,16);	
			oled_ShowString(16*7,2*2,"%",16);	
			//第三行	温度
			oled_ShowCHinese(16*0,2*3,8);
			oled_ShowCHinese(16*1,2*3,9);	
			oled_ShowString(16*4,2*3,":",16);
			oled_ShowNum(16*5,2*3,SensorData.TempInt,2,16);
			oled_ShowCHinese(16*7,2*3,10);

}
else//自动模式页面2
{
			oled_ShowCHinese(16*0,2*0,11);
			oled_ShowCHinese(16*1,2*0,12);	
			oled_ShowString(16*4,2*0,":",16);
			oled_ShowNum(16*5,2*0,SensorData.HumiInt,2,16);
			oled_ShowString(16*7,2*0,"%",16);	

    oled_ShowCHinese(16*0,2*1,13);
			oled_ShowCHinese(16*1,2*1,14);
			oled_ShowString(16*4,2*1,":",16);
			//判断火焰传感器输入的数字 0为有火焰 1为没有
			if(SensorData.Flame==0){
			oled_ShowCHinese(16*6,2*1,15);
			oled_ShowCHinese(16*7,2*1,16); 	
			}else{
			oled_ShowCHinese(16*6,2*1,17);
			oled_ShowCHinese(16*7,2*1,18); 	
			}
}

}

/******************
功能:自动控制 参数:无 返回值:无 ******************/

void AutoContrl(void) { //1.当监测到防盗开启时 监测到有人 蜂鸣器开启报警并且 显示屏显示警告 if (System.BurglarFlag == 1 && SensorData.HumanBody == 1) { System.Buzzer = 1; } else { System.Buzzer = 0; }

//2.监测到烟雾浓度超过阈值开启窗帘
if (SensorData.Fumes > Threshold.Smoke_Threshold) {
    System.Curtain = 1;
} else {
    System.Curtain = 0;
}

//3.监测到火焰开启水泵
if (SensorData.Flame == 0) {
    System.Water_Pump = 1;
} else {
    System.Water_Pump = 0;
}

//4.监测到光照低于阈值开启灯光
if (SensorData.Lllumination < Threshold.Lighting_Threshold) {
    System.Lamplight = 1;
} else {
    System.Lamplight = 0;
}

//5.温度超过阈值开启风扇
if (SensorData.TempInt > Threshold.Temperature_Threshold) {
    System.Fan = 1;
} else {
    System.Fan = 0;
}

//6.湿度超过阈值开启空调除湿
if (SensorData.HumiInt > Threshold.Humidity_Threshold) {
    System.Air_Conditioning = 1;
} else {
    System.Air_Conditioning = 0;
}

}

/******************
功能:防盗模式 参数:无 返回值:无 ******************/ void Anti_theft_mode(){

  oled_ShowCHinese(16 * 2, 2 * 0, 58);
oled_ShowCHinese(16 * 3, 2 * 0, 59);
oled_ShowCHinese(16 * 4, 2 * 0, 60);
oled_ShowCHinese(16 * 5, 2 * 0, 61);

oled_ShowCHinese(16 * 0, 2 * 1, 19);
oled_ShowCHinese(16 * 1, 2 * 1, 20);
oled_ShowString(16 * 4, 2 * 1, ":", 16);

//通过标志位判读是否开启防盗   开启 1  关闭0  默认0
if (System.BurglarFlag == 1) {
    oled_ShowCHinese(16 * 6, 2 * 1, 21);
    oled_ShowCHinese(16 * 7, 2 * 1, 22);
} else {
    oled_ShowCHinese(16 * 6, 2 * 1, 23);
    oled_ShowCHinese(16 * 7, 2 * 1, 24);
}

//判断防盗开启并且监测到有人时 显示屏显示非法闯入
if (System.BurglarFlag == 1 && SensorData.HumanBody == 1) {
    oled_ShowCHinese(16 * 0, 2 * 2, 25);
    oled_ShowCHinese(16 * 1, 2 * 2, 26);
    oled_ShowCHinese(16 * 2, 2 * 2, 27);
    oled_ShowCHinese(16 * 3, 2 * 2, 28);
} else {
    oled_ShowString(16 * 0, 2 * 2, "          ", 16);
}

	if(isKey3){
	  System.BurglarFlag=!System.BurglarFlag;
	  isKey3=0;
	}

}

/******************
功能:手动控制界面 参数:无 返回值:无 ******************/ void Manual_Contrl(void) {

//手动模式
oled_ShowCHinese(16 * 2, 2 * 0, 66);
oled_ShowCHinese(16 * 3, 2 * 0, 67);
oled_ShowCHinese(16 * 4, 2 * 0, 68);
oled_ShowCHinese(16 * 5, 2 * 0, 69);

/*按键检测*/
if(isKey2)
{
    IndexFlag++;
    if(IndexFlag==7) IndexFlag=1;//选项个数限制
    
    if(IndexFlag==1||IndexFlag==4) {CursorFlag=1;oled_Clear();}
    else if(IndexFlag==2||IndexFlag==5) CursorFlag=2;
    else if(IndexFlag==3||IndexFlag==6) CursorFlag=3;
    isKey2=0;
}
if(isKey3)
{
    if(IndexFlag==1) System.Fan=!System.Fan;
    else if(IndexFlag==2) System.Water_Pump=!System.Water_Pump;
    else if(IndexFlag==3) System.Lamplight=!System.Lamplight;
    else if(IndexFlag==4) System.Air_Conditioning=!System.Air_Conditioning;
    else if(IndexFlag==5) System.Curtain=!System.Curtain;
    else if(IndexFlag==6) System.Buzzer=!System.Buzzer;
    isKey3=0;
}
if(IndexFlag<=3)//第一页
{
  //第一行显示风扇 	判断状态开启或者关闭
oled_ShowCHinese(16 * 0, 2 * 1, 31);
oled_ShowCHinese(16 * 1, 2 * 1, 32);
oled_ShowString(16 * 3, 2 * 1, ":", 16);

if (System.Fan == 1) {
    oled_ShowCHinese(16 * 4, 2 * 1, 21);
    oled_ShowCHinese(16 * 5, 2 * 1, 22);
} else {
    oled_ShowCHinese(16 * 4, 2 * 1, 23);
    oled_ShowCHinese(16 * 5, 2 * 1, 24);
}

//第二行显示水泵 	判断状态开启或者关闭
oled_ShowCHinese(16 * 0, 2 * 2, 33);
oled_ShowCHinese(16 * 1, 2 * 2, 34);
oled_ShowString(16 * 3, 2 * 2, ":", 16);

if (System.Water_Pump == 1) {
    oled_ShowCHinese(16 * 4, 2 * 2, 21);
    oled_ShowCHinese(16 * 5, 2 * 2, 22);
} else {
    oled_ShowCHinese(16 * 4, 2 * 2, 23);
    oled_ShowCHinese(16 * 5, 2 * 2, 24);
}

//第三行显示灯光 	判断状态开启或者关闭
oled_ShowCHinese(16 * 0, 2 * 3, 35);
oled_ShowCHinese(16 * 1, 2 * 3, 36);
oled_ShowString(16 * 3, 2 * 3, ":", 16);

if (System.Lamplight == 1) {
    oled_ShowCHinese(16 * 4, 2 * 3, 21);
    oled_ShowCHinese(16 * 5, 2 * 3, 22);
} else {
    oled_ShowCHinese(16 * 4, 2 * 3, 23);
    oled_ShowCHinese(16 * 5, 2 * 3, 24);
}



}
else//第二页
{
		
		
		   //第四行显示空调 	判断状态开启或者关闭
oled_ShowCHinese(16 * 0, 2 * 1, 37);
oled_ShowCHinese(16 * 1, 2 * 1, 38);
oled_ShowString(16 * 3, 2 * 1, ":", 16);

if (System.Air_Conditioning == 1) {
    oled_ShowCHinese(16 * 4, 2 * 1, 21);
    oled_ShowCHinese(16 * 5, 2 * 1, 22);
} else {
    oled_ShowCHinese(16 * 4, 2 * 1, 23);
    oled_ShowCHinese(16 * 5, 2 * 1, 24);
}
		
		
		
		
 oled_ShowCHinese(16 * 0, 2 * 2, 39);
 oled_ShowCHinese(16 * 1, 2 * 2, 40);
 oled_ShowString(16 * 3, 2 * 2, ":", 16);

if (System.Curtain == 1) {
    oled_ShowCHinese(16 * 4, 2 * 2, 21);
    oled_ShowCHinese(16 * 5, 2 * 2, 22);
} else {
    oled_ShowCHinese(16 * 4, 2 * 2, 23);
    oled_ShowCHinese(16 * 5, 2 * 2, 24);
}

//第二行显示蜂鸣器 判断状态开启或者关闭
oled_ShowCHinese(16 * 0, 2 * 3, 41);
oled_ShowCHinese(16 * 1, 2 * 3, 42);
oled_ShowCHinese(16 * 2, 2 * 3, 43);
oled_ShowString(16 * 3, 2 * 3, ":", 16);

if (System.Buzzer == 1) {
    oled_ShowCHinese(16 * 4, 2 * 3, 21);
    oled_ShowCHinese(16 * 5, 2 * 3, 22);
} else {
    oled_ShowCHinese(16 * 4, 2 * 3, 23);
    oled_ShowCHinese(16 * 5, 2 * 3, 24);
}
}
	
	

if (CursorFlag == 1) { oled_ShowString(16 * 7, 2 * 1, "*", 16); } else { oled_ShowString(16 * 7, 2 * 1, " ", 16); }

//第三行
if (CursorFlag == 2) {
    oled_ShowString(16 * 7, 2 * 2, "*", 16);
} else {
    oled_ShowString(16 * 7, 2 * 2, " ", 16);
}

//第四行
if (CursorFlag == 3) {
    oled_ShowString(16 * 7, 2 * 3, "*", 16);
} else {
    oled_ShowString(16 * 7, 2 * 3, " ", 16);
}

}

/******************
功能:阈值设置 参数:无 返回值:无 ******************/ void ThresholdSet(void) {

         //阈值设置
oled_ShowCHinese(16 * 2, 2 * 0, 62);
oled_ShowCHinese(16 * 3, 2 * 0, 63);
oled_ShowCHinese(16 * 4, 2 * 0, 64);
oled_ShowCHinese(16 * 5, 2 * 0, 65);	

/*按键检测*/
if(isKey2)
{
    IndexFlag1++;
    if(IndexFlag1==5) IndexFlag1=1;
    
    if(IndexFlag1==1||IndexFlag1==4) {CursorFlag1=1;oled_Clear();}
    else if(IndexFlag1==2) CursorFlag1=2;
    else if(IndexFlag1==3) CursorFlag1=3;
    isKey2=0;
}
else if(isKey3)
{
    isKey3=0;
    if(IndexFlag1==1) Threshold.Smoke_Threshold++;
    else if(IndexFlag1==2) Threshold.Lighting_Threshold++;
    else if(IndexFlag1==3) Threshold.Temperature_Threshold++;
    else if(IndexFlag1==4) Threshold.Humidity_Threshold++;

}
else if(isKey4)
{
    isKey4=0;
    if(IndexFlag1==1) Threshold.Smoke_Threshold--;
    else if(IndexFlag1==2) Threshold.Lighting_Threshold--;
    else if(IndexFlag1==3) Threshold.Temperature_Threshold--;
    else if(IndexFlag1==4) Threshold.Humidity_Threshold--;

}

if(IndexFlag1<=3)//第一页
{

  //第一行  烟雾
oled_ShowCHinese(16 * 0, 2 * 1, 0);
oled_ShowCHinese(16 * 1, 2 * 1, 1);
oled_ShowCHinese(16 * 2, 2 * 1, 29);
oled_ShowCHinese(16 * 3, 2 * 1, 30);
oled_ShowString(16 * 4, 2 * 1, ":", 16);
oled_ShowNum(16 * 5, 2 * 1, Threshold.Smoke_Threshold, 2, 16);
//第二行	光照
oled_ShowCHinese(16 * 0, 2 * 2, 4);
oled_ShowCHinese(16 * 1, 2 * 2, 5);
oled_ShowCHinese(16 * 2, 2 * 2, 29);
oled_ShowCHinese(16 * 3, 2 * 2, 30);
oled_ShowString(16 * 4, 2 * 2, ":", 16);
oled_ShowNum(16 * 5, 2 * 2, Threshold.Lighting_Threshold, 2, 16);
//第三行	温度
oled_ShowCHinese(16 * 0, 2 * 3, 8);
oled_ShowCHinese(16 * 1, 2 * 3, 9);
oled_ShowCHinese(16 * 2, 2 * 3, 29);
oled_ShowCHinese(16 * 3, 2 * 3, 30);
oled_ShowString(16 * 4, 2 * 3, ":", 16);
oled_ShowNum(16 * 5, 2 * 3, Threshold.Temperature_Threshold, 2, 16);
		
}
else//第二页
{
		

		
oled_ShowCHinese(16 * 0, 2 * 1, 11);
oled_ShowCHinese(16 * 1, 2 * 1, 12);
oled_ShowCHinese(16 * 2, 2 * 1, 29);
oled_ShowCHinese(16 * 3, 2 * 1, 30);
oled_ShowString(16 * 4, 2 * 1, ":", 16);
oled_ShowNum(16 * 5, 2 * 1, Threshold.Humidity_Threshold, 2, 16);
}        

  if (CursorFlag1 == 1 ) {
    oled_ShowString(16 * 7, 2 * 1, "*", 16);
} else {
    oled_ShowString(16 * 7, 2 * 1, " ", 16);
}

//第三行
if (CursorFlag1 == 2) {
    oled_ShowString(16 * 7, 2 * 2, "*", 16);
} else {
    oled_ShowString(16 * 7, 2 * 2, " ", 16);
}

//第四行
if (CursorFlag1 == 3) {
    oled_ShowString(16 * 7, 2 * 3, "*", 16);
} else {
    oled_ShowString(16 * 7, 2 * 3, " ", 16);
}

//阈值限幅   
if(Threshold.Smoke_Threshold>=100)  Threshold.Smoke_Threshold=100;
if(Threshold.Lighting_Threshold>=100)  Threshold.Lighting_Threshold=100;
if(Threshold.Temperature_Threshold>=100)  Threshold.Temperature_Threshold=100;
if(Threshold.Humidity_Threshold>=100)  Threshold.Humidity_Threshold=100;

} void Manual_Mode() {

//风扇标志位 1  开启风扇的继电器   0 关闭
if (System.Fan == 1)   {
    RELAY_Fan_ON;
}   else  {
    RELAY_Fan_OFF;
}

//水泵标志位 1  开启水泵的继电器   0 关闭
if (System.Water_Pump == 1) {
    RELAY_Water_Pump_ON;
}	 else {
    RELAY_Water_Pump_OFF;
}

//灯光标志位 1  开启灯光   0 关闭
if (System.Lamplight == 1) {
    Lamplight_ON;
}  else {
    Lamplight_OFF;
}

//空调标志位 1  开启空调的继电器   0 关闭
if (System.Air_Conditioning == 1) {
    RELAY_Air_Conditioning_ON;
} else {
    RELAY_Air_Conditioning_OFF;
}

//窗帘标志位 1  转90度     0 返回0度
if (System.Curtain == 1) {
    Control_SG90(2000);
} else {
    Control_SG90(500);
}

//蜂鸣器标志位  1  开启蜂鸣器   0 关闭
if (System.Buzzer == 1) {
    Buzzer_ON;
} else {
    Buzzer_OFF;
}

}

liaowentao520 avatar Jul 06 '25 15:07 liaowentao520