mirror of
https://github.com/esphome/esphome.git
synced 2025-04-02 17:08:17 +01:00
[gt911][cst226][ektf2232] Swap x and y calibration values (#8450)
Co-authored-by: Keith Burzinski <kbx81x@gmail.com>
This commit is contained in:
parent
6787730aa4
commit
6cfe3ac44d
@ -72,6 +72,8 @@ void CST226Touchscreen::continue_setup_() {
|
|||||||
if (this->read16_(0xD1F8, buffer, 4)) {
|
if (this->read16_(0xD1F8, buffer, 4)) {
|
||||||
this->x_raw_max_ = buffer[0] + (buffer[1] << 8);
|
this->x_raw_max_ = buffer[0] + (buffer[1] << 8);
|
||||||
this->y_raw_max_ = buffer[2] + (buffer[3] << 8);
|
this->y_raw_max_ = buffer[2] + (buffer[3] << 8);
|
||||||
|
if (this->swap_x_y_)
|
||||||
|
std::swap(this->x_raw_max_, this->y_raw_max_);
|
||||||
} else {
|
} else {
|
||||||
this->x_raw_max_ = this->display_->get_native_width();
|
this->x_raw_max_ = this->display_->get_native_width();
|
||||||
this->y_raw_max_ = this->display_->get_native_height();
|
this->y_raw_max_ = this->display_->get_native_height();
|
||||||
|
@ -34,26 +34,29 @@ void EKTF2232Touchscreen::setup() {
|
|||||||
|
|
||||||
// Get touch resolution
|
// Get touch resolution
|
||||||
uint8_t received[4];
|
uint8_t received[4];
|
||||||
if (this->x_raw_max_ == this->x_raw_min_) {
|
if (this->x_raw_max_ == 0 || this->y_raw_max_ == 0) {
|
||||||
this->write(GET_X_RES, 4);
|
auto err = this->write(GET_X_RES, 4);
|
||||||
if (this->read(received, 4)) {
|
if (err == i2c::ERROR_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to read X resolution!");
|
err = this->read(received, 4);
|
||||||
|
if (err == i2c::ERROR_OK) {
|
||||||
|
this->x_raw_max_ = ((received[2])) | ((received[3] & 0xf0) << 4);
|
||||||
|
err = this->write(GET_Y_RES, 4);
|
||||||
|
if (err == i2c::ERROR_OK) {
|
||||||
|
err = this->read(received, 4);
|
||||||
|
if (err == i2c::ERROR_OK) {
|
||||||
|
this->y_raw_max_ = ((received[2])) | ((received[3] & 0xf0) << 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (err != i2c::ERROR_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to read calibration values!");
|
||||||
this->interrupt_pin_->detach_interrupt();
|
this->interrupt_pin_->detach_interrupt();
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this->x_raw_max_ = ((received[2])) | ((received[3] & 0xf0) << 4);
|
if (this->swap_x_y_)
|
||||||
}
|
std::swap(this->x_raw_max_, this->y_raw_max_);
|
||||||
|
|
||||||
if (this->y_raw_max_ == this->y_raw_min_) {
|
|
||||||
this->write(GET_Y_RES, 4);
|
|
||||||
if (this->read(received, 4)) {
|
|
||||||
ESP_LOGE(TAG, "Failed to read Y resolution!");
|
|
||||||
this->interrupt_pin_->detach_interrupt();
|
|
||||||
this->mark_failed();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this->y_raw_max_ = ((received[2])) | ((received[3] & 0xf0) << 4);
|
|
||||||
}
|
}
|
||||||
this->set_power_state(true);
|
this->set_power_state(true);
|
||||||
}
|
}
|
||||||
|
@ -60,20 +60,25 @@ void GT911Touchscreen::setup() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (err == i2c::ERROR_OK) {
|
if (this->x_raw_max_ == 0 || this->y_raw_max_ == 0) {
|
||||||
err = this->write(GET_MAX_VALUES, 2);
|
// no calibration? Attempt to read the max values from the touchscreen.
|
||||||
if (err == i2c::ERROR_OK) {
|
if (err == i2c::ERROR_OK) {
|
||||||
err = this->read(data, sizeof(data));
|
err = this->write(GET_MAX_VALUES, 2);
|
||||||
if (err == i2c::ERROR_OK) {
|
if (err == i2c::ERROR_OK) {
|
||||||
if (this->x_raw_max_ == this->x_raw_min_) {
|
err = this->read(data, sizeof(data));
|
||||||
|
if (err == i2c::ERROR_OK) {
|
||||||
this->x_raw_max_ = encode_uint16(data[1], data[0]);
|
this->x_raw_max_ = encode_uint16(data[1], data[0]);
|
||||||
}
|
|
||||||
if (this->y_raw_max_ == this->y_raw_min_) {
|
|
||||||
this->y_raw_max_ = encode_uint16(data[3], data[2]);
|
this->y_raw_max_ = encode_uint16(data[3], data[2]);
|
||||||
|
if (this->swap_x_y_)
|
||||||
|
std::swap(this->x_raw_max_, this->y_raw_max_);
|
||||||
}
|
}
|
||||||
esph_log_d(TAG, "calibration max_x/max_y %d/%d", this->x_raw_max_, this->y_raw_max_);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (err != i2c::ERROR_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to read calibration values from touchscreen!");
|
||||||
|
this->mark_failed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (err != i2c::ERROR_OK) {
|
if (err != i2c::ERROR_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to communicate!");
|
ESP_LOGE(TAG, "Failed to communicate!");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user