Xinyuan-LilyGO / LilyGo-LoRa-Series

LILYGO LoRa Series examples
603 stars 169 forks source link

2nd Line of Text Sent Not Centered on Receiver OLED Display #74

Closed va7ta closed 1 year ago

va7ta commented 1 year ago

When I try to transmit two lines of text from the sender using println for line 2 the following line sent is not displayed properly on the receiver OLED. As shown by the attached debug screen-capture of the repetitive ASCII text lines from the LoRa receiver the text lines are received normally with each line-end terminated with CRLF. Upon detecting CRLF the receiver display code shifts the Y-axis down correctly for the next line. But display incorrectly starts the beginning of the WiFi RSSI line at the X-axis center of the OLED screen instead of centering the whole line properly on the X-axis. As shown by the attached screen photo this results in the disappearance of the last half of the last line as it is beyond the X-axis screen edge.


2ndLineNotCenteredIssue_ReceivedText


2ndLineNotCenteredIssue


va7ta commented 1 year ago

I decided to work around the apparent display limitation by separating the two lines in the receiver code which provides individual control of the position of each line. Below is my loop snippet for the ino file:

//*****

void loop() {

if LORA_SENDER

int32_t rssi;
if (WiFi.status() == WL_CONNECTED) {
    rssi = WiFi.RSSI();
    display.clear();
    display.setTextAlignment(TEXT_ALIGN_CENTER);
    display.drawString(display.getWidth() / 2, display.getHeight() / 2, "Send RSSI:" + String(rssi));
    display.display();
    LoRa.beginPacket();
    LoRa.println("First Line Info");
    LoRa.print("WiFi RSSI: ");
    LoRa.print(rssi);
    LoRa.endPacket();
} else {
    Serial.println("WiFi Connect lost ...");
}
delay(2500);

else

if (LoRa.parsePacket()) {
    String recv = "";
    int lf = 10;
    int cr = 0x0D;
    int pktcharcount = 0;
    while (LoRa.available()) {
        recv += (char)LoRa.read();
        pktcharcount++;
    }
    Serial.print("pktcharcount = ");  //debug statement
    Serial.println(pktcharcount);     //debug statement
    String line_1 = "";
    int charval = 1;
    int idx=0;
    while((idx < pktcharcount)&&(charval != 10)){
      line_1 += recv[idx];
      charval = recv[idx];
      idx++;
    }
    int line1charcount = idx;
    Serial.print("line1chars = ");  //debug statement
    Serial.println(line1charcount); //debug statement       
    Serial.print("line_1 = ");      //debug statement
    Serial.println(line_1);         //debug statement

    String line_2 = "";
    int line2available = false;
    if (line1charcount < pktcharcount) {
      line2available = true;
      charval = 1;
      idx=line1charcount;
      while((idx < pktcharcount)&&(charval != 10)){
        line_2 += recv[idx];
        charval = recv[idx];
        idx++;
      }
      int line2charcount = (idx-line1charcount);
      Serial.print("line2chars = ");  //debug statement
      Serial.println(line2charcount); //debug statement   
      Serial.print("line_2 = ");      //debug statement
      Serial.println(line_2);         //debug statement
    }

//**** count++; // Serial.println(recv); // debug statement // Now draw and position the lines of text display.clear(); display.setTextAlignment(TEXT_ALIGN_CENTER); int displaywidth = display.getWidth(); // =128 int displayheight = display.getHeight(); // = 64 //line 0 // Convert the rx packet count to text and get LoRa signal level, then draw info line String info = "[" + String(count) + "]" + "RSSI " + String(LoRa.packetRssi()); display.drawString(displaywidth/2, displayheight/2 - 32, info); //** // Draw and display LoRa packet message //line 1 display.setTextAlignment(TEXT_ALIGN_LEFT); display.drawString(0, 24, line_1); // x=113, y=24 display.display(); //line 2 if (line2available) { display.setTextAlignment(TEXT_ALIGN_LEFT); display.drawString(0, 44, line_2); // x=58, y=44 display.display(); } }