Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some issues #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Example.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ long value;

#define buttonPageID 0
#define sliderPageID 0
#define buttonID 2
#define buttonID 1
#define sliderID 2

void main()
Expand Down Expand Up @@ -44,4 +44,4 @@ void buttonCallback(void *ptr)
void sliderCallback(void *ptr)
{
//TODO
}
}
97 changes: 41 additions & 56 deletions nextion/NexHardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,19 @@ uint8_t recvRetNumber(uint32_t *number)
uint8_t ret = 0;
char temp[8];

if (!number)
{
goto __return;
}

nexDelay(100);
if (8 != nexSerial_readBytes((char *)temp, 8))
{
goto __return;
}

if (temp[0] == NEX_RET_NUMBER_HEAD && temp[5] == 0xFF && temp[6] == 0xFF && temp[7] == 0xFF)
{
*number = ((uint32_t)temp[4] << 24) | ((uint32_t)temp[3] << 16) | (temp[2] << 8) | (temp[1]);
ret = 1;
if (number){

nexDelay(100);
if (8 == nexSerial_readBytes((char *)temp, 8)){

if (temp[0] == NEX_RET_NUMBER_HEAD && temp[5] == 0xFF && temp[6] == 0xFF && temp[7] == 0xFF){

*number = ((uint32_t)temp[4] << 24) | ((uint32_t)temp[3] << 16) | (temp[2] << 8) | (temp[1]);
ret = 1;
}
}
}

__return:

/*if (ret)
{
dbSerialPrint("recvRetNumber :");
Expand Down Expand Up @@ -101,55 +95,46 @@ uint16_t recvRetString(char *buffer, uint16_t len)
uint16_t ret = 0;
uint8_t str_start_flag = 0;
uint8_t cnt_0xff = 0;
char arr[32];
char *temp = arr;
uint8_t arr[32];
uint8_t *temp = arr;
uint8_t c = 0;
long start;

if (!buffer || len == 0)
{
goto __return;
}

start = 500;
while (start)
{
while (nexSerial_available())
{
c = nexSerial_read();
if (str_start_flag)
{
if (0xFF == c)
{
cnt_0xff++;
if (cnt_0xff >= 3)
{
break;
if (buffer && len){

start = 50000;

while (start){
while (nexSerial_available()){

c = nexSerial_read();

if (str_start_flag){

if (0xFF == c){
cnt_0xff++;
if (cnt_0xff >= 3){
break;
}
}else{
*temp++ = c;
}
}
else
{
temp += (char)c;
} else if (NEX_RET_STRING_HEAD == c){
str_start_flag = 1;
}
}
else if (NEX_RET_STRING_HEAD == c)
{
str_start_flag = 1;

if (cnt_0xff >= 3){
break;
}
--start;
}

if (cnt_0xff >= 3)
{
break;
}
--start;
ret = ArrayLength(temp);
ret = ret > len ? len : ret;
strncpy(buffer, temp, ret);
}

ret = ArrayLength(temp);
ret = ret > len ? len : ret;
strncpy(buffer, temp, ret);

__return:
/*
dbSerialPrint("recvRetString[");
dbSerialPrint(temp.length());
Expand Down Expand Up @@ -250,4 +235,4 @@ void nexLoop(struct NexObject *nex_listen_list[])
}
}
}
}
}