Example #1
0
File: main.go Project: zyxar/berry
func scan(...string) error {
	var addr uint
	fmt.Println("     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f")
	for addr = 0x00; addr < 0x77; addr++ {
		if addr%16 == 0 {
			fmt.Printf("%02x: ", addr/16)
		}
		s, err := bus.NewI2C(addr, *dev)
		if err != nil {
			return err
		}
		if ((addr < 0x30) || (addr >= 0x40 && addr <= 0x47) || (addr >= 0x60)) && s.Mask()&bus.I2C_FUNC_SMBUS_QUICK != 0 {
			if err = bus.SMBusWriteQuick(s.Fd(), bus.SMBUS_WRITE); err != nil {
				fmt.Print("~~ ")
			} else {
				fmt.Print("XX ")
			}
		} else {
			b, err := bus.SMBusRead(s.Fd(), 0, bus.SMBUS_BYTE)
			if err != nil {
				fmt.Print("-- ")
			} else {
				fmt.Printf("%02X ", b[0])
			}
		}
		if addr%16 == 15 {
			fmt.Println()
		}
	}
	fmt.Println()
	return nil
}
Example #2
0
File: main.go Project: zyxar/berry
func smbread(fd uintptr, size int, args []string) (err error) {
	if len(args) < 1 {
		err = errNoRegister
		return
	}
	var reg uint64
	var b []byte
	for _, arg := range args {
		reg, err = strconv.ParseUint(arg, 10, 8)
		if err != nil {
			fmt.Fprintf(os.Stderr, "[%02d] %v\n", reg, err)
			continue
		}
		b, err = bus.SMBusRead(fd, uint8(reg), size)
		if err != nil {
			fmt.Fprintf(os.Stderr, "[%02d] %v\n", reg, err)
			continue
		}
		fmt.Printf("[%02d] %X\n", reg, b)
	}
	return nil
}