Skip to content

Commit

Permalink
add bluetooth audio status
Browse files Browse the repository at this point in the history
  • Loading branch information
bavarianbidi committed Jan 17, 2024
1 parent c98cca4 commit ebb835e
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: build
build: ## Build i3-bar
go build -o i3-bar i3-bar.go
go build -o i3-bar

.PHONY: imports
imports: ## Runs goimports.
Expand Down
46 changes: 46 additions & 0 deletions bluetooth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"barista.run/bar"
"barista.run/colors"
"barista.run/modules/bluetooth"
"barista.run/modules/meta/split"
"barista.run/outputs"
"barista.run/pango"
)

func bluetoothAudio(adapter, address, icon string) (bar.Module, bar.Module) {
return split.New(bluetooth.Device(adapter, address).Output(func(b bluetooth.DeviceInfo) bar.Output {

out := outputs.Group()

color := colorOn
iconAppendix := ""

if !b.Connected {
color = colorOff
iconAppendix = "-off"
}

// summary
out.Append(outputs.Pango(
pango.Icon("mdi-" + icon + iconAppendix).Alpha(0.6).Color(colors.Hex(color)),
))

// detail
out.Append(outputs.Pango(
pango.Icon("mdi-"+icon).Alpha(0.6).Color(colors.Hex(color)),
spacer,
pango.Text(b.Name),
))

if b.Connected {
out.Append(outputs.Pango(
pango.Icon("mdi-battery").Alpha(0.6),
pango.Textf("%s: %d%%", b.Alias, b.Battery),
))
}

return out
}), 1)
}
6 changes: 6 additions & 0 deletions color.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main

const (
colorOn = "#34eb55"
colorOff = "#eb4034"
)
75 changes: 12 additions & 63 deletions i3-bar.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import (
"barista.run/pango"
"barista.run/pango/icons/mdi"

"github.com/bavarianbidi/i3-bar/shelly"
colorful "github.com/lucasb-eyer/go-colorful"
"github.com/martinlindhe/unit"
)
Expand Down Expand Up @@ -467,70 +466,20 @@ func main() {
}
sysMode.Detail(rootDiskspace, mainDiskio)

quickMillSummary, quickMillDetail := split.New(shelly.New("192.168.178.64").
//RefreshInterval(3*time.Second).
Output(func(s shelly.ShellyState) bar.Output {

out := outputs.Group()

if s.Reachable() {
if s.Connected() {
out.Append(
outputs.Pango(
pango.Icon("mdi-coffee").Color(colors.Hex("#34eb55")),
))
}
if !s.Connected() {
out.Append(
outputs.Pango(
pango.Icon("mdi-coffee-outline").Color(colors.Hex("#eb4034")),
))
}

out.OnClick(click.Left(func() {
s.Toggle()
}))
// headphones
headsetSummary, headsetDetail := bluetoothAudio("hci0", "14:3F:A6:1B:FA:77", "headphones")

if s.IsUpdateAvailable() {
out.Append(outputs.Pango(
pango.Icon("mdi-package-down").Color(colors.Hex("#34eb55")),
spacer,
pango.Textf("version %s available", s.GetVersion()),
))
}
if !s.IsUpdateAvailable() {
out.Append(outputs.Pango(
pango.Icon("mdi-package-down"),
spacer,
pango.Textf("up to date"),
))
}

out.Append(outputs.Pango(
pango.Icon("mdi-harddisk"),
spacer,
pango.Textf("%.0f%% used", s.DiskUtilization()),
))

out.Append(outputs.Pango(
pango.Icon("mdi-memory"),
spacer,
pango.Textf("%.0f%% RAM usage", s.MemoryUtilization()),
))
} else {
out.Append(
outputs.Pango(
pango.Icon("mdi-coffee-off").Color(colors.Hex("#eb4034")),
))

out.Append(outputs.Pango(
spacer,
pango.Textf("shelly not reachable"),
))
}
// bluetooth box
soundcoreSummary, soundcoreDetail := bluetoothAudio("hci0", "08:EB:ED:83:82:01", "speaker")

return out
}), 1)
mainModal.Mode("bluetooth-audio").
SetOutput(makeIconOutput("mdi-bluetooth")).
Add(soundcoreSummary).
Add(headsetSummary).
Detail(soundcoreDetail).
Detail(headsetDetail)

quickMillSummary, quickMillDetail := shellyStatus("192.168.178.64", "coffee")

mainModal.Mode("shelly").
SetOutput(makeIconOutput("mdi-coffee")).
Expand Down
81 changes: 81 additions & 0 deletions shelly.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package main

import (
"barista.run/bar"
"barista.run/base/click"
"barista.run/colors"
"barista.run/modules/meta/split"
"barista.run/outputs"
"barista.run/pango"
"github.com/bavarianbidi/i3-bar/shelly"
)

func shellyStatus(address, icon string) (bar.Module, bar.Module) {
return split.New(shelly.New(address).
//RefreshInterval(3*time.Second).
Output(func(s shelly.ShellyState) bar.Output {

color := colorOn
iconAppendix := ""

out := outputs.Group()

if s.Reachable() {
if !s.Connected() {
color = colorOff
iconAppendix = "-outline"
}
out.Append(
outputs.Pango(
pango.Icon("mdi-" + icon + iconAppendix).Color(colors.Hex(color)),
))

out.OnClick(click.Left(func() {
s.Toggle()
}))

if s.IsUpdateAvailable() {
out.Append(outputs.Pango(
pango.Icon("mdi-package-down").Color(colors.Hex("#34eb55")),
spacer,
pango.Textf("version %s available", s.GetVersion()),
))
}
if !s.IsUpdateAvailable() {
out.Append(outputs.Pango(
pango.Icon("mdi-package-down"),
spacer,
pango.Textf("up to date"),
))
}

out.Append(outputs.Pango(
pango.Icon("mdi-harddisk"),
spacer,
pango.Textf("%.0f%% used", s.DiskUtilization()),
))

out.Append(outputs.Pango(
pango.Icon("mdi-memory"),
spacer,
pango.Textf("%.0f%% RAM usage", s.MemoryUtilization()),
))
} else {

color = colorOff
iconAppendix = "-off"

out.Append(
outputs.Pango(
pango.Icon("mdi-" + icon + iconAppendix).Color(colors.Hex(color)),
))

out.Append(outputs.Pango(
spacer,
pango.Textf("shelly not reachable"),
))
}

return out
}), 1)
}

0 comments on commit ebb835e

Please sign in to comment.