Files
xiaozhi-esp32/main/iot/things/battery.cc
2025-03-04 07:56:07 +08:00

34 lines
830 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "iot/thing.h"
#include "board.h"
#include <esp_log.h>
#define TAG "Battery"
namespace iot {
// 这里仅定义 Battery 的属性和方法,不包含具体的实现
class Battery : public Thing {
private:
int level_ = 0;
bool charging_ = false;
public:
Battery() : Thing("Battery", "电池管理") {
// 定义设备的属性
properties_.AddNumberProperty("level", "当前电量百分比0-100", [this]() -> int {
auto& board = Board::GetInstance();
if (board.GetBatteryLevel(level_, charging_)) {
return level_;
}
return 0;
});
properties_.AddBooleanProperty("charging", "是否充电中", [this]() -> int {
return charging_;
});
}
};
} // namespace iot
DECLARE_THING(Battery);