dynamically probe for screen and don't even use it if...

waking from deep sleep timer
This commit is contained in:
geeksville 2020-01-19 10:12:48 -08:00
parent 2da1f623ff
commit a35c6dcbe9
2 changed files with 28 additions and 6 deletions

View File

@ -272,7 +272,7 @@ void doDeepSleep()
// Perform power on init that we do on each wake from deep sleep // Perform power on init that we do on each wake from deep sleep
void initDeepSleep() { void initDeepSleep() {
bootCount++; bootCount++;
wakeCause = esp_sleep_get_wakeup_cause(); wakeCause = esp_sleep_get_wakeup_cause();
/* /*
Not using yet because we are using wake on all buttons being low Not using yet because we are using wake on all buttons being low
@ -293,12 +293,15 @@ void setup() {
initDeepSleep(); initDeepSleep();
// delay(1000); FIXME - remove // delay(1000); FIXME - remove
#ifdef T_BEAM_V10
Wire.begin(I2C_SDA, I2C_SCL); Wire.begin(I2C_SDA, I2C_SCL);
scanI2Cdevice(); scanI2Cdevice();
// FIXME - remove once we know dynamic probing is working
#ifdef T_BEAM_V10
axp192_found = true; axp192_found = true;
axp192Init(); ssd1306_found = true;
#endif #endif
axp192Init();
// Buttons & LED // Buttons & LED
pinMode(BUTTON_PIN, INPUT_PULLUP); pinMode(BUTTON_PIN, INPUT_PULLUP);
@ -309,8 +312,9 @@ void setup() {
// Hello // Hello
DEBUG_MSG(APP_NAME " " APP_VERSION "\n"); DEBUG_MSG(APP_NAME " " APP_VERSION "\n");
// Display // Don't init display if we don't have one or we are waking headless due to a timer event
screen_setup(); if(ssd1306_found && wakeCause != ESP_SLEEP_WAKEUP_TIMER)
screen_setup();
// Init GPS // Init GPS
gps_setup(); gps_setup();

View File

@ -32,6 +32,8 @@ SSD1306Wire * display;
uint8_t _screen_line = SCREEN_HEADER_HEIGHT - 1; uint8_t _screen_line = SCREEN_HEADER_HEIGHT - 1;
void _screen_header() { void _screen_header() {
if(!display) return;
char buffer[20]; char buffer[20];
// Message count // Message count
@ -51,25 +53,36 @@ void _screen_header() {
} }
void screen_show_logo() { void screen_show_logo() {
if(!display) return;
uint8_t x = (display->getWidth() - TTN_IMAGE_WIDTH) / 2; uint8_t x = (display->getWidth() - TTN_IMAGE_WIDTH) / 2;
uint8_t y = SCREEN_HEADER_HEIGHT + (display->getHeight() - SCREEN_HEADER_HEIGHT - TTN_IMAGE_HEIGHT) / 2 + 1; uint8_t y = SCREEN_HEADER_HEIGHT + (display->getHeight() - SCREEN_HEADER_HEIGHT - TTN_IMAGE_HEIGHT) / 2 + 1;
display->drawXbm(x, y, TTN_IMAGE_WIDTH, TTN_IMAGE_HEIGHT, TTN_IMAGE); display->drawXbm(x, y, TTN_IMAGE_WIDTH, TTN_IMAGE_HEIGHT, TTN_IMAGE);
} }
void screen_off() { void screen_off() {
if(!display) return;
display->displayOff(); display->displayOff();
} }
void screen_on() { void screen_on() {
if(!display) return;
display->displayOn(); display->displayOn();
} }
void screen_clear() { void screen_clear() {
if(!display) return;
display->clear(); display->clear();
} }
void screen_print(const char * text, uint8_t x, uint8_t y, uint8_t alignment) { void screen_print(const char * text, uint8_t x, uint8_t y, uint8_t alignment) {
DEBUG_MSG(text); DEBUG_MSG(text);
if(!display) return;
display->setTextAlignment((OLEDDISPLAY_TEXT_ALIGNMENT) alignment); display->setTextAlignment((OLEDDISPLAY_TEXT_ALIGNMENT) alignment);
display->drawString(x, y, text); display->drawString(x, y, text);
} }
@ -79,6 +92,8 @@ void screen_print(const char * text, uint8_t x, uint8_t y) {
} }
void screen_print(const char * text) { void screen_print(const char * text) {
if(!display) return;
display->print(text); display->print(text);
if (_screen_line + 8 > display->getHeight()) { if (_screen_line + 8 > display->getHeight()) {
// scroll // scroll
@ -88,7 +103,8 @@ void screen_print(const char * text) {
} }
void screen_update() { void screen_update() {
display->display(); if(display)
display->display();
} }
void screen_setup() { void screen_setup() {
@ -103,6 +119,8 @@ void screen_setup() {
} }
void screen_loop() { void screen_loop() {
if(!display) return;
#ifdef T_BEAM_V10 #ifdef T_BEAM_V10
if (axp192_found && pmu_irq) { if (axp192_found && pmu_irq) {
pmu_irq = false; pmu_irq = false;