Files
player/Project/Src/MyWinApp/mywin_user_bluetooth.c

261 lines
8.2 KiB
C
Raw Normal View History

2025-06-27 00:32:57 +08:00
#include "mywin_user_bluetooth.h"
#include "mywin_inc.h"
2025-06-27 00:32:57 +08:00
#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) {
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣѭ<CFA2><D1AD>
if (msgLoop == 0) {
msgLoop = (void (*)(struct _WIN_WindowStruct *win,
WIN_MsgStruct *msg))BLUETOOTH_defaultMsgLoop;
}
WIN_BlueToothStruct *ret = mymalloc(sizeof(WIN_BlueToothStruct));
// <20><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD><ECBAAF>
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)) {
// <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
myfree(ret);
ret = 0;
} else {
((WIN_WindowStruct *)ret)->winType = WIN_BLUETOOTH_TYPE;
((WIN_WindowStruct *)ret)->intercept = 1;
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>
ret->title = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
ret->rectColor = 0x221f18;
ret->txtColor = 0x342e27;
ret->selectRectColor = 0x342f2a;
ret->selectTxtColor = 0xc2ae9b;
}
}
return ret;
2025-06-27 00:32:57 +08:00
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ
void BLUETOOTH_AddItem(WIN_BlueToothStruct *bluetooth, char *txt) {
if (bluetooth->itemNum < BLUETOOTH_ITEMNUM_MAX) {
mymemcpy(bluetooth->item[bluetooth->itemNum], txt, strlen(txt) + 1);
bluetooth->itemNum++;
}
2025-06-27 00:32:57 +08:00
}
void BLUETOOTH_KeyEnter(WIN_BlueToothStruct *bluetooth) {
if (bluetooth->index == 0) {
bluetooth->index++;
// <20><><EFBFBD><EFBFBD><EFBFBD>򿪻<EFBFBD><F2BFAABB>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD>
// Bluetooth_Power(bluetooth->power)
if (bluetooth->power == 0) {
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
MSGBOX_TipsTime((WIN_WindowStruct *)bluetooth, "<EFBFBD><EFBFBD>ʾ", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹر<EFBFBD>",
"ȷ<EFBFBD><EFBFBD>", 5000);
((WIN_WindowStruct *)bluetooth)
->deleteWindow((WIN_WindowStruct *)bluetooth);
}
} else {
if (bluetooth->power == 0) {
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
MSGBOX_TipsTime((WIN_WindowStruct *)bluetooth, "<EFBFBD><EFBFBD>ʾ", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹر<EFBFBD>",
"ȷ<EFBFBD><EFBFBD>", 5000);
((WIN_WindowStruct *)bluetooth)
->deleteWindow((WIN_WindowStruct *)bluetooth);
} else {
// ѡ<><D1A1>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int ret = -1;
// ret=connectDevice (bluetooth->selectItem);
if (ret == 0) {
MSGBOX_TipsTime((WIN_WindowStruct *)bluetooth, "<EFBFBD><EFBFBD>ʾ", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳɹ<EFBFBD>",
"ȷ<EFBFBD><EFBFBD>", 5000);
} else {
MSGBOX_TipsTime((WIN_WindowStruct *)bluetooth, "<EFBFBD><EFBFBD>ʾ", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>",
"ȷ<EFBFBD><EFBFBD>", 5000);
}
((WIN_WindowStruct *)bluetooth)
->deleteWindow((WIN_WindowStruct *)bluetooth);
}
}
2025-06-27 00:32:57 +08:00
}
void BLUETOOTH_KeyBack(WIN_BlueToothStruct *bluetooth) {
// ʲôҲû<D2B2><C3BB><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD>
// Bluetooth_Power(0);
MSGBOX_TipsTime((WIN_WindowStruct *)bluetooth, "<EFBFBD><EFBFBD>ʾ", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹر<EFBFBD>", "ȷ<EFBFBD><EFBFBD>",
5000);
((WIN_WindowStruct *)bluetooth)->deleteWindow((WIN_WindowStruct *)bluetooth);
2025-06-27 00:32:57 +08:00
}
void BLUETOOTH_KeyUp(WIN_BlueToothStruct *bluetooth) {
if (bluetooth->index == 0) {
bluetooth->power = !bluetooth->power;
} else {
if (bluetooth->selectItem < bluetooth->itemNum - 1) {
bluetooth->selectItem++;
if (bluetooth->startItem < bluetooth->selectItem - 3) {
bluetooth->startItem++;
}
} else {
bluetooth->selectItem = 0;
bluetooth->startItem = 0;
}
}
2025-06-27 00:32:57 +08:00
}
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->startItem < bluetooth->selectItem - 3) {
bluetooth->startItem = bluetooth->selectItem - 3;
}
}
}
2025-06-27 00:32:57 +08:00
}
// <20><>Ϣ<EFBFBD><CFA2><EFBFBD>Ļ<EFBFBD><C4BB>ƺ<EFBFBD><C6BA><EFBFBD>
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);
// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
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;
// <20><><EFBFBD>ƾ<EFBFBD><C6BE><EFBFBD>
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);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (bluetooth->power) {
WIN_SetLcdColor(bluetooth->selectTxtColor);
} else {
WIN_SetLcdColor(bluetooth->txtColor);
}
WIN_DrawTxtHCenterAt("<EFBFBD><EFBFBD>", 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("<EFBFBD><EFBFBD>", x + x_step + x_step / 2,
y + y_step / 2 - WIN_GetFontHight() / 2);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>б<EFBFBD>
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->startItem < bluetooth->itemNum) {
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;
}
}
2025-06-27 00:32:57 +08:00
}
// <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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;
// <20>յ<EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD>򷵻ؼ<F2B7B5BB>
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;
}
2025-06-27 00:32:57 +08:00
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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;
2025-06-27 00:32:57 +08:00
}