Skip to content

Commit

Permalink
NEW PANEL
Browse files Browse the repository at this point in the history
  • Loading branch information
coral committed Sep 18, 2020
1 parent 6c15779 commit 90edcb2
Show file tree
Hide file tree
Showing 12 changed files with 449 additions and 106 deletions.
41 changes: 41 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"panel": {
"buttons": [
{
"name": "play",
"gpio": "GPIO2"
},
{
"name": "escape",
"gpio": "GPIO3"
}
],
"rotary": {
"name": "play",
"led": {
"name": "rotaryLED",
"red": "PWM1",
"green": "PWM2",
"blue": "PWM3"
},
"button": {
"name": "encoderClick",
"gpio": "GPIO2"
},
"encoderLeft": "GPIO17",
"encoderRight": "GPIO27"
}
},
"lcd": {
"device": "/dev/cu.usbmodem142444301",
"baud": 115200
},
"fluidsynth": {
"soundfonts": "files/soundfonts",
"default": "SC-55.sf2"
},
"floppy": {
"device": "/dev/sdb",
"mountpoint": "/media/floppy"
}
}
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package config

func Load(filename string) *C {

}
37 changes: 37 additions & 0 deletions config/definition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package config
a
type C struct {
Panel struct {
Buttons []struct {
Name string `json:"name"`
Gpio string `json:"gpio"`
} `json:"buttons"`
Rotary struct {
Name string `json:"name"`
Led struct {
Name string `json:"name"`
Red string `json:"red"`
Green string `json:"green"`
Blue string `json:"blue"`
} `json:"led"`
Button struct {
Name string `json:"name"`
Gpio string `json:"gpio"`
} `json:"button"`
EncoderLeft string `json:"encoderLeft"`
EncoderRight string `json:"encoderRight"`
} `json:"rotary"`
} `json:"panel"`
Lcd struct {
Device string `json:"device"`
Baud int `json:"baud"`
} `json:"lcd"`
Fluidsynth struct {
Soundfonts string `json:"soundfonts"`
Default string `json:"default"`
} `json:"fluidsynth"`
Floppy struct {
Device string `json:"device"`
Mountpoint string `json:"mountpoint"`
} `json:"floppy"`
}
1 change: 1 addition & 0 deletions controller/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Browser struct {
func (m *Browser) Run(c *Controller, events <-chan string, end chan bool) string {

c.display.SetColor(0, 255, 255)
c.panel.SetEncoderColor(0, 120, 255)
update := make(chan bool, 1)
update <- true
files := c.storage.ListFiles()
Expand Down
27 changes: 23 additions & 4 deletions controller/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controller
import (
"math"
"path/filepath"
"strconv"
"strings"
"time"

Expand All @@ -14,7 +15,6 @@ type Status struct {
}

func (m *Status) Run(c *Controller, events <-chan string, end chan bool) string {
//c.display.SetColor(0, 255, 0)
m.c = c
var renderEnd = make(chan bool)
m.render()
Expand All @@ -30,6 +30,17 @@ func (m *Status) Run(c *Controller, events <-chan string, end chan bool) string
pg := int(math.Ceil(ic * c.player.GetProgress()))
st := c.player.GetState()

switch st {
case "PLAYING":
c.panel.SetEncoderColor(0, 255, 0)
case "PAUSED":
c.panel.SetEncoderColor(255, 255, 0)
case "DONE":
c.panel.SetEncoderColor(255, 255, 255)
case "READY":
c.panel.SetEncoderColor(255, 255, 255)
}

if progress != pg && state != "PAUSED" {
progress = pg
m.render()
Expand All @@ -50,13 +61,19 @@ func (m *Status) Run(c *Controller, events <-chan string, end chan bool) string
case <-end:
renderEnd <- true
return "status"
case m := <-events:
switch m {
case ev := <-events:
switch ev {
case "play":
//c.player.Play("files/passport.mid")
case "encoderClick":
renderEnd <- true
return "browser"
case "encoderRight":
c.player.ChangeTempo(+5)
m.render()
case "encoderLeft":
c.player.ChangeTempo(-5)
m.render()
case "menu":
renderEnd <- true
return "soundfonts"
Expand All @@ -70,12 +87,14 @@ func (m *Status) Name() string {
}

func (m *Status) render() {
t := strconv.Itoa(m.c.player.GetBPM())
t = t + " BPM"
go m.c.display.RenderStatus(
lcd.StatusScreen{
Title: strings.TrimSuffix(
m.c.player.GetPlayingSong(),
filepath.Ext(m.c.player.GetPlayingSong())),
Tempo: m.c.player.GetBPM(),
Tempo: t,
Volume: "100%",
Progress: m.c.player.GetProgress(),
State: m.c.player.GetState(),
Expand Down
50 changes: 50 additions & 0 deletions dev/newpanel/newpanel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"fmt"
"io"
"log"
"time"

"github.com/tarm/serial"
)

func main() {
c := &serial.Config{Name: "/dev/cu.usbmodem14444301", Baud: 115200}
s, err := serial.OpenPort(c)
if err != nil {
log.Fatal(err)
}
go func() {

// scanner := bufio.NewScanner(s)
// for {
// for scanner.Scan() {
// fmt.Println(scanner.Text())
// }
// }
buf := make([]byte, 1)
for {
n, err := s.Read(buf)
if n > 0 {
fmt.Println(buf[0])
}
if err == io.EOF {
break
}
}
}()

time.Sleep(4 * time.Second)
fmt.Println([]byte{0xCA, 0xFE, 0xBA, 0xBE, 0x00, 0x00, 0x00})

n, err := s.Write([]byte{0xCA, 0xFE, 0xBA, 0xBE, 0x00, 30, 128})
if err != nil {
panic(err)
}
time.Sleep(50 * time.Millisecond)
fmt.Println(n)

m := make(chan bool)
m <- true
}
Loading

0 comments on commit 90edcb2

Please sign in to comment.