New setting: Max volume
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is failing

This commit is contained in:
nemunaire 2024-06-18 18:09:00 +02:00
commit 11163f059b
4 changed files with 24 additions and 2 deletions

View file

@ -21,6 +21,7 @@ var CommonPlayer *Player
type Player struct {
Playlist []string
MaxRunTime time.Duration
MaxVolume uint16
Stopper chan bool
currentCmd *exec.Cmd
currentCmdCh chan bool
@ -77,6 +78,7 @@ func NewPlayer(cfg *config.Config, routines []reveil.Identifier) (*Player, error
Stopper: make(chan bool, 1),
currentCmdCh: make(chan bool, 1),
MaxRunTime: settings.MaxRunTime * time.Minute,
MaxVolume: uint16(settings.MaxVolume),
weatherTime: settings.WeatherDelay * time.Minute,
weatherAction: wact,
claironTime: settings.GongInterval * time.Minute,
@ -270,7 +272,11 @@ func (p *Player) NextTrack() {
}
func (p *Player) SetVolume(volume uint16) error {
cmd := exec.Command("amixer", "-D", mixerCard, "set", mixerName, fmt.Sprintf("%d", volume))
if p.MaxVolume == 0 {
p.MaxVolume = 65535
}
cmd := exec.Command("amixer", "-D", mixerCard, "set", mixerName, fmt.Sprintf("%d", uint32(volume)*uint32(p.MaxVolume)/65535))
return cmd.Run()
}