mirror of
https://github.com/esphome/esphome.git
synced 2024-12-12 08:24:55 +01:00
Merge branch 'add-graphical-layout-system' of github.com:MrMDavidson/esphome into add-graphical-layout-system
This commit is contained in:
commit
395d1d10a4
2 changed files with 9 additions and 7 deletions
|
@ -14,6 +14,7 @@ static const uint8_t GET_TOUCHES[2] = {0x81, 0x4F};
|
||||||
static const uint8_t GET_SWITCHES[2] = {0x80, 0x4D};
|
static const uint8_t GET_SWITCHES[2] = {0x80, 0x4D};
|
||||||
static const uint8_t GET_MAX_VALUES[2] = {0x80, 0x48};
|
static const uint8_t GET_MAX_VALUES[2] = {0x80, 0x48};
|
||||||
static const size_t MAX_TOUCHES = 5; // max number of possible touches reported
|
static const size_t MAX_TOUCHES = 5; // max number of possible touches reported
|
||||||
|
static const size_t MAX_BUTTONS = 4; // max number of buttons scanned
|
||||||
|
|
||||||
#define ERROR_CHECK(err) \
|
#define ERROR_CHECK(err) \
|
||||||
if ((err) != i2c::ERROR_OK) { \
|
if ((err) != i2c::ERROR_OK) { \
|
||||||
|
@ -79,9 +80,6 @@ void GT911Touchscreen::update_touches() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num_of_touches == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
err = this->write(GET_TOUCHES, sizeof(GET_TOUCHES), false);
|
err = this->write(GET_TOUCHES, sizeof(GET_TOUCHES), false);
|
||||||
ERROR_CHECK(err);
|
ERROR_CHECK(err);
|
||||||
// num_of_touches is guaranteed to be 0..5. Also read the key data
|
// num_of_touches is guaranteed to be 0..5. Also read the key data
|
||||||
|
@ -94,12 +92,15 @@ void GT911Touchscreen::update_touches() {
|
||||||
uint16_t y = encode_uint16(data[i][4], data[i][3]);
|
uint16_t y = encode_uint16(data[i][4], data[i][3]);
|
||||||
this->add_raw_touch_position_(id, x, y);
|
this->add_raw_touch_position_(id, x, y);
|
||||||
}
|
}
|
||||||
auto keys = data[num_of_touches][0];
|
auto keys = data[num_of_touches][0] & ((1 << MAX_BUTTONS) - 1);
|
||||||
for (size_t i = 0; i != 4; i++) {
|
if (keys != this->button_state_) {
|
||||||
|
this->button_state_ = keys;
|
||||||
|
for (size_t i = 0; i != MAX_BUTTONS; i++) {
|
||||||
for (auto *listener : this->button_listeners_)
|
for (auto *listener : this->button_listeners_)
|
||||||
listener->update_button(i, (keys & (1 << i)) != 0);
|
listener->update_button(i, (keys & (1 << i)) != 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GT911Touchscreen::dump_config() {
|
void GT911Touchscreen::dump_config() {
|
||||||
ESP_LOGCONFIG(TAG, "GT911 Touchscreen:");
|
ESP_LOGCONFIG(TAG, "GT911 Touchscreen:");
|
||||||
|
|
|
@ -26,6 +26,7 @@ class GT911Touchscreen : public touchscreen::Touchscreen, public i2c::I2CDevice
|
||||||
|
|
||||||
InternalGPIOPin *interrupt_pin_{};
|
InternalGPIOPin *interrupt_pin_{};
|
||||||
std::vector<GT911ButtonListener *> button_listeners_;
|
std::vector<GT911ButtonListener *> button_listeners_;
|
||||||
|
uint8_t button_state_{0xFF}; // last button state. Initial FF guarantees first update.
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gt911
|
} // namespace gt911
|
||||||
|
|
Loading…
Reference in a new issue