void setLastReceivedChar(char c)
{
  lastRxChar = c;
  displayNeedsUpdate = true;
}

void pushRxHistoryChar(char c)
{
  for (int i = 0; i < rxHistoryLen - 1; i++) {
    rxHistory[i] = rxHistory[i + 1];
  }
  rxHistory[rxHistoryLen - 1] = c;
  rxHistory[rxHistoryLen] = '\0';
  displayNeedsUpdate = true;
}

void showStatus()
{
  long countCopy;
  noInterrupts();
  countCopy = encoderCount;
  interrupts();

  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);

  display.setTextSize(1);
  display.setCursor(0, 0);

  if (digitalRead(afskTestPin) == LOW) {
    display.print("AFSK");
  } else if (digitalRead(modePin) == LOW) {
    display.print("GENER");
  } else {
    display.print("ECHO");
  }

  display.setCursor(52, 0);
  display.print(rxFiguresMode ? "FIGS" : "LTRS");

  char encBuf[16];
  snprintf(encBuf, sizeof(encBuf), "%ld", countCopy);
  int16_t x1, y1;
  uint16_t w, h;
  display.getTextBounds(encBuf, 0, 0, &x1, &y1, &w, &h);
  display.setCursor(127 - w, 0);
  display.print(encBuf);

  display.drawLine(0, 10, 127, 10, SSD1306_WHITE);

  display.setTextSize(5);
  display.setCursor(42, 16);
  if (lastRxChar >= 32 && lastRxChar <= 126) {
    display.write(lastRxChar);
  } else {
    display.print("?");
  }

  display.setTextSize(1);
  display.setCursor(0, 56);
  display.print(rxHistory);

  display.display();
}