Skip to content

Commit 17788f9

Browse files
committed
修复串口命令失效的问题
1 parent 39d4c42 commit 17788f9

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/SmallDesktopDisplay.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,17 +372,23 @@ void SmartConfig(void)
372372
#endif
373373

374374
String SMOD = ""; // 0亮度
375-
//串口调试设置函数
375+
String incomingByte = "";
376+
// 串口调试设置函数
376377
void Serial_set()
377378
{
378-
String incomingByte = "";
379379
if (Serial.available() > 0)
380380
{
381-
while (Serial.available() > 0) //监测串口缓存,当有数据输入时,循环赋值给incomingByte
381+
byte b;
382+
delay(1); // 不能省略,因为读取缓冲区数据需要时间
383+
b = Serial.read();
384+
if (b != '\r')
382385
{
383-
incomingByte += char(Serial.read()); //读取单个字符值,转换为字符,并按顺序一个个赋值给incomingByte
384-
delay(2); //不能省略,因为读取缓冲区数据需要时间
386+
char c = char(b);
387+
incomingByte += c; // 读取单个字符值,转换为字符,并按顺序一个个赋值给incomingByte
388+
Serial.print(c);
389+
return;
385390
}
391+
Serial.println();
386392
if (SMOD == "0x01") //设置1亮度设置
387393
{
388394
int LCDBL = atoi(incomingByte.c_str()); // int n = atoi(xxx.c_str());//String转int
@@ -475,14 +481,15 @@ void Serial_set()
475481
Serial.printf("天气更新时间更改为:");
476482
Serial.print(updateweater_time);
477483
Serial.println("分钟");
484+
reflash_openWifi.setInterval(updateweater_time * 60 * TMS); //设置所需间隔
478485
}
479486
else
480487
Serial.println("更新时间太长,请重新设置(1-60)");
481488
}
482489
else
483490
{
484491
SMOD = incomingByte;
485-
delay(2);
492+
incomingByte = "";
486493
if (SMOD == "0x01")
487494
Serial.println("请输入亮度值,范围0-100");
488495
else if (SMOD == "0x02")

0 commit comments

Comments
 (0)