STM32 oled实现多级子菜单,框架清晰易懂易维护,超级实用

发布时间:2023-11-15 08:30

#ifndef MYOLED_UI_H
#define MYOLED_UI_H

#include \"sys.h\"

#include \"oled.h\"
#include \"encoder.h\"

typedef void(*MyFrom)();

typedef struct
{
	 u8 current;
	 u8 up;//向上翻索引号
	 u8 down;//向下翻索引号
	 u8 enter;//确认索引号
	 
	 MyFrom FromShow;
}MyFromControl;

typedef struct
{
	int goalTemp;
	int goalTime;
}CuringConf;

extern int gl_LastKeyValue;
extern int gl_KeyValue;
extern u8 gl_fromIndex;
extern MyFromControl gl_MyFroms[];

void From_Control();
void fromStart();
void fromTime();
void fromTemp();
void fromBack();
void fromEdit();
void fromPause();
void fromEnd();
void fromTimeShow();
void fromTempShow();
void fromPauseShow();
void fromEndShow();
void frame1();
void frame2();
void frame3();

#endif
#include \"MYOLED_UI.h\"
#include \"font.h\"

u8 gl_fromIndex=0;  //界面索引

MyFromControl gl_MyFroms[]=
{
	{0,2,1,3,fromStart},
	{1,0,2,7,fromTime},
	{2,1,0,8,fromTemp},
	/*******From1******/
	
	{3,6,4,3,fromBack},
	{4,3,5,1,fromEdit},
	{5,4,6,4,fromPause},
	{6,5,3,4,fromEnd},
	/*******FromStart Show******/
	
	{7,7,7,1,fromTimeShow},
	/*******FromTime Show****/
	
	{8,8,8,2,fromTempShow},
	/*******FromTime Show****/
	
	{8,8,8,2,fromPauseShow},
	/*******FromPause Show****/
	
	{8,8,8,2,fromEndShow},
	/*******FromEnd Show****/
};

CuringConf CurSetting={30,60};

void From_Control()
{
	switch(Key_Scan())
	{
		case NORMAl:
		gl_fromIndex = gl_MyFroms[gl_fromIndex].current;	
		break;
		case FORWARD: 
		gl_fromIndex = gl_MyFroms[gl_fromIndex].up;
		break;
		case BACKWARD:
		gl_fromIndex = gl_MyFroms[gl_fromIndex].down;
		break;
	}
}

#define TIME 700
void frame1()
{
	OLED_DrawBMP(0,0,128,8,(unsigned char *)BMP1);
	delay_ms(TIME);
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP1);
	delay_ms(TIME);//LOGO
	
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP2);
	delay_ms(TIME);
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP3);
	delay_ms(TIME);
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP4);
	delay_ms(TIME);
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP5);
	delay_ms(TIME);//界面1 1.2.3.4
	
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP2);
	delay_ms(TIME);
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP6);
	delay_ms(555);
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP7);
	delay_ms(555);//Start 加热1.2
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP6);
	delay_ms(555);
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP7);
	delay_ms(555);//Start 加热1.2
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP6);
	delay_ms(555);
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP7);
	delay_ms(555);//Start 加热1.2
	
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP8);
	delay_ms(TIME);
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP9);
	delay_ms(TIME);
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP10);
	delay_ms(TIME);
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP11);
	delay_ms(TIME);//Start界面 1.2.3.4
	
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP8);
	delay_ms(TIME);
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP9);
	delay_ms(TIME);
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP12);
	delay_ms(TIME);
//	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP13);
//	delay_ms(TIME);
//	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP14);
//	delay_ms(TIME);
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP15);
	delay_ms(TIME);//Edit 时间1.2.3.4
	
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP9);
	delay_ms(TIME);
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP10);
	delay_ms(TIME);
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP16);
	delay_ms(TIME);
	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP17);
	delay_ms(TIME);
//	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP16);
//	delay_ms(TIME);
//	OLED_DrawBMPS(0,0,128,8,(unsigned char *)BMP10);
//	delay_ms(TIME);
	
	
//		OLED_ShowStrS(2,0,(unsigned char*)START,5);
//		OLED_ShowStr(2,2,(unsigned char*)TIME,4);
//		OLED_ShowStr(2,4,(unsigned char*)TEMP,4);	
}

void frame2()
{
		OLED_ShowStr(2,0,(unsigned char*)START,5);
		OLED_ShowStrS(2,2,(unsigned char*)TIME,4);
		OLED_ShowStr(2,4,(unsigned char*)TEMP,4);	
}

void frame3()
{
		OLED_ShowStr(2,0,(unsigned char*)START,5);
		OLED_ShowStr(2,2,(unsigned char*)TIME,4);
		OLED_ShowStrS(2,4,(unsigned char*)TEMP,4);	
}



void fromStart()
{
	printf(\"fromStart\\r\\n\");
	frame1();
}

void fromTime()
{
	printf(\"fromTime\\r\\n\");
	frame2();
}

void fromTemp()
{
	printf(\"fromTemp\\r\\n\");
	frame3();
}

void fromBack()
{
	printf(\"fromBack\\r\\n\");
}

void fromEdit()
{
	printf(\"fromEdit\\r\\n\");
}

void fromPause()
{
	printf(\"fromPause\\r\\n\");
}

void fromEnd()
{
	printf(\"fromEnd\\r\\n\");
}

void fromTimeShow()
{
	u16 line1Num = 0,line2Num=0,line3Num=0;
	
	if(CurSetting.goalTime<=60)
	{
		line1Num=CurSetting.goalTime-1;
	}
	else if(CurSetting.goalTime<=120)
	{
		line1Num=CurSetting.goalTime-5;
	}
	else
	{
		line1Num=CurSetting.goalTime-10;
	}
	
	if(CurSetting.goalTime<60)
	{
		line2Num=CurSetting.goalTime+1;
		line3Num=CurSetting.goalTime+2;
	}
	else if(CurSetting.goalTime<120)
	{
		line2Num=CurSetting.goalTime+5;
		line3Num=CurSetting.goalTime+10;
	}
	else
	{
		line2Num=CurSetting.goalTime+10;
		line3Num=CurSetting.goalTime+20;
	}
	printf(\"fromTimeShow\\r\\n\");
}

void fromTempShow()
{
	printf(\"fromTempShow\\r\\n\");
}

void fromPauseShow()
{
	printf(\"fromPauseShow\\r\\n\");
}

void fromEndShow()
{
	printf(\"fromEndShow\\r\\n\");
}
#include \"main.h\"

int test=0;
int main(void)
{
  Device_Init();

	while(1)
	{
      gl_MyFroms[gl_fromIndex].FromShow();
	}
}




ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号