Skip to content

Commit

Permalink
add printf
Browse files Browse the repository at this point in the history
  • Loading branch information
wadesherman committed Aug 27, 2024
1 parent 91d1ad7 commit 39cf0b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 14 additions & 2 deletions esphome/components/ht16k33/ht16k33.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ size_t HT16K33Component::write(uint16_t *encoded_chars) {
return 0;
}

size_t HT16K33Component::print(const char *str) {
void HT16K33Component::print(const char *str) {
uint16_t encoded_chars[display_size] = {};
uint8_t i = 0;
while (*str != '\0' && i < display_size)
Expand All @@ -122,7 +122,19 @@ size_t HT16K33Component::print(const char *str) {
i++;
}

return write(encoded_chars);
write(encoded_chars);
}

void HT16K33Component::print(const std::string &str) { print(str.c_str()); }

void HT16K33Component::printf(const char *format, ...) {
va_list arg;
va_start(arg, format);
char buffer[64];
int ret = vsnprintf(buffer, sizeof(buffer), format, arg);
va_end(arg);
if (ret > 0)
print(buffer);
}

bool HT16K33Component::update_display() {
Expand Down
4 changes: 3 additions & 1 deletion esphome/components/ht16k33/ht16k33.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ class HT16K33Component : public PollingComponent, public i2c::I2CDevice {
bool decimal_on(bool update_now);
bool decimal_off(bool update_now);

size_t print(const char *str);
void print(const char *str);
void print(const std::string &str);
void printf(const char *format, ...) __attribute__((format(printf, 2, 3)));

bool update_display();

Expand Down

0 comments on commit 39cf0b3

Please sign in to comment.