1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-03 09:18:16 +00:00

fixing reboot issue

This commit is contained in:
NP v/d Spek 2024-12-05 21:36:19 +01:00
parent c359e2ddd3
commit 47e3be21e3
2 changed files with 12 additions and 10 deletions

View File

@ -24,6 +24,7 @@ namespace esphome {
namespace espnow { namespace espnow {
static const char *const TAG = "espnow"; static const char *const TAG = "espnow";
const char *const ESPNowTAG::TAG = "espnow";
static const size_t SEND_BUFFER_SIZE = 200; static const size_t SEND_BUFFER_SIZE = 200;
@ -564,8 +565,6 @@ bool ESPNowProtocol::send(uint64_t peer, const uint8_t *data, uint8_t len, uint8
return this->parent_->send(packet); return this->parent_->send(packet);
} }
const char *const SetChannel::TAG = "espnow.changechannel";
} // namespace espnow } // namespace espnow
} // namespace esphome } // namespace esphome

View File

@ -38,6 +38,12 @@ static const uint64_t FAILED = 0;
struct ESPNowPacket; struct ESPNowPacket;
class ESPNowTAG {
public:
// could be made inline with C++17
static const char *const TAG;
};
template<typename T> std::string espnow_i2h(T i) { return sprintf("%04x", i); } template<typename T> std::string espnow_i2h(T i) { return sprintf("%04x", i); }
std::string espnow_rdm(std::string::size_type length); std::string espnow_rdm(std::string::size_type length);
@ -103,7 +109,10 @@ struct ESPNowPacket {
inline uint8_t *get_content() const { return (uint8_t *) &(this->content); } inline uint8_t *get_content() const { return (uint8_t *) &(this->content); }
inline uint8_t *get_payload() const { return (uint8_t *) &(this->content.payload); } inline uint8_t *get_payload() const { return (uint8_t *) &(this->content.payload); }
inline uint8_t at(uint8_t pos) const { inline uint8_t at(uint8_t pos) const {
assert(pos < this->size); if (pos >= this->content_size()) {
esph_log_e(ESPNowTAG::TAG, "Trying to read out of space (%d of %d).", pos, this->content_size());
return 0;
}
return *(((uint8_t *) &this->content) + pos); return *(((uint8_t *) &this->content) + pos);
} }
@ -354,18 +363,12 @@ template<typename... Ts> class DelPeerAction : public Action<Ts...>, public Pare
} }
}; };
class SetChannel {
public:
// could be made inline with C++17
static const char *const TAG;
};
template<typename... Ts> class SetChannelAction : public Action<Ts...>, public Parented<ESPNowComponent> { template<typename... Ts> class SetChannelAction : public Action<Ts...>, public Parented<ESPNowComponent> {
public: public:
TEMPLATABLE_VALUE(int8_t, channel); TEMPLATABLE_VALUE(int8_t, channel);
void play(Ts... x) override { void play(Ts... x) override {
#ifdef USE_WIFI #ifdef USE_WIFI
esph_log_e(SetChannel::TAG, "Manual changing the channel is not possible with WIFI enabled."); esph_log_e(ESPNowTAG::TAG, "Manual changing the channel is not possible with WIFI enabled.");
#else #else
int8_t value = this->channel_.value(x...); int8_t value = this->channel_.value(x...);
parent_->set_wifi_channel(value); parent_->set_wifi_channel(value);