Add get_size method to QR Code header (#6430)

This commit is contained in:
Daniel Eisterhold 2024-03-27 18:56:26 -05:00 committed by GitHub
parent 0ff543ffe5
commit 9194f7eb27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 56 additions and 0 deletions

View File

@ -51,5 +51,17 @@ void QrCode::draw(display::Display *buff, uint16_t x_offset, uint16_t y_offset,
}
}
}
uint8_t QrCode::get_size() {
if (this->needs_update_) {
this->generate_qr_code();
this->needs_update_ = false;
}
uint8_t size = qrcodegen_getSize(this->qr_);
return size;
}
} // namespace qr_code
} // namespace esphome

View File

@ -24,6 +24,8 @@ class QrCode : public Component {
void generate_qr_code();
uint8_t get_size();
protected:
std::string value_;
qrcodegen_Ecc ecc_;

View File

@ -11,6 +11,13 @@ display:
cs_pin: 8
dc_pin: 9
reset_pin: 10
lambda: |-
// Draw a QR code in the center of the screen
auto scale = 2;
auto size = id(homepage_qr).get_size() * scale;
auto x = (it.get_width() / 2) - (size / 2);
auto y = (it.get_height() / 2) - (size / 2);
it.qr_code(x, y, id(homepage_qr), Color(255,255,255), scale);
qr_code:
- id: homepage_qr

View File

@ -11,6 +11,13 @@ display:
cs_pin: 8
dc_pin: 9
reset_pin: 10
lambda: |-
// Draw a QR code in the center of the screen
auto scale = 2;
auto size = id(homepage_qr).get_size() * scale;
auto x = (it.get_width() / 2) - (size / 2);
auto y = (it.get_height() / 2) - (size / 2);
it.qr_code(x, y, id(homepage_qr), Color(255,255,255), scale);
qr_code:
- id: homepage_qr

View File

@ -11,6 +11,13 @@ display:
cs_pin: 12
dc_pin: 13
reset_pin: 21
lambda: |-
// Draw a QR code in the center of the screen
auto scale = 2;
auto size = id(homepage_qr).get_size() * scale;
auto x = (it.get_width() / 2) - (size / 2);
auto y = (it.get_height() / 2) - (size / 2);
it.qr_code(x, y, id(homepage_qr), Color(255,255,255), scale);
qr_code:
- id: homepage_qr

View File

@ -11,6 +11,13 @@ display:
cs_pin: 12
dc_pin: 13
reset_pin: 21
lambda: |-
// Draw a QR code in the center of the screen
auto scale = 2;
auto size = id(homepage_qr).get_size() * scale;
auto x = (it.get_width() / 2) - (size / 2);
auto y = (it.get_height() / 2) - (size / 2);
it.qr_code(x, y, id(homepage_qr), Color(255,255,255), scale);
qr_code:
- id: homepage_qr

View File

@ -11,6 +11,13 @@ display:
cs_pin: 5
dc_pin: 15
reset_pin: 16
lambda: |-
// Draw a QR code in the center of the screen
auto scale = 2;
auto size = id(homepage_qr).get_size() * scale;
auto x = (it.get_width() / 2) - (size / 2);
auto y = (it.get_height() / 2) - (size / 2);
it.qr_code(x, y, id(homepage_qr), Color(255,255,255), scale);
qr_code:
- id: homepage_qr

View File

@ -11,6 +11,13 @@ display:
cs_pin: 20
dc_pin: 21
reset_pin: 22
lambda: |-
// Draw a QR code in the center of the screen
auto scale = 2;
auto size = id(homepage_qr).get_size() * scale;
auto x = (it.get_width() / 2) - (size / 2);
auto y = (it.get_height() / 2) - (size / 2);
it.qr_code(x, y, id(homepage_qr), Color(255,255,255), scale);
qr_code:
- id: homepage_qr