func (this *LedArray) Store(address, value iris16.Word) error { if address == (this.base + commandCell) { cmd := ledCommand(value) if cmd >= numLedCommands { return fmt.Errorf("Illegal unicornhat opcode %x", cmd) } else { switch cmd { case ledCommandClear: unicornhat.ClearLEDBuffer() case ledCommandSetPixel: if pos, err := unicornhat.PixelPosition(int(this.x), int(this.y)); err != nil { return err } else { unicornhat.SetPixelColor(pos, byte(this.red), byte(this.green), byte(this.blue)) } case ledCommandGetPixel: if pos, err := unicornhat.PixelPosition(int(this.x), int(this.y)); err != nil { return err } else { pix := unicornhat.GetPixelColor(pos) this.red, this.green, this.blue = iris16.Word(pix.R), iris16.Word(pix.G), iris16.Word(pix.B) } case ledCommandSetBrightness: setBrightness(this.brightness) case ledCommandGetBrightness: this.brightness = getBrightness() case ledCommandShow: unicornhat.Show() } return nil } } else if address == (this.base + brightnessCell) { setBrightness(value) return nil } else if address == (this.base + xCell) { this.x = value return nil } else if address == (this.base + yCell) { this.y = value return nil } else if address == (this.base + redChannel) { this.red = value return nil } else if address == (this.base + blueChannel) { this.blue = value return nil } else if address == (this.base + greenChannel) { this.green = value return nil } else { return fmt.Errorf("Illegal address %x provided!", address) } }
func getBrightness() iris16.Word { return iris16.Word(unicornhat.GetBrightness()) }