add this-> prefix

This commit is contained in:
Tomasz Duda 2024-07-22 12:35:52 +02:00
parent 487cf39101
commit e44c02523a
6 changed files with 32 additions and 32 deletions

View file

@ -19,7 +19,7 @@ void Logger::loop() {
} }
static bool opened = false; static bool opened = false;
uint32_t dtr = 0; uint32_t dtr = 0;
uart_line_ctrl_get(uart_dev_, UART_LINE_CTRL_DTR, &dtr); uart_line_ctrl_get(this->uart_dev_, UART_LINE_CTRL_DTR, &dtr);
/* Poll if the DTR flag was set, optional */ /* Poll if the DTR flag was set, optional */
if (opened == dtr) { if (opened == dtr) {
@ -52,7 +52,7 @@ void Logger::pre_setup() {
if (!device_is_ready(uart_dev)) { if (!device_is_ready(uart_dev)) {
ESP_LOGE(TAG, "%s is not ready.", get_uart_selection_()); ESP_LOGE(TAG, "%s is not ready.", get_uart_selection_());
} else { } else {
uart_dev_ = uart_dev; this->uart_dev_ = uart_dev;
} }
} }
global_logger = this; global_logger = this;
@ -63,14 +63,14 @@ void HOT Logger::write_msg_(const char *msg) {
#ifdef CONFIG_PRINTK #ifdef CONFIG_PRINTK
printk("%s\n", msg); printk("%s\n", msg);
#endif #endif
if (nullptr == uart_dev_) { if (nullptr == this->uart_dev_) {
return; return;
} }
while (*msg) { while (*msg) {
uart_poll_out(uart_dev_, *msg); uart_poll_out(this->uart_dev_, *msg);
++msg; ++msg;
} }
uart_poll_out(uart_dev_, '\n'); uart_poll_out(this->uart_dev_, '\n');
} }
const char *const UART_SELECTIONS[] = {"UART0", "UART1", "USB_CDC"}; const char *const UART_SELECTIONS[] = {"UART0", "UART1", "USB_CDC"};

View file

@ -1,4 +1,4 @@
#if 1 #ifdef USE_ZEPHYR
#include <zephyr/kernel.h> #include <zephyr/kernel.h>
#include <zephyr/drivers/watchdog.h> #include <zephyr/drivers/watchdog.h>

View file

@ -40,8 +40,8 @@ struct ISRPinArg {
ISRInternalGPIOPin ZephyrGPIOPin::to_isr() const { ISRInternalGPIOPin ZephyrGPIOPin::to_isr() const {
auto *arg = new ISRPinArg{}; auto *arg = new ISRPinArg{};
arg->pin = pin_; arg->pin = this->pin_;
arg->inverted = inverted_; arg->inverted = this->inverted_;
return ISRInternalGPIOPin((void *) arg); return ISRInternalGPIOPin((void *) arg);
} }
@ -76,33 +76,33 @@ void ZephyrGPIOPin::setup() {
} }
void ZephyrGPIOPin::pin_mode(gpio::Flags flags) { void ZephyrGPIOPin::pin_mode(gpio::Flags flags) {
if (nullptr == gpio_) { if (nullptr == this->gpio_) {
return; return;
} }
gpio_pin_configure(gpio_, pin_ % 32, flags_to_mode(flags, inverted_, value_)); gpio_pin_configure(this->gpio_, this->pin_ % 32, flags_to_mode(flags, this->inverted_, this->value_));
} }
std::string ZephyrGPIOPin::dump_summary() const { std::string ZephyrGPIOPin::dump_summary() const {
char buffer[32]; char buffer[32];
snprintf(buffer, sizeof(buffer), "GPIO%u", pin_); snprintf(buffer, sizeof(buffer), "GPIO%u", this->pin_);
return buffer; return buffer;
} }
bool ZephyrGPIOPin::digital_read() { bool ZephyrGPIOPin::digital_read() {
if (nullptr == gpio_) { if (nullptr == this->gpio_) {
return false; return false;
} }
return bool(gpio_pin_get(gpio_, pin_ % 32) != inverted_); return bool(gpio_pin_get(this->gpio_, this->pin_ % 32) != this->inverted_);
} }
void ZephyrGPIOPin::digital_write(bool value) { void ZephyrGPIOPin::digital_write(bool value) {
// make sure that value is not ignored since it can be inverted e.g. on switch side // make sure that value is not ignored since it can be inverted e.g. on switch side
// that way init state should be correct // that way init state should be correct
value_ = value; this->value_ = value;
if (nullptr == gpio_) { if (nullptr == this->gpio_) {
return; return;
} }
gpio_pin_set(gpio_, pin_ % 32, value != inverted_ ? 1 : 0); gpio_pin_set(this->gpio_, this->pin_ % 32, value != this->inverted_ ? 1 : 0);
} }
void ZephyrGPIOPin::detach_interrupt() const { void ZephyrGPIOPin::detach_interrupt() const {
// TODO // TODO

View file

@ -8,9 +8,9 @@ namespace zephyr {
class ZephyrGPIOPin : public InternalGPIOPin { class ZephyrGPIOPin : public InternalGPIOPin {
public: public:
void set_pin(uint8_t pin) { pin_ = pin; } void set_pin(uint8_t pin) { this->pin_ = pin; }
void set_inverted(bool inverted) { inverted_ = inverted; } void set_inverted(bool inverted) { this->inverted_ = inverted; }
void set_flags(gpio::Flags flags) { flags_ = flags; } void set_flags(gpio::Flags flags) { this->flags_ = flags; }
void setup() override; void setup() override;
void pin_mode(gpio::Flags flags) override; void pin_mode(gpio::Flags flags) override;
@ -19,8 +19,8 @@ class ZephyrGPIOPin : public InternalGPIOPin {
std::string dump_summary() const override; std::string dump_summary() const override;
void detach_interrupt() const override; void detach_interrupt() const override;
ISRInternalGPIOPin to_isr() const override; ISRInternalGPIOPin to_isr() const override;
uint8_t get_pin() const override { return pin_; } uint8_t get_pin() const override { return this->pin_; }
bool is_inverted() const override { return inverted_; } bool is_inverted() const override { return this->inverted_; }
protected: protected:
void attach_interrupt(void (*func)(void *), void *arg, gpio::InterruptType type) const override; void attach_interrupt(void (*func)(void *), void *arg, gpio::InterruptType type) const override;

View file

@ -19,7 +19,7 @@ class ZephyrPreferenceBackend : public ESPPreferenceBackend {
bool save(const uint8_t *data, size_t len) override { bool save(const uint8_t *data, size_t len) override {
this->data.resize(len); this->data.resize(len);
std::memcpy(this->data.data(), data, len); std::memcpy(this->data.data(), data, len);
ESP_LOGVV(TAG, "save key: %u, len: %d", type_, len); ESP_LOGVV(TAG, "save key: %u, len: %d", this->type_, len);
return true; return true;
} }
@ -29,12 +29,12 @@ class ZephyrPreferenceBackend : public ESPPreferenceBackend {
return false; return false;
} }
std::memcpy(data, this->data.data(), len); std::memcpy(data, this->data.data(), len);
ESP_LOGVV(TAG, "load key: %u, len: %d", type_, len); ESP_LOGVV(TAG, "load key: %u, len: %d", this->type_, len);
return true; return true;
} }
const uint32_t get_type() const { return type_; } const uint32_t get_type() const { return this->type_; }
const std::string get_key() const { return str_sprintf(ESPHOME_SETTINGS_KEY "/%" PRIx32, type_); } const std::string get_key() const { return str_sprintf(ESPHOME_SETTINGS_KEY "/%" PRIx32, this->type_); }
std::vector<uint8_t> data; std::vector<uint8_t> data;
@ -68,7 +68,7 @@ class ZephyrPreferences : public ESPPreferences {
ESP_LOGE(TAG, "Cannot load settings, err: %d", err); ESP_LOGE(TAG, "Cannot load settings, err: %d", err);
return; return;
} }
ESP_LOGD(TAG, "Loaded %u settings.", backends_.size()); ESP_LOGD(TAG, "Loaded %u settings.", this->backends_.size());
} }
ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash) override { ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash) override {
@ -76,15 +76,15 @@ class ZephyrPreferences : public ESPPreferences {
} }
ESPPreferenceObject make_preference(size_t length, uint32_t type) override { ESPPreferenceObject make_preference(size_t length, uint32_t type) override {
for (auto backend : backends_) { for (auto backend : this->backends_) {
if (backend->get_type() == type) { if (backend->get_type() == type) {
return ESPPreferenceObject(backend); return ESPPreferenceObject(backend);
} }
} }
printf("type %u size %u\n", type, backends_.size()); printf("type %u size %u\n", type, this->backends_.size());
auto *pref = new ZephyrPreferenceBackend(type); auto *pref = new ZephyrPreferenceBackend(type);
ESP_LOGD(TAG, "Add new setting %s.", pref->get_key().c_str()); ESP_LOGD(TAG, "Add new setting %s.", pref->get_key().c_str());
backends_.push_back(pref); this->backends_.push_back(pref);
return ESPPreferenceObject(pref); return ESPPreferenceObject(pref);
} }
@ -100,7 +100,7 @@ class ZephyrPreferences : public ESPPreferences {
bool reset() override { bool reset() override {
ESP_LOGD(TAG, "Reset settings"); ESP_LOGD(TAG, "Reset settings");
for (auto backend : backends_) { for (auto backend : this->backends_) {
// save empty delete data // save empty delete data
backend->data.clear(); backend->data.clear();
} }

View file

@ -57,7 +57,7 @@
#endif #endif
#ifdef USE_ZEPHYR #ifdef USE_ZEPHYR
#include <zephyr/random/rand32.h> #include <zephyr/random/random.h>
#endif #endif
namespace esphome { namespace esphome {
@ -635,7 +635,7 @@ void Mutex::lock() {}
bool Mutex::try_lock() { return true; } bool Mutex::try_lock() { return true; }
void Mutex::unlock() {} void Mutex::unlock() {}
#elif defined(USE_ZEPHYR) #elif defined(USE_ZEPHYR)
Mutex::Mutex() { k_mutex_init(&handle_); } Mutex::Mutex() { k_mutex_init(&this->handle_); }
void Mutex::lock() { k_mutex_lock(&this->handle_, K_FOREVER); } void Mutex::lock() { k_mutex_lock(&this->handle_, K_FOREVER); }
bool Mutex::try_lock() { return k_mutex_lock(&this->handle_, K_NO_WAIT) == 0; } bool Mutex::try_lock() { return k_mutex_lock(&this->handle_, K_NO_WAIT) == 0; }
void Mutex::unlock() { k_mutex_unlock(&this->handle_); } void Mutex::unlock() { k_mutex_unlock(&this->handle_); }