新增手动控制风扇选项,并关闭控制台
This commit is contained in:
parent
1bb6530b29
commit
96102eba80
@ -15,11 +15,15 @@ add_subdirectory(third_party/cpp-httplib)
|
|||||||
set(ALL_FILES "")
|
set(ALL_FILES "")
|
||||||
retrieve_files(${CMAKE_CURRENT_SOURCE_DIR}/src ALL_FILES)
|
retrieve_files(${CMAKE_CURRENT_SOURCE_DIR}/src ALL_FILES)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} ${ALL_FILES})
|
if (WIN32)
|
||||||
|
add_executable(${PROJECT_NAME} WIN32 ${ALL_FILES})
|
||||||
|
else ()
|
||||||
|
add_executable(${PROJECT_NAME} ${ALL_FILES})
|
||||||
|
endif ()
|
||||||
target_link_libraries(${PROJECT_NAME} imgui httplib)
|
target_link_libraries(${PROJECT_NAME} imgui httplib)
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||||
|
|
||||||
# 关闭windows控制台
|
# 关闭windows控制台
|
||||||
add_link_options(-mwindows)
|
add_link_options(${PROJECT_NAME} PRIVATE -mwindows)
|
||||||
# 拷贝resources文件夹到build目录
|
# 拷贝resources文件夹到build目录
|
||||||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
@ -23,11 +23,11 @@ enum class fan_status {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct fan_info {
|
struct fan_info {
|
||||||
int id;
|
int id = -1;
|
||||||
int present;
|
int present = -1;
|
||||||
fan_status status;
|
fan_status status = fan_status::absent;
|
||||||
int speed_percent;
|
int speed_percent = -1;
|
||||||
int speed_rpm;
|
int speed_rpm = -1;
|
||||||
static fan_info from_json(const rapidjson::Value& obj) {
|
static fan_info from_json(const rapidjson::Value& obj) {
|
||||||
fan_info out{
|
fan_info out{
|
||||||
.id = obj["Id"].GetInt(),
|
.id = obj["Id"].GetInt(),
|
||||||
@ -47,9 +47,18 @@ struct fan_info {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct fan_mode_info {
|
||||||
|
bool manual_mode= false;
|
||||||
|
static fan_mode_info from_json(const rapidjson::Value& obj) {
|
||||||
|
return {
|
||||||
|
.manual_mode = obj["fanMode"].GetInt() == 1
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct running_time {
|
struct running_time {
|
||||||
int days;
|
int days = -1;
|
||||||
int hours;
|
int hours = -1;
|
||||||
static running_time from_json(const rapidjson::Value& obj) {
|
static running_time from_json(const rapidjson::Value& obj) {
|
||||||
return {
|
return {
|
||||||
.days = obj["Days"].GetInt(),
|
.days = obj["Days"].GetInt(),
|
||||||
@ -59,22 +68,22 @@ struct running_time {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct psu_status {
|
struct psu_status {
|
||||||
int id;
|
int id = -1;
|
||||||
int present;
|
int present = -1;
|
||||||
int power_status;
|
int power_status = -1;
|
||||||
int temperature;
|
int temperature = -1;
|
||||||
int pwr_in_watts;
|
int pwr_in_watts = -1;
|
||||||
int input_power;
|
int input_power = -1;
|
||||||
int input_volt;
|
int input_volt = -1;
|
||||||
int output_volt;
|
int output_volt = -1;
|
||||||
int input_current;
|
int input_current = -1;
|
||||||
int output_current;
|
int output_current = -1;
|
||||||
int err_status;
|
int err_status = -1;
|
||||||
std::string fw_version;
|
std::string fw_version = "unknown";
|
||||||
int output_power_max;
|
int output_power_max = -1;
|
||||||
std::string mfr_model;
|
std::string mfr_model = "unknown";
|
||||||
std::string mfr_id;
|
std::string mfr_id = "unknown";
|
||||||
std::string sn;
|
std::string sn = "unknown";
|
||||||
|
|
||||||
static psu_status from_json(const rapidjson::Value& obj) {
|
static psu_status from_json(const rapidjson::Value& obj) {
|
||||||
return {
|
return {
|
||||||
|
@ -137,7 +137,18 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class set_fan_mode_task : public post_task<void> {
|
||||||
|
public:
|
||||||
|
set_fan_mode_task() : post_task("setfanmode") {}
|
||||||
|
void setup(bool manual_mode) {
|
||||||
|
httplib::Params params;
|
||||||
|
params.emplace("MODE", std::to_string(manual_mode ? 1 : 0));
|
||||||
|
set_params(params);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
SIMPLE_GET_TASK(get_fan_info_task, "getfaninfo", std::vector<fan_info>)
|
SIMPLE_GET_TASK(get_fan_info_task, "getfaninfo", std::vector<fan_info>)
|
||||||
SIMPLE_GET_TASK(get_running_time_task, "getrunningtime", running_time)
|
SIMPLE_GET_TASK(get_running_time_task, "getrunningtime", running_time)
|
||||||
SIMPLE_GET_TASK(get_psu_info_task, "getallpsuinfo", std::vector<psu_status>)
|
SIMPLE_GET_TASK(get_psu_info_task, "getallpsuinfo", std::vector<psu_status>)
|
||||||
|
SIMPLE_GET_TASK(get_fan_mode, "getfanmode", fan_mode_info)
|
||||||
SIMPLE_GET_TASK(logout_task, "WEBSES/logout", void)
|
SIMPLE_GET_TASK(logout_task, "WEBSES/logout", void)
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "request_task.h"
|
#include "request_task.h"
|
||||||
|
|
||||||
|
inline std::vector<std::function<void()>> g_tasks;
|
||||||
|
|
||||||
#define FUTURE_PARAM(task_type, name) \
|
#define FUTURE_PARAM(task_type, name) \
|
||||||
inline std::future<task_type::result_type> name##_future; \
|
inline std::future<task_type::result_type> name##_future; \
|
||||||
inline task_type::result_type name##_; \
|
inline task_type::result_type name##_; \
|
||||||
@ -15,16 +17,22 @@
|
|||||||
} else { \
|
} else { \
|
||||||
name##_future = task_executor<task_type>::run_task(); \
|
name##_future = task_executor<task_type>::run_task(); \
|
||||||
} \
|
} \
|
||||||
}
|
} \
|
||||||
|
struct name##_task_register { \
|
||||||
|
name##_task_register() { \
|
||||||
|
g_tasks.emplace_back(update_##name); \
|
||||||
|
} \
|
||||||
|
} name##_task_register_instance;
|
||||||
|
|
||||||
FUTURE_PARAM(get_fan_info_task, fan_infos)
|
FUTURE_PARAM(get_fan_info_task, fan_infos)
|
||||||
|
FUTURE_PARAM(get_fan_mode, fan_mode)
|
||||||
FUTURE_PARAM(get_running_time_task, running_time)
|
FUTURE_PARAM(get_running_time_task, running_time)
|
||||||
FUTURE_PARAM(get_psu_info_task, psu_status)
|
FUTURE_PARAM(get_psu_info_task, psu_status)
|
||||||
|
|
||||||
inline void update_infos() {
|
inline void update_infos() {
|
||||||
update_fan_infos();
|
for (const auto& task : g_tasks) {
|
||||||
update_running_time();
|
task();
|
||||||
update_psu_status();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void draw_running_time() {
|
inline void draw_running_time() {
|
||||||
@ -45,6 +53,8 @@ inline ImU32 get_fan_status_color(fan_status status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void draw_fan_infos() {
|
inline void draw_fan_infos() {
|
||||||
|
if (ImGui::Checkbox("Manual Mode", &fan_mode_.manual_mode))
|
||||||
|
task_executor<set_fan_mode_task>::run_task(fan_mode_.manual_mode);
|
||||||
for (auto& fan_info : fan_infos_) {
|
for (auto& fan_info : fan_infos_) {
|
||||||
// 根据风扇状态绘制不同的颜色 和 启用/禁用输入框
|
// 根据风扇状态绘制不同的颜色 和 启用/禁用输入框
|
||||||
ImGui::PushStyleColor(ImGuiCol_Text, get_fan_status_color(fan_info.status));
|
ImGui::PushStyleColor(ImGuiCol_Text, get_fan_status_color(fan_info.status));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user