Skip to content
Snippets Groups Projects
Commit 1ba0430c authored by John Lee's avatar John Lee
Browse files

16x2lcd: add text sliding

parent 2676eadf
Branches
No related tags found
No related merge requests found
...@@ -160,7 +160,7 @@ ...@@ -160,7 +160,7 @@
<label for="text-10" style="margin:15px 10px 0 0; text-align:right;">Build date</label> <label for="text-10" style="margin:15px 10px 0 0; text-align:right;">Build date</label>
</div> </div>
<div class="ui-block-d"> <div class="ui-block-d">
<input data-mini="true" disabled="disabled" id="text-10" value="160914" type="text"> <input data-mini="true" disabled="disabled" id="text-10" value="161206" type="text">
</div> </div>
</div> </div>
</div> </div>
......
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
#define USE_SERIAL Serial #define USE_SERIAL Serial
#define MAX_LCD_SSID_LENGTH 12
#define MAX_LCD_IP_LENGTH 14
#define ON 0 #define ON 0
#define OFF 1 #define OFF 1
#define HOME 0 #define HOME 0
...@@ -275,7 +278,6 @@ void handleClientData(uint8_t num, String data) ...@@ -275,7 +278,6 @@ void handleClientData(uint8_t num, String data)
sendStatus(i, 1); sendStatus(i, 1);
} }
} }
break; break;
} }
case MEASUREWATTHOUR: case MEASUREWATTHOUR:
...@@ -312,15 +314,16 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght ...@@ -312,15 +314,16 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
break; break;
case WStype_CONNECTED : { case WStype_CONNECTED : {
IPAddress ip = webSocket.remoteIP(num); IPAddress ip = webSocket.remoteIP(num);
USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n\r", num, ip[0], ip[1], ip[2], ip[3], payload); USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n\r",
num, ip[0], ip[1], ip[2], ip[3], payload);
client_sp2[num].connected = 1; client_sp2[num].connected = 1;
connectedWeb = 1; connectedWeb = 1;
}
break; break;
}
case WStype_TEXT : { case WStype_TEXT : {
handleClientData(num, String((char *)&payload[0])); handleClientData(num, String((char *)&payload[0]));
}
break; break;
}
case WStype_BIN : case WStype_BIN :
USE_SERIAL.printf("[%u] get binary lenght: %u\n\r", num, lenght); USE_SERIAL.printf("[%u] get binary lenght: %u\n\r", num, lenght);
hexdump(payload, lenght); hexdump(payload, lenght);
...@@ -436,39 +439,82 @@ void printPower_LCD(void) ...@@ -436,39 +439,82 @@ void printPower_LCD(void)
if (watth < 10) { if (watth < 10) {
lcd.print(watth, 3); lcd.print(watth, 3);
lcd.print(" ");
} else if (watth < 100) { } else if (watth < 100) {
lcd.print(watth, 2); lcd.print(watth, 2);
} else { lcd.print(" ");
} else if (watth < 1000) {
lcd.print(watth, 1); lcd.print(watth, 1);
lcd.print(" ");
} else {
lcd.print(watth/1000, 0);
lcd.print(" K");
} }
lcd.print("Wh "); lcd.print("Wh ");
} }
uint8_t cnt_ssid; uint8_t cnt_ssid;
uint8_t cursor_lcd; int8_t cnt_ip;
int8_t cursor_ssid;
int8_t cursor_ip;
void printInfo_LCD(void) void printInfo_LCD(void)
{ {
for (int i = 0; i < 30; i++) { String str;
if (ssid[i] == '\0') { int i;
cnt_ssid = i; cnt_ssid = String(ssid).length();
break;
}
}
lcd.setCursor(0, 0); lcd.setCursor(0, 0);
lcd.print("SSID:"); lcd.print("SSID:");
lcd.print(ssid); str = String(ssid);
if (cnt_ssid < 11) { if (cnt_ssid < MAX_LCD_SSID_LENGTH) {
for (int i = 0; i < 11 - cnt_ssid; i++) { lcd.print(str);
for (i = 0; i < MAX_LCD_SSID_LENGTH; i++) {
lcd.print(" ");
}
} else {
if ((cursor_ssid - 5) == cnt_ssid) {
cursor_ssid = 0;
}
lcd.print(str.substring(cursor_ssid++));
if ((cnt_ssid - cursor_ssid) < MAX_LCD_SSID_LENGTH - 5) {
if (cnt_ssid < cursor_ssid) {
for (i = 0; i < 6 - (cursor_ssid - cnt_ssid); i++)
lcd.print(" ");
} else {
lcd.print(" ");
}
lcd.print(str);
} else if ((cnt_ssid - cursor_ssid) < MAX_LCD_SSID_LENGTH) {
for (i = 0; i < MAX_LCD_SSID_LENGTH - (cnt_ssid - cursor_ssid); i++)
lcd.print(" "); lcd.print(" ");
} }
} }
lcd.setCursor(0, 1); lcd.setCursor(0, 1);
lcd.print("IP:"); lcd.print("IP:");
cnt_ip = ip.toString().length();
if (cnt_ip < MAX_LCD_IP_LENGTH) {
lcd.print(ip.toString());
for (i = 0; i < MAX_LCD_IP_LENGTH - cnt_ip; i++)
lcd.print(" ");
} else {
if ((cursor_ip - 5) == cnt_ip) {
cursor_ip = 0;
}
lcd.print(ip.toString().substring(cursor_ip++));
if ((cnt_ip - cursor_ip) < MAX_LCD_IP_LENGTH - 5) {
if (cnt_ip < cursor_ip) {
for (i = 0; i < 6 - (cursor_ip - cnt_ip); i++)
lcd.print(" ");
} else {
lcd.print(" ");
}
lcd.print(ip.toString()); lcd.print(ip.toString());
} else if((cnt_ip - cursor_ip) < MAX_LCD_IP_LENGTH) {
for (i = 0; i < MAX_LCD_IP_LENGTH - (cnt_ip - cursor_ip); i++)
lcd.print(" "); lcd.print(" ");
} }
}
}
void readPower(void) void readPower(void)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment