aboutsummaryrefslogtreecommitdiff
path: root/RealUnicorn.go
diff options
context:
space:
mode:
authorMartin Ashby <martin@ashbysoft.com>2018-05-18 22:49:25 +0000
committerMartin Ashby <martin@ashbysoft.com>2018-05-18 22:49:25 +0000
commit20ee809e540556801fca87a573852d16c2ac7388 (patch)
tree7fafc3115565c07f736d6bc6a42948a270e0a5f6 /RealUnicorn.go
parentd2dea8058c88b39f161178f59c6bfec0e32dfa02 (diff)
downloadunicornpaint-20ee809e540556801fca87a573852d16c2ac7388.tar.gz
unicornpaint-20ee809e540556801fca87a573852d16c2ac7388.tar.bz2
unicornpaint-20ee809e540556801fca87a573852d16c2ac7388.tar.xz
unicornpaint-20ee809e540556801fca87a573852d16c2ac7388.zip
Go server now working
Diffstat (limited to 'RealUnicorn.go')
-rw-r--r--RealUnicorn.go27
1 files changed, 16 insertions, 11 deletions
diff --git a/RealUnicorn.go b/RealUnicorn.go
index d9665d8..31fd229 100644
--- a/RealUnicorn.go
+++ b/RealUnicorn.go
@@ -1,7 +1,8 @@
package main
import (
- "golang.org/x/exp/io/spi"
+ //"golang.org/x/exp/io/spi"
+ "github.com/ecc1/spi"
"log"
)
@@ -13,14 +14,16 @@ type RealUnicorn struct {
// NewReal ...
// Constructs a new real unicorn from fairy dust and sprinkles
func NewReal() (*RealUnicorn, error) {
- dev, err := spi.Open(&spi.Devfs{
+ /*dev, err := spi.Open(&spi.Devfs{
Dev: "/dev/spidev0.0",
- Mode: spi.Mode0,
+ Mode: spi.Mode3,
MaxSpeed: 9000000,
- })
+ })*/
+ dev, err := spi.Open("/dev/spidev0.0", 9000000, 0)
if err != nil {
return nil, err
}
+ //dev.SetBitOrder(spi.LSBFirst)
return &RealUnicorn{
BaseUnicorn{
@@ -32,24 +35,26 @@ func NewReal() (*RealUnicorn, error) {
func (u *RealUnicorn) Show() {
// Width * height * colours + leading bit
- width := u.GetWidth()
- height := u.GetHeight()
- write := make([]byte, (width*height*3)+1)
+ width := int(u.GetWidth())
+ height := int(u.GetHeight())
+ sz := (width*height*3)+1
+ write := make([]byte, sz)
// Add the leading bit
write[0] = 0x72
// Add all the pixel values
ix := 1
- for x := uint8(0); x < width; x++ {
- for y := uint8(0); y < height; y++ {
+ for x := 0; x < width; x++ {
+ for y := 0; y < height; y++ {
for j := 0; j < 3; j++ {
- write[ix] = u.pixels[x][y][j]
+ write[ix] = byte(u.pixels[x][y][j])
ix++
}
}
}
// Write to the device
- err := u.device.Tx(write, nil)
+ //err := u.device.Tx(write, nil)
+ err := u.device.Transfer(write)
if err != nil {
log.Printf("Error writing to SPI device %v", err)
}