Skip to content

Commit

Permalink
Update to use version 2 eeprom data
Browse files Browse the repository at this point in the history
  • Loading branch information
CameronRP committed Aug 1, 2024
1 parent d7240cc commit 83a7f15
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 43 deletions.
92 changes: 58 additions & 34 deletions cmd/eeprom-programmer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"bytes"
"fmt"
"log"
"strconv"
"strings"
"time"

"github.com/TheCacophonyProject/tc2-hat-controller/eeprom"
Expand All @@ -14,6 +12,28 @@ import (
"periph.io/x/host/v3"
)

//LogLevel string `arg:"-l, --log-level" default:"info" help:"Set the logging level (debug, info, warn, error)"`

type Args struct {
MainPCBVersion string `arg:"--main" help:"Main PCB version"`
PowerPCBVersion string `arg:"--power" help:"Main PCB version"`
TouchPCBVersion string `arg:"--touch" help:"Main PCB version"`
MicPCBVersion string `arg:"--mic" help:"Main PCB version"`
AudioOnly bool `arg:"--audio-only" help:"Device only for audio recordings, no lepton module"`
}

var version = "<not set>"

func (Args) Version() string {
return version
}

func procArgs() Args {
args := Args{}
arg.MustParse(&args)
return args
}

func main() {
if err := runMain(); err != nil {
log.Fatal(err)
Expand All @@ -23,40 +43,60 @@ func main() {
func runMain() error {
args := procArgs()

parts := strings.Split(args.PCBVersion, ".")
if len(parts) != 3 {
return fmt.Errorf("invalid hardware version '%s'", args.PCBVersion)
}
/*
parts := strings.Split(args.PCBVersion, ".")
if len(parts) != 3 {
return fmt.Errorf("invalid hardware version '%s'", args.PCBVersion)
}
major, err := strconv.ParseInt(parts[0], 10, 64)
major, err := strconv.ParseInt(parts[0], 10, 64)
if err != nil {
return err
}
minor, err := strconv.ParseInt(parts[1], 10, 64)
if err != nil {
return err
}
patch, err := strconv.ParseInt(parts[2], 10, 64)
if err != nil {
return err
}
*/

mainPcbVersion, err := eeprom.NewSemVer(args.MainPCBVersion)
if err != nil {
return err
}
powerPcbVersion, err := eeprom.NewSemVer(args.PowerPCBVersion)
if err != nil {
return err
}
minor, err := strconv.ParseInt(parts[1], 10, 64)
touchPcbVersion, err := eeprom.NewSemVer(args.TouchPCBVersion)
if err != nil {
return err
}
patch, err := strconv.ParseInt(parts[2], 10, 64)
micPcbVersion, err := eeprom.NewSemVer(args.MicPCBVersion)
if err != nil {
return err
}

eepromData := &eeprom.EepromData{
Version: 1,
Major: byte(major),
Minor: byte(minor),
Patch: byte(patch),
ID: eeprom.GenerateRandomID(),
Time: time.Now().Truncate(time.Second),
eepromData := &eeprom.EepromDataV2{
Version: 2,
MainPCB: *mainPcbVersion,
PowerPCB: *powerPcbVersion,
TouchPCB: *touchPcbVersion,
MicrophonePCB: *micPcbVersion,
AudioOnly: args.AudioOnly,
ID: eeprom.GenerateRandomID(),
Time: time.Now().Truncate(time.Second),
}

data := eepromData.WriteData()

log.Println("Initializing host")
log.Println("Initializing I2C")
if _, err := host.Init(); err != nil {
return err
}

bus, err := i2creg.Open("")
if err != nil {
return err
Expand Down Expand Up @@ -97,19 +137,3 @@ func runMain() error {

return nil
}

var version = "<not set>"

func (Args) Version() string {
return version
}

func procArgs() Args {
args := Args{}
arg.MustParse(&args)
return args
}

type Args struct {
PCBVersion string `arg:"required" help:"Write to a register."`
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/TheCacophonyProject/eeprom-programmer
go 1.22.3

require (
github.com/TheCacophonyProject/tc2-hat-controller v0.6.7
github.com/TheCacophonyProject/tc2-hat-controller v0.10.2
github.com/alexflint/go-arg v1.5.0
periph.io/x/conn/v3 v3.7.0
periph.io/x/host/v3 v3.8.2
Expand Down
18 changes: 10 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
github.com/TheCacophonyProject/tc2-hat-controller v0.6.7 h1:QKvyekMUPTSgrrDrKSIisHAcrt/zZK86scb1lxIgLBQ=
github.com/TheCacophonyProject/tc2-hat-controller v0.6.7/go.mod h1:lei4dqVdRWhBmUvG4v3lD8dxmqbmbidix/dsLiDRUnE=
github.com/TheCacophonyProject/tc2-hat-controller v0.10.2 h1:82FyaFAXQtUPy6iXqIKwlIiUwj9YpVWVWllWe7IDCBo=
github.com/TheCacophonyProject/tc2-hat-controller v0.10.2/go.mod h1:EdLlIX63UfVOYgqQIS4XwaFichSgkn2F38OU93CWqjs=
github.com/alexflint/go-arg v1.5.0 h1:rwMKGiaQuRbXfZNyRUvIfke63QvOBt1/QTshlGQHohM=
github.com/alexflint/go-arg v1.5.0/go.mod h1:A7vTJzvjoaSTypg4biM5uYNTkJ27SkNTArtYXnlqVO8=
github.com/alexflint/go-scalar v1.2.0 h1:WR7JPKkeNpnYIOfHRa7ivM21aWAdHD0gEWHCx+WQBRw=
github.com/alexflint/go-scalar v1.2.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/godbus/dbus v4.1.0+incompatible h1:WqqLRTsQic3apZUK9qC5sGNfXthmPXzUZ7nQPrNITa4=
github.com/godbus/dbus v4.1.0+incompatible/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=
github.com/jonboulle/clockwork v0.3.0 h1:9BSCMi8C+0qdApAp4auwX0RkLGUjs956h0EkuQymUhg=
github.com/jonboulle/clockwork v0.3.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
periph.io/x/conn/v3 v3.7.0 h1:f1EXLn4pkf7AEWwkol2gilCNZ0ElY+bxS4WE2PQXfrA=
periph.io/x/conn/v3 v3.7.0/go.mod h1:ypY7UVxgDbP9PJGwFSVelRRagxyXYfttVh7hJZUHEhg=
periph.io/x/host/v3 v3.8.2 h1:ayKUDzgUCN0g8+/xM9GTkWaOBhSLVcVHGTfjAOi8OsQ=
Expand Down

0 comments on commit 83a7f15

Please sign in to comment.