From a06b38f53446e2653e3b061cb346a91652ca3233 Mon Sep 17 00:00:00 2001 From: NBonaparte <98007b33@opayq.com> Date: Wed, 9 Nov 2016 22:52:11 -0800 Subject: [PATCH] feat(temperature): Added temp module and examples --- cmake/build/options.cmake | 2 ++ examples/config | 9 +++++ examples/config.bspwm | 9 +++++ include/config.hpp.cmake | 4 ++- include/modules/temperature.hpp | 40 ++++++++++++++++++++++ src/components/controller.cpp | 3 ++ src/modules/temperature.cpp | 60 +++++++++++++++++++++++++++++++++ 7 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 include/modules/temperature.hpp create mode 100644 src/modules/temperature.cpp diff --git a/cmake/build/options.cmake b/cmake/build/options.cmake index 685ad137..eee16e2f 100644 --- a/cmake/build/options.cmake +++ b/cmake/build/options.cmake @@ -39,6 +39,8 @@ set(SETTING_PATH_CPU_INFO "/proc/stat" CACHE STRING "Path to file containing cpu info") set(SETTING_PATH_MEMORY_INFO "/proc/meminfo" CACHE STRING "Path to file containing memory info") +set(SETTING_PATH_TEMPERATURE_INFO "/sys/class/thermal/thermal_zone%zone%/temp" + CACHE STRING "Path to file containing the current temperature") find_package(ALSA QUIET) if(NOT ALSA_FOUND) diff --git a/examples/config b/examples/config index 224e1dce..9e676cba 100644 --- a/examples/config +++ b/examples/config @@ -225,6 +225,15 @@ bar-progress-empty-font = 3 label-time-foreground = #77 +[module/temperature] +type = internal/temperature + +thermal-zone = 0 +warn-temperature = 60 +label = 🌡 %temperature% +label-warn = 🔥 %temperature% + + [module/powermenu] type = custom/menu diff --git a/examples/config.bspwm b/examples/config.bspwm index 8d6cb0a0..bd2b7207 100644 --- a/examples/config.bspwm +++ b/examples/config.bspwm @@ -327,6 +327,15 @@ bar-progress-empty-font = 3 label-time-foreground = #77 +[module/temperature] +type = internal/temperature + +thermal-zone = 0 +warn-temperature = 60 +label = 🌡 %temperature% +label-warn = 🔥 %temperature% + + [module/powermenu] type = custom/menu diff --git a/include/config.hpp.cmake b/include/config.hpp.cmake index e025cc75..c781dfaf 100644 --- a/include/config.hpp.cmake +++ b/include/config.hpp.cmake @@ -38,6 +38,7 @@ #define BSPWM_STATUS_PREFIX "@SETTING_BSPWM_STATUS_PREFIX@" #define PATH_CPU_INFO "@SETTING_PATH_CPU_INFO@" #define PATH_MEMORY_INFO "@SETTING_PATH_MEMORY_INFO@" +#define PATH_TEMPERATURE_INFO "@SETTING_PATH_TEMPERATURE_INFO@" auto print_build_info = []() { // clang-format off @@ -59,7 +60,8 @@ auto print_build_info = []() { << "PATH_BACKLIGHT_VAL " << PATH_BACKLIGHT_VAL << "\n" << "PATH_BATTERY_CAPACITY " << PATH_BATTERY_CAPACITY << "\n" << "PATH_CPU_INFO " << PATH_CPU_INFO << "\n" - << "PATH_MEMORY_INFO " << PATH_MEMORY_INFO << "\n"; + << "PATH_MEMORY_INFO " << PATH_MEMORY_INFO << "\n" + << "PATH_TEMPERATURE_INFO " << PATH_TEMPERATURE_INFO << "\n"; // clang-format on }; diff --git a/include/modules/temperature.hpp b/include/modules/temperature.hpp new file mode 100644 index 00000000..d0e7cbd1 --- /dev/null +++ b/include/modules/temperature.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include + +#include "config.hpp" +#include "drawtypes/label.hpp" +#include "modules/meta.hpp" +#include "utils/file.hpp" + +LEMONBUDDY_NS + +namespace modules { + enum class temp_state { NORMAL = 0, WARN }; + + + class temperature_module : public timer_module { + public: + using timer_module::timer_module; + + void setup(); + bool update(); + string get_format() const; + bool build(builder* builder, string tag) const; + + private: + static constexpr auto TAG_LABEL = "