diff options
| -rw-r--r-- | compressor/compressor.go | 116 | ||||
| -rw-r--r-- | compressor/res/borgwarner/efr/6258.toml | 8 | ||||
| -rw-r--r-- | compressor/res/borgwarner/k/03.toml | 8 | ||||
| -rw-r--r-- | compressor/res/borgwarner/k/04.toml | 8 | ||||
| -rw-r--r-- | compressor/res/garrett/g/25-660.toml | 8 | ||||
| -rw-r--r-- | go.mod | 5 | ||||
| -rw-r--r-- | go.sum | 2 | ||||
| -rw-r--r-- | main.go | 9 | ||||
| -rw-r--r-- | ui.go | 2 |
9 files changed, 116 insertions, 50 deletions
diff --git a/compressor/compressor.go b/compressor/compressor.go index fc12f26..4a30c19 100644 --- a/compressor/compressor.go +++ b/compressor/compressor.go @@ -1,12 +1,17 @@ package compressor import ( + "github.com/BurntSushi/toml" + "io/fs" + fp "path/filepath" "time" "github.com/sam-anthony/volute/mass" "github.com/sam-anthony/volute/util" ) +const root = "compressor/res/" + type Compressor struct { Name string FileName string @@ -27,60 +32,79 @@ type Compressor struct { MaxPressureRatio float32 } +// [manufacturer][series][model] var compressors = make(map[string]map[string]map[string]Compressor) func init() { - compressors["Garrett"] = make(map[string]map[string]Compressor) - compressors["Garrett"]["G"] = make(map[string]Compressor) - compressors["Garrett"]["G"]["25-660"] = garrettG25660() - compressors["BorgWarner"] = make(map[string]map[string]Compressor) - compressors["BorgWarner"]["K"] = make(map[string]Compressor) - compressors["BorgWarner"]["K"]["03"] = borgwarnerK03() - compressors["BorgWarner"]["K"]["04"] = borgwarnerK04() - compressors["BorgWarner"]["EFR"] = make(map[string]Compressor) - compressors["BorgWarner"]["EFR"]["6258"] = borgwarnerEFR6258() -} + // Walk root, looking for .toml files describing a compressor. + // Parse these toml files, create a Compressor and add it to compressors. + err := fp.WalkDir(root, func(path string, d fs.DirEntry, err error) error { + if err != nil { + return err + } -func Compressors() map[string]map[string]map[string]Compressor { - return compressors -} + if fp.Ext(path) != ".toml" { + return nil + } -func garrettG25660() Compressor { - maxFlow, err := mass.NewFlowRate( - mass.Mass{70, mass.Pound}, - time.Minute, - mass.PoundsPerMinute, - ) + path = path[len(root):] + + // manufacturer/series, model + manSer, mod := fp.Split(path) + manSer = fp.Clean(manSer) // Clean trailing slash + mod = mod[:len(mod)-len(".toml")] // Trim .toml extension + // manufacturer, series + man, ser := fp.Split(manSer) + man = fp.Clean(man) // Clean trailing slash + + var exists bool + _, exists = compressors[man] + if !exists { + compressors[man] = make(map[string]map[string]Compressor) + } + _, exists = compressors[man][ser] + if !exists { + compressors[man][ser] = make(map[string]Compressor) + } + + tomlFile := fp.Join(root, path) + + var c Compressor + _, err = toml.DecodeFile(tomlFile, &c) + if err != nil { + return err + } + + // Replace .toml with .jpg + imageFile := tomlFile[:len(tomlFile)-len(".toml")] + ".jpg" + c.FileName = imageFile + + // Must parse MaxFlow seperately because the MassFlowRateUnit + // is stored as a string and must be converted with + // FlowRateUnitFromString(). + flow := struct { + FlowVal float32 + FlowUnit string + }{} + _, err = toml.DecodeFile(tomlFile, &flow) + if err != nil { + return err + } + u, err := mass.FlowRateUnitFromString(flow.FlowUnit) + if err != nil { + return err + } + c.MaxFlow = mass.FlowRate{flow.FlowVal, u} + + compressors[man][ser][mod] = c + + return nil + }) util.Check(err) - return Compressor{ - "Garrett G25-660", - "compressor/res/garrett/g/25-660.jpg", - 204, - 1885, - 1665, - 25, - maxFlow, - 4.0, - } } -func borgwarnerEFR6258() Compressor { - maxFlow, err := mass.NewFlowRate( - mass.Mass{0.50, mass.Kilogram}, - time.Second, - mass.KilogramsPerSecond, - ) - util.Check(err) - return Compressor{ - "BorgWarner EFR6258", - "compressor/res/borgwarner/efr/6258.jpg", - 47, - 455, - 773, - 6, - maxFlow, - 3.8, - } +func Compressors() map[string]map[string]map[string]Compressor { + return compressors } func borgwarnerK04() Compressor { diff --git a/compressor/res/borgwarner/efr/6258.toml b/compressor/res/borgwarner/efr/6258.toml new file mode 100644 index 0000000..1a678a0 --- /dev/null +++ b/compressor/res/borgwarner/efr/6258.toml @@ -0,0 +1,8 @@ +name = "BorgWarner EFR6258" +minx = 47 +miny = 455 +maxx = 773 +maxy = 6 +maxpr = 3.8 +flowval = 0.50 +flowunit = "kg/s" diff --git a/compressor/res/borgwarner/k/03.toml b/compressor/res/borgwarner/k/03.toml new file mode 100644 index 0000000..06f808c --- /dev/null +++ b/compressor/res/borgwarner/k/03.toml @@ -0,0 +1,8 @@ +name = "BorgWarner K03" +minx = 30 +miny = 714 +maxx = 876 +maxy = 4 +maxpr = 2.8 +flowval = 0.13 +flowunit = "kg/s" diff --git a/compressor/res/borgwarner/k/04.toml b/compressor/res/borgwarner/k/04.toml new file mode 100644 index 0000000..48908d2 --- /dev/null +++ b/compressor/res/borgwarner/k/04.toml @@ -0,0 +1,8 @@ +name = "BorgWarner K04" +minx = 33 +miny = 712 +maxx = 1090 +maxy = 2 +maxpr = 2.8 +flowval = 0.18 +flowunit = "kg/s" diff --git a/compressor/res/garrett/g/25-660.toml b/compressor/res/garrett/g/25-660.toml new file mode 100644 index 0000000..6c7b948 --- /dev/null +++ b/compressor/res/garrett/g/25-660.toml @@ -0,0 +1,8 @@ +name = "Garrett G25-660" +minx = 204 +miny = 1885 +maxx = 1665 +maxy = 25 +maxpr = 4.0 +flowval = 70 +flowunit = "lb/min" @@ -2,7 +2,10 @@ module github.com/sam-anthony/volute go 1.18 -require github.com/AllenDang/giu v0.6.2 +require ( + github.com/AllenDang/giu v0.6.2 + github.com/BurntSushi/toml v1.1.0 +) require ( github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8 // indirect @@ -4,6 +4,8 @@ github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8 h1:dKZMqib/y github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8/go.mod h1:b4uuDd0s6KRIPa84cEEchdQ9ICh7K0OryZHbSzMca9k= github.com/AllenDang/imgui-go v1.12.1-0.20220322114136-499bbf6a42ad h1:Kr961C2uEEAklK+jBRiZVnQH0AgS7o6pXrIgUTUUGiM= github.com/AllenDang/imgui-go v1.12.1-0.20220322114136-499bbf6a42ad/go.mod h1:kuPs9RWleaUuK7D49bE6HPxyRA36Lp4ICKGp+5OnnbY= +github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= +github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 h1:baVdMKlASEHrj19iqjARrPbaRisD7EuZEVJj6ZMLl1Q= @@ -134,9 +134,14 @@ func setCompressor(c compressor.Compressor) { } func init() { - c, ok := compressor.Compressors()["Garrett"]["G"]["25-660"] + manufacturer := "garrett" + series := "g" + model := "25-660" + c, ok := compressor.Compressors()[manufacturer][series][model] if !ok { - fmt.Println("Garrett G25-660 not in compressor.Compressors().") + fmt.Printf("compressor.Compressors()[\"%s\"][\"%s\"][\"%s\"] does not exist.\n", + manufacturer, series, model, + ) os.Exit(1) } @@ -287,7 +287,7 @@ func init() { var modNodes []g.Widget for mod, c := range compressors[man][ser] { mod := mod // Model - c := c // Compressor + c := c // Compressor modNodes = append( modNodes, g.Selectable(mod).OnClick(func() { |