|
|
|
@ -4,12 +4,14 @@ package I2C
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
_ "fmt"
|
|
|
|
|
"log"
|
|
|
|
|
_ "log"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"os/user"
|
|
|
|
|
"bytes"
|
|
|
|
|
"strings"
|
|
|
|
|
"sync"
|
|
|
|
|
"strconv"
|
|
|
|
|
"FRMS/internal/pkg/logging"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type I2CBus struct {
|
|
|
|
@ -32,9 +34,11 @@ func (b *I2CBus) Scan() map[int]bool {
|
|
|
|
|
bus := strconv.Itoa(b.int)
|
|
|
|
|
cmd := exec.Command("i2cdetect", "-y", "-r", bus)
|
|
|
|
|
var out bytes.Buffer
|
|
|
|
|
var errs bytes.Buffer
|
|
|
|
|
cmd.Stderr = &errs
|
|
|
|
|
cmd.Stdout = &out
|
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
logging.Debug(logging.DError, "I2C ERROR: %v", errs.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
outString := out.String()
|
|
|
|
@ -81,7 +85,7 @@ func (b *I2CBus) GetStatus(addr int) bool {
|
|
|
|
|
var out bytes.Buffer
|
|
|
|
|
cmd.Stdout = &out
|
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
logging.Debug(logging.DError,"I2C ERROR: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
outString := out.String()
|
|
|
|
|