Update 2023-11-01 10:17 OpenBSD/amd64-x13
This commit is contained in:
parent
2fadf9f402
commit
ccea430175
47
.config/spectrwm/baraction.sh
Executable file
47
.config/spectrwm/baraction.sh
Executable file
@ -0,0 +1,47 @@
|
||||
#!/bin/sh -e
|
||||
#
|
||||
if [ $(hostname -s) == "x1" ]
|
||||
then
|
||||
while true;
|
||||
do
|
||||
printf 'BAT: %s%% CPU: %s°C %s Mhz %s\n' \
|
||||
"$(/usr/sbin/apm -l)" \
|
||||
"$(/sbin/sysctl -n hw.sensors.ksmn0.temp0 | cut -d"." -f1)" \
|
||||
"$(/sbin/sysctl -n hw.cpuspeed)" \
|
||||
"$(/sbin/sysctl -n hw.sensors.acpithinkpad0.fan0)";
|
||||
sleep 1;
|
||||
done
|
||||
fi
|
||||
|
||||
if [ $(hostname -s) == "x13" ]
|
||||
then
|
||||
while true;
|
||||
do
|
||||
printf 'BAT: %s%% CPU: %s°C %s Mhz %s\n' \
|
||||
"$(/usr/sbin/apm -l)" \
|
||||
"$(/sbin/sysctl -n hw.sensors.ksmn0.temp0 | cut -d"." -f1)" \
|
||||
"$(/sbin/sysctl -n hw.cpuspeed)" \
|
||||
"$(/sbin/sysctl -n hw.sensors.acpithinkpad0.fan0)";
|
||||
sleep 1;
|
||||
done
|
||||
fi
|
||||
|
||||
if [ $(hostname -s) == "wotan" ]
|
||||
then
|
||||
while true;
|
||||
do
|
||||
printf 'BAT: %s%% CPU: %s°C\n' \
|
||||
"$(/usr/sbin/apm -l)" \
|
||||
"$(/sbin/sysctl -n hw.sensors.cpu0.temp0 | cut -d"." -f1)";
|
||||
sleep 15;
|
||||
done
|
||||
fi
|
||||
|
||||
if [ $(hostname -s) == "sunny25" ]
|
||||
then
|
||||
while true;
|
||||
do
|
||||
printf "Hello, I'm sunny!\n"
|
||||
sleep 15;
|
||||
done
|
||||
fi
|
54
.config/spectrwm/baraction.sh.expand
Executable file
54
.config/spectrwm/baraction.sh.expand
Executable file
@ -0,0 +1,54 @@
|
||||
#!/bin/sh -e
|
||||
|
||||
# colors:
|
||||
# 0 = neutral
|
||||
# 1 = green
|
||||
# 2 = yellow
|
||||
# 3 = red
|
||||
|
||||
CPU_TEMP="N/A"
|
||||
CPU_SPEED="N/A"
|
||||
FAN_SPEED="N/A"
|
||||
BATTERY="N/A"
|
||||
|
||||
cpu_temp_openbsd() {
|
||||
_v=$(/sbin/sysctl -n hw.sensors.acpithinkpad0.fan0)
|
||||
CPU_TEMP=$(set_value_color 1400 1 1700 2 $_v )
|
||||
}
|
||||
cpu_speed_openbsd() {
|
||||
_v=$(/sbin/sysctl -n hw.cpuspeed)
|
||||
CPU_SPEED=$(set_value_color 1400 1 1700 2 $_v )
|
||||
}
|
||||
battery_openbsd() {
|
||||
_v=$(/usr/sbin/apm -l)
|
||||
BATTERY=$(set_value_color 10 3 98 1 $_v )
|
||||
}
|
||||
fan_speed_openbsd() {
|
||||
_v=$(/sbin/sysctl -n hw.sensors.ksmn0.temp0 | cut -d"." -f1)
|
||||
FAN_SPEED=$(set_value_color 0 1 3600 3 $_v )
|
||||
}
|
||||
|
||||
set_value_color() {
|
||||
# $1 low_value
|
||||
# $2 low_color
|
||||
# $3 high_value
|
||||
# $4 high_color
|
||||
# $5 current_value
|
||||
[ $5 -ge $3 ] && printf '+@fg=%s;%s+@fg=0;' $4 $5 && return
|
||||
[ $5 -le $1 ] && printf '+@fg=%s;%s+@fg=0;' $2 $5 && return
|
||||
printf "$5"
|
||||
}
|
||||
|
||||
while true;
|
||||
do
|
||||
cpu_temp_openbsd
|
||||
cpu_speed_openbsd
|
||||
battery_openbsd
|
||||
fan_speed_openbsd
|
||||
printf 'BAT: %s%% CPU: %s°C %s Mhz %s\n' \
|
||||
"$BATTERY" \
|
||||
"$FAN_SPEED" \
|
||||
"$CPU_SPEED" \
|
||||
"$CPU_TEMP";
|
||||
sleep 1;
|
||||
done
|
@ -1,132 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/sensors.h>
|
||||
|
||||
#include <sndio.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <machine/apmvar.h>
|
||||
|
||||
|
||||
static int battery_percent = 23;
|
||||
static int cpu_temp = 23;
|
||||
static int fan_speed = 23;
|
||||
static int cpu_base_speed = 23;
|
||||
static int cpu_avg_speed = 23;
|
||||
static int volume = 23;
|
||||
|
||||
|
||||
//void update_volume(void *arg, unsigned addr, unsigned val) {
|
||||
// printf("volume update\n");
|
||||
//
|
||||
// }
|
||||
//
|
||||
// void register_volume_callback() {
|
||||
// struct sioctl_hdl *hdl;
|
||||
//
|
||||
// hdl = sioctl_open(SIO_DEVANY, SIOCTL_READ, 0);
|
||||
// sioctl_onval(hdl, update_volume, NULL);
|
||||
// sioctl_close(hdl);
|
||||
// }
|
||||
|
||||
void update_cpu_base_speed() {
|
||||
size_t slen = sizeof(cpu_base_speed);
|
||||
int mib[5] = { CTL_HW, HW_CPUSPEED }; // Lenovo x1g10
|
||||
if (sysctl(mib, 2, &cpu_base_speed, &slen, NULL, 0) == -1) {
|
||||
cpu_base_speed = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void update_cpu_avg_speed() {
|
||||
struct sensor sensor;
|
||||
size_t slen = sizeof(sensor);
|
||||
int i;
|
||||
for (i = 0; i < 12; i++) {
|
||||
int mib[5] = { CTL_HW, HW_SENSORS, 0, SENSOR_FREQ, 0 }; // Lenovo x1g10
|
||||
if (sysctl(mib, 5, &sensor, &slen, NULL, 0) != -1) {
|
||||
cpu_avg_speed += ( sensor.value / 1000000 / 1000000 );
|
||||
}
|
||||
}
|
||||
cpu_avg_speed = cpu_avg_speed / i;
|
||||
}
|
||||
|
||||
void update_fan_speed() {
|
||||
struct sensor sensor;
|
||||
size_t slen = sizeof(sensor);
|
||||
// int mib[5] = { CTL_HW, HW_SENSORS, 5, SENSOR_FANRPM, 0 }; // Lenovo x230
|
||||
int mib[5] = { CTL_HW, HW_SENSORS, 12, SENSOR_FANRPM, 0 }; // Lenovo x1g10
|
||||
if (sysctl(mib, 5, &sensor, &slen, NULL, 0) != -1) {
|
||||
fan_speed = sensor.value;
|
||||
return;
|
||||
}
|
||||
fan_speed = -1;
|
||||
}
|
||||
|
||||
void update_cpu_temp() {
|
||||
struct sensor sensor;
|
||||
size_t slen = sizeof(sensor);
|
||||
//int mib[5] = { CTL_HW, HW_SENSORS, 0, SENSOR_TEMP, 0 }; // cpu0.temp0 (x230)
|
||||
int mib[5] = { CTL_HW, HW_SENSORS, 12, SENSOR_TEMP, 0 }; // acpitz0.temp0 (x1)
|
||||
if (sysctl(mib, 5, &sensor, &slen, NULL, 0) != -1) {
|
||||
cpu_temp = (sensor.value - 273150000) / 1000000.0;
|
||||
return;
|
||||
}
|
||||
cpu_temp = -1;
|
||||
}
|
||||
|
||||
void update_battery() {
|
||||
int fd;
|
||||
struct apm_power_info pi;
|
||||
|
||||
if ((fd = open("/dev/apm", O_RDONLY)) == -1 ||
|
||||
ioctl(fd, APM_IOC_GETPOWER, &pi) == -1 ||
|
||||
close(fd) == -1) {
|
||||
battery_percent = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (pi.battery_state == APM_BATT_UNKNOWN ||
|
||||
pi.battery_state == APM_BATTERY_ABSENT) {
|
||||
battery_percent = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
battery_percent = pi.battery_life;
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
|
||||
//register_volume_callback();
|
||||
|
||||
while(1) {
|
||||
|
||||
// XXX can update at different intervals
|
||||
update_battery();
|
||||
update_cpu_temp();
|
||||
update_cpu_avg_speed();
|
||||
update_cpu_base_speed();
|
||||
update_fan_speed();
|
||||
|
||||
wprintf(L"%s %d%% %s %dC %s %4dRPM %s %4dMhz (~%4dMhz) %s %d %s\n",
|
||||
"", battery_percent,
|
||||
" ", cpu_temp,
|
||||
" ", fan_speed,
|
||||
" ", cpu_base_speed, cpu_avg_speed,
|
||||
" ", volume,
|
||||
" ");
|
||||
sleep(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user