Skip to content

Commit

Permalink
Merge pull request #3 from jtbg/i2c_search
Browse files Browse the repository at this point in the history
move i2c search into main function
  • Loading branch information
jtbg authored Apr 20, 2023
2 parents 38944c0 + 696eab5 commit 31c3293
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
7 changes: 6 additions & 1 deletion dasung/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ import (
"os/exec"
"strings"
"log"
"context"
"time"
)

func FindDasungI2CDevicePaths() ([]string, error) {
cmd := exec.Command("ddcutil", "detect", "--verbose")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, "ddcutil", "detect", "--verbose")
//cmd := exec.Command("ddcutil", "detect", "--verbose")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/jtbg/paperlike-go

go 1.18

require golang.org/x/exp v0.0.0-20230419192730-864b3d6c5c2c
require golang.org/x/exp v0.0.0-20230419192730-864b3d6c5c2c
14 changes: 14 additions & 0 deletions paperlike-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ func init() {
}

func main() {
flag.Parse()

if *flagDevicePath == "" {
path, err := dasung.FindDasungI2CDevicePaths()
if err != nil {
log.Fatal("Failed to find Dasung Paperlike display:", err)
}
*flagDevicePath = path[0]
}

if !strings.HasPrefix(filepath.Clean(*flagDevicePath), "/dev/i2c-") {
log.Fatal("invalid device path (must start with /dev/i2c-)")
}

d, err := dasung.NewDasungControl(*flagDevicePath)
if err != nil {
log.Fatal(err)
Expand Down
Binary file modified paperlike-cli/paperlike-cli
Binary file not shown.

0 comments on commit 31c3293

Please sign in to comment.