Update 2022-12-07 23:28 OpenBSD/amd64

This commit is contained in:
c0dev0id 2022-12-07 23:28:01 +01:00
parent 9aadb82b21
commit 14267ef1e0
3 changed files with 47 additions and 64 deletions

View File

@ -11,72 +11,61 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/sensors.h> #include <sys/sensors.h>
#include <sys/audioio.h> #include <sndio.h>
#include <ifaddrs.h>
#include <sys/socket.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/param.h> #include <sys/param.h>
#include <machine/apmvar.h> #include <machine/apmvar.h>
static int battery_percent = 50; static int battery_percent = 23;
static int cpu_temp = 46; static int cpu_temp = 23;
static int fan_speed = 3392; static int fan_speed = 23;
static int cpu_base_speed = 2501; static int cpu_base_speed = 23;
static int cpu_avg_speed = 468; static int cpu_avg_speed = 23;
static int volume = 50; static int volume = 23;
void update_volume() { void update_volume(void *arg, unsigned addr, unsigned val) {
static int cls = -1, fd, v; // printf("volume update\n");
static struct mixer_devinfo mdi; //
static struct mixer_ctrl mc; // }
//
// 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);
// }
if ((fd = open("/dev/mixer", O_RDONLY)) == -1) { void update_cpu_base_speed() {
volume = -1; 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;
} }
}
for (mdi.index = 0; cls == -1; ++mdi.index) { void update_cpu_avg_speed() {
if (ioctl(fd, AUDIO_MIXER_DEVINFO, &mdi) == -1) struct sensor sensor;
goto fail; size_t slen = sizeof(sensor);
if (mdi.type == AUDIO_MIXER_CLASS && int i;
strcmp(mdi.label.name, AudioCoutputs) == 0) for (i = 0; i < 12; i++) {
cls = mdi.index; int mib[5] = { CTL_HW, HW_SENSORS, 0, SENSOR_FREQ, 0 }; // Lenovo x1g10
} if (sysctl(mib, 5, &sensor, &slen, NULL, 0) != -1) {
for (mdi.index = 0, v = -1; v == -1; ++mdi.index) { cpu_avg_speed += ( sensor.value / 1000000 / 1000000 );
if (ioctl(fd, AUDIO_MIXER_DEVINFO, &mdi) == -1)
goto fail;
if (mdi.type == AUDIO_MIXER_VALUE &&
mdi.prev == AUDIO_MIXER_LAST &&
mdi.mixer_class == cls &&
strcmp(mdi.label.name, AudioNmaster) == 0) {
mc.dev = mdi.index;
if (ioctl(fd, AUDIO_MIXER_READ, &mc) == -1)
goto fail;
v = MAX(mc.un.value.level[AUDIO_MIXER_LEVEL_MONO],
mc.un.value.level[AUDIO_MIXER_LEVEL_RIGHT]);
} }
} }
cpu_avg_speed = cpu_avg_speed / i;
if (v == -1 || close(fd) == -1) {
volume = -1;
return;
}
volume = v * 100 / 255;
fail:
(void)close(fd);
volume = -1;
return;
} }
void update_fan_speed() { void update_fan_speed() {
struct sensor sensor; struct sensor sensor;
size_t slen = sizeof(sensor); size_t slen = sizeof(sensor);
// XXX hw.sensors.acpithinkpad0.fan0 // int mib[5] = { CTL_HW, HW_SENSORS, 5, SENSOR_FANRPM, 0 }; // Lenovo x230
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) { if (sysctl(mib, 5, &sensor, &slen, NULL, 0) != -1) {
fan_speed = sensor.value; fan_speed = sensor.value;
return; return;
@ -87,7 +76,8 @@ void update_fan_speed() {
void update_cpu_temp() { void update_cpu_temp() {
struct sensor sensor; struct sensor sensor;
size_t slen = sizeof(sensor); size_t slen = sizeof(sensor);
int mib[5] = { CTL_HW, HW_SENSORS, 0, SENSOR_TEMP, 0 }; //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) { if (sysctl(mib, 5, &sensor, &slen, NULL, 0) != -1) {
cpu_temp = (sensor.value - 273150000) / 1000000.0; cpu_temp = (sensor.value - 273150000) / 1000000.0;
return; return;
@ -118,19 +108,23 @@ void update_battery() {
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
//register_volume_callback();
while(1) { while(1) {
// XXX can update at different intervals // XXX can update at different intervals
update_battery(); update_battery();
update_cpu_temp(); update_cpu_temp();
update_cpu_avg_speed();
update_cpu_base_speed();
update_fan_speed(); update_fan_speed();
update_volume();
wprintf(L"%s %d%% %s %dC %s %4dRPM %s %4dMhz (~%4dMhz) %s\n", wprintf(L"%s %d%% %s %dC %s %4dRPM %s %4dMhz (~%4dMhz) %s %d %s\n",
"", battery_percent, "", battery_percent,
" ", cpu_temp, " ", cpu_temp,
" ", fan_speed, " ", fan_speed,
" ", cpu_base_speed, cpu_avg_speed, " ", cpu_base_speed, cpu_avg_speed,
" ", volume,
" "); " ");
sleep(1); sleep(1);
} }

View File

@ -10,7 +10,7 @@ bind[float_toggle] = MOD+space
# FOCUS # FOCUS
bind[focus_main] = MOD+m bind[focus_main] = MOD+m
bind[focus_next] = MOD+Down bind[focus_next] = MOD+Down
bind[focus_next] = MOD+Tab # bind[focus_next] = MOD+Tab
bind[focus_prev] = MOD+Up bind[focus_prev] = MOD+Up
bind[focus_prev] = MOD+Shift+Tab bind[focus_prev] = MOD+Shift+Tab
bind[focus_urgent] = MOD+u bind[focus_urgent] = MOD+u
@ -42,6 +42,7 @@ bind[ws_9] = MOD+9
bind[ws_10] = MOD+0 bind[ws_10] = MOD+0
bind[ws_next_all] = MOD+Page_Down bind[ws_next_all] = MOD+Page_Down
bind[ws_prev_all] = MOD+Page_Up bind[ws_prev_all] = MOD+Page_Up
bind[ws_prior] = MOD+Tab
# MOVE WINDOW TO OTHER WS # MOVE WINDOW TO OTHER WS
bind[mvrg_1] = MOD+Shift+KP_End bind[mvrg_1] = MOD+Shift+KP_End

View File

@ -1,12 +0,0 @@
let g:netrw_dirhistmax =10
let g:netrw_dirhistcnt =4
let g:netrw_dirhist_4='/home/sdk/.bin'
let g:netrw_dirhist_3='/home/sdk'
let g:netrw_dirhist_2='/home/sdk/.vim'
let g:netrw_dirhist_1='sftp://sdk@gopher.codevoid.de/../www/htdocs/gopher/'
let g:netrw_dirhist_0='/home/sdk/code/bcbackup'
let g:netrw_dirhist_9='/home/sdk/code'
let g:netrw_dirhist_8='/home/sdk/code/bar'
let g:netrw_dirhist_7='/home/sdk/code/drist'
let g:netrw_dirhist_6='/home/sdk/code'
let g:netrw_dirhist_5='/home/sdk/.FontForge'