#include "mywin_inc.h" #include "mywin_user_bluetooth.h" #define WIN_BLUETOOTH_TYPE "WIN_BlueToothStruct" WIN_BlueToothStruct *WIN_CreatBlueTooth (WIN_WindowStruct *base, void (*msgLoop)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg), int x,int y,int x_size,int y_size) { //重设消息循环 if (msgLoop==0) { msgLoop=(void (*)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg))BLUETOOTH_defaultMsgLoop; } WIN_BlueToothStruct *ret=mymalloc (sizeof ( WIN_BlueToothStruct)); //调用父类的构造函数 if (ret) { mymemset (ret,0,sizeof ( WIN_BlueToothStruct)); // if (0==WIN_CreatWindowExt((WIN_WindowStruct *)ret,base,msgLoop,x,y,x_size,y_size)) if (0==WIN_CreatTouchEx((WIN_TouchWinStruct *)ret,base,msgLoop,x,y,x_size,y_size)) { //创建失败 myfree (ret); ret=0; } else { ((WIN_WindowStruct *)ret)->winType=WIN_BLUETOOTH_TYPE; ((WIN_WindowStruct *)ret)->intercept=1; //构造一个消息框 ret->title="蓝牙"; ret->rectColor=0x221f18; ret->txtColor=0x342e27; ret->selectRectColor=0x342f2a; ret->selectTxtColor=0xc2ae9b; } } return ret; } //添加条目 void BLUETOOTH_AddItem (WIN_BlueToothStruct *bluetooth,char *txt) { if (bluetooth->itemNumitem[bluetooth->itemNum],txt,strlen(txt)+1); bluetooth->itemNum++; } } void BLUETOOTH_KeyEnter (WIN_BlueToothStruct *bluetooth) { if (bluetooth->index==0) { bluetooth->index++; //这里打开或关闭蓝牙 //Bluetooth_Power(bluetooth->power) if (bluetooth->power==0) { //蓝牙关了 MSGBOX_TipsTime ((WIN_WindowStruct*)bluetooth,"提示","蓝牙已关闭","确定",5000); ((WIN_WindowStruct *)bluetooth)->deleteWindow((WIN_WindowStruct *)bluetooth); } } else { if (bluetooth->power==0) { //蓝牙关了 MSGBOX_TipsTime ((WIN_WindowStruct*)bluetooth,"提示","蓝牙已关闭","确定",5000); ((WIN_WindowStruct *)bluetooth)->deleteWindow((WIN_WindowStruct *)bluetooth); } else { //选择一个设备来连接 int ret=-1; //ret=connectDevice (bluetooth->selectItem); if (ret==0) { MSGBOX_TipsTime ((WIN_WindowStruct*)bluetooth,"提示","蓝牙连接成功","确定",5000); } else { MSGBOX_TipsTime ((WIN_WindowStruct*)bluetooth,"提示","蓝牙连接失败","确定",5000); } ((WIN_WindowStruct *)bluetooth)->deleteWindow((WIN_WindowStruct *)bluetooth); } } } void BLUETOOTH_KeyBack (WIN_BlueToothStruct *bluetooth) { //什么也没有设置,这里关闭蓝牙 //Bluetooth_Power(0); MSGBOX_TipsTime ((WIN_WindowStruct*)bluetooth,"提示","蓝牙已关闭","确定",5000); ((WIN_WindowStruct *)bluetooth)->deleteWindow((WIN_WindowStruct *)bluetooth); } void BLUETOOTH_KeyUp (WIN_BlueToothStruct *bluetooth) { if (bluetooth->index==0) { bluetooth->power=!bluetooth->power; } else { if (bluetooth->selectItemitemNum-1) { bluetooth->selectItem++; if (bluetooth->startItemselectItem-3) { bluetooth->startItem++; } } else { bluetooth->selectItem=0; bluetooth->startItem=0; } } } void BLUETOOTH_KeyDown (WIN_BlueToothStruct *bluetooth) { if (bluetooth->index==0) { bluetooth->power=!bluetooth->power; } else { if (bluetooth->selectItem>0) { bluetooth->selectItem--; if (bluetooth->startItem>bluetooth->selectItem) { bluetooth->startItem--; } } else { bluetooth->selectItem=bluetooth->itemNum-1; if (bluetooth->startItemselectItem-3) { bluetooth->startItem=bluetooth->selectItem-3; } } } } //消息框的绘制函数 void BLUETOOTH_DefaultPaint (WIN_BlueToothStruct *bluetooth) { int x=0; int y=0; int x_size=((WIN_WindowStruct *)bluetooth)->x_size; int y_size=((WIN_WindowStruct *)bluetooth)->y_size; char txt_buff[20]={0}; WIN_PaintBackGround ((WIN_WindowStruct *)bluetooth); //显示标题 WIN_SetLcdColor (((WIN_WindowStruct *)bluetooth)->color); WIN_DrawTxtHCenterAt (bluetooth->title,x_size/4,8); x+=25;x_size-=25*2; y+=45;y_size-=45*2; //绘制矩形 int x_step=x_size/2; int y_step=y_size/3; x+=(x_size-x_step*2)/2; y+=(y_size-y_step*3)/2; x_size=x_step*2; y_size=y_step*3; if (bluetooth->power) { WIN_SetLcdColor (bluetooth->selectRectColor); } else { WIN_SetLcdColor (bluetooth->rectColor); } //WIN_FillRectByColor (x,y,x_step-1,y_step-1); WIN_FillRectByColorAlpha (x,y,x_step-1,y_step-1,16); if (bluetooth->power) { WIN_SetLcdColor (bluetooth->rectColor); } else { WIN_SetLcdColor (bluetooth->selectRectColor); } //WIN_FillRectByColor (x+x_step,y,x_step-1,y_step-1); WIN_FillRectByColorAlpha (x+x_step,y,x_step-1,y_step-1,16); //绘制文字 if (bluetooth->power) { WIN_SetLcdColor (bluetooth->selectTxtColor); } else { WIN_SetLcdColor (bluetooth->txtColor); } WIN_DrawTxtHCenterAt ("开",x+x_step/2,y+y_step/2-WIN_GetFontHight()/2); if (bluetooth->power) { WIN_SetLcdColor (bluetooth->txtColor); } else { WIN_SetLcdColor (bluetooth->selectTxtColor); } WIN_DrawTxtHCenterAt ("关",x+x_step+x_step/2,y+y_step/2-WIN_GetFontHight()/2); //在蓝牙开启的时候显示设备列表 int item_x=x; int item_y=y+y_step; int item_xstep=x_step; int item_ystep=y_step/2; if (bluetooth->index==1) { for (int i=0;i<4;i++) { if (i+bluetooth->startItemitemNum) { if (i+bluetooth->startItem==bluetooth->selectItem) { WIN_SetLcdColor (bluetooth->selectRectColor); //WIN_FillRectByColor (item_x,item_y,x_size-1,item_ystep-1); WIN_FillRectByColorAlpha (item_x,item_y,x_size-1,item_ystep-1,16); WIN_SetLcdColor (bluetooth->selectTxtColor); WIN_DrawTxtCenterAtRect (bluetooth->item[i+bluetooth->startItem],item_x,item_y,x_size-1,item_ystep-1); } else { WIN_SetLcdColor (bluetooth->rectColor); //WIN_FillRectByColor (item_x,item_y,x_size-1,item_ystep-1); WIN_FillRectByColorAlpha (item_x,item_y,x_size-1,item_ystep-1,16); WIN_SetLcdColor (bluetooth->txtColor); WIN_DrawTxtCenterAtRect (bluetooth->item[i+bluetooth->startItem],item_x,item_y,x_size-1,item_ystep-1); } }else {break;} item_y+=item_ystep; } } } //消息框的消息处理函数 void BLUETOOTH_defaultMsgLoop (WIN_BlueToothStruct *bluetooth,WIN_MsgStruct *msg) { WIN_KeyStruct *k=0; switch (msg->msg) { case WIN_MSG_PAINT: BLUETOOTH_DefaultPaint(bluetooth); break; case WIN_MSG_KEY: k=msg->data.p; //收到确定或返回键 if (k->shortPress&KEY_VALUE_UP) { BLUETOOTH_KeyDown (bluetooth); } else if (k->shortPress&KEY_VALUE_DOWN) { BLUETOOTH_KeyUp (bluetooth); } else if (k->shortPress&KEY_VALUE_ENTER) { BLUETOOTH_KeyEnter (bluetooth); } else if (k->shortPress&KEY_VALUE_HOME) { BLUETOOTH_KeyBack (bluetooth); } else if (k->longPress&KEY_VALUE_ENTER) { } if (k->shortPress) { WIN_SetInvalid ((WIN_WindowStruct *)bluetooth); } break;//case WIN_MSG_KEY: default: WIN_DefaultMsgLoop((WIN_WindowStruct *)bluetooth,msg); break; } } //蓝牙设置 int BLUETOOTH_BlueToothSet (WIN_WindowStruct *base) { WIN_BlueToothStruct *bluetooth=WIN_CreatBlueTooth (base,0,0,0,base->x_size,base->y_size); WIN_SetBackPicPath ((WIN_WindowStruct *)bluetooth,base->pic_path); WIN_ShowWindow((WIN_WindowStruct *)bluetooth); //return WIN_RunBlock ((WIN_WindowStruct *)bluetooth); char txt[20]={0}; for (int i=0;i<11;i++) { sprintf (txt,"device:%06d",i); BLUETOOTH_AddItem (bluetooth,txt); } return 0; }