mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-26 04:15:42 +02:00
fixup! modules: add temp module
This commit is contained in:
parent
9bbe57a306
commit
9a4062db7c
5 changed files with 25 additions and 42 deletions
|
@ -18,7 +18,7 @@
|
|||
(https://codeberg.org/dnkl/yambar/issues/139).
|
||||
* mem: a module handling system memory monitoring
|
||||
* cpu: a module offering cpu usage monitoring
|
||||
* temp: a module displaying the temperature of the thermal zones in the machine.
|
||||
* temperature: a module displaying the temperature of the thermal zones in the machine.
|
||||
|
||||
|
||||
### Changed
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
yambar-modules-temp(5)
|
||||
yambar-modules-temperature(5)
|
||||
|
||||
# NAME
|
||||
temp - This module displays the temperature of the thermal zones available on
|
||||
temperature - This module displays the temperature of the thermal zones available on
|
||||
the system
|
||||
|
||||
# TAGS
|
||||
|
@ -9,7 +9,7 @@ the system
|
|||
[[ *Name*
|
||||
:[ *Type*
|
||||
:[ *Description*
|
||||
| temp
|
||||
| temperature
|
||||
: string
|
||||
: Current temperature of a given thermal zone
|
||||
|
||||
|
@ -26,7 +26,8 @@ the system
|
|||
| unit
|
||||
: string
|
||||
: no
|
||||
: Unit of the temperature. It can be Celsius (C) or Farenheit (F) (default=C)
|
||||
: Unit of the temperature. It can be Celsius (C or Celsius) or Fahrenheit (F or
|
||||
Fahrenheit) (default=C)
|
||||
|
||||
| thermal_zone
|
||||
: int
|
||||
|
@ -38,11 +39,11 @@ the system
|
|||
```
|
||||
bar:
|
||||
left:
|
||||
- temp:
|
||||
- temperature:
|
||||
interval: 1000
|
||||
thermal_zone: 0
|
||||
content:
|
||||
string: {text: "{temp}C"}
|
||||
string: {text: "{temperature}℃ (DEGREE CELSIUS)"}
|
||||
```
|
||||
|
||||
# SEE ALSO
|
|
@ -19,7 +19,7 @@ mod_data = {
|
|||
'clock': [[], []],
|
||||
'cpu': [[], []],
|
||||
'mem': [[], []],
|
||||
'temp': [[], []],
|
||||
'temperature': [[], []],
|
||||
'i3': [['i3-common.c', 'i3-common.h'], [dynlist, json]],
|
||||
'label': [[], []],
|
||||
'network': [[], []],
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#define LOG_MODULE "temp"
|
||||
#define LOG_MODULE "temperature"
|
||||
#define LOG_ENABLE_DBG 0
|
||||
#define SMALLEST_INTERVAL 500
|
||||
#include "../bar/bar.h"
|
||||
|
@ -40,11 +40,11 @@ destroy(struct module *mod)
|
|||
static const char *
|
||||
description(struct module *mod)
|
||||
{
|
||||
return "temp";
|
||||
return "temperature";
|
||||
}
|
||||
|
||||
static bool
|
||||
get_temp(uint16_t thermal_zone, enum temp_unit unit, double *temp)
|
||||
get_temperature(uint16_t thermal_zone, enum temp_unit unit, double *temp)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
char *line = NULL;
|
||||
|
@ -72,17 +72,9 @@ get_temp(uint16_t thermal_zone, enum temp_unit unit, double *temp)
|
|||
goto exit;
|
||||
}
|
||||
|
||||
switch (unit) {
|
||||
case TEMP_UNIT_CELSIUS:
|
||||
*temp = read_temp / 1000;
|
||||
break;
|
||||
case TEMP_UNIT_FAHRENHEIT:
|
||||
*temp = read_temp;
|
||||
*temp = (*temp * (9 / 5)) + 32;
|
||||
break;
|
||||
default:
|
||||
goto exit;
|
||||
break;
|
||||
*temp = read_temp / 1000;
|
||||
if (TEMP_UNIT_FAHRENHEIT == unit) {
|
||||
*temp = (*temp * (9.0 / 5.0)) + 32;
|
||||
}
|
||||
res = true;
|
||||
|
||||
|
@ -98,14 +90,14 @@ static struct exposable *
|
|||
content(struct module *mod)
|
||||
{
|
||||
const struct private *p = mod->private;
|
||||
double temp = 0;
|
||||
double temperature = 0;
|
||||
|
||||
if (!get_temp(p->thermal_zone, p->unit, &temp)) {
|
||||
if (!get_temperature(p->thermal_zone, p->unit, &temperature)) {
|
||||
LOG_ERR("unable to retrieve the temperature");
|
||||
}
|
||||
|
||||
struct tag_set tags = {
|
||||
.tags = (struct tag *[]){tag_new_int(mod, "temp", round(temp))},
|
||||
.tags = (struct tag *[]){tag_new_int(mod, "temperature", round(temperature))},
|
||||
.count = 1,
|
||||
};
|
||||
|
||||
|
@ -114,7 +106,6 @@ content(struct module *mod)
|
|||
return exposable;
|
||||
}
|
||||
|
||||
#include <pthread.h>
|
||||
static int
|
||||
run(struct module *mod)
|
||||
{
|
||||
|
@ -145,11 +136,11 @@ run(struct module *mod)
|
|||
static enum temp_unit
|
||||
str_to_unit(const char *unit_str)
|
||||
{
|
||||
if (0 == strcasecmp(unit_str, "C")) {
|
||||
if (0 == strcasecmp(unit_str, "C") || 0 == strcasecmp(unit_str, "Celsius")) {
|
||||
return TEMP_UNIT_CELSIUS;
|
||||
}
|
||||
|
||||
if (0 == strcasecmp(unit_str, "F")) {
|
||||
if (0 == strcasecmp(unit_str, "F") || 0 == strcasecmp(unit_str, "Fahrenheit")) {
|
||||
return TEMP_UNIT_FAHRENHEIT;
|
||||
}
|
||||
|
||||
|
@ -203,16 +194,7 @@ conf_verify_interval(keychain_t *chain, const struct yml_node *node)
|
|||
static bool
|
||||
conf_verify_unit(keychain_t *chain, const struct yml_node *node)
|
||||
{
|
||||
if (!conf_verify_string(chain, node))
|
||||
return false;
|
||||
|
||||
enum temp_unit unit = str_to_unit(yml_value_as_string(node));
|
||||
if (unit == TEMP_UNIT_INVALID) {
|
||||
LOG_ERR("%s: invalid unit, must be C or F", conf_err_prefix(chain, node));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return conf_verify_enum(chain, node, (const char *[]){"C", "F", "Celsius", "Fahrenheit"}, 4);
|
||||
}
|
||||
|
||||
static bool
|
||||
|
@ -228,11 +210,11 @@ verify_conf(keychain_t *chain, const struct yml_node *node)
|
|||
return conf_verify_dict(chain, node, attrs);
|
||||
}
|
||||
|
||||
const struct module_iface module_temp_iface = {
|
||||
const struct module_iface module_temperature_iface = {
|
||||
.verify_conf = &verify_conf,
|
||||
.from_conf = &from_conf,
|
||||
};
|
||||
|
||||
#if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES)
|
||||
extern const struct module_iface iface __attribute__((weak, alias("module_temp_iface")));
|
||||
extern const struct module_iface iface __attribute__((weak, alias("module_temperature_iface")));
|
||||
#endif
|
4
plugin.c
4
plugin.c
|
@ -51,7 +51,7 @@ EXTERN_MODULE(xkb);
|
|||
EXTERN_MODULE(xwindow);
|
||||
EXTERN_MODULE(cpu);
|
||||
EXTERN_MODULE(mem);
|
||||
EXTERN_MODULE(temp);
|
||||
EXTERN_MODULE(temperature);
|
||||
|
||||
EXTERN_PARTICLE(empty);
|
||||
EXTERN_PARTICLE(list);
|
||||
|
@ -141,7 +141,7 @@ init(void)
|
|||
#endif
|
||||
REGISTER_CORE_MODULE(mem, mem);
|
||||
REGISTER_CORE_MODULE(cpu, cpu);
|
||||
REGISTER_CORE_MODULE(temp, temp);
|
||||
REGISTER_CORE_MODULE(temperature, temperature);
|
||||
|
||||
REGISTER_CORE_PARTICLE(empty, empty);
|
||||
REGISTER_CORE_PARTICLE(list, list);
|
||||
|
|
Loading…
Add table
Reference in a new issue