示例#1
0
func (um *UnicornManager) Stop() {
	for i := 0; i < 64; i++ {
		unicornhat.SetPixelColor(uint(i), 0, 0, 0)
	}
	unicornhat.Show()
	unicornhat.Shutdown(0)
}
示例#2
0
func (this *LedArray) Shutdown() error {
	if !this.initialized {
		return fmt.Errorf("Can't shutdown the LedArray when it has either been shutdown or never initialized!")
	} else {
		if unicornhatInitialized {
			unicornhat.Shutdown()
			unicornhatInitialized = false
		}
		this.initialized = false
		return nil
	}
}
示例#3
0
func main() {
	flag.Parse()
	delay := time.Duration(*msecdelay)
	var cpus []*µcore
	var memory Memory
	runtime.GOMAXPROCS(runtime.NumCPU())
	defer unicornhat.Shutdown()
	unicornhat.SetBrightness(unicornhat.DefaultBrightness / 2)
	if err := unicornhat.Initialize(); err != nil {
		fmt.Println(err)
		return
	}
	unicornhat.ClearLEDBuffer()
	unicornhat.Show()
	cpus = make([]*µcore, NumCpus)
	memory = make(Memory, MemSize)
	logPrint("Randomizing memory")
	for i, j := 0, 0; i < len(memory); i, j = i+4, j+1 {
		memory[i+red] = 0
		memory[i+blue] = 0
		memory[i+green] = 0
		if *xmas {
			offset := red
			if rand.Int()%2 == 0 {
				offset = red
			} else {
				offset = green
			}
			memory[i+offset] = byte(j + rand.Int())
		} else if *gscale {
			intensity := byte(j * rand.Int())
			memory[i+red] = intensity
			memory[i+green] = intensity
			memory[i+blue] = intensity
		} else if *purple {
			intensity := byte(j + rand.Int())
			memory[i+red] = intensity
			memory[i+blue] = intensity
		} else if *blueOnly {
			memory[i+blue] = byte(j + rand.Int())
		} else {
			memory[i+red] = byte(j + rand.Int())
			memory[i+green] = byte(j + rand.Int())
			memory[i+blue] = byte(j + rand.Int())
		}
		if *drainfill {
			if val := byte(j * rand.Int()); val%2 == 0 {
				memory[i+control] = OpFill
			} else {
				memory[i+control] = OpDrain
			}
		} else {
			memory[i+control] = byte(j + rand.Int())
		}
		//logPrint(fmt.Sprintf("@%d = {%d, %d, %d}", i, memory[i+red], memory[i+green], memory[i+blue]))
	}
	logPrint("Done randomizing memory")
	upperHalf := memory
	for i := 0; i < 64; i++ {
		targetMem := upperHalf[:µcoreSize]
		cpus[i] = New(i, targetMem)
		go cpus[i].Execute()
		upperHalf = upperHalf[µcoreSize:]
	}

	count := 0
	for {
		if count >= 64 {
			break
		}
		for i := 0; i < 64; i++ {
			if c := cpus[i]; c == nil {
				continue
			} else {
				select {
				case value := <-c.result:
					unicornhat.SetPixelColor(c.index, value.R, value.G, value.B)
				case <-c.done:
					count++
					cpus[i] = nil
				default:
				}
			}
		}
		unicornhat.Show()
		MillisecondDelay(delay)
	}
}