mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-27 12:25:39 +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).
|
(https://codeberg.org/dnkl/yambar/issues/139).
|
||||||
* mem: a module handling system memory monitoring
|
* mem: a module handling system memory monitoring
|
||||||
* cpu: a module offering cpu usage 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
|
### Changed
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
yambar-modules-temp(5)
|
yambar-modules-temperature(5)
|
||||||
|
|
||||||
# NAME
|
# 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
|
the system
|
||||||
|
|
||||||
# TAGS
|
# TAGS
|
||||||
|
@ -9,7 +9,7 @@ the system
|
||||||
[[ *Name*
|
[[ *Name*
|
||||||
:[ *Type*
|
:[ *Type*
|
||||||
:[ *Description*
|
:[ *Description*
|
||||||
| temp
|
| temperature
|
||||||
: string
|
: string
|
||||||
: Current temperature of a given thermal zone
|
: Current temperature of a given thermal zone
|
||||||
|
|
||||||
|
@ -26,7 +26,8 @@ the system
|
||||||
| unit
|
| unit
|
||||||
: string
|
: string
|
||||||
: no
|
: 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
|
| thermal_zone
|
||||||
: int
|
: int
|
||||||
|
@ -38,11 +39,11 @@ the system
|
||||||
```
|
```
|
||||||
bar:
|
bar:
|
||||||
left:
|
left:
|
||||||
- temp:
|
- temperature:
|
||||||
interval: 1000
|
interval: 1000
|
||||||
thermal_zone: 0
|
thermal_zone: 0
|
||||||
content:
|
content:
|
||||||
string: {text: "{temp}C"}
|
string: {text: "{temperature}℃ (DEGREE CELSIUS)"}
|
||||||
```
|
```
|
||||||
|
|
||||||
# SEE ALSO
|
# SEE ALSO
|
|
@ -19,7 +19,7 @@ mod_data = {
|
||||||
'clock': [[], []],
|
'clock': [[], []],
|
||||||
'cpu': [[], []],
|
'cpu': [[], []],
|
||||||
'mem': [[], []],
|
'mem': [[], []],
|
||||||
'temp': [[], []],
|
'temperature': [[], []],
|
||||||
'i3': [['i3-common.c', 'i3-common.h'], [dynlist, json]],
|
'i3': [['i3-common.c', 'i3-common.h'], [dynlist, json]],
|
||||||
'label': [[], []],
|
'label': [[], []],
|
||||||
'network': [[], []],
|
'network': [[], []],
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#define LOG_MODULE "temp"
|
#define LOG_MODULE "temperature"
|
||||||
#define LOG_ENABLE_DBG 0
|
#define LOG_ENABLE_DBG 0
|
||||||
#define SMALLEST_INTERVAL 500
|
#define SMALLEST_INTERVAL 500
|
||||||
#include "../bar/bar.h"
|
#include "../bar/bar.h"
|
||||||
|
@ -40,11 +40,11 @@ destroy(struct module *mod)
|
||||||
static const char *
|
static const char *
|
||||||
description(struct module *mod)
|
description(struct module *mod)
|
||||||
{
|
{
|
||||||
return "temp";
|
return "temperature";
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
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;
|
FILE *fp = NULL;
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
|
@ -72,17 +72,9 @@ get_temp(uint16_t thermal_zone, enum temp_unit unit, double *temp)
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (unit) {
|
*temp = read_temp / 1000;
|
||||||
case TEMP_UNIT_CELSIUS:
|
if (TEMP_UNIT_FAHRENHEIT == unit) {
|
||||||
*temp = read_temp / 1000;
|
*temp = (*temp * (9.0 / 5.0)) + 32;
|
||||||
break;
|
|
||||||
case TEMP_UNIT_FAHRENHEIT:
|
|
||||||
*temp = read_temp;
|
|
||||||
*temp = (*temp * (9 / 5)) + 32;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
goto exit;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
res = true;
|
res = true;
|
||||||
|
|
||||||
|
@ -98,14 +90,14 @@ static struct exposable *
|
||||||
content(struct module *mod)
|
content(struct module *mod)
|
||||||
{
|
{
|
||||||
const struct private *p = mod->private;
|
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");
|
LOG_ERR("unable to retrieve the temperature");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tag_set tags = {
|
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,
|
.count = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -114,7 +106,6 @@ content(struct module *mod)
|
||||||
return exposable;
|
return exposable;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
static int
|
static int
|
||||||
run(struct module *mod)
|
run(struct module *mod)
|
||||||
{
|
{
|
||||||
|
@ -145,11 +136,11 @@ run(struct module *mod)
|
||||||
static enum temp_unit
|
static enum temp_unit
|
||||||
str_to_unit(const char *unit_str)
|
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;
|
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;
|
return TEMP_UNIT_FAHRENHEIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,16 +194,7 @@ conf_verify_interval(keychain_t *chain, const struct yml_node *node)
|
||||||
static bool
|
static bool
|
||||||
conf_verify_unit(keychain_t *chain, const struct yml_node *node)
|
conf_verify_unit(keychain_t *chain, const struct yml_node *node)
|
||||||
{
|
{
|
||||||
if (!conf_verify_string(chain, node))
|
return conf_verify_enum(chain, node, (const char *[]){"C", "F", "Celsius", "Fahrenheit"}, 4);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@ -228,11 +210,11 @@ verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
return conf_verify_dict(chain, node, attrs);
|
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,
|
.verify_conf = &verify_conf,
|
||||||
.from_conf = &from_conf,
|
.from_conf = &from_conf,
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES)
|
#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
|
#endif
|
4
plugin.c
4
plugin.c
|
@ -51,7 +51,7 @@ EXTERN_MODULE(xkb);
|
||||||
EXTERN_MODULE(xwindow);
|
EXTERN_MODULE(xwindow);
|
||||||
EXTERN_MODULE(cpu);
|
EXTERN_MODULE(cpu);
|
||||||
EXTERN_MODULE(mem);
|
EXTERN_MODULE(mem);
|
||||||
EXTERN_MODULE(temp);
|
EXTERN_MODULE(temperature);
|
||||||
|
|
||||||
EXTERN_PARTICLE(empty);
|
EXTERN_PARTICLE(empty);
|
||||||
EXTERN_PARTICLE(list);
|
EXTERN_PARTICLE(list);
|
||||||
|
@ -141,7 +141,7 @@ init(void)
|
||||||
#endif
|
#endif
|
||||||
REGISTER_CORE_MODULE(mem, mem);
|
REGISTER_CORE_MODULE(mem, mem);
|
||||||
REGISTER_CORE_MODULE(cpu, cpu);
|
REGISTER_CORE_MODULE(cpu, cpu);
|
||||||
REGISTER_CORE_MODULE(temp, temp);
|
REGISTER_CORE_MODULE(temperature, temperature);
|
||||||
|
|
||||||
REGISTER_CORE_PARTICLE(empty, empty);
|
REGISTER_CORE_PARTICLE(empty, empty);
|
||||||
REGISTER_CORE_PARTICLE(list, list);
|
REGISTER_CORE_PARTICLE(list, list);
|
||||||
|
|
Loading…
Add table
Reference in a new issue