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