Adapt playback layout and fonts for displays and add contrast fading
This commit is contained in:
9 files changed
+95
-19
No files matched your search
@@ -41,6 +41,9 @@ type Context interface {
|
|||||||
|
|
||||||
// Settings are the user settings.
|
// Settings are the user settings.
|
||||||
Settings() *config.Settings
|
Settings() *config.Settings
|
||||||
|
|
||||||
|
// SetContrast updates all screen's contrast.
|
||||||
|
SetContrast(level uint8)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Widget interface {
|
type Widget interface {
|
||||||
|
|||||||
Binary file not shown.
@@ -17,6 +17,9 @@ var (
|
|||||||
|
|
||||||
//go:embed asset/spleen-8x16.bdf
|
//go:embed asset/spleen-8x16.bdf
|
||||||
spleen8x16BDF []byte
|
spleen8x16BDF []byte
|
||||||
|
|
||||||
|
//go:embed asset/unifont-16.0.02.bdf
|
||||||
|
unifontBDF []byte
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ var (
|
|||||||
Spleen5x8 = Must(NewFromBytes(spleen5x8BDF))
|
Spleen5x8 = Must(NewFromBytes(spleen5x8BDF))
|
||||||
Spleen6x12 = Must(NewFromBytes(spleen6x12BDF))
|
Spleen6x12 = Must(NewFromBytes(spleen6x12BDF))
|
||||||
Spleen8x16 = Must(NewFromBytes(spleen8x16BDF))
|
Spleen8x16 = Must(NewFromBytes(spleen8x16BDF))
|
||||||
|
Unifont = Must(NewFromBytes(unifontBDF))
|
||||||
)
|
)
|
||||||
|
|
||||||
// Icons mapped in SM4TIK
|
// Icons mapped in SM4TIK
|
||||||
|
|||||||
+44
-14
@@ -11,6 +11,7 @@ import (
|
|||||||
"periph.io/x/conn/v3/physic"
|
"periph.io/x/conn/v3/physic"
|
||||||
|
|
||||||
"github.com/BeatGlow/audio"
|
"github.com/BeatGlow/audio"
|
||||||
|
"github.com/BeatGlow/display/pixel"
|
||||||
|
|
||||||
"github.com/BeatGlow/beatglow/app"
|
"github.com/BeatGlow/beatglow/app"
|
||||||
"github.com/BeatGlow/beatglow/app/font"
|
"github.com/BeatGlow/beatglow/app/font"
|
||||||
@@ -48,11 +49,20 @@ type playing struct {
|
|||||||
spectrumWidget *widget.Spectrum
|
spectrumWidget *widget.Spectrum
|
||||||
}
|
}
|
||||||
|
|
||||||
const playingWaterfallHeight = 32
|
|
||||||
|
|
||||||
func Playing(ctx app.Context) app.Layout {
|
func Playing(ctx app.Context) app.Layout {
|
||||||
bounds := ctx.Display().Bounds()
|
var (
|
||||||
styles := app.StylesFor(ctx.Display().ColorModel())
|
config = ctx.Settings()
|
||||||
|
bounds = ctx.Display().Bounds()
|
||||||
|
cmodel = ctx.Display().ColorModel()
|
||||||
|
styles = app.StylesFor(cmodel)
|
||||||
|
playingWaterfallHeight = bounds.Dy() - 32
|
||||||
|
maxWidth = bounds.Dx() - bounds.Dy()
|
||||||
|
)
|
||||||
|
|
||||||
|
if !config.Player.ShowArt {
|
||||||
|
maxWidth = bounds.Dx()
|
||||||
|
}
|
||||||
|
|
||||||
layout := &playing{
|
layout := &playing{
|
||||||
base: base{name: "playing"},
|
base: base{name: "playing"},
|
||||||
settings: ctx.Settings(),
|
settings: ctx.Settings(),
|
||||||
@@ -62,21 +72,29 @@ func Playing(ctx app.Context) app.Layout {
|
|||||||
durationText: durationTextPlaceholder,
|
durationText: durationTextPlaceholder,
|
||||||
durationWidget: widget.NewText(image.Pt(2+len(durationTextPlaceholder)*9, 12)),
|
durationWidget: widget.NewText(image.Pt(2+len(durationTextPlaceholder)*9, 12)),
|
||||||
trackText: trackTextPlaceholder,
|
trackText: trackTextPlaceholder,
|
||||||
trackWidget: widget.NewText(image.Pt(bounds.Dx()-bounds.Dy(), bounds.Dy()-12-playingWaterfallHeight)),
|
trackWidget: widget.NewText(image.Pt(maxWidth, bounds.Dy()-12-playingWaterfallHeight)),
|
||||||
iconText: iconTextPlaceholder,
|
iconText: iconTextPlaceholder,
|
||||||
iconWidget: widget.NewText(image.Pt(10, 12)),
|
iconWidget: widget.NewText(image.Pt(10, 12)),
|
||||||
artWidget: widget.NewImage(image.Pt(bounds.Dy(), bounds.Dy())),
|
spectrumWidget: widget.NewSpectrum(image.Pt(maxWidth, playingWaterfallHeight)),
|
||||||
spectrumWidget: widget.NewSpectrum(image.Pt(bounds.Dx()-bounds.Dy(), playingWaterfallHeight)),
|
}
|
||||||
|
if config.Player.ShowArt {
|
||||||
|
layout.artWidget = widget.NewImage(image.Pt(bounds.Dy(), bounds.Dy()))
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
formatStyle = styles.Text.WithFont(font.Spleen6x12)
|
formatStyle = styles.Text.WithFont(font.Spleen6x12)
|
||||||
iconStyle = styles.Text.WithFont(font.SM4TIK).WithForegroundColor(color.Gray{0x3f})
|
iconStyle = styles.Text.WithFont(font.SM4TIK).WithForegroundColor(color.Gray{0x80})
|
||||||
durationStyle = formatStyle
|
durationStyle = formatStyle
|
||||||
titleStyle = styles.Text.WithFont(font.Montserrat.WithPointSize(20))
|
titleStyle = styles.Text.WithFont(font.Montserrat.WithPointSize(20))
|
||||||
offset int
|
offset int
|
||||||
)
|
)
|
||||||
|
|
||||||
|
switch cmodel {
|
||||||
|
case pixel.MonoModel:
|
||||||
|
titleFont := font.Unifont
|
||||||
|
titleStyle = styles.Text.WithFont(titleFont)
|
||||||
|
}
|
||||||
|
|
||||||
layout.phonesWidget.
|
layout.phonesWidget.
|
||||||
SetStyle(iconStyle).
|
SetStyle(iconStyle).
|
||||||
Update(string(font.IconNote)).
|
Update(string(font.IconNote)).
|
||||||
@@ -110,8 +128,10 @@ func Playing(ctx app.Context) app.Layout {
|
|||||||
Bind(&layout.trackText).
|
Bind(&layout.trackText).
|
||||||
Move(image.Pt(0, 12))
|
Move(image.Pt(0, 12))
|
||||||
|
|
||||||
|
if config.Player.ShowArt {
|
||||||
layout.artWidget.
|
layout.artWidget.
|
||||||
Move(image.Pt(bounds.Dx()-bounds.Dy(), 0))
|
Move(image.Pt(bounds.Dx()-bounds.Dy(), 0))
|
||||||
|
}
|
||||||
|
|
||||||
layout.spectrumWidget.
|
layout.spectrumWidget.
|
||||||
SetWaterfall(false).
|
SetWaterfall(false).
|
||||||
@@ -125,9 +145,11 @@ func Playing(ctx app.Context) app.Layout {
|
|||||||
layout.iconWidget,
|
layout.iconWidget,
|
||||||
layout.durationWidget,
|
layout.durationWidget,
|
||||||
layout.trackWidget,
|
layout.trackWidget,
|
||||||
layout.artWidget,
|
|
||||||
layout.spectrumWidget,
|
layout.spectrumWidget,
|
||||||
}
|
}
|
||||||
|
if config.Player.ShowArt {
|
||||||
|
layout.widgets = append(layout.widgets, layout.artWidget)
|
||||||
|
}
|
||||||
|
|
||||||
return layout
|
return layout
|
||||||
}
|
}
|
||||||
@@ -160,9 +182,11 @@ func (l *playing) TrackChanged(ctx app.Context, track *player.Track) {
|
|||||||
|
|
||||||
if !track.Eq(l.track) {
|
if !track.Eq(l.track) {
|
||||||
l.track = track
|
l.track = track
|
||||||
|
if ctx.Settings().Player.ShowArt {
|
||||||
l.artWidget.Update(beatglowLogo, ctx.Display().ColorModel())
|
l.artWidget.Update(beatglowLogo, ctx.Display().ColorModel())
|
||||||
go l.updateArt(ctx, track)
|
go l.updateArt(ctx, track)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *playing) updateArt(ctx app.Context, track *player.Track) {
|
func (l *playing) updateArt(ctx app.Context, track *player.Track) {
|
||||||
@@ -175,6 +199,7 @@ func (l *playing) updateArt(ctx app.Context, track *player.Track) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Debug("updating album art failed: unavailable")
|
log.Debug("updating album art failed: unavailable")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *playing) StatusChanged(ctx app.Context, status *player.Status) {
|
func (l *playing) StatusChanged(ctx app.Context, status *player.Status) {
|
||||||
@@ -188,10 +213,13 @@ func (l *playing) StatusChanged(ctx app.Context, status *player.Status) {
|
|||||||
|
|
||||||
if status.Paused {
|
if status.Paused {
|
||||||
l.iconText = string(font.IconPause)
|
l.iconText = string(font.IconPause)
|
||||||
|
ctx.SetContrast(ctx.Settings().Display.Contrast)
|
||||||
} else if status.Playing {
|
} else if status.Playing {
|
||||||
l.iconText = string(font.IconPlay)
|
l.iconText = string(font.IconPlay)
|
||||||
|
ctx.SetContrast(ctx.Settings().Display.Contrast)
|
||||||
} else {
|
} else {
|
||||||
l.iconText = string(font.IconStop)
|
l.iconText = string(font.IconStop)
|
||||||
|
ctx.SetContrast(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if status.Duration > 0 {
|
if status.Duration > 0 {
|
||||||
@@ -199,12 +227,14 @@ func (l *playing) StatusChanged(ctx app.Context, status *player.Status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if status.Track != nil {
|
if status.Track != nil {
|
||||||
if l.formatRate {
|
//if l.formatRate {
|
||||||
l.formatText = fmt.Sprintf("%04d@%s", status.Format.BitRate, formatRate(status.Format.SampleRate))
|
// l.formatText = fmt.Sprintf("%04d@%s", status.Format.BitRate, formatRate(status.Format.SampleRate))
|
||||||
} else {
|
//} else {
|
||||||
l.formatText = fmt.Sprintf("%-4s@%s", strings.ToUpper(status.Track.Format), formatRate(status.Format.SampleRate))
|
l.formatText = fmt.Sprintf("%-4s@%s", strings.ToUpper(status.Track.Format), formatRate(status.Format.SampleRate))
|
||||||
}
|
//}
|
||||||
l.formatRate = !l.formatRate
|
//l.formatRate = !l.formatRate
|
||||||
|
} else {
|
||||||
|
l.formatText = formatTextPlaceholder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -24,6 +24,7 @@ var (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
defaultMonoObjectStyle = ObjectStyle{
|
defaultMonoObjectStyle = ObjectStyle{
|
||||||
|
BackgroundImage: image.Black,
|
||||||
BackgroundColor: pixel.Off,
|
BackgroundColor: pixel.Off,
|
||||||
ForegroundColor: pixel.On,
|
ForegroundColor: pixel.On,
|
||||||
BorderColor: pixel.On,
|
BorderColor: pixel.On,
|
||||||
@@ -35,7 +36,7 @@ var (
|
|||||||
Graph: defaultMonoObjectStyle,
|
Graph: defaultMonoObjectStyle,
|
||||||
Text: TextStyle{
|
Text: TextStyle{
|
||||||
ObjectStyle: defaultMonoObjectStyle,
|
ObjectStyle: defaultMonoObjectStyle,
|
||||||
Font: font.SmoochSans,
|
Font: font.Spleen5x8,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -24,10 +24,12 @@ type Settings struct {
|
|||||||
type DisplaySettings struct {
|
type DisplaySettings struct {
|
||||||
Contrast uint8 `hcl:"contrast" menu:"Display contrast" icon:"md_contrast_box"`
|
Contrast uint8 `hcl:"contrast" menu:"Display contrast" icon:"md_contrast_box"`
|
||||||
Sleep string `hcl:"sleep" menu:"Display sleep time" options:"5min,15min,hour,day" icon:"md_power"`
|
Sleep string `hcl:"sleep" menu:"Display sleep time" options:"5min,15min,hour,day" icon:"md_power"`
|
||||||
|
Brightness uint8 `hcl:"brightness" menu:"Display brightness" icon:"md_brightness_6"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PlayerSettings struct {
|
type PlayerSettings struct {
|
||||||
Pause bool
|
Pause bool `hcl:"pause" menu:"Pause" icon:"md_pause"`
|
||||||
|
ShowArt bool `hcl:"show_art" menu:"Show album art" icon:"md_image"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SpectrumSettings struct {
|
type SpectrumSettings struct {
|
||||||
@@ -47,6 +49,10 @@ var DefaultSettings = Settings{
|
|||||||
Display: DisplaySettings{
|
Display: DisplaySettings{
|
||||||
Contrast: 0x80,
|
Contrast: 0x80,
|
||||||
Sleep: "hour",
|
Sleep: "hour",
|
||||||
|
Brightness: 0x7F,
|
||||||
|
},
|
||||||
|
Player: PlayerSettings{
|
||||||
|
ShowArt: true,
|
||||||
},
|
},
|
||||||
Spectrum: SpectrumSettings{
|
Spectrum: SpectrumSettings{
|
||||||
Hold: 10,
|
Hold: 10,
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ type controllerContext struct {
|
|||||||
previous app.Layout
|
previous app.Layout
|
||||||
settingsLayout app.Layout
|
settingsLayout app.Layout
|
||||||
settings *config.Settings
|
settings *config.Settings
|
||||||
|
contrast uint8
|
||||||
|
contrastTarget uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c controllerContext) Display() display.Display {
|
func (c controllerContext) Display() display.Display {
|
||||||
@@ -240,4 +242,8 @@ func (c *controllerContext) handleRotaryLongPress() {
|
|||||||
c.Show(c.settingsLayout)
|
c.Show(c.settingsLayout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *controllerContext) SetContrast(level uint8) {
|
||||||
|
c.contrastTarget = level
|
||||||
|
}
|
||||||
|
|
||||||
var _ app.Context = (*controllerContext)(nil)
|
var _ app.Context = (*controllerContext)(nil)
|
||||||
+26
-3
@@ -87,6 +87,13 @@ func (c *Controller) configureDisplay(log *logrus.Entry, settings *config.Displa
|
|||||||
} else if err = c.ctx.display.Refresh(); err != nil {
|
} else if err = c.ctx.display.Refresh(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
userSettings := c.ctx.Settings()
|
||||||
|
c.ctx.contrast = userSettings.Display.Contrast
|
||||||
|
if err = c.ctx.display.SetContrast(userSettings.Display.Contrast); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
log.WithField("display", c.ctx.display).Debug("setup display done")
|
log.WithField("display", c.ctx.display).Debug("setup display done")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -181,6 +188,8 @@ func (c *Controller) Run(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) onFrame(now time.Time) {
|
func (c *Controller) onFrame(now time.Time) {
|
||||||
|
log := logrus.WithField("component", "controller")
|
||||||
|
|
||||||
var refresh bool
|
var refresh bool
|
||||||
for _, layout := range c.ctx.layouts {
|
for _, layout := range c.ctx.layouts {
|
||||||
for _, widget := range layout.Widgets() {
|
for _, widget := range layout.Widgets() {
|
||||||
@@ -195,7 +204,7 @@ func (c *Controller) onFrame(now time.Time) {
|
|||||||
if refresh {
|
if refresh {
|
||||||
logrus.Trace("display refresh required")
|
logrus.Trace("display refresh required")
|
||||||
if err := c.ctx.display.Refresh(); err != nil {
|
if err := c.ctx.display.Refresh(); err != nil {
|
||||||
logrus.WithError(err).Warn("display refresh failed")
|
log.WithError(err).Warn("display refresh failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.recorder != nil {
|
if c.recorder != nil {
|
||||||
@@ -205,12 +214,26 @@ func (c *Controller) onFrame(now time.Time) {
|
|||||||
go c.recorderSave()
|
go c.recorderSave()
|
||||||
}
|
}
|
||||||
} else if now.After(c.recorderStart) {
|
} else if now.After(c.recorderStart) {
|
||||||
logrus.Info("recorder starting")
|
log.Info("recorder starting")
|
||||||
c.recorder = new(gif.GIF)
|
c.recorder = new(gif.GIF)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
logrus.Trace("display refresh skipped, widgets not changed")
|
log.Trace("display refresh skipped, widgets not changed")
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.ctx.contrast < c.ctx.contrastTarget {
|
||||||
|
c.ctx.contrast++
|
||||||
|
log.Debugf("increasing contrast %d to reach %d", c.ctx.contrast, c.ctx.contrastTarget)
|
||||||
|
if err := c.ctx.display.SetContrast(c.ctx.contrast); err != nil {
|
||||||
|
log.WithError(err).Warn("can't set display contrast")
|
||||||
|
}
|
||||||
|
} else if c.ctx.contrast > c.ctx.contrastTarget {
|
||||||
|
c.ctx.contrast--
|
||||||
|
log.Debugf("decreasing contrast %d to reach %d", c.ctx.contrast, c.ctx.contrastTarget)
|
||||||
|
if err := c.ctx.display.SetContrast(c.ctx.contrast); err != nil {
|
||||||
|
log.WithError(err).Warn("can't set display contrast")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user