Esempio n. 1
0
func main() {
	fmt.Println("Attempting to engage in Penguin SPI-ing")
	fmt.Printf("Speed: %d\n\tDelay: %d\n\tBPW: %d\n", spi_speed, spi_delay, spi_bits)

	if err := embd.InitSPI(); err != nil {
		fmt.Println("Having a wee panic")
		panic(err)
	}
	defer embd.CloseSPI()

	var channel byte = 0

	// Spi minor appears to be spi dev
	// Notes: chanel cf chip select
	// Todo, get spi1,2,and 2.1
	spiBus := embd.NewSPIBus(embd.SPIMode0, channel, spi_speed, spi_bits, spi_delay)
	defer spiBus.Close()

	adc := mcp3008.New(mcp3008.SingleMode, spiBus)

	for i := 0; i < 20; i++ {
		time.Sleep(1 * time.Second)

		for ch := 0; ch < 16; ch++ {
			val, err := adc.AnalogValueAt(0)
			if err != nil {
				panic(err)
			}
			fmt.Printf("analog channel %v value is: %v\n", ch, val)
		}
	}
}
Esempio n. 2
0
func main() {
	flag.Parse()
	fmt.Println("this is a sample code for mcp3008 10bit 8 channel ADC")

	if err := embd.InitSPI(); err != nil {
		panic(err)
	}
	defer embd.CloseSPI()

	spiBus := embd.NewSPIBus(embd.SPIMode0, channel, speed, bpw, delay)
	defer spiBus.Close()

	adc := &mcp3008.MCP3008{Mode: mcp3008.SingleMode, Bus: spiBus, Bits: mcp3008.Bits12}

	// adc := mcp3008.New(mcp3008.SingleMode, spiBus)

	for i := 0; i < 20; i++ {
		time.Sleep(1 * time.Second)
		val, err := adc.AnalogValueAt(0)
		if err != nil {
			fmt.Println("Error: ", err)
		}
		fmt.Printf("analog value is: %v\n", val)
	}
}
Esempio n. 3
0
func hardware() {
	if err := embd.InitGPIO(); err != nil {
		panic(err)
	}
	defer embd.CloseGPIO()

	if err := embd.InitSPI(); err != nil {
		panic(err)
	}
	defer embd.CloseSPI()

	lights, err := OpenLights()
	if err != nil {
		panic(err)
	}
	defer lights.Close()

	digits, err := OpenDigits()
	if err != nil {
		panic(err)
	}
	defer digits.Close()

	go digits.Try()

	for !quit {
		statusMutex.Lock()
		yellow := status.Warning
		red := status.Critical
		redBlink := status.Paging
		green := !(red || yellow)
		//lastPageTime := status.LastPageTime
		statusMutex.Unlock()

		var redVal int
		var yellowVal int
		var greenVal int
		if red {
			redVal = embd.High
		}
		if yellow {
			yellowVal = embd.High
		}
		if green {
			greenVal = embd.High
		}
		lights.redPin.Write(redVal)
		lights.yellowPin.Write(yellowVal)
		lights.greenPin.Write(greenVal)
		time.Sleep(500 * time.Millisecond)
		if red && redBlink {
			lights.redPin.Write(embd.Low)
		}
		time.Sleep(500 * time.Millisecond)
	}
}
Esempio n. 4
0
//Init door
func (d *Door) Init(cfg DoorSettings) {
	d.Cfg = cfg
	if err := embd.InitSPI(); err != nil {
		panic(err)
	}

	spiBus := embd.NewSPIBus(d.Cfg.Mode, d.Cfg.Channel, d.Cfg.Speed, d.Cfg.Bpw, d.Cfg.Delay)
	// defer embd.CloseSPI()
	// defer spiBus.Close()

	d.MPC3008 = mcp3008.New(mcp3008.SingleMode, spiBus)
}
Esempio n. 5
0
func main() {
	flag.Parse()
	if err := embd.InitSPI(); err != nil {
		panic(err)
	}
	defer embd.CloseSPI()

	bus := embd.NewSPIBus(embd.SPIMode0, channel, speed, bpw, delay)
	defer bus.Close()

	for i := 0; i < 30; i++ {
		time.Sleep(1 * time.Second)
		val, err := getSensorValue(bus)
		if err != nil {
			panic(err)
		}
		fmt.Printf("value is: %v\n", val)
	}
}
Esempio n. 6
0
func main() {
	var err error
	err = embd.InitSPI()
	if err != nil {
		panic(err)
	}
	defer embd.CloseSPI()

	spiBus := embd.NewSPIBus(embd.SPI_MODE_0, 0, 1000000, 8, 0)
	defer spiBus.Close()

	dataBuf := make([]uint8, 3)
	dataBuf[0] = uint8(1)
	dataBuf[1] = uint8(2)
	dataBuf[2] = uint8(3)

	err = spiBus.TransferAndRecieveData(dataBuf)
	if err != nil {
		panic(err)
	}

	fmt.Println("Recived data is: %v", dataBuf)

	dataReceived, err := spiBus.ReceiveData(3)
	if err != nil {
		panic(err)
	}

	fmt.Println("Recived data is: %v", dataReceived)

	dataByte := byte(1)
	receivedByte, err := spiBus.TransferAndReceiveByte(dataByte)
	if err != nil {
		panic(err)
	}
	fmt.Println("Recived byte is: %v", receivedByte)

	receivedByte, err = spiBus.ReceiveByte()
	if err != nil {
		panic(err)
	}
	fmt.Println("Recived byte is: %v", receivedByte)
}
Esempio n. 7
0
File: spi.go Progetto: kidoman/embd
func main() {
	if err := embd.InitSPI(); err != nil {
		panic(err)
	}
	defer embd.CloseSPI()

	spiBus := embd.NewSPIBus(embd.SPIMode0, 0, 1000000, 8, 0)
	defer spiBus.Close()

	dataBuf := [3]uint8{1, 2, 3}

	if err := spiBus.TransferAndReceiveData(dataBuf[:]); err != nil {
		panic(err)
	}

	fmt.Println("received data is:", dataBuf)

	dataReceived, err := spiBus.ReceiveData(3)
	if err != nil {
		panic(err)
	}

	fmt.Println("received data is:", dataReceived)

	dataByte := byte(1)
	receivedByte, err := spiBus.TransferAndReceiveByte(dataByte)
	if err != nil {
		panic(err)
	}
	fmt.Println("received byte is:", receivedByte)

	receivedByte, err = spiBus.ReceiveByte()
	if err != nil {
		panic(err)
	}
	fmt.Println("received byte is:", receivedByte)
}