Skip to content

Commit

Permalink
Move PartitionsDumper to a class
Browse files Browse the repository at this point in the history
  • Loading branch information
wrfz committed Nov 16, 2024
1 parent 531729b commit b64b684
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
9 changes: 5 additions & 4 deletions components/daikin_rotex_can/partitions_dumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#include <iomanip>
#include <esp_ota_ops.h>
#include "esphome/core/log.h"
#include "esp_partition.h"

namespace esphome {
namespace daikin_rotex_can {

std::string to_hex(std::array<uint8_t, 16> const& data) {
std::string PartitionsDumper::to_hex(std::array<uint8_t, 16> const& data) {
std::stringstream str;
str.setf(std::ios_base::hex, std::ios::basefield);
str.setf(std::ios_base::uppercase);
Expand All @@ -27,7 +27,7 @@ std::string to_hex(std::array<uint8_t, 16> const& data) {
return str.str();
}

void print_ota_partition(esp_partition_t const* partition, std::string const& partition_getter) {
void PartitionsDumper::print_ota_partition(esp_partition_t const* partition, std::string const& partition_getter) {
std::string label;
esp_err_t err_state;
esp_ota_img_states_t ota_state;
Expand All @@ -51,7 +51,7 @@ void print_ota_partition(esp_partition_t const* partition, std::string const& pa
partition_getter.c_str(), label.c_str(), err_state, ota_state, data.c_str());
}

void dump_partitions() {
void PartitionsDumper::dump() {
ESP_LOGE("TEST", "esp_ota_get_app_partition_count: %d",
esp_ota_get_app_partition_count());

Expand All @@ -61,4 +61,5 @@ void dump_partitions() {
print_ota_partition(esp_ota_get_next_update_partition(nullptr), "esp_ota_get_next_update_partition");
}

}
}
19 changes: 18 additions & 1 deletion components/daikin_rotex_can/partitions_dumper.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
#pragma once

#include <array>
#include <string>
#include "esp_partition.h"

namespace esphome {
void dump_partitions();
namespace daikin_rotex_can {

class PartitionsDumper {
public:
static void dump();

private:
static std::string to_hex(std::array<uint8_t, 16> const& data);
static void print_ota_partition(esp_partition_t const* partition, std::string const& partition_getter);
};

}
}
4 changes: 3 additions & 1 deletion examples/full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ esphome:
- "-fno-rtti"
build_flags:
- "-std=gnu++17"
includes:
- "components/daikin_rotex_can/partitions_dumper.h"

esp32:
board: esp32-s3-devkitc-1
Expand Down Expand Up @@ -76,7 +78,7 @@ button:
- platform: template
name: Dump Partitions
on_press:
- lambda: dump_partitions();
- lambda: esphome::daikin_rotex_can::PartitionsDumper::dump();
#switch:
# - platform: gpio
# name: Smart Grid
Expand Down

0 comments on commit b64b684

Please sign in to comment.