smarter cmake, conditional hass, still need to do conditional gzip logging
This commit is contained in:
@@ -36,10 +36,19 @@ target_compile_options(linuxSmartie
|
|||||||
-fdiagnostics-color=always
|
-fdiagnostics-color=always
|
||||||
)
|
)
|
||||||
|
|
||||||
# Link libraries
|
find_package(libwebsockets QUIET)
|
||||||
target_link_libraries(linuxSmartie
|
find_package(ZLIB QUIET)
|
||||||
PRIVATE
|
|
||||||
websockets
|
|
||||||
z
|
|
||||||
)
|
|
||||||
|
|
||||||
|
if(libwebsockets_FOUND)
|
||||||
|
target_link_libraries(linuxSmartie PRIVATE websockets)
|
||||||
|
target_compile_definitions(linuxSmartie PRIVATE ENABLE_HOME_ASSISTANT)
|
||||||
|
else()
|
||||||
|
message(STATUS "no libwebsockets found, disabling hass")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ZLIB_FOUND)
|
||||||
|
target_link_libraries(linuxSmartie PRIVATE z)
|
||||||
|
target_compile_definitions(linuxSmartie PRIVATE ENABLE_ZLIB)
|
||||||
|
else()
|
||||||
|
message(STATUS "no zlib found, disabling saving logs to gz")
|
||||||
|
endif()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef HASS_HPP
|
#ifndef HASS_HPP
|
||||||
#define HASS_HPP
|
#define HASS_HPP
|
||||||
|
|
||||||
|
#ifdef ENABLE_HOME_ASSISTANT
|
||||||
#include <libwebsockets.h>
|
#include <libwebsockets.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -32,3 +33,5 @@ class HomeAssistant {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
25
src/app.cpp
25
src/app.cpp
@@ -63,8 +63,11 @@ void Application::Crash(const int ret) {
|
|||||||
kill(m_mainPid, SIGINT);
|
kill(m_mainPid, SIGINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::hassThread(const std::stop_token& st) {
|
|
||||||
|
void Application::hassThread(const std::stop_token& st) { //NOLINT
|
||||||
applog(LOG::START, "Thread started");
|
applog(LOG::START, "Thread started");
|
||||||
|
#ifdef ENABLE_HOME_ASSISTANT
|
||||||
|
static double power;
|
||||||
HomeAssistant::Config config;
|
HomeAssistant::Config config;
|
||||||
config.address = m_config.hass.url;
|
config.address = m_config.hass.url;
|
||||||
config.entity = m_config.hass.entity;
|
config.entity = m_config.hass.entity;
|
||||||
@@ -74,12 +77,23 @@ void Application::hassThread(const std::stop_token& st) {
|
|||||||
pc_power.connect();
|
pc_power.connect();
|
||||||
while (!st.stop_requested()) {
|
while (!st.stop_requested()) {
|
||||||
pc_power.service();
|
pc_power.service();
|
||||||
{
|
if (power != pc_power.state) {
|
||||||
std::lock_guard lock(m_control.sensors);
|
power = pc_power.state;
|
||||||
m_sensors.hass_state = pc_power.state;
|
{
|
||||||
|
std::lock_guard lock(m_control.sensors);
|
||||||
|
m_sensors.hass_state = power;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
(void)st;
|
||||||
|
applog(LOG::WRN, "feature disabled at compile time, probably no libwebsockets on host. exiting thread");
|
||||||
|
{
|
||||||
|
std::lock_guard lock(m_control.sensors);
|
||||||
|
m_sensors.hass_state = -1.0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::sensorsThread(const std::stop_token& st) {
|
void Application::sensorsThread(const std::stop_token& st) {
|
||||||
@@ -169,7 +183,8 @@ void Application::displayThread(const std::stop_token& st) {
|
|||||||
|
|
||||||
lcd.writeBuf(1, 0, utils::pad(std::to_string(m_sensors.cpu.tctl) + "/" + std::to_string(m_sensors.cpu.tccd1) + LCDDisplay::cc(0), 8, utils::just::left));
|
lcd.writeBuf(1, 0, utils::pad(std::to_string(m_sensors.cpu.tctl) + "/" + std::to_string(m_sensors.cpu.tccd1) + LCDDisplay::cc(0), 8, utils::just::left));
|
||||||
lcd.writeBuf(1, 7, utils::pad(utils::pBytes(m_sensors.ram.used, true), 6, utils::just::left));
|
lcd.writeBuf(1, 7, utils::pad(utils::pBytes(m_sensors.ram.used, true), 6, utils::just::left));
|
||||||
lcd.writeBuf(1, 13, utils::pad(utils::pNum(m_sensors.hass_state) + "W", 4));
|
if (m_sensors.hass_state >= 0)
|
||||||
|
lcd.writeBuf(1, 13, utils::pad(utils::pNum(m_sensors.hass_state) + "W", 4));
|
||||||
lcd.writeBuf(1, 19, std::to_string(m_sensors.sys.t_sensor) + LCDDisplay::cc(0)); // t_sensor temp
|
lcd.writeBuf(1, 19, std::to_string(m_sensors.sys.t_sensor) + LCDDisplay::cc(0)); // t_sensor temp
|
||||||
lcd.writeBuf(1, 32 - gpu_temps.size(), utils::pad(utils::pBytes(m_sensors.gpu.vram_used), 6));
|
lcd.writeBuf(1, 32 - gpu_temps.size(), utils::pad(utils::pBytes(m_sensors.gpu.vram_used), 6));
|
||||||
lcd.writeBuf(1, 39 - gpu_temps.size(), gpu_temps + LCDDisplay::cc(0));
|
lcd.writeBuf(1, 39 - gpu_temps.size(), gpu_temps + LCDDisplay::cc(0));
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#ifdef ENABLE_HOME_ASSISTANT
|
||||||
|
|
||||||
HomeAssistant::HomeAssistant(const Config& config) {
|
HomeAssistant::HomeAssistant(const Config& config) {
|
||||||
m_config = config;
|
m_config = config;
|
||||||
}
|
}
|
||||||
@@ -158,3 +160,5 @@ void HomeAssistant::service(const int timeout_ms) const {
|
|||||||
void HomeAssistant::disconnect() const {
|
void HomeAssistant::disconnect() const {
|
||||||
lws_context_destroy(context);
|
lws_context_destroy(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user