OLED init and debug

This commit is contained in:
Timm Bogner 2023-01-20 09:05:06 -06:00
parent 8560f51da0
commit 81ddfd7b73

View File

@ -65,18 +65,20 @@ enum {
cmd_ack
};
void debug_OLED(String debug_text);
#ifdef FDRS_DEBUG
#ifdef USE_OLED
#define DBG(a) (Serial.println(a); debug_OLED(a))
#else
#define DBG(a) (Serial.println(a))
#endif
#ifdef USE_OLED
#define DBG(a) debug_OLED(String(a));
#else
#ifdef USE_OLED
#define DBG(a) (debug_OLED(a))
#else
#define DBG(a)
#endif
#define DBG(a) Serial.println(a);
#endif
#else
#ifdef USE_OLED
#define DBG(a) debug_OLED(String(a));
#else
#define DBG(a)
#endif
#endif
#if defined (ESP32)
@ -149,7 +151,6 @@ enum {
#endif //USE_WIFI
#ifdef USE_LORA
// select LoRa band configuration
#if defined(LORA_BAND)
#define FDRS_BAND LORA_BAND
@ -332,6 +333,56 @@ static uint16_t crc16_update(uint16_t crc, uint8_t a)
#include <fdrs_lora.h>
#include <fdrs_espnow.h>
#define USE_OLED
#define OLED_HEADER "FDRS"
#define OLED_SDA 4
#define OLED_SCL 15
#define OLED_RST 16
String debug_buffer[5] = {"", "", "", "", ""};
SSD1306Wire display(0x3c, OLED_SDA, OLED_SCL); // ADDRESS, SDA, SCL
void draw_OLED_header()
{
display.clear();
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawString(0, 0, String(UNIT_MAC, HEX));
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.drawString(63, 0, OLED_HEADER);
display.setTextAlignment(TEXT_ALIGN_RIGHT);
display.drawString(127, 0, "TBD");
display.display();
display.setTextAlignment(TEXT_ALIGN_LEFT);
}
void debug_OLED(String debug_text)
{
#ifdef FDRS_DEBUG
Serial.println(debug_text);
#endif
draw_OLED_header();
for (uint8_t i = 4; i > 0; i--)
{
debug_buffer[i] = debug_buffer[i-1];
}
debug_buffer[0] = debug_text;
Serial.println("updated buffer");
uint8_t lineNumber = 0;
for (uint8_t i = 0; i < 5; i++)
{
Serial.println("line");
uint8_t ret = display.drawStringMaxWidth(0, 15 +(lineNumber*9), 127,debug_buffer[i]);
Serial.println("--" + debug_buffer[i]);
lineNumber = ret + lineNumber;
if (lineNumber > 5)
break;
}
display.display();
}
void getSerial() {
String incomingString;
@ -756,13 +807,30 @@ void handleCommands() {
}
void beginFDRS(){
#if defined(ESP8266)
#if defined(ESP8266)
Serial.begin(115200);
#elif defined(ESP32)
Serial.begin(115200);
UART_IF.begin(115200, SERIAL_8N1, RXD2, TXD2);
#endif
#ifdef USE_OLED
pinMode(OLED_RST, OUTPUT);
digitalWrite(OLED_RST, LOW);
delay(30);
digitalWrite(OLED_RST, HIGH);
Wire.begin(OLED_SDA, OLED_SCL);
// Initialising the UI will init the display too.
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
draw_OLED_header();
DBG("Display initialized!")
DBG("Hello, World!")
#endif
DBG("Address:" + String (UNIT_MAC, HEX));
#ifdef USE_LED
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
leds[0] = CRGB::Blue;