From b4c0061b7e7ccf8d14f9caa21837b52f953b8417 Mon Sep 17 00:00:00 2001 From: lewis Date: Sat, 16 Dec 2023 22:43:48 +0800 Subject: [PATCH] Modify initialization rules --- src/LilyGo_AMOLED.cpp | 54 +++++++++++++++++++++++++------------------ src/LilyGo_AMOLED.h | 1 + 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/LilyGo_AMOLED.cpp b/src/LilyGo_AMOLED.cpp index 80acc74..41d7967 100644 --- a/src/LilyGo_AMOLED.cpp +++ b/src/LilyGo_AMOLED.cpp @@ -427,11 +427,16 @@ bool LilyGo_AMOLED::beginAMOLED_191(bool touchFunc) bool res = TouchDrvCSTXXX::init(Wire, boards->touch->sda, boards->touch->scl, CST816_SLAVE_ADDRESS); if (!res) { log_e("Failed to find CST816T - check your wiring!"); - return false; + // return false; + _touchOnline = false; + } else { + TouchDrvCSTXXX::setMaxCoordinates(RM67162_HEIGHT, RM67162_WIDTH); + _touchOnline = true; } - TouchDrvCSTXXX::setMaxCoordinates(RM67162_HEIGHT, RM67162_WIDTH); } } + } else { + _touchOnline = false; } return true; } @@ -459,9 +464,11 @@ bool LilyGo_AMOLED::beginAMOLED_241() bool res = TouchDrvCSTXXX::init(Wire, boards->touch->sda, boards->touch->scl, CST226SE_SLAVE_ADDRESS); if (!res) { log_e("Failed to find CST226SE - check your wiring!"); - return false; + // return false; + } else { + _touchOnline = true; + TouchDrvCSTXXX::setMaxCoordinates(RM690B0_HEIGHT, RM690B0_WIDTH); } - TouchDrvCSTXXX::setMaxCoordinates(RM690B0_HEIGHT, RM690B0_WIDTH); } } @@ -505,31 +512,32 @@ bool LilyGo_AMOLED::beginAMOLED_147() } TouchDrvCHSC5816::setPins(boards->touch->rst, boards->touch->irq); - bool res = TouchDrvCHSC5816::begin(Wire, CHSC5816_SLAVE_ADDRESS, boards->touch->sda, boards->touch->scl); - if (!res) { + _touchOnline = TouchDrvCHSC5816::begin(Wire, CHSC5816_SLAVE_ADDRESS, boards->touch->sda, boards->touch->scl); + if (!_touchOnline) { log_e("Failed to find CHSC5816 - check your wiring!"); - return false; + // return false; + } else { + TouchDrvCHSC5816::setMaxCoordinates(SH8501_HEIGHT, SH8501_WIDTH); + TouchDrvCHSC5816::setSwapXY(true); + TouchDrvCHSC5816::setMirrorXY(false, true); } - TouchDrvCHSC5816::setMaxCoordinates(SH8501_HEIGHT, SH8501_WIDTH); - TouchDrvCHSC5816::setSwapXY(true); - TouchDrvCHSC5816::setMirrorXY(false, true); // Share I2C Bus - res = SensorCM32181::begin(Wire, CM32181_SLAVE_ADDRESS, boards->sensor->sda, boards->sensor->scl); + bool res = SensorCM32181::begin(Wire, CM32181_SLAVE_ADDRESS, boards->sensor->sda, boards->sensor->scl); if (!res) { log_e("Failed to find CM32181 - check your wiring!"); - return false; + // return false; + } else { + /* + Sensitivity mode selection + SAMPLING_X1 + SAMPLING_X2 + SAMPLING_X1_8 + SAMPLING_X1_4 + */ + SensorCM32181::setSampling(SensorCM32181::SAMPLING_X2), + powerOn(); } - /* - Sensitivity mode selection - SAMPLING_X1 - SAMPLING_X2 - SAMPLING_X1_8 - SAMPLING_X1_4 - */ - SensorCM32181::setSampling(SensorCM32181::SAMPLING_X2), - powerOn(); - // Temperature detect beginCore(); @@ -802,7 +810,7 @@ void LilyGo_AMOLED::wakeup() bool LilyGo_AMOLED::hasTouch() { - if (boards) { + if (boards && _touchOnline) { if (boards->touch) { return true; } diff --git a/src/LilyGo_AMOLED.h b/src/LilyGo_AMOLED.h index a199284..6b6a52e 100644 --- a/src/LilyGo_AMOLED.h +++ b/src/LilyGo_AMOLED.h @@ -339,6 +339,7 @@ class LilyGo_AMOLED: spi_device_handle_t spi; uint8_t _brightness; const BoardsConfigure_t *boards; + bool _touchOnline; #if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(5,0,0) temperature_sensor_handle_t temp_sensor;