17 #define NEX_RET_CMD_FINISHED (0x01)
18 #define NEX_RET_EVENT_LAUNCHED (0x88)
19 #define NEX_RET_EVENT_UPGRADED (0x89)
20 #define NEX_RET_EVENT_TOUCH_HEAD (0x65)
21 #define NEX_RET_EVENT_POSITION_HEAD (0x67)
22 #define NEX_RET_EVENT_SLEEP_POSITION_HEAD (0x68)
23 #define NEX_RET_CURRENT_PAGE_ID_HEAD (0x66)
24 #define NEX_RET_STRING_HEAD (0x70)
25 #define NEX_RET_NUMBER_HEAD (0x71)
26 #define NEX_RET_INVALID_CMD (0x00)
27 #define NEX_RET_INVALID_COMPONENT_ID (0x02)
28 #define NEX_RET_INVALID_PAGE_ID (0x03)
29 #define NEX_RET_INVALID_PICTURE_ID (0x04)
30 #define NEX_RET_INVALID_FONT_ID (0x05)
31 #define NEX_RET_INVALID_BAUD (0x11)
32 #define NEX_RET_INVALID_VARIABLE (0x1A)
33 #define NEX_RET_INVALID_OPERATION (0x1B)
45 bool recvRetNumber(uint32_t *number, uint32_t timeout)
48 uint8_t temp[8] = {0};
56 if (
sizeof(temp) !=
nexSerial.readBytes((
char *)temp,
sizeof(temp)))
61 if (temp[0] == NEX_RET_NUMBER_HEAD
67 *number = (temp[4] << 24) | (temp[3] << 16) | (temp[2] << 8) | (temp[1]);
75 dbSerialPrint(
"recvRetNumber :");
76 dbSerialPrintln(*number);
80 dbSerialPrintln(
"recvRetNumber err");
97 uint16_t recvRetString(
char *buffer, uint16_t len, uint32_t timeout)
100 bool str_start_flag =
false;
101 uint8_t cnt_0xff = 0;
102 String temp = String(
"");
106 if (!buffer || len == 0)
112 while (millis() - start <= timeout)
132 else if (NEX_RET_STRING_HEAD == c)
134 str_start_flag =
true;
145 ret = ret > len ? len : ret;
146 strncpy(buffer, temp.c_str(), ret);
150 dbSerialPrint(
"recvRetString[");
151 dbSerialPrint(temp.length());
154 dbSerialPrintln(
"]");
164 void sendCommand(
const char* cmd)
187 bool recvRetCommandFinished(uint32_t timeout)
190 uint8_t temp[4] = {0};
193 if (
sizeof(temp) !=
nexSerial.readBytes((
char *)temp,
sizeof(temp)))
198 if (temp[0] == NEX_RET_CMD_FINISHED
209 dbSerialPrintln(
"recvRetCommandFinished ok");
213 dbSerialPrintln(
"recvRetCommandFinished err");
228 sendCommand(
"bkcmd=1");
229 ret1 = recvRetCommandFinished();
230 sendCommand(
"page 0");
231 ret2 = recvRetCommandFinished();
237 static uint8_t __buffer[10];
247 if (NEX_RET_EVENT_TOUCH_HEAD == c)
252 for (i = 1; i < 7; i++)
258 if (0xFF == __buffer[4] && 0xFF == __buffer[5] && 0xFF == __buffer[6])
260 NexTouch::iterate(nex_listen_list, __buffer[1], __buffer[2], (int32_t)__buffer[3]);
void nexLoop(NexTouch *nex_listen_list[])
Listen touch event and calling callbacks attached before.
#define nexSerial
Define nexSerial for communicate with Nextion touch panel.
bool nexInit(void)
Init Nextion.
The definition of base API for using Nextion.
Father class of the components with touch events.