diff options
author | Martin Ashby <martin@martin-laptop.lan> | 2018-05-21 10:16:32 +0100 |
---|---|---|
committer | Martin Ashby <martin@martin-laptop.lan> | 2018-05-21 10:16:32 +0100 |
commit | b1c8a696e4e40ea1ae72f886e0cfb4468eb737e8 (patch) | |
tree | 6342f364a3f611ea2d642dccc862f23108e90e44 /RealUnicorn.go | |
parent | 34f1a11454fc38a77338569f466df879fd1792f7 (diff) | |
download | unicornpaint-b1c8a696e4e40ea1ae72f886e0cfb4468eb737e8.tar.gz unicornpaint-b1c8a696e4e40ea1ae72f886e0cfb4468eb737e8.tar.bz2 unicornpaint-b1c8a696e4e40ea1ae72f886e0cfb4468eb737e8.tar.xz unicornpaint-b1c8a696e4e40ea1ae72f886e0cfb4468eb737e8.zip |
Moved unicorn to it's own package
Diffstat (limited to 'RealUnicorn.go')
-rw-r--r-- | RealUnicorn.go | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/RealUnicorn.go b/RealUnicorn.go deleted file mode 100644 index 31fd229..0000000 --- a/RealUnicorn.go +++ /dev/null @@ -1,67 +0,0 @@ -package main - -import ( - //"golang.org/x/exp/io/spi" - "github.com/ecc1/spi" - "log" -) - -type RealUnicorn struct { - BaseUnicorn - device *spi.Device -} - -// NewReal ... -// Constructs a new real unicorn from fairy dust and sprinkles -func NewReal() (*RealUnicorn, error) { - /*dev, err := spi.Open(&spi.Devfs{ - Dev: "/dev/spidev0.0", - 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{ - pixels: makePixels(16, 16), - }, - dev, - }, nil -} - -func (u *RealUnicorn) Show() { - // Width * height * colours + leading bit - 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 := 0; x < width; x++ { - for y := 0; y < height; y++ { - for j := 0; j < 3; j++ { - write[ix] = byte(u.pixels[x][y][j]) - ix++ - } - } - } - // Write to the device - //err := u.device.Tx(write, nil) - err := u.device.Transfer(write) - if err != nil { - log.Printf("Error writing to SPI device %v", err) - } -} -func (u *RealUnicorn) Off() { - u.Close() -} -func (u *RealUnicorn) Close() error { - return u.device.Close() -} |