Fixed display blinking & cleaned code
This commit is contained in:
parent
e38fbd54f8
commit
4022e5489e
|
@ -18,35 +18,32 @@ void setup() {
|
|||
M5.Lcd.begin();
|
||||
M5.Lcd.setTextSize(1);
|
||||
M5.Lcd.setFreeFont(&Ubuntu_24px);
|
||||
M5.Lcd.setTextPadding(0);
|
||||
M5.Lcd.drawString("Connecting to LoRaWAN...", 0, 0);
|
||||
while (!LoRaWAN.checkDeviceConnect());
|
||||
LoRaWAN.writeCMD("AT?\r\n");
|
||||
delay(100);
|
||||
Serial2.flush();
|
||||
|
||||
// Disable Log Information
|
||||
LoRaWAN.writeCMD("AT+ILOGLVL=0\r\n");
|
||||
// Enable Log Information
|
||||
LoRaWAN.writeCMD("AT+CSAVE\r\n");
|
||||
LoRaWAN.writeCMD("AT+IREBOOT=0\r\n");
|
||||
delay(1000);
|
||||
// Set Join Mode OTAA.
|
||||
LoRaWAN.configOTTA("00bdea85badeedf1", // Device EUI
|
||||
"00bdea85badeed01", // APP EUI
|
||||
"00bdea85badeed0100bdea85badeed01", // APP KEY
|
||||
"2" // Upload Download Mode
|
||||
LoRaWAN.configOTTA(
|
||||
"00bdea85badeedf1", // Device EUI
|
||||
"00bdea85badeed01", // APP EUI
|
||||
"00bdea85badeed0100bdea85badeed01", // APP KEY
|
||||
"2" // Upload Download Mode
|
||||
);
|
||||
LoRaWAN.waitMsg(1000);
|
||||
|
||||
// Set ClassC mode
|
||||
LoRaWAN.setClass("2");
|
||||
LoRaWAN.writeCMD("AT+CWORKMODE=2\r\n");
|
||||
|
||||
// LoRaWAN868
|
||||
// TX Freq
|
||||
// Transmit frequencies
|
||||
// 868.1 - SF7BW125 to SF12BW125
|
||||
// 868.3 - SF7BW125 to SF12BW125 and SF7BW250
|
||||
// 868.5 - SF7BW125 to SF12BW125 best
|
||||
// 868.5 - SF7BW125 to SF12BW125
|
||||
// 867.1 - SF7BW125 to SF12BW125
|
||||
// 867.3 - SF7BW125 to SF12BW125
|
||||
// 867.5 - SF7BW125 to SF12BW125
|
||||
|
@ -172,8 +169,7 @@ void receiveMsg() {
|
|||
String decodedMsg = decodeMsg(split(recvMsg, ',', 3));
|
||||
Serial.println(decodedMsg);
|
||||
if(decodedMsg.substring(0,5) == "CLEAR") {
|
||||
memset(departures, 0, sizeof(departures));
|
||||
departureIndex = 0;
|
||||
clearDepartures();
|
||||
} else
|
||||
if(decodedMsg.substring(0,5) == "TIME|") {
|
||||
unixtime = (decodedMsg.substring(5,30).toInt()) - last_update*6;
|
||||
|
@ -186,17 +182,16 @@ void receiveMsg() {
|
|||
|
||||
|
||||
|
||||
// Departure functions
|
||||
// Global display variables
|
||||
|
||||
struct departure parseDeparture(String s) {
|
||||
struct departure d;
|
||||
d.id = split(s, '|', 0).toInt();
|
||||
d.type = split(s, '|', 1).toInt();
|
||||
d.line = split(s, '|', 2);
|
||||
d.last_stop = split(s, '|', 3);
|
||||
d.departure = split(s, '|', 4).toInt();
|
||||
return d;
|
||||
}
|
||||
String displayedLines[7];
|
||||
String displayedLastStops[7];
|
||||
String displayedDepartureTimes[7];
|
||||
|
||||
String displayedTime;
|
||||
String displayedDate;
|
||||
|
||||
// Display functions
|
||||
|
||||
void displayTimeDate(int lines) {
|
||||
char date[20];
|
||||
|
@ -204,69 +199,63 @@ void displayTimeDate(int lines) {
|
|||
unsigned long timestamp = unixtime + last_update*6;
|
||||
unixToDate(timestamp, date);
|
||||
unixToTime(timestamp, time);
|
||||
M5.Lcd.fillRect(0, lines*30, 320, 30, BLACK);
|
||||
M5.Lcd.drawString(String(date), 0, lines*30+5);
|
||||
M5.Lcd.setTextDatum(TR_DATUM);
|
||||
M5.Lcd.drawString(String(time), 320, lines*30+5);
|
||||
if(displayedDate != date) {
|
||||
displayedDate = date;
|
||||
M5.Lcd.setTextDatum(TL_DATUM);
|
||||
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
M5.Lcd.fillRect(0, lines*30, 160, 30, BLACK);
|
||||
M5.Lcd.drawString(String(date), 0, lines*30+5);
|
||||
}
|
||||
if(displayedTime != time) {
|
||||
displayedTime = time;
|
||||
M5.Lcd.setTextDatum(TR_DATUM);
|
||||
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
M5.Lcd.fillRect(160, lines*30, 160, 30, BLACK);
|
||||
M5.Lcd.drawString(String(time), 320, lines*30+5);
|
||||
}
|
||||
}
|
||||
|
||||
void displayLine(String line, int type, int y) {
|
||||
if(displayedLines[y] == line) return;
|
||||
displayedLines[y] = line;
|
||||
uint16_t color = 0xFFFFFF;
|
||||
if(type == 1) color = 0xFFEA;
|
||||
if(type == 2) color = 0x6FF0;
|
||||
if(type == 3) color = 0xFAAD;
|
||||
M5.Lcd.setTextDatum(TL_DATUM);
|
||||
M5.Lcd.setTextColor(color, TFT_BLACK);
|
||||
M5.Lcd.fillRect(0, y*30, 40, 30, BLACK);
|
||||
M5.Lcd.drawString(line, 0, y*30);
|
||||
}
|
||||
|
||||
void displayLastStop(String lastStop, int y) {
|
||||
if(displayedLastStops[y] == lastStop) return;
|
||||
displayedLastStops[y] = lastStop;
|
||||
M5.Lcd.setTextDatum(TL_DATUM);
|
||||
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
M5.Lcd.fillRect(40, y*30, 255, 30, BLACK);
|
||||
M5.Lcd.drawString(lastStop, 40, y*30);
|
||||
}
|
||||
|
||||
void displayDepartureTime(String departure, int y) {
|
||||
if(displayedDepartureTimes[y] == departure) return;
|
||||
displayedDepartureTimes[y] = departure;
|
||||
M5.Lcd.setTextDatum(TR_DATUM);
|
||||
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
M5.Lcd.fillRect(290, y*30, 30, 30, BLACK);
|
||||
M5.Lcd.drawString(departure, 320, y*30);
|
||||
}
|
||||
|
||||
void displayDeparture(struct departure d, int y) {
|
||||
|
||||
uint16_t color = 0xFFFFFF;
|
||||
if(d.type == 1) color = 0xFFEA; // žlutá: 0xEF53 / 0xFFEB
|
||||
if(d.type == 2) color = 0x6FF0;
|
||||
if(d.type == 3) color = 0xFAAD;
|
||||
M5.Lcd.setTextColor(color, TFT_BLACK);
|
||||
M5.Lcd.fillRect(0, y*30, 40, 30, BLACK);
|
||||
M5.Lcd.drawString(d.line, 0, y*30);
|
||||
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
|
||||
M5.Lcd.fillRect(40, y*30, 255, 30, BLACK);
|
||||
M5.Lcd.drawString(d.last_stop, 40, y*30);
|
||||
|
||||
displayLine(d.line, d.type, y);
|
||||
displayLastStop(d.last_stop, y);
|
||||
String departure = "<1";
|
||||
if(d.departure >= 10) departure = String(d.departure/10);
|
||||
M5.Lcd.setTextDatum(TR_DATUM);
|
||||
M5.Lcd.fillRect(290, y*30, 30, 30, BLACK);
|
||||
M5.Lcd.drawString(departure, 320, y*30);
|
||||
M5.Lcd.setTextDatum(TL_DATUM);
|
||||
displayDepartureTime(departure, y);
|
||||
|
||||
}
|
||||
|
||||
int departureComparation(const void* a,const void* b) {
|
||||
departure* x = (departure*) a;
|
||||
departure* y = (departure*) b;
|
||||
return x->departure - y->departure;
|
||||
}
|
||||
|
||||
void sortDepartures() {
|
||||
qsort(departures, departureIndex, sizeof(departure), departureComparation);
|
||||
}
|
||||
|
||||
void removeDeparture(int pos) {
|
||||
for (int i = pos; i < departureIndex-1; i++) {
|
||||
departures[i] = departures[i+1];
|
||||
}
|
||||
departureIndex--;
|
||||
}
|
||||
|
||||
void addDeparture(String s) {
|
||||
struct departure d = parseDeparture(s);
|
||||
for(int i=0; i<departureIndex; i++) {
|
||||
if(departures[i].id == d.id) {
|
||||
if(d.line != "") departures[i].line = d.line;
|
||||
if(d.type != 0) departures[i].type = d.type;
|
||||
if(d.last_stop != "") departures[i].last_stop = d.last_stop;
|
||||
if(d.departure != 0) departures[i].departure = d.departure;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(d.line == "" || d.last_stop == "") return;
|
||||
departures[departureIndex] = d;
|
||||
departureIndex++;
|
||||
}
|
||||
|
||||
void displayDepartures(int lines) {
|
||||
String displayed[50];
|
||||
int displayedIndex = 0;
|
||||
|
@ -290,6 +279,62 @@ void displayDepartures(int lines) {
|
|||
|
||||
|
||||
|
||||
// Departure functions
|
||||
|
||||
struct departure parseDeparture(String s) {
|
||||
struct departure d;
|
||||
d.id = split(s, '|', 0).toInt();
|
||||
d.type = split(s, '|', 1).toInt();
|
||||
d.line = split(s, '|', 2);
|
||||
d.last_stop = split(s, '|', 3);
|
||||
d.departure = split(s, '|', 4).toInt();
|
||||
return d;
|
||||
}
|
||||
|
||||
int departureComparation(const void* a,const void* b) {
|
||||
departure* x = (departure*) a;
|
||||
departure* y = (departure*) b;
|
||||
return x->departure - y->departure;
|
||||
}
|
||||
|
||||
void sortDepartures() {
|
||||
qsort(departures, departureIndex, sizeof(departure), departureComparation);
|
||||
}
|
||||
|
||||
void removeDeparture(int pos) {
|
||||
for (int i = pos; i < departureIndex-1; i++) {
|
||||
departures[i] = departures[i+1];
|
||||
}
|
||||
departureIndex--;
|
||||
}
|
||||
|
||||
void clearDepartures() {
|
||||
memset(departures, 0, sizeof(departures));
|
||||
departureIndex = 0;
|
||||
memset(displayedLines, 0, sizeof(displayedLines));
|
||||
memset(displayedLastStops, 0, sizeof(displayedLastStops));
|
||||
memset(displayedDepartureTimes, 0, sizeof(displayedDepartureTimes));
|
||||
}
|
||||
|
||||
void addDeparture(String s) {
|
||||
struct departure d = parseDeparture(s);
|
||||
for(int i=0; i<departureIndex; i++) {
|
||||
if(departures[i].id == d.id) {
|
||||
if(d.line != "") departures[i].line = d.line;
|
||||
if(d.type != 0) departures[i].type = d.type;
|
||||
if(d.last_stop != "") departures[i].last_stop = d.last_stop;
|
||||
if(d.departure != 0) departures[i].departure = d.departure;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(d.line == "" || d.last_stop == "") return;
|
||||
departures[departureIndex] = d;
|
||||
departureIndex++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Main loop with time counting
|
||||
|
||||
void loop() {
|
||||
|
|
Loading…
Reference in a new issue