mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
Add get_size method to QR Code header (#6430)
This commit is contained in:
parent
0ff543ffe5
commit
9194f7eb27
8 changed files with 56 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -24,6 +24,8 @@ class QrCode : public Component {
|
|||
|
||||
void generate_qr_code();
|
||||
|
||||
uint8_t get_size();
|
||||
|
||||
protected:
|
||||
std::string value_;
|
||||
qrcodegen_Ecc ecc_;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue