2024-01-08 21:04:17 +00:00
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
|
|
#include <functional>
|
|
|
|
#include "observable.h"
|
|
|
|
|
|
|
|
#define ESP_LOG1 ESP_LOGD
|
|
|
|
#define ESP_LOG2 ESP_LOGD
|
|
|
|
|
|
|
|
|
|
|
|
namespace esphome {
|
|
|
|
namespace ratgdo {
|
|
|
|
|
2024-01-09 16:42:11 +00:00
|
|
|
namespace protocol {
|
|
|
|
|
2024-01-08 21:04:17 +00:00
|
|
|
struct SetRollingCodeCounter { uint32_t counter; };
|
|
|
|
struct GetRollingCodeCounter {};
|
|
|
|
struct SetClientID { uint64_t client_id; };
|
2024-01-09 16:42:11 +00:00
|
|
|
struct QueryStatus{};
|
|
|
|
struct QueryOpenings{};
|
2024-01-08 21:04:17 +00:00
|
|
|
struct ActivateLearn {};
|
|
|
|
struct InactivateLearn {};
|
|
|
|
|
|
|
|
|
|
|
|
// a poor man's sum-type, because C++
|
2024-01-09 16:42:11 +00:00
|
|
|
class Args {
|
2024-01-08 21:04:17 +00:00
|
|
|
public:
|
|
|
|
union {
|
|
|
|
SetRollingCodeCounter set_rolling_code_counter;
|
|
|
|
GetRollingCodeCounter get_rolling_code_counter;
|
|
|
|
SetClientID set_client_id;
|
2024-01-09 16:42:11 +00:00
|
|
|
QueryStatus query_status;
|
|
|
|
QueryOpenings query_openings;
|
2024-01-08 21:04:17 +00:00
|
|
|
ActivateLearn activate_learn;
|
|
|
|
InactivateLearn inactivate_learn;
|
|
|
|
} value;
|
|
|
|
|
|
|
|
enum class Tag {
|
|
|
|
set_rolling_code_counter,
|
|
|
|
get_rolling_code_counter,
|
|
|
|
set_client_id,
|
2024-01-09 16:42:11 +00:00
|
|
|
query_status,
|
|
|
|
query_openings,
|
2024-01-08 21:04:17 +00:00
|
|
|
activate_learn,
|
|
|
|
inactivate_learn,
|
|
|
|
} tag;
|
|
|
|
|
2024-01-09 16:42:11 +00:00
|
|
|
Args(GetRollingCodeCounter&& arg): tag(Tag::get_rolling_code_counter) {
|
2024-01-08 21:04:17 +00:00
|
|
|
value.get_rolling_code_counter = std::move(arg);
|
|
|
|
}
|
2024-01-09 16:42:11 +00:00
|
|
|
Args(SetRollingCodeCounter&& arg): tag(Tag::set_rolling_code_counter) {
|
2024-01-08 21:04:17 +00:00
|
|
|
value.set_rolling_code_counter = std::move(arg);
|
|
|
|
}
|
2024-01-09 16:42:11 +00:00
|
|
|
Args(SetClientID&& arg): tag(Tag::set_client_id) {
|
2024-01-08 21:04:17 +00:00
|
|
|
value.set_client_id = std::move(arg);
|
|
|
|
}
|
2024-01-09 16:42:11 +00:00
|
|
|
Args(QueryStatus&& arg): tag(Tag::query_status) {
|
|
|
|
value.query_status = std::move(arg);
|
|
|
|
}
|
|
|
|
Args(QueryOpenings&& arg): tag(Tag::query_openings) {
|
|
|
|
value.query_openings = std::move(arg);
|
|
|
|
}
|
|
|
|
Args(ActivateLearn&& arg): tag(Tag::activate_learn) {
|
2024-01-08 21:04:17 +00:00
|
|
|
value.activate_learn = std::move(arg);
|
|
|
|
}
|
2024-01-09 16:42:11 +00:00
|
|
|
Args(InactivateLearn&& arg): tag(Tag::inactivate_learn) {
|
2024-01-08 21:04:17 +00:00
|
|
|
value.inactivate_learn = std::move(arg);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-01-09 16:42:11 +00:00
|
|
|
struct RollingCodeCounter { observable<uint32_t>* value; };
|
|
|
|
|
|
|
|
class Result {
|
|
|
|
public:
|
|
|
|
union {
|
|
|
|
RollingCodeCounter rolling_code_counter;
|
|
|
|
} value;
|
|
|
|
|
|
|
|
enum class Tag {
|
|
|
|
rolling_code_counter,
|
|
|
|
void_,
|
|
|
|
} tag;
|
|
|
|
|
|
|
|
Result(): tag(Tag::void_) {
|
|
|
|
}
|
|
|
|
Result(RollingCodeCounter&& arg): tag(Tag::rolling_code_counter) {
|
|
|
|
value.rolling_code_counter = std::move(arg);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace protocol
|
2024-01-08 21:04:17 +00:00
|
|
|
} // namespace ratgdo
|
|
|
|
} // namespace esphome
|