package main import ( "fmt" "os" "os/exec" "path/filepath" "time" "github.com/theater/picomap/lib/client" "github.com/theater/picomap/lib/picotool" ) func main() { wd, err := os.Getwd() if err != nil { fmt.Fprintf(os.Stderr, "error: %v\n", err) os.Exit(1) } buildDir := filepath.Join(wd, "build") if err := run(buildDir); err != nil { fmt.Fprintf(os.Stderr, "error: %v\n", err) os.Exit(1) } } func run(buildDir string) error { fmt.Println("Configuring...") cmake := exec.Command("cmake", "-B", buildDir) cmake.Stdout = os.Stdout cmake.Stderr = os.Stderr if err := cmake.Run(); err != nil { return fmt.Errorf("cmake failed: %w", err) } fmt.Println("Building...") cmd := exec.Command("make", "-C", buildDir) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil { return fmt.Errorf("build failed: %w", err) } devs, err := client.ListSerial() if err != nil { return err } if len(devs) > 0 { dev := devs[0] fmt.Printf("Sending PICOBOOT request to %s...\n", dev) c, err := client.NewSerial(dev, 2*time.Second) if err != nil { return err } err = c.PICOBOOT() c.Close() if err != nil { fmt.Fprintf(os.Stderr, "warning: PICOBOOT request failed: %v\n", err) } else { fmt.Println("Device confirmed reboot into PICOBOOT mode.") } time.Sleep(2 * time.Second) } uf2 := filepath.Join(buildDir, "picomap.uf2") fmt.Println("Loading firmware...") if err := picotool.Load(uf2); err != nil { return err } fmt.Println("Rebooting...") _ = picotool.Reboot() fmt.Println("Done.") return nil }