From 28f6d00ef9cbdbd188072eb1e4505ae0fa8aa578 Mon Sep 17 00:00:00 2001 From: Ingo Unterweger Date: Thu, 5 Oct 2023 15:55:12 +0200 Subject: [PATCH 1/6] feat: new TempWidget type for temperature data Allows one to display current temperature readings as a bar. Utilizes the gopsutil/host package behind the scenes. --- widget.go | 3 ++ widget_temp.go | 130 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 widget_temp.go diff --git a/widget.go b/widget.go index 60764b1..1d95235 100644 --- a/widget.go +++ b/widget.go @@ -119,6 +119,9 @@ func NewWidget(dev *streamdeck.Device, base string, kc KeyConfig, bg image.Image case "top": return NewTopWidget(bw, kc.Widget), nil + case "temp": + return NewTempWidget(bw, kc.Widget), nil + case "command": return NewCommandWidget(bw, kc.Widget), nil diff --git a/widget_temp.go b/widget_temp.go new file mode 100644 index 0000000..b094730 --- /dev/null +++ b/widget_temp.go @@ -0,0 +1,130 @@ +package main + +import ( + "fmt" + "image" + "image/color" + "image/draw" + "strconv" + "time" + + "github.com/shirou/gopsutil/host" +) + +// TempWidget is a widget displaying temperature sensor data as a bar. +type TempWidget struct { + *BaseWidget + + label string + sensorKey string + maxTemp float64 + + color color.Color + fillColor color.Color + + lastValue float64 +} + +// NewTempWidget returns a new TempWidget. +func NewTempWidget(bw *BaseWidget, opts WidgetConfig) *TempWidget { + bw.setInterval(time.Duration(opts.Interval)*time.Millisecond, time.Second*5) + + var label, sensorKey string + _ = ConfigValue(opts.Config["label"], &label) + _ = ConfigValue(opts.Config["sensorKey"], &sensorKey) + var maxTemp float64 + _ = ConfigValue(opts.Config["maxTemp"], &maxTemp) + + var color, fillColor color.Color + _ = ConfigValue(opts.Config["color"], &color) + _ = ConfigValue(opts.Config["fillColor"], &fillColor) + + return &TempWidget{ + BaseWidget: bw, + label: label, + sensorKey: sensorKey, + maxTemp: maxTemp, + color: color, + fillColor: fillColor, + } +} + +// Update renders the widget. +func (w *TempWidget) Update() error { + var value float64 + + sensors, err := host.SensorsTemperatures() + if err != nil { + return fmt.Errorf("can't retrieve sensors data: %s", err) + } + + for i := range sensors { + if sensors[i].SensorKey == w.sensorKey { + value = sensors[i].Temperature + break + } + } + + if w.lastValue == value { + w.lastUpdate = time.Now() + return nil + } + w.lastValue = value + + if w.maxTemp == 0 { + w.maxTemp = 100 + } + if w.color == nil { + w.color = DefaultColor + } + if w.fillColor == nil { + w.fillColor = color.RGBA{166, 155, 182, 255} + } + + size := int(w.dev.Pixels) + margin := size / 18 + img := image.NewRGBA(image.Rect(0, 0, size, size)) + + draw.Draw(img, + image.Rect(12, 6, size-12, size-18), + &image.Uniform{w.color}, + image.Point{}, draw.Src) + draw.Draw(img, + image.Rect(13, 7, size-14, size-20), + &image.Uniform{color.RGBA{0, 0, 0, 255}}, + image.Point{}, draw.Src) + draw.Draw(img, + image.Rect(14, 7+int(float64(size-26)*(1-value/w.maxTemp)), size-15, size-21), + &image.Uniform{w.fillColor}, + image.Point{}, draw.Src) + + // draw percentage + bounds := img.Bounds() + bounds.Min.Y = 6 + bounds.Max.Y -= 18 + + drawString(img, + bounds, + ttfFont, + strconv.FormatInt(int64(value), 10), + w.dev.DPI, + 13, + w.color, + image.Pt(-1, -1)) + + // draw description + bounds = img.Bounds() + bounds.Min.Y = size - 16 + bounds.Max.Y -= margin + + drawString(img, + bounds, + ttfFont, + "°C "+w.label, + w.dev.DPI, + -1, + w.color, + image.Pt(-1, -1)) + + return w.render(w.dev, img) +} From cdd122d1cf144b7f53a88a737ed65b06f54c201d Mon Sep 17 00:00:00 2001 From: Ingo Unterweger Date: Fri, 6 Oct 2023 08:26:00 +0200 Subject: [PATCH 2/6] feat(widget_temp): handle unknown sensor keys --- widget_temp.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/widget_temp.go b/widget_temp.go index b094730..9aa0e21 100644 --- a/widget_temp.go +++ b/widget_temp.go @@ -58,13 +58,19 @@ func (w *TempWidget) Update() error { return fmt.Errorf("can't retrieve sensors data: %s", err) } + found := false for i := range sensors { if sensors[i].SensorKey == w.sensorKey { + found = true value = sensors[i].Temperature break } } + if !found { + return fmt.Errorf("unknown temperature sensor key: %s", w.sensorKey) + } + if w.lastValue == value { w.lastUpdate = time.Now() return nil From 94cb31c7fdf89b8b6ac8449a848f5771016f6aa7 Mon Sep 17 00:00:00 2001 From: Ingo Unterweger Date: Fri, 6 Oct 2023 10:17:02 +0200 Subject: [PATCH 3/6] chore: switch gopsutil to github.com/shirou/gopsutil/v3 --- go.mod | 16 ++++++++-------- go.sum | 48 ++++++++++++++++++++++++++++++++++++------------ widget_temp.go | 2 +- widget_top.go | 4 ++-- 4 files changed, 47 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index bf198a4..808d5ec 100644 --- a/go.mod +++ b/go.mod @@ -15,20 +15,20 @@ require ( github.com/mitchellh/go-homedir v1.1.0 github.com/muesli/streamdeck v0.4.0 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 - github.com/shirou/gopsutil v3.21.11+incompatible + github.com/shirou/gopsutil/v3 v3.23.9 golang.org/x/image v0.7.0 ) require ( github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 // indirect github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-ole/go-ole v1.2.6 // indirect github.com/karalabe/hid v1.0.1-0.20190806082151-9c14560f9ee8 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/testify v1.2.2 // indirect - github.com/tklauser/go-sysconf v0.3.9 // indirect - github.com/tklauser/numcpus v0.3.0 // indirect - github.com/yusufpapurcu/wmi v1.2.2 // indirect - golang.org/x/sys v0.5.0 // indirect + github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect + github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect + github.com/shoenig/go-m1cpu v0.1.6 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect + github.com/yusufpapurcu/wmi v1.2.3 // indirect + golang.org/x/sys v0.12.0 // indirect ) diff --git a/go.sum b/go.sum index 7bf1e95..325dbb8 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,7 @@ github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn github.com/bendahl/uinput v1.6.1 h1:A8b6mtqC3E7ZkpLdQWNeyZNmLPhqxGS+fScrim3TV/k= github.com/bendahl/uinput v1.6.1/go.mod h1:Np7w3DINc9wB83p12fTAM3DPPhFnAKP0WTXRqCQJ6Z8= github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/flopp/go-findfont v0.1.0 h1:lPn0BymDUtJo+ZkV01VS3661HL6F4qFlkhcJN55u6mU= @@ -19,6 +20,9 @@ github.com/godbus/dbus v4.1.0+incompatible h1:WqqLRTsQic3apZUK9qC5sGNfXthmPXzUZ7 github.com/godbus/dbus v4.1.0+incompatible/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jezek/xgb v1.1.0 h1:wnpxJzP1+rkbGclEkmwpVFQWpuE2PUGNUzP8SbfFobk= github.com/jezek/xgb v1.1.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk= @@ -28,6 +32,8 @@ github.com/karalabe/hid v1.0.1-0.20190806082151-9c14560f9ee8 h1:AP5krei6PpUCFOp2 github.com/karalabe/hid v1.0.1-0.20190806082151-9c14560f9ee8/go.mod h1:Vr51f8rUOLYrfrWDFlV12GGQgM5AT8sVh+2fY4MPeu8= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/muesli/coral v1.0.0/go.mod h1:bf91M/dkp7iHQw73HOoR9PekdTJMTD6ihJgWoDitde8= @@ -37,19 +43,30 @@ github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= -github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +github.com/shirou/gopsutil/v3 v3.23.9 h1:ZI5bWVeu2ep4/DIxB4U9okeYJ7zp/QLTO4auRb/ty/E= +github.com/shirou/gopsutil/v3 v3.23.9/go.mod h1:x/NWSb71eMcjFIO0vhyGW5nZ7oSIgVjrCnADckb85GA= +github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= +github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= +github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= +github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/tklauser/go-sysconf v0.3.9 h1:JeUVdAOWhhxVcU6Eqr/ATFHgXk/mmiItdKeJPev3vTo= -github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs= -github.com/tklauser/numcpus v0.3.0 h1:ILuRUQBtssgnxw0XXIjKUC56fgnOrFoQQ/4+DeU2biQ= -github.com/tklauser/numcpus v0.3.0/go.mod h1:yFGUr7TUHQRAhyqBcEg0Ge34zDBAsIvJJcyE6boqnA8= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= -github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= +github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/image v0.6.0/go.mod h1:MXLdDR43H7cDJq5GEGXEVeeNhPgi+YYEQ2pC1byI1x0= @@ -67,12 +84,15 @@ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= @@ -87,5 +107,9 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/widget_temp.go b/widget_temp.go index 9aa0e21..5485087 100644 --- a/widget_temp.go +++ b/widget_temp.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - "github.com/shirou/gopsutil/host" + "github.com/shirou/gopsutil/v3/host" ) // TempWidget is a widget displaying temperature sensor data as a bar. diff --git a/widget_top.go b/widget_top.go index 0b377cf..06b3919 100644 --- a/widget_top.go +++ b/widget_top.go @@ -8,8 +8,8 @@ import ( "strconv" "time" - "github.com/shirou/gopsutil/cpu" - "github.com/shirou/gopsutil/mem" + "github.com/shirou/gopsutil/v3/cpu" + "github.com/shirou/gopsutil/v3/mem" ) // TopWidget is a widget displaying the current CPU/MEM usage as a bar. From fe64b8f1da68750f1aba910d7eeaac3b3428cb47 Mon Sep 17 00:00:00 2001 From: Ingo Unterweger Date: Fri, 6 Oct 2023 11:27:23 +0200 Subject: [PATCH 4/6] docs(widget_temp): add usage to README --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index c8ac30b..0b2fde8 100644 --- a/README.md +++ b/README.md @@ -284,6 +284,30 @@ corresponding icons with correct names need to be placed in `~/.local/share/deckmaster/themes/[theme]`. The default icons with their respective names can be found [here](https://github.com/muesli/deckmaster/tree/master/assets/weather). +#### Temperature + +This widget shows temperature sensor data as a bar graph. + +```toml +[keys.widget] + id = "temp" + [keys.widget.config] + sensorKey = "k10temp_tctl" + label = "CPU" + maxTemp = 100 #optional + color = "#fefefe" # optional + fillColor = "#d497de" # optional +``` + +The values for sensorKey are platform dependent. On most Linux systems they're based on the file structure found under /sys/class/hwmon. + +Example: k10temp_tctl + +k10temp: the name for a specific sensor interface, for example, the value reported from /sys/class/hwmon/hwmon0/name +tctl: the label for a specific sensor, for example, the value reported from /sys/class/hwmon/hwmon0/temp1_label (label is converted to lowercase and spaces are replaced with underscores) + +For the full explanation on how these sensor keys are created on all platforms, check out the SensorTemperatures* functions from the [gopsutil/host](https://github.com/shirou/gopsutil/blob/master/host/host.go) package. + ### Actions You can hook up any key with several actions. A regular keypress will trigger From 92652e8db33e130c64770be02b06cf5b6ff447e0 Mon Sep 17 00:00:00 2001 From: Ingo Unterweger Date: Fri, 6 Oct 2023 11:49:05 +0200 Subject: [PATCH 5/6] docs(widget_temp): better formatting in README section --- README.md | 19 +++++++++++++------ widget_temp.go | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0b2fde8..8ef041e 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ An application to control your Elgato Stream Deck on Linux - Weather - Command output - Recently used windows (X11-only) + - Hardware temperature sensor data - Lets you trigger several actions: - Run commands - Emulate a key-press @@ -286,7 +287,7 @@ respective names can be found [here](https://github.com/muesli/deckmaster/tree/m #### Temperature -This widget shows temperature sensor data as a bar graph. +This widget shows hardware temperature sensor data as a bar graph. ```toml [keys.widget] @@ -299,14 +300,20 @@ This widget shows temperature sensor data as a bar graph. fillColor = "#d497de" # optional ``` -The values for sensorKey are platform dependent. On most Linux systems they're based on the file structure found under /sys/class/hwmon. +The values for sensorKey are platform dependent. On most Linux systems they're +based on the [hwmon-sysfs-interface](https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface) under `/sys/class/hwmon`. -Example: k10temp_tctl +Example: `k10temp_tctl` -k10temp: the name for a specific sensor interface, for example, the value reported from /sys/class/hwmon/hwmon0/name -tctl: the label for a specific sensor, for example, the value reported from /sys/class/hwmon/hwmon0/temp1_label (label is converted to lowercase and spaces are replaced with underscores) +- `k10temp`: the name for a specific sensor interface, for example, the value +reported from `/sys/class/hwmon/hwmon0/name` +- `tctl`: the label for a specific sensor, for example, the value reported from +`/sys/class/hwmon/hwmon0/temp1_label` (label is converted to lowercase and +spaces are replaced with underscores) -For the full explanation on how these sensor keys are created on all platforms, check out the SensorTemperatures* functions from the [gopsutil/host](https://github.com/shirou/gopsutil/blob/master/host/host.go) package. +For the full explanation on how these sensor keys are created on all platforms, +check the `SensorTemperatures*` functions in the [gopsutil](https://github.com/shirou/gopsutil/blob/master/host/host.go) +package. ### Actions diff --git a/widget_temp.go b/widget_temp.go index 5485087..9fd7a27 100644 --- a/widget_temp.go +++ b/widget_temp.go @@ -11,7 +11,7 @@ import ( "github.com/shirou/gopsutil/v3/host" ) -// TempWidget is a widget displaying temperature sensor data as a bar. +// TempWidget is a widget displaying hardware temperature sensor data as a bar. type TempWidget struct { *BaseWidget From bd52a35e3ebfd9fb7fe3d8e7168b2457a94b37c2 Mon Sep 17 00:00:00 2001 From: Ingo Unterweger Date: Mon, 9 Oct 2023 19:51:21 +0200 Subject: [PATCH 6/6] docs(widget_temp): small explanation where temp data can be found --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8ef041e..12ce0c9 100644 --- a/README.md +++ b/README.md @@ -310,6 +310,7 @@ reported from `/sys/class/hwmon/hwmon0/name` - `tctl`: the label for a specific sensor, for example, the value reported from `/sys/class/hwmon/hwmon0/temp1_label` (label is converted to lowercase and spaces are replaced with underscores) +- For this example, the temperature value would be available in `/sys/class/hwmon/hwmon0/temp1_input` For the full explanation on how these sensor keys are created on all platforms, check the `SensorTemperatures*` functions in the [gopsutil](https://github.com/shirou/gopsutil/blob/master/host/host.go)