ESPHome  2024.9.2
raw_protocol.cpp
Go to the documentation of this file.
1 #include "raw_protocol.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace remote_base {
6 
7 static const char *const TAG = "remote.raw";
8 
10  char buffer[256];
11  uint32_t buffer_offset = 0;
12  buffer_offset += sprintf(buffer, "Received Raw: ");
13 
14  for (int32_t i = 0; i < src.size() - 1; i++) {
15  const int32_t value = src[i];
16  const uint32_t remaining_length = sizeof(buffer) - buffer_offset;
17  int written;
18 
19  if (i + 1 < src.size() - 1) {
20  written = snprintf(buffer + buffer_offset, remaining_length, "%" PRId32 ", ", value);
21  } else {
22  written = snprintf(buffer + buffer_offset, remaining_length, "%" PRId32, value);
23  }
24 
25  if (written < 0 || written >= int(remaining_length)) {
26  // write failed, flush...
27  buffer[buffer_offset] = '\0';
28  ESP_LOGI(TAG, "%s", buffer);
29  buffer_offset = 0;
30  written = sprintf(buffer, " ");
31  if (i + 1 < src.size()) {
32  written += sprintf(buffer + written, "%" PRId32 ", ", value);
33  } else {
34  written += sprintf(buffer + written, "%" PRId32, value);
35  }
36  }
37 
38  buffer_offset += written;
39  }
40  if (buffer_offset != 0) {
41  ESP_LOGI(TAG, "%s", buffer);
42  }
43  return true;
44 }
45 
46 } // namespace remote_base
47 } // namespace esphome
bool dump(RemoteReceiveData src) override
Definition: raw_protocol.cpp:9
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7