forked from xiaozhi/xiaozhi-esp32
添加 jiuchuan-s3 开发板支持 (#775)
* 添加 jiuchuang-s3 开发板支持 * 增加编译指南 * 优开发板支持包文件目录,更新README.md 删除了多余板载文件 [* ]README.md -> 更新了编译指南和烧录指南 * 修改板级支持包名 * 使用乐鑫提供的电源监测 * 修复部分代码格式问题 * 解决合并冲突 * 解决部分合并内容 * 完善合并内容 * 修复电量映射表错误 --------- Co-authored-by: unknown <jake12355>
This commit is contained in:
51
main/boards/jiuchuan-s3/power_controller.h
Normal file
51
main/boards/jiuchuan-s3/power_controller.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
#include <mutex>
|
||||
#include <functional>
|
||||
#include <driver/gpio.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
class PowerController {
|
||||
public:
|
||||
enum class PowerState {
|
||||
ACTIVE,
|
||||
LIGHT_SLEEP,
|
||||
DEEP_SLEEP,
|
||||
SHUTDOWN
|
||||
};
|
||||
|
||||
static PowerController& Instance() {
|
||||
static PowerController instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void SetState(PowerState newState) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (currentState_ != newState) {
|
||||
ESP_LOGI("PowerCtrl", "State change: %d -> %d",
|
||||
static_cast<int>(currentState_),
|
||||
static_cast<int>(newState));
|
||||
|
||||
currentState_ = newState;
|
||||
if (stateChangeCallback_) {
|
||||
stateChangeCallback_(newState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PowerState GetState() const {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return currentState_;
|
||||
}
|
||||
|
||||
void OnStateChange(std::function<void(PowerState)> callback) {
|
||||
stateChangeCallback_ = callback;
|
||||
}
|
||||
|
||||
private:
|
||||
PowerController() = default;
|
||||
~PowerController() = default;
|
||||
|
||||
PowerState currentState_ = PowerState::ACTIVE;
|
||||
std::function<void(PowerState)> stateChangeCallback_;
|
||||
mutable std::mutex mutex_;
|
||||
};
|
||||
Reference in New Issue
Block a user