Compare commits

...

3 Commits

Author SHA1 Message Date
11163f059b New setting: Max volume
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is failing
2024-06-18 18:09:12 +02:00
41f8092419 Split command executed in a separate file 2024-06-18 18:09:12 +02:00
6f495f4fe1 Add missing routes for sveltekit 1 2024-06-18 18:09:12 +02:00
9 changed files with 46 additions and 7 deletions

View File

@ -27,7 +27,7 @@ steps:
- apk --no-cache add alsa-lib-dev build-base git pkgconf - apk --no-cache add alsa-lib-dev build-base git pkgconf
- go get -v -d - go get -v -d
- go vet -v - go vet -v
- go build -v -ldflags '-w -X main.Version=${DRONE_BRANCH}-${DRONE_COMMIT} -X main.build=${DRONE_BUILD_NUMBER}' -o deploy/reveil-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH} - go build -tags pulse -ldflags '-w -X main.Version=${DRONE_BRANCH}-${DRONE_COMMIT} -X main.build=${DRONE_BUILD_NUMBER}' -o deploy/reveil-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}
- ln deploy/reveil-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH} reveil - ln deploy/reveil-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH} reveil
when: when:
event: event:
@ -40,7 +40,7 @@ steps:
- apk --no-cache add alsa-lib-dev build-base git pkgconf - apk --no-cache add alsa-lib-dev build-base git pkgconf
- go get -v -d - go get -v -d
- go vet -v - go vet -v
- go build -v -ldflags '-w -X main.Version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -o deploy/reveil-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}v7 - go build -tags pulse -ldflags '-w -X main.Version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -o deploy/reveil-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}v7
- ln deploy/reveil-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}v7 reveil - ln deploy/reveil-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}v7 reveil
when: when:
event: event:
@ -50,7 +50,7 @@ steps:
image: golang:1-alpine image: golang:1-alpine
commands: commands:
- apk --no-cache add alsa-lib-dev build-base git pkgconf - apk --no-cache add alsa-lib-dev build-base git pkgconf
- go build -v -tags netgo -ldflags '-w -X main.Version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -o deploy/reveil-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}hf - go build -tags pulse,netgo -ldflags '-w -X main.Version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -o deploy/reveil-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}hf
environment: environment:
CGO_ENABLED: 0 CGO_ENABLED: 0
GOARM: 6 GOARM: 6

View File

@ -15,7 +15,7 @@ RUN apk --no-cache add git go-bindata
COPY . /go/src/git.nemunai.re/nemunaire/reveil COPY . /go/src/git.nemunai.re/nemunaire/reveil
COPY --from=nodebuild /ui/build /go/src/git.nemunai.re/nemunaire/reveil/ui/build COPY --from=nodebuild /ui/build /go/src/git.nemunai.re/nemunaire/reveil/ui/build
WORKDIR /go/src/git.nemunai.re/nemunaire/reveil WORKDIR /go/src/git.nemunai.re/nemunaire/reveil
RUN go get -v && go generate -v && go build -v -ldflags="-s -w" RUN go get -v && go generate -v && go build -tags pulse -ldflags="-s -w"
FROM alpine:3.20 FROM alpine:3.20

View File

@ -13,6 +13,7 @@ type Settings struct {
WeatherDelay time.Duration `json:"weather_delay"` WeatherDelay time.Duration `json:"weather_delay"`
WeatherAction string `json:"weather_action"` WeatherAction string `json:"weather_action"`
MaxRunTime time.Duration `json:"max_run_time"` MaxRunTime time.Duration `json:"max_run_time"`
MaxVolume uint16 `json:"max_volume"`
} }
// ExistsSettings checks if the settings file can by found at the given path. // ExistsSettings checks if the settings file can by found at the given path.

View File

@ -21,6 +21,7 @@ var CommonPlayer *Player
type Player struct { type Player struct {
Playlist []string Playlist []string
MaxRunTime time.Duration MaxRunTime time.Duration
MaxVolume uint16
Stopper chan bool Stopper chan bool
currentCmd *exec.Cmd currentCmd *exec.Cmd
currentCmdCh chan bool currentCmdCh chan bool
@ -77,6 +78,7 @@ func NewPlayer(cfg *config.Config, routines []reveil.Identifier) (*Player, error
Stopper: make(chan bool, 1), Stopper: make(chan bool, 1),
currentCmdCh: make(chan bool, 1), currentCmdCh: make(chan bool, 1),
MaxRunTime: settings.MaxRunTime * time.Minute, MaxRunTime: settings.MaxRunTime * time.Minute,
MaxVolume: uint16(settings.MaxVolume),
weatherTime: settings.WeatherDelay * time.Minute, weatherTime: settings.WeatherDelay * time.Minute,
weatherAction: wact, weatherAction: wact,
claironTime: settings.GongInterval * time.Minute, claironTime: settings.GongInterval * time.Minute,
@ -136,7 +138,7 @@ func (p *Player) launchAction(cfg *config.Config, a *reveil.Action) (err error)
} }
func (p *Player) playFile(filepath string) (err error) { func (p *Player) playFile(filepath string) (err error) {
p.currentCmd = exec.Command("paplay", filepath) p.currentCmd = exec.Command(playCommand, filepath)
if err = p.currentCmd.Start(); err != nil { if err = p.currentCmd.Start(); err != nil {
log.Println("Running paplay err: ", err.Error()) log.Println("Running paplay err: ", err.Error())
p.currentCmdCh <- true p.currentCmdCh <- true
@ -270,7 +272,11 @@ func (p *Player) NextTrack() {
} }
func (p *Player) SetVolume(volume uint16) error { func (p *Player) SetVolume(volume uint16) error {
cmd := exec.Command("amixer", "-D", "pulse", "set", "Master", 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() return cmd.Run()
} }

9
player/player_pulse.go Normal file
View File

@ -0,0 +1,9 @@
//go:build pulse
package player
const (
playCommand = "paplay"
mixerCard = "pulse"
mixerName = "Master"
)

View File

@ -58,8 +58,10 @@ func DeclareRoutes(router *gin.Engine, cfg *config.Config) {
router.GET("/.svelte-kit/*_", serveOrReverse("", cfg)) router.GET("/.svelte-kit/*_", serveOrReverse("", cfg))
router.GET("/node_modules/*_", serveOrReverse("", cfg)) router.GET("/node_modules/*_", serveOrReverse("", cfg))
router.GET("/@vite/*_", serveOrReverse("", cfg)) router.GET("/@vite/*_", serveOrReverse("", cfg))
router.GET("/@id/*_", serveOrReverse("", cfg))
router.GET("/@fs/*_", serveOrReverse("", cfg)) router.GET("/@fs/*_", serveOrReverse("", cfg))
router.GET("/src/*_", serveOrReverse("", cfg)) router.GET("/src/*_", serveOrReverse("", cfg))
router.GET("/home/*_", serveOrReverse("", cfg))
} }
router.GET("/", serveOrReverse("", cfg)) router.GET("/", serveOrReverse("", cfg))

View File

@ -5,12 +5,13 @@ export class Settings {
} }
} }
update({ language, gong_interval, weather_delay, weather_action, max_run_time }) { update({ language, gong_interval, weather_delay, weather_action, max_run_time, max_volume }) {
this.language = language; this.language = language;
this.gong_interval = gong_interval; this.gong_interval = gong_interval;
this.weather_delay = weather_delay; this.weather_delay = weather_delay;
this.weather_action = weather_action; this.weather_action = weather_action;
this.max_run_time = max_run_time; this.max_run_time = max_run_time;
this.max_volume = max_volume;
} }
async save() { async save() {

View File

@ -116,6 +116,20 @@
<InputGroupText>min</InputGroupText> <InputGroupText>min</InputGroupText>
</InputGroup> </InputGroup>
</FormGroup> </FormGroup>
<FormGroup>
<Label for="maxVolume">Volume maximum</Label>
<InputGroup>
<Input
type="range"
id="maxVolume"
min="0"
max="65535"
bind:value={settings.max_volume}
on:input={submitSettings}
/>
</InputGroup>
</FormGroup>
{/await} {/await}
</Form> </Form>
</Container> </Container>

View File

@ -2,6 +2,12 @@ import { sveltekit } from '@sveltejs/kit/vite';
/** @type {import('vite').UserConfig} */ /** @type {import('vite').UserConfig} */
const config = { const config = {
server: {
hmr: {
port: 10000
}
},
plugins: [sveltekit()] plugins: [sveltekit()]
}; };