menu_lcd.c

来自「一些基于IRA环境开发的zigbee实例程序」· C语言 代码 · 共 1,031 行 · 第 1/2 页

C
1,031
字号
#include "app_ex.h"
#include "hal.h"
#include "lcd128_64.h"
#include "string.h"
#include "Font.h"
#include "Menu.h"
#include "hal_key.h"
#include "OSAL.h"
#include "ZGlobals.h"
#include "AF.h"
#include "aps_groups.h"
#include "ZDApp.h"
#include "stdio.h"
#include "SampleApp.h"
#include "SampleAppHw.h"
#include "wxl_uart.h"

#include  "hal_types.h"
INT8U NowItem = 0;
INT8U FirstItem = 0;
INT8U TopDisp = 1;
unsigned char MenuItem[13][17];					//菜单缓冲区
extern INT8U ContrastValue;


extern struct join
{
	uint8 RfdCount;		//RFD计数器
	uint8 RouterCount;	//路由器计数器
	uint8 RfdAddr[20][10];	//存储RFD节点地址用,高两位为网络地址,低8位为物理地址
	uint8 RouterAddr[20][10];//存储RFD节点地址用,高两位为网络地址,低8位为物理地址
}JoinNode;

extern union j{
  uint8 TxBuf[29];
  struct RFTXBUF
  {
        uint8 HeadCom[3]; //命令头
        uint8 Laddr[8];
        uint16 Saddr;
        uint8 DataBuf[16];  //数据缓冲区
  }TXDATA;
}RfTx;//无线发送缓冲区

void Page1Display(INT8U ss, INT8U tt);
INT8U  DrawMenu(INT8U MenuItem[][17] , INT8U MenuNo,uint8 key);
void MenuMenuDisp( uint8 keys );
void Menu_all(uint8 key);
void Zigbee_Network(INT8U key);
void Aboat_Driver(uint8 key);
void IEEE_menu(void);
void Short_menu(void);
void Zigbee_Network(INT8U key);
INT8U Ten_to_16(INT8U Source_Data);
void Send_Test(INT8U key);
void Send_Broadcast(uint8 key);
void Send_Option(uint8 key);
extern uint8 SendData(uint8 *buf, uint16 addr, uint8 Leng);
void ClearScreenLcd(void);
void SelectTxAddr(INT8U key);
void Uart_Menu(INT8U key);
void Sensor_Menu(INT8U key);
void Uart_Send(INT8U key);
void Uart_RX(INT8U key);
void Uart_Pingpong(INT8U key);
uint16 ReadBattery(void);
uint16 Read_Temp(void);
void Temp_menu(INT8U key);
void ReadBattery_menu(INT8U key);
extern void SingleTxTest(uint8 key);
void PingpongTxTest(uint8 key);
extern void ConsecutionTxTest(uint8 key);
extern void halWait(BYTE wait);

INT8U disp_ieee[17],Short_Add[7];
int Menu_option = Aboat_Menu_2;
int Uart_Rx_Flag = 0;
int Uart_PP_Flag = 0;
int Send_Flag;
int Send_Flag_Consecution = 0;
#ifdef ZG_Coord
INT16U SrcSaddr = 0xffff;//发送数据地址
#else
INT16U SrcSaddr = 0x0000;//发送数据地址
#endif


void ClearScreenLcd(void)
{
  ClearScreen();
#ifdef	ZG_Coord
  Print(0,4,"-----COORD-----",1);
#endif	
#ifdef	ZG_Router
  Print(0,0,"-----ROUTER-----",1);
#endif
#ifdef	ZG_ENDDEVICE
  Print(0,4,"---ENDDEVICE----",1);
#endif
}
//*********************************************************************************
//函数名:INT8U  DrawMenu(INT8U MenuItem[][16] , INT8U MenuNo)
//功能:菜单显示
//输入:无
//输出:无
//*********************************************************************************
INT8U  DrawMenu(INT8U MenuItem[][17] , INT8U MenuNo,uint8 key)
{
	INT8U ii;
        INT8U sel;
	ClearScreenLcd();
        if(HAL_KEY_UP == key)
	{
		if(NowItem > 0) NowItem -= 1;
		else if(FirstItem > 0) FirstItem -= 1;
	}
	if(HAL_KEY_DOWN == key)
	{
		if(MenuNo > 2)
		{
			if(NowItem < 2) 	NowItem += 1;
			else if((FirstItem + 3) < MenuNo) 	FirstItem += 1;
		}
		else
		{
			if(NowItem < 1) 	NowItem += 1;	
		}
	}
	if(HAL_KEY_ENTER == key)
	{
		sel = FirstItem + NowItem;
		
	}
	if(HAL_KEY_CANCEL == key)
	{
		sel = 0xff;
	}
		if(MenuNo > 2)
		{
			for(ii = 0 ; ii < 3 ; ii++)
			{
				if(NowItem != ii)
				{				
					Print((ii*2+2),0,MenuItem[FirstItem + ii],1);
				}
				else
				{	
					Print((ii*2+2),0,MenuItem[FirstItem + ii],0);				
				}
			}
		}
		else
		{
			for(ii = 0 ; ii < MenuNo ; ii++)
			{
				if(NowItem != ii)
				{				
					Print((ii*2+2),0,MenuItem[FirstItem + ii],1);
				}
				else
				{	
					Print((ii*2+2),0,MenuItem[FirstItem + ii],0);				
				}
			}
		}
		
        return sel;
}
//*********************************************************************************
//函数名:void MenuMenuDisp( void )
//功能:主菜单显示
//输入:无
//输出:无
//*********************************************************************************
void MenuMenuDisp( uint8 key )
{
    INT8U sel;
    strcpy((char*)MenuItem[0] ,"1:ZigBee Test   ");
    strcpy((char*)MenuItem[1] ,"2:Uart Test     ");
#ifndef ZG_Coord
    strcpy((char*)MenuItem[2] ,"3:Sensor Test   ");
    strcpy((char*)MenuItem[3] ,"4:About         ");
    sel = DrawMenu(MenuItem , 4,key);
#else
    strcpy((char*)MenuItem[2] ,"3:About         ");
    sel = DrawMenu(MenuItem , 3,key);
#endif


    halWait(5);
    switch(sel)
    {
      case 0:
      {
        Menu_option = Zigbee_Menu_2;
        Menu_all(0);
        //Zigbee_Network(key);
      }break;
      case 1:
      {
        Menu_option = Uart_Menu_2;
        FirstItem = 0;
        NowItem = 0;
        Menu_all(0);
			//stop_watch_main();
      }break;
#ifndef ZG_Coord
      case 2:
      {

	Menu_option = Sensor_Menu_2;

        NowItem = 0;
        Menu_all(0);
      }break;
      case 3:
      {
	Menu_option = Aboat_Menu_2;
        Menu_all(0);			//clockmodes_main();
      }break;
#else
      case 2:
      {
	Menu_option = Aboat_Menu_2;
        Menu_all(0);			//clockmodes_main();
      }break;
#endif
      case 0xFF:
      {
        Menu_all(0);
      }break;
      default:
      break;
    }
}

//*********************************************************************************
//函数名:void Menu_all(uint8 key)
//功能:菜单选择
//输入:无
//输出:无
//*********************************************************************************


void Menu_all(uint8 key)
{
  if(Menu_option == Main_Menu_1)
  {
    MenuMenuDisp(key);
  }
  else if(Menu_option == Zigbee_Menu_2)
  {
    Zigbee_Network(key);
  }
  else if(Menu_option == Aboat_Menu_2)
  {
    Aboat_Driver(key);
  }
  else if(Menu_option == Send_Menu_3)
  {
    Send_Option(key);
  }
  else if((Menu_option == Single_Send_Menu_4)||(Menu_option == Continuous_Send_Menu_4))
  {
    Send_Test(key);
  }
  else if(Menu_option == Send_Broadcast_Menu_5)
  {
    Send_Broadcast(key);
  }
  else if(Menu_option == Pingpong_Test_Menu_5)
  {
    PingpongTxTest(key);
  }
  else if(Menu_option == Nod_Menu_3)
  {
    SelectTxAddr(key);
  }
  else if(Menu_option == Send_Short_Addr_Menu_5)
  {
    SingleTxTest(key);
  }
  else if(Menu_option == Uart_Menu_2)
  {
    Uart_Menu(key);
  }
  else if(Menu_option == Uart_TX_Menu_3)
  {
    Uart_Send(key);
  }
  else if(Menu_option == Uart_RX_Menu_3)
  {
    Uart_RX(key);
  }
  else if(Menu_option == Uart_PP_Menu_3)
  {
    Uart_Pingpong(key);
  }
#ifndef ZG_Coord
  else if(Menu_option == Sensor_ReadBattery_Menu_3)
  {
    ReadBattery_menu(key);
  }
  else if(Menu_option == Sensor_Menu_2)
  {
    Sensor_Menu(key);
  }
  else if(Menu_option == Sensor_Temp_Menu_3)
  {
    Temp_menu(key);
  }
#endif
}
//*********************************************************************************
//函数名:void Zigbee_Network(INT8U key)
//功能:ZIGBEE菜单
//输入:无
//输出:无
//*********************************************************************************
void Zigbee_Network(INT8U key)
{
  INT8U sel;
   strcpy((char*)MenuItem[0] ,"1:Send Test     ");
    strcpy((char*)MenuItem[1] ,"2:Network nod   ");
    sel = DrawMenu(MenuItem ,2,key);
      switch(sel)
      {
        case 0:
          Menu_option = Send_Menu_3;
          Menu_all(0);
          //SelectTxAddr(key);//选择地址
        break;
        case 1:
          Menu_option = Nod_Menu_3;

          NowItem = 0;
          Menu_all(0);
        break;
        case 0xff:
          Menu_option = Main_Menu_1;
          FirstItem = 0;
          NowItem = 0;
          Menu_all(0);
          break;
      }
}
//*********************************************************************************
//函数名:void Send_Option(uint8 key)
//功能:发送菜单选项
//输入:无
//输出:无
//*********************************************************************************
void Send_Option(uint8 key)
{
  INT8U sel;
  strcpy((char*)MenuItem[0] ,"1:Single Send   ");
  strcpy((char*)MenuItem[1] ,"2:Continuous    ");
  sel = DrawMenu(MenuItem ,2,key);
  switch(sel)
  {
    case 0:
      Send_Flag = Send_Flag_Single;
      NowItem = 0;
      Menu_option = Single_Send_Menu_4;
      Menu_all(0);
     break;
    case 1:
      Send_Flag = Send_Flag_Continuous;
      NowItem = 0;
      Menu_option = Continuous_Send_Menu_4;
      Menu_all(0);
    break;
    case 0xff:
      Menu_option = Zigbee_Menu_2;
      FirstItem = 0;
      NowItem = 0;
      Menu_all(0);
    break;
  }
}
//*********************************************************************************
//函数名:void Send_Test(INT8U key)
//功能:发送测试菜单
//输入:无
//输出:无
//*********************************************************************************
void Send_Test(INT8U key)
{
  INT8U sel;
   strcpy((char*)MenuItem[0] ,"1:Short Addr    ");                 //短地址(网络地址)发送
   strcpy((char*)MenuItem[1] ,"2:Broadcast Send");                 //广播发送
#ifdef ZG_Coord
   strcpy((char*)MenuItem[2] ,"3:PingPong  Send");                 //乒乓测试
   sel = DrawMenu(MenuItem ,3,key);
#else
   sel = DrawMenu(MenuItem ,2,key);
#endif
      switch(sel)
      {
        case 0:
          Menu_option = Send_Short_Addr_Menu_5;
          Menu_all(0);
        break;
        case 1:
          Menu_option = Send_Broadcast_Menu_5;
          Menu_all(0);
        break;
        case 2:
          Menu_option = Pingpong_Test_Menu_5;
          Menu_all(0);
        break;
        case 0xff:
          Menu_option = Send_Menu_3;
          FirstItem = 0;
          NowItem = 0;
          Menu_all(0);
          break;
      }
}
//*********************************************************************************
//函数名:void Send_Broadcast(uint8 key)
//功能:广播方式发送
//输入:无
//输出:无
//*********************************************************************************
void Send_Broadcast(uint8 key)
{
  if(Send_Flag == Send_Flag_Single)
  {
    SendData("hello", Send_Mode_Broadcast, 5);
    Menu_option = Single_Send_Menu_4;
    FirstItem = 0;
    NowItem = 0;

  }
  else if(Send_Flag == Send_Flag_Continuous)
  {
    ClearScreenLcd();
    //Rectangle(0,2,127,7);
    Print(3,3,"Consecution Tx",1);
    Send_Flag_Consecution = Broadcast_Continuous;
    FirstItem = 0;
    NowItem = 0;
    Menu_option = Send_Broadcast_Menu_5;
  }
  if(key == HAL_KEY_CANCEL)
  {
    Menu_option = Single_Send_Menu_4;
    Send_Flag_Consecution = 0;
    FirstItem = 0;
    NowItem = 0;
    Menu_all(0);
  }
}

void Aboat_Driver(uint8 key)
{
  ClearScreen();
  Print(0,0,"Name:",1);
  Print(4,0,"IEEE Add:(Hex)",1);
  Print(2,0,"Short Add:",1);
    Short_menu();
  Print(2,80,Short_Add,1);
  IEEE_menu();
  Print(6,0,disp_ieee,1);
#ifdef ZG_Coord
  Print(0,40,"Coord",1);
#endif
#ifdef ZG_Router
  Print(0,40,"Router",1);
#endif
#ifdef ZG_ENDDEVICE
  Print(0,40,"END",1);
#endif
  if(key == HAL_KEY_CANCEL)
  {
    Menu_option = Main_Menu_1;
    FirstItem = 0;
    NowItem = 0;
    Menu_all(0);
  }
}

void IEEE_menu(void)
{
  int j;
  INT8U TEMP[16],ieee[8],*ABC = NLME_GetExtAddr() ;
  for(j=0;j<8;j++)
  {
    ieee[j] = *ABC++;
  }
for(j=0;j<8;j++)
  {
    TEMP[2*j]= ieee[j]%16;
    TEMP[2*j] = Ten_to_16(TEMP[2*j]);
  }
for(j=0;j<8;j++)
  {
    TEMP[2*j+1]= ieee[j] / 16;
    TEMP[2*j+1] = Ten_to_16(TEMP[2*j+1]);
  }

  for(j=15;j>=0;j--)
  {
    disp_ieee[15-j] = TEMP[j] ;
  }
  disp_ieee[16] = '\0';
}

INT8U Ten_to_16(INT8U Source_Data)
{
  INT8U Destination_Data;
  if(Source_Data == 10)
    Destination_Data = 'A';
  if(Source_Data == 11)
    Destination_Data = 'B';

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?