Changeset 1087

Show
Ignore:
Timestamp:
11/03/08 14:28:07 (2 months ago)
Author:
bhimebau
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • analog/pyeac/branches/pyeac_pygame/eac_sim.py

    r1077 r1087  
    9797        p.show() 
    9898 
     99 
     100    def update(self,full_form): 
     101        self.isrc_dict = {} 
     102        self.lla_dict = {} 
     103        for key in full_form.keys(): 
     104            (x,y,op) = key.split(',') 
     105            if op == 'type': 
     106                if full_form[key] == 'I': 
     107                    value = -int(full_form["%s,%s,current"%(x,y)]) 
     108                    if value != 0: 
     109                        self.isrc_add("I%s_%s"%(x,y),(int(x),int(y),"%du"%(value))) 
     110                if full_form[key] == 'L': 
     111                    try: 
     112                        function = int(full_form["%s,%s,function"%(x,y)]) 
     113                        if function > 0 and function < 27: 
     114                            self.lla_add('lla%s_%s'%(x,y),(int(x),int(y),function)) 
     115                        else: 
     116                            print "function value out of range",function 
     117                    except ValueError: 
     118                        pass 
     119#                    print "add lla at",x,y,"lla function is",full_form["%s,%s,function"%(x,y)] 
     120        print self.isrc_dict 
     121        print self.lla_dict 
     122         
     123  
    99124if __name__ == '__main__': 
    100125    myeac = eac() 
  • analog/pyeac/branches/pyeac_pygame/main.py

    r1085 r1087  
    5353 
    5454 
    55     phyeac_vis = Visualizer((0,0,100)
     55    phyeac_vis = Visualizer(absolute=True
    5656    phyeac_vis.update(phyeac.voltage_values) 
    5757 
    58     simeac_vis = Visualizer(
     58    simeac_vis = Visualizer(absolute=False
    5959    simeac_vis.update(simeac.evaluate()) 
    6060 
  • analog/pyeac/branches/pyeac_pygame/visualizer.py

    r1084 r1087  
    99class Visualizer(): 
    1010 
    11     def __init__(self, fill_color=(100,0,0)): 
    12         self.fill_color = fill_color 
     11    def __init__(self, absolute=True): 
     12        self.absolute = absolute 
     13        self.fill_color = (100,0,0) 
    1314        self.palette = self.createpalette() 
    1415        self.surface = pygame.Surface((300,300)) 
     
    1617        for y in range(5): 
    1718            for x in range(5): 
    18                 self.surface.fill(fill_color,fill_window) 
     19                self.surface.fill(self.fill_color,fill_window) 
    1920                fill_window = fill_window.move(60,0) 
    2021            fill_window = fill_window.move(-300,60) 
     
    2930 
    3031    def update(self,vdata): 
    31         for y in range(5): 
    32             for x in range(5): 
    33                 if self.fill_color[2]==0: 
    34                     cdata = self.palette[int((vdata[y][x]/5.0)*255)] 
    35                 else: 
    36                     cdata = self.palette[int((vdata[y][x]/5.0)*255)] 
    37                 self.set_block((x,y),cdata) 
    38          
     32        if self.absolute: 
     33            max = 5.0 
     34            min = 0.0 
     35            for y in range(5): 
     36                for x in range(5): 
     37                    voltage = float(vdata[y][x]) 
     38                    if voltage > max: 
     39                        voltage = max 
     40                    elif voltage < min: 
     41                        voltage = min 
     42                    cdata = self.palette[int((voltage/max)*255)] 
     43                    self.set_block((x,y),cdata) 
     44        else: 
     45            max = 0.0 
     46            min = 5.0 
     47            for y in range(5): 
     48                for x in range(5): 
     49                    voltage = float(vdata[y][x]) 
     50                    if voltage > max: 
     51                        max = voltage 
     52                    if voltage < min: 
     53                        min = voltage 
     54            span = max-min 
     55            print min, max, span 
     56            if span > 0: 
     57                for y in range(5): 
     58                    for x in range(5): 
     59                        voltage = float(vdata[y][x]) 
     60                        vnorm = (voltage - min)/span  
     61                        cdata = self.palette[int(vnorm*255)] 
     62                        self.set_block((x,y),cdata) 
     63 
     64        
    3965    def createpalette(self): 
     66        """function to create thermal type palette  
     67 
     68        used from the heat tutorial at http://www.penzilla.net/tutorials/python/pygame/heat/ 
     69 
     70        """ 
    4071        r,g,b = -1,0,256 
    4172        palette = []