Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
roffe committed Jan 2, 2025
1 parent 778cb3a commit 978c7cd
Show file tree
Hide file tree
Showing 29 changed files with 475 additions and 176 deletions.
2 changes: 1 addition & 1 deletion FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Website = "https://roffe.nu/"
Name = "txlogger"
ID = "com.roffe.txlogger"
Version = "2.0.0"
Build = 399
Build = 400
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ require (
github.com/soypat/cyw43439 v0.0.0-20241116210509-ae1ce0e084c5 // indirect
github.com/soypat/seqs v0.0.0-20240527012110-1201bab640ef // indirect
github.com/tinygo-org/pio v0.0.0-20240901140349-27cbe9d986eb // indirect
golang.design/x/clipboard v0.7.0
golang.org/x/exp v0.0.0-20241210194714-1829a127f884 // indirect
golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63 // indirect
)

require (
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
golang.design/x/clipboard v0.7.0 h1:4Je8M/ys9AJumVnl8m+rZnIvstSnYj1fvzqYrU3TXvo=
golang.design/x/clipboard v0.7.0/go.mod h1:PQIvqYO9GP29yINEfsEn5zSQKAz3UgXmZKzDA6dnq2E=
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand All @@ -407,6 +409,8 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20241210194714-1829a127f884 h1:Y/Mj/94zIQQGHVSv1tTtQBDaQaJe62U9bkDZKKyhPCU=
golang.org/x/exp v0.0.0-20241210194714-1829a127f884/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c=
golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63 h1:3AGKexOYqL+ztdWdkB1bDwXgPBuTS/S8A4WzuTvJ8Cg=
golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63/go.mod h1:UH99kUObWAZkDnWqppdQe5ZhPYESUw8I0zVV1uWBR+0=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.23.0 h1:HseQ7c2OpPKTPVzNjG5fwJsOTCiiwS4QdsYi5XU6H68=
Expand Down
32 changes: 19 additions & 13 deletions pkg/capture/capture.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
package capture

import (
"fmt"
"image/jpeg"
"bytes"
"image/png"
"log"
"os"
"time"
"strings"

"fyne.io/fyne/v2"
"golang.design/x/clipboard"
)

func Screenshot(c fyne.Canvas) {
cap := c.Capture()
filename := fmt.Sprintf("capture-%s.jpg", time.Now().Format("2006-01-02-15-04-05"))
f, err := os.Create(filename)
if err != nil {
//filename := fmt.Sprintf("capture-%s.jpg", time.Now().Format("2006-01-02-15-04-05"))
//f, err := os.Create(filename)
//if err != nil {
// log.Println(err)
// return
//}
//defer f.Close()
buff := bytes.NewBuffer(nil)
if err := png.Encode(buff, cap); err != nil {
log.Println(err)
return
}
defer f.Close()
if err := jpeg.Encode(f, cap, &jpeg.Options{Quality: 95}); err != nil {
log.Println(err)
return
}
log.Println("Screenshot saved to", filename)
var image strings.Builder
image.WriteString("image/jpeg")
image.Write(buff.Bytes())

log.Println("Copied to clipboard")
clipboard.Write(clipboard.FmtImage, buff.Bytes())
}
4 changes: 2 additions & 2 deletions pkg/eventbus/eventbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ func (e *Controller) Publish(topic string, data float64) error {

// SubscribeFunc returns a function that can be used to unsubscribe the function
func (e *Controller) SubscribeFunc(topic string, f func(float64)) (cancel func()) {
log.Println("SubscribeFunc", topic)
// log.Println("SubscribeFunc", topic)
respChan := e.Subscribe(topic)
go func() {
for v := range respChan {
f(v)
}
}()
cancel = func() {
log.Println("UnsubscribeFunc", topic)
// log.Println("UnsubscribeFunc", topic)
e.Unsubscribe(respChan)
}
return
Expand Down
6 changes: 3 additions & 3 deletions pkg/widgets/cbar/cbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type CBar struct {
displayText *canvas.Text
bars []*canvas.Line

cfg widgets.GaugeConfig
cfg *widgets.GaugeConfig

// Cached values
value float64
Expand All @@ -38,7 +38,7 @@ type CBar struct {
stepFactor float32
}

func New(cfg widgets.GaugeConfig) *CBar {
func New(cfg *widgets.GaugeConfig) *CBar {
if cfg.MinSize.Width == 0 {
cfg.MinSize.Width = 50
}
Expand Down Expand Up @@ -68,7 +68,7 @@ func New(cfg widgets.GaugeConfig) *CBar {
return s
}

func (s *CBar) GetConfig() widgets.GaugeConfig {
func (s *CBar) GetConfig() *widgets.GaugeConfig {
return s.cfg
}

Expand Down
20 changes: 10 additions & 10 deletions pkg/widgets/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,66 +89,66 @@ func NewDashboard(cfg *Config) *Dashboard {
//logBtn: cfg.LogBtn,
logplayer: cfg.Logplayer,
gauges: Gauges{
airmass: dualdial.New(widgets.GaugeConfig{
airmass: dualdial.New(&widgets.GaugeConfig{
Title: "mg/c",
Min: 0,
Max: 2200,
Steps: 22,
MinSize: fyne.NewSize(100, 100),
}),
speed: dial.New(widgets.GaugeConfig{
speed: dial.New(&widgets.GaugeConfig{
Title: speedometerText,
Min: 0,
Max: 300,
Steps: 30,
DisplayString: "%.1f",
MinSize: fyne.NewSize(100, 100),
}),
rpm: dial.New(widgets.GaugeConfig{
rpm: dial.New(&widgets.GaugeConfig{
Title: "RPM",
Min: 0,
Max: 8000,
Steps: 20,
MinSize: fyne.NewSize(100, 100),
}),
iat: dial.New(widgets.GaugeConfig{
iat: dial.New(&widgets.GaugeConfig{
Title: "IAT",
Min: 0,
Max: 80,
Steps: 16,
MinSize: fyne.NewSize(100, 100),
}),
pressure: dualdial.New(widgets.GaugeConfig{
pressure: dualdial.New(&widgets.GaugeConfig{
Title: "MAP",
Min: 0,
Max: 3,
Steps: 30,
DisplayString: "%.2f",
MinSize: fyne.NewSize(100, 100),
}),
throttle: vbar.New(widgets.GaugeConfig{
throttle: vbar.New(&widgets.GaugeConfig{
Title: "TPS",
Min: 0,
Max: 100,
Steps: 20,
MinSize: fyne.NewSize(50, 50),
ColorScale: widgets.TraditionalScale,
}),
pwm: vbar.New(widgets.GaugeConfig{
pwm: vbar.New(&widgets.GaugeConfig{
Title: "PWM",
Min: 0,
Max: 100,
Steps: 20,
MinSize: fyne.NewSize(50, 50),
ColorScale: widgets.TraditionalScale,
}),
engineTemp: dial.New(widgets.GaugeConfig{
engineTemp: dial.New(&widgets.GaugeConfig{
Title: "tEng",
Min: -20,
Max: 130,
Steps: 16,
}),
wblambda: cbar.New(widgets.GaugeConfig{
wblambda: cbar.New(&widgets.GaugeConfig{
Title: "",
Min: 0.50,
Center: 1,
Expand All @@ -159,7 +159,7 @@ func NewDashboard(cfg *Config) *Dashboard {
DisplayTextSize: 20,
TextPosition: widgets.TextAtTop,
}),
nblambda: cbar.New(widgets.GaugeConfig{
nblambda: cbar.New(&widgets.GaugeConfig{
Title: "",
Min: -25,
Center: 0,
Expand Down
2 changes: 1 addition & 1 deletion pkg/widgets/dashboard/setters.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func knkDetSetter(icon *icon.Icon) func(float64) {
// log.Printf("knkDetSetter: %08X\n", knockValue)

knkCyl1 := uint8(knockValue & 0xFF000000 >> 24)
knkCyl2 := uint8(knockValue & 0x00FF0000 >> 16)
knkCyl2 := uint8(knockValue & 0xFF0000 >> 16)
knkCyl3 := uint8(knockValue & 0xFF00 >> 8)
knkCyl4 := uint8(knockValue & 0xFF)

Expand Down
6 changes: 3 additions & 3 deletions pkg/widgets/dial/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Dial struct {
widget.BaseWidget
displayString string

cfg widgets.GaugeConfig
cfg *widgets.GaugeConfig

factor float64
value float64
Expand Down Expand Up @@ -48,7 +48,7 @@ type Dial struct {
buf bytes.Buffer
}

func New(cfg widgets.GaugeConfig) *Dial {
func New(cfg *widgets.GaugeConfig) *Dial {
c := &Dial{
cfg: cfg,
displayString: "%.0f",
Expand Down Expand Up @@ -98,7 +98,7 @@ func New(cfg widgets.GaugeConfig) *Dial {
return c
}

func (c *Dial) GetConfig() widgets.GaugeConfig {
func (c *Dial) GetConfig() *widgets.GaugeConfig {
return c.cfg
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/widgets/dualdial/dual_dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
type DualDial struct {
widget.BaseWidget

cfg widgets.GaugeConfig
cfg *widgets.GaugeConfig

titleText *canvas.Text
displayString string
Expand Down Expand Up @@ -52,7 +52,7 @@ type DualDial struct {
buf1, buf2 bytes.Buffer
}

func New(cfg widgets.GaugeConfig) *DualDial {
func New(cfg *widgets.GaugeConfig) *DualDial {
s := &DualDial{
cfg: cfg,
steps: 10,
Expand Down Expand Up @@ -107,7 +107,7 @@ func New(cfg widgets.GaugeConfig) *DualDial {
return s
}

func (c *DualDial) GetConfig() widgets.GaugeConfig {
func (c *DualDial) GetConfig() *widgets.GaugeConfig {
return c.cfg
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/widgets/gauge/gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/roffe/txlogger/pkg/widgets/vbar"
)

func New(cfg widgets.GaugeConfig) (widgets.IGauge, []func(), error) {
func New(cfg *widgets.GaugeConfig) (widgets.IGauge, []func(), error) {
switch cfg.Type {
case "Dial":
dial := dial.New(cfg)
Expand Down
2 changes: 1 addition & 1 deletion pkg/widgets/gaugeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type Gauge interface {
GetConfig() GaugeConfig
GetConfig() *GaugeConfig
}

type GaugeConfig struct {
Expand Down
6 changes: 3 additions & 3 deletions pkg/widgets/hbar/hbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type HBar struct {
titleText *canvas.Text
bars []*canvas.Line

cfg widgets.GaugeConfig
cfg *widgets.GaugeConfig

value float64

Expand All @@ -31,7 +31,7 @@ type HBar struct {
oldSize fyne.Size
}

func New(cfg widgets.GaugeConfig) *HBar {
func New(cfg *widgets.GaugeConfig) *HBar {
s := &HBar{
cfg: cfg,
}
Expand All @@ -46,7 +46,7 @@ func New(cfg widgets.GaugeConfig) *HBar {
return s
}

func (s *HBar) GetConfig() widgets.GaugeConfig {
func (s *HBar) GetConfig() *widgets.GaugeConfig {
return s.cfg
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/widgets/igauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ type IGauge interface {
fyne.Widget
SetValue(float64)
SetValue2(float64)
GetConfig() GaugeConfig
GetConfig() *GaugeConfig
}
7 changes: 4 additions & 3 deletions pkg/widgets/logplayer/logplayer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package logplayer

import (
"log"
"sort"
"sync"
"time"
Expand All @@ -10,6 +9,7 @@ import (
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/roffe/txlogger/pkg/capture"
"github.com/roffe/txlogger/pkg/ebus"
"github.com/roffe/txlogger/pkg/layout"
"github.com/roffe/txlogger/pkg/logfile"
Expand Down Expand Up @@ -95,15 +95,16 @@ func (l *Logplayer) Tapped(_ *fyne.PointEvent) {
}

func (l *Logplayer) FocusGained() {
log.Println("FocusGained")
}

func (l *Logplayer) FocusLost() {
log.Println("FocusLost")
}

func (l *Logplayer) TypedKey(ev *fyne.KeyEvent) {
switch ev.Name {
case fyne.KeyF12:
c := fyne.CurrentApp().Driver().CanvasForObject(l)
capture.Screenshot(c)
case fyne.KeyPlus:
l.objs.speedSelect.SetSelectedIndex(l.objs.speedSelect.SelectedIndex() + 1)
case fyne.KeyMinus:
Expand Down
Loading

0 comments on commit 978c7cd

Please sign in to comment.