Fix the universes bug
Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
This commit is contained in:
		
							parent
							
								
									209bebe51d
								
							
						
					
					
						commit
						c41fca9c5a
					
				
					 1 changed files with 9 additions and 5 deletions
				
			
		|  | @ -24,11 +24,12 @@ var sema = make(chan struct{}, 1) // a binary semaphore guarding currentFrame | |||
| 
 | ||||
| var currentEffect queue.QueueItem | ||||
| var globalEffectChannel = make(chan queue.QueueItem, 1024) | ||||
| var universeCount int = 0 | ||||
| 
 | ||||
| func foreverLoop() { | ||||
| 	for /*ever*/ { | ||||
| 		time.Sleep(40 * time.Millisecond) //25fps | ||||
| 		for u := 0; u < 2; u++ { | ||||
| 		for u := 0; u < universeCount; u++ { | ||||
| 			sema <- struct{}{} // acquire token | ||||
| 			channels[u] <- currentFrame[u] | ||||
| 			<-sema | ||||
|  | @ -43,8 +44,6 @@ func reduceBrightness(universe [512]byte, percentage int) [512]byte { | |||
| 	return universe | ||||
| } | ||||
| 
 | ||||
| var universeCount int = 0 | ||||
| 
 | ||||
| func main() { | ||||
| 	go func() { | ||||
| 		var err error | ||||
|  | @ -74,7 +73,7 @@ func main() { | |||
| 	} | ||||
| 
 | ||||
| 	universeCount = int(math.Ceil(float64(PanelHeight*PanelWidth*3) / 510)) | ||||
| 	fmt.Printf("Universe count is %d", universeCount) | ||||
| 	fmt.Printf("Universe count is %d\n", universeCount) | ||||
| 
 | ||||
| 	PanelBrightness, err := strconv.Atoi(os.Getenv("PANEL_BRIGHTNESS")) | ||||
| 	if err != nil { | ||||
|  | @ -111,7 +110,8 @@ func main() { | |||
| 	e.SeedColour[1] = 255 | ||||
| 	e.SeedColour[2] = 0 | ||||
| 	globalEffectChannel <- e | ||||
| 	e.Effect = "default" | ||||
| 	e.Effect = "plasma" | ||||
| 	e.Speed = 40 | ||||
| 	globalEffectChannel <- e | ||||
| 
 | ||||
| 	go func() { | ||||
|  | @ -120,7 +120,11 @@ func main() { | |||
| 				currentEffect.Duration -= 40 | ||||
| 			} else { | ||||
| 				if len(globalEffectChannel) > 0 { | ||||
| 					lastEffect := currentEffect | ||||
| 					currentEffect = <-globalEffectChannel | ||||
| 					if lastEffect != currentEffect { | ||||
| 						fmt.Printf("New effect selected : %s\n", currentEffect.Effect) | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 			var rearranged [][]byte | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue