From 9c9babfa7032b443138c4b457aabaf79fad385b3 Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Fri, 26 Nov 2010 00:07:14 -0500 Subject: Add PixelMapper functionality to abstract away from mapping locations->Pixels. --- pixelcore/Pixel.py | 13 +++++++++---- pixelcore/PixelStrip.py | 2 +- pixelcore/Screen.py | 8 +++++++- 3 files changed, 17 insertions(+), 6 deletions(-) (limited to 'pixelcore') diff --git a/pixelcore/Pixel.py b/pixelcore/Pixel.py index a71dba5..8c42581 100644 --- a/pixelcore/Pixel.py +++ b/pixelcore/Pixel.py @@ -3,26 +3,31 @@ import pdb from pixelevents.StepEvent import * #Pixel keeps a queue of events (PixelEvent objects) (actually a dictionary #keyed by event time). Every time is state is -#requested, it processes all the members of its cue. If a member returns none, +#requested, it processes all the members of its queue. If a member returns none, #it is removed from the queue. Otherwise, its value added to the Pixels color #weighted by z-index. class Pixel: radius = 2 timeOff = -1 - def __init__(self, location, color): + def __init__(self, location): self.location = location - self.color = color self.events = {} def turnOn(self): self.turnOnFor(-1) + #Turn the light white for 'time' ms. Really only meant for testing. Use + #processInput instead. Also, you shouldn't use this anyway. You should be + #using the input method on the screen! def turnOnFor(self, time): - event = StepEvent.generate(time, (255,0,255)) #TODO: Move color to + event = StepEvent.generate(time, (255,255,255)) #TODO: Move color to self.processInput(event, 0) #arg + #Add a pixelEvent to the list of active events def processInput(self,pixelEvent,zindex): #consider migrating arg to dict self.events[Util.time()] = (zindex, pixelEvent) def clearAllEvents(self): self.events = {} + #Combines all PixelEvents currently active and computes the current color of + #the pixel. def state(self): deadEvents = [] currentTime = Util.time() diff --git a/pixelcore/PixelStrip.py b/pixelcore/PixelStrip.py index 45d2c8b..c82a87a 100644 --- a/pixelcore/PixelStrip.py +++ b/pixelcore/PixelStrip.py @@ -11,7 +11,7 @@ class PixelStrip: self.argDict = layoutEngine.getStripArgs() def initStrip(self, layoutEngine): pixelLocations = layoutEngine.getPixelLocations() - self.pixels = [Pixel(l, (0,0,0)) for l in pixelLocations] + self.pixels = [Pixel(l) for l in pixelLocations] def __iter__(self): return self.pixels.__iter__() def render(self, surface): diff --git a/pixelcore/Screen.py b/pixelcore/Screen.py index 9806daa..561dc21 100644 --- a/pixelcore/Screen.py +++ b/pixelcore/Screen.py @@ -9,6 +9,8 @@ class Screen: self.pixelStrips.append(lS) def render(self, surface): [lS.render(surface) for lS in self.pixelStrips] + def setMapper(self, mapper): + self.mapper = mapper def allOn(self): [lS.allOn(-1) for lS in self.pixelStrips] def __iter__(self): #the iterator of all our pixel strips chained togther @@ -27,5 +29,9 @@ class Screen: #private def processResponse(self, responseInfo): #we need to make a new dict for #each to prevent interference - [strip.respond(dict(responseInfo)) for strip in self.pixelStrips] + #[strip.respond(dict(responseInfo)) for strip in self.pixelStrips] + pixelWeightList = self.mapper.mapEvent(responseInfo['Location'], self) + Util.addPixelEventIfMissing(responseInfo) + for (pixel, weight) in pixelWeightList: #TODO: weighting + pixel.processInput(responseInfo['PixelEvent'], 0) #TODO: z-index -- cgit v1.2.3