Changeset 1094
- Timestamp:
- 11/06/08 11:13:18 (2 months ago)
- Files:
-
- analog/pyeac/branches/pyeac_pygame/eeepc/controlpanel.py (modified) (3 diffs)
- analog/pyeac/branches/pyeac_pygame/eeepc/controlpanel.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/eac_physical.py (modified) (5 diffs)
- analog/pyeac/branches/pyeac_pygame/eeepc/eac_physical.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/__init__.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/__init__.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/app.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/area.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/basic.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/button.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/const.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/container.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/deprecated.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/dialog.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/document.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/form.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/group.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/input.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/keysym.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/layout.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/menus.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/misc.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/select.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/slider.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/style.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/surface.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/table.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/theme.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pgu/gui/widget.pyc (modified) (previous)
- analog/pyeac/branches/pyeac_pygame/eeepc/pyeac.py (modified) (6 diffs)
- analog/pyeac/branches/pyeac_pygame/eeepc/raw_display.py (modified) (1 diff)
- analog/pyeac/branches/pyeac_pygame/eeepc/visualizer.py (modified) (4 diffs)
- analog/pyeac/branches/pyeac_pygame/eeepc/visualizer.pyc (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
analog/pyeac/branches/pyeac_pygame/eeepc/controlpanel.py
r1086 r1094 29 29 self.td(e) 30 30 31 e = gui.Input(value=" f1",name="%s,function"%(params['pin']),size=5)31 e = gui.Input(value="1",name="%s,function"%(params['pin']),size=5) 32 32 self.td(e) 33 33 … … 70 70 self.td(CellControl(pin='5,5'),align=0) 71 71 72 class TableBorder: 73 74 def __init__(self): 75 self.surface = pygame.Surface((200,200)) 76 self.cellrect = pygame.Rect((0,0),(50,20)) 77 self.get_border() 78 79 def get_border(self): 80 pygame.draw.rect(self.surface,(255,255,255),self.cellrect,1) 81 return (self.surface) 82 72 class ButtonPanel(gui.Table): 83 73 74 def __init__(self, resetf=None, ledonf=None, ledofff=None, **params): 75 gui.Table.__init__(self,**params) 76 77 # print reset_func 84 78 79 self.ledonf = ledonf 80 self.ledofff = ledofff 81 self.tr() 82 b1 = gui.Button("RESET",width=70) 83 b1.connect(gui.CLICK,resetf) 84 self.td(b1,align=-1) 85 86 self.tr() 87 self.s1 = gui.Switch(value=True) 88 self.s1.connect(gui.CHANGE,self.handler) 89 self.td(gui.Label("LED ENABLE",color=(255,255,255)),align=-1,width=70) 90 self.td(self.s1,align=-1) 91 92 def handler(self): 93 if self.s1.value: 94 self.ledonf() 95 else: 96 self.ledofff() 97 85 98 if __name__ == '__main__': 86 99 screen = pygame.display.set_mode((1024,600)) … … 88 101 app = gui.App() 89 102 ecc = EacPanel() 103 bcc = ButtonPanel() 104 90 105 c = gui.Container(align=-1,valign=-1) 91 106 c.add(ecc,0,325) 107 c.add(bcc,325,0) 92 108 app.init(c) 93 109 analog/pyeac/branches/pyeac_pygame/eeepc/eac_physical.py
r1086 r1094 37 37 from numpy import array,arange,zeros,meshgrid 38 38 39 40 class LLA: 41 42 def __init__(self, eac, input_pin, output_pin, num_desc, function, period): 43 self.eac = eac 44 self.enable = True 45 self.input_pin = input_pin 46 self.output_pin = output_pin 47 self.num_desc = num_desc 48 self.function = function 49 self.period = period 50 self.eac.lla_add(input_pin,output_pin,num_desc,function,period) 51 self.input_current = None 52 self.output_current = None 53 54 def disable(self): 55 self.enable = False 56 self.eac.lla_disable(self.num_desc) 57 58 def enable(self): 59 self.enable = True 60 self.eac.lla_enable(self.num_desc) 61 62 def update(self): 63 (self.input_current,self.output_current) = self.eac.lla_report(self.num_desc) 64 65 class Pin: 66 67 def __init__(self,pin=None): 68 # V, L, S 69 self.pin = pin 70 self.mode = "V" 71 self.voltage = 0.0 72 self.current_input = None 73 self.current_output = None 74 75 class PinGrid: 76 77 def __init__(self,ueac_device='/dev/ttyUSB0',baud=19200): 78 self.lla_dict = {} 79 self.lla_count = 1 80 self.ueac = ueac(ueac_device='/dev/ttyUSB0',baud=19200) 81 self.ueac.reset() 82 self.grid = [] 83 for y in range(5): 84 temp = [] 85 for x in range(5): 86 temp.append(Pin((x+1,y+1))) 87 self.grid.append(temp) 88 89 def read_grid_current(self): 90 self.ueac.read_i() 91 for y in range(5): 92 for x in range(5): 93 if self.grid[y][x].mode == 'S': 94 self.grid[y][x].current_output = ueac.current_values[y][x] 95 96 def read_grid_voltage(self): 97 self.ueac.read_v() 98 for y in range(5): 99 for x in range(5): 100 self.grid[y][x].voltage = ueac.voltage_values[y][x] 101 102 def set_current_source(self, pin, value): 103 (x,y) = pin 104 self.ueac.write_i(x,y,value) 105 x -= 1 106 y -= 1 107 if self.grid[y][x].mode != 'S': 108 self.grid[y][x].mode = 'S' 109 self.grid[y][x].current_output = value 110 111 def lla_add(self, tag, input_pin, output_pin, function, period): 112 if self.lla_count >= 10: 113 return (None) 114 115 if self.lla_dict.has_key(tag): 116 return (None) 117 else: 118 self.set_voltage_input(input_pin) 119 (x,y) = input_pin 120 self.grid[y-1][x-1].mode = 'L' 121 self.lla_dict[tag] = LLA(self.ueac, input_pin, output_pin, self.lla_count, function, period) 122 self.lla_count += 1 123 return self.lla_count-1 124 125 def lla_disable(self, tag): 126 if self.lla_dict.has_key(tag): 127 self.lla_dict[tag].disable() 128 return True 129 else: 130 return (None) 131 132 def lla_enable(self, tag): 133 if self.lla_dict.has_key(tag): 134 self.lla_dict[tag].enable() 135 return True 136 else: 137 return (None) 138 139 def lla_update(self, tag): 140 if self.lla_dict.has_key(tag): 141 return self.lla_dict[tag].update() 142 else: 143 return (None) 144 145 def set_voltage_input(self, pin): 146 (x,y) = pin 147 self.ueac.write_i(x,y,0) 148 x -= 1 149 y -= 1 150 if self.grid[y][x].mode != 'V': 151 self.grid[y][x].mode = 'V' 152 self.grid[y][x].current_output = None 153 154 def get_data(self): 155 self.read_grid_voltage() 156 self.read_grid_current() 157 for tag in self.lla_dict.keys(): 158 self.lla_update(tag) 159 160 def reset(self): 161 self.lla_dict = {} 162 self.lla_count = 1 163 self.grid = [] 164 for y in range(5): 165 temp = [] 166 for x in range(5): 167 temp.append(Pin((x+1,y+1))) 168 self.grid.append(temp) 169 self.ueac.reset() 170 self.get_data() 171 172 173 def lof(self): 174 self.ueac.lof() 175 176 def lon(self): 177 self.ueac.lon() 178 179 def update(self, update_dict, full_form): 180 for key in update_dict.keys(): 181 (x,y,op) = key.split(',') 182 x = int(x) 183 y = int(y) 184 value = update_dict[key] 185 if op == 'type': 186 if value == 'V': 187 self.set_voltage_input((x,y)) 188 if value == 'I': 189 current_value_key = "%s,%s,current"%(x,y) 190 self.set_current_source((x,y),int(full_form[current_value_key])) 191 if value == 'L': 192 current_value_key = "%d,%d,function"%(x,y) 193 self.lla_add("lla1",(x,y),(0,0),int(full_form[current_value_key]),1) 194 print int(full_form[current_value_key]) 195 # print "need to add lla" 196 elif op == 'function': 197 print "lla function changed to",value 198 elif op == "current": 199 self.set_current_source((x,y),int(value)) 200 201 202 def __str__(self): 203 outstr = "" 204 for y in range(5): 205 # Row 1 206 for x in range(5): 207 outstr += " %s "%(self.grid[y][x].mode) 208 outstr += "\n" 209 210 # Row 2 211 for x in range(5): 212 outstr += " %4.3f "%(self.grid[y][x].voltage) 213 outstr += "\n" 214 215 # Row 3 216 for x in range(5): 217 if self.grid[y][x].mode == 'V': 218 outstr += " " 219 elif self.grid[y][x].mode == 'S': 220 outstr += " %d " % (self.grid[y][x].current_output) 221 elif self.grid[y][x].mode == 'L': 222 for key in self.lla_dict.keys(): 223 (lx,ly) = self.lla_dict[key].input_pin 224 if lx == (x+1) and ly == (y+1): 225 outstr += " %d " % (int(self.lla_dict[key].input_current)) 226 outstr += "\n" 227 228 # Row 4 229 for x in range(5): 230 if self.grid[y][x].mode == 'V': 231 outstr += " " 232 elif self.grid[y][x].mode == 'S': 233 outstr += " " 234 elif self.grid[y][x].mode == 'L': 235 for key in self.lla_dict.keys(): 236 (lx,ly) = self.lla_dict[key].input_pin 237 if lx == (x+1) and ly == (y+1): 238 outstr += " %d " % (int(self.lla_dict[key].output_current)) 239 outstr += "\n" 240 outstr += "\n" 241 outstr += "############################################" 242 return outstr 243 39 244 class ueac: 40 """ Class used to comm inicate with the uEAC R002 board"""245 """ Class used to communicate with the uEAC R002 board""" 41 246 42 247 voltage_values = zeros((5,5)) … … 102 307 self.ser.write('p,v\n') 103 308 self.ser.flush() 104 self.convert_ueac_string_v(self.ser.readline()) 309 line = self.ser.readline() 310 if line != None: 311 self.convert_ueac_string_v(line) 105 312 sleep(0.01) 106 313 … … 109 316 self.ser.write('p,i\n') 110 317 self.ser.flush() 111 self.convert_ueac_string_i(self.ser.readline()) 318 319 line = self.ser.readline() 320 if line != None: 321 self.convert_ueac_string_i(line) 112 322 sleep(0.01) 113 323 … … 120 330 sleep(0.01) 121 331 122 def lla_add(self, x,y):123 """ Adds an lla at the node specified by x,y. The function is hard coded in this version, intended just to be used as input"""124 write_string = "l,a,"+repr(x)+","+repr(y)+",0,0,1,18,1\n"125 self.ser.write( write_string)332 def lla_add(self,input,output,num_desc,function,period): 333 (xi,yi) = input 334 (xo,yo) = output 335 self.ser.write("l,a,%d,%d,%d,%d,%d,%d,%d\n" % (xi,yi,xo,yo,num_desc,function,period)) 126 336 self.ser.flush() 127 337 self.ser.readline() 128 338 sleep(0.01) 339 340 def lla_enable(self,num_desc): 341 self.ser.write("l,e,1,1,0,0,%d,18,1\n"%(num_desc)) 342 self.ser.flush() 343 self.ser.readline() 344 sleep(0.01) 345 346 def lla_disable(self,num_desc): 347 self.ser.write("l,d,1,1,0,0,%d,18,1\n"%(num_desc)) 348 self.ser.flush() 349 self.ser.readline() 350 sleep(0.01) 351 352 def lla_report(self,num_desc): 353 self.ser.write("l,r,2,2,0,0,%d,18,1\n"%(num_desc)) 354 self.ser.flush() 355 line = self.ser.readline() 356 if line != None and line != "\rueac> NOK\n": 357 fields = line.split(',') 358 (temp,icurrent) = fields[0].split(' ') 359 ocurrent = fields[1] 360 sleep(0.01) 361 return ((icurrent,ocurrent)) 129 362 130 363 def raw_read(self): … … 139 372 def close_port(self): 140 373 self.ser.close() 141 142 def update(self, update_dict, full_form):143 for key in update_dict.keys():144 (x,y,op) = key.split(',')145 value = update_dict[key]146 if op == 'type':147 if value == 'V':148 self.write_i(int(x),int(y),0)149 if value == 'I':150 current_value_key = "%s,%s,current"%(x,y)151 self.write_i(int(x),int(y),int(full_form[current_value_key]))152 if value == 'L':153 pass154 elif op == 'function':155 print "lla function changed to",value156 elif op == "current":157 self.write_i(int(x),int(y),int(value))158 159 160 374 161 375 if __name__ == "__main__": 162 ue = ueac(ueac_device='/dev/ttyUSB0') # Connect to the uEAC device 163 ue.reset() # Reset the board to clear any previous config 164 ue.lof() # turn off the board Leds 165 ue.lla_add(3,3) # Instantiate an lla at position (3,3). 166 ue.write_i(1,1,100) # write pin (1,1) as current source 167 ue.write_i(5,5,100) # write pin (5,5) as current source 168 169 for i in range(20): 170 ue.read_v() # read the sheet voltages from the board - store in class variable (voltage_values) 171 ue.read_i() # read the pin currents from the board - store in class variable (current_values) 172 print "** voltage values **\n",ue.voltage_values,"\n" 173 print "** current values **\n",ue.current_values,"\n" 174 175 ue.close_port() 176 177 # Code end 376 pg = PinGrid() 377 pg.lof() 378 pg.read_grid_voltage() 379 pg.lla_add("lla1",(3,3),(0,0),18,1) 380 pg.set_current_source((1,1),70) 381 382 pg.get_data() 383 print pg 384 385 pg.lla_add("lla2",(5,5),(0,0),18,1) 386 pg.get_data() 387 print pg 388 389 pg.reset() 390 pg.lof() 391 pg.get_data() 392 print pg 393 analog/pyeac/branches/pyeac_pygame/eeepc/pyeac.py
r1092 r1094 24 24 if __name__ == '__main__': 25 25 from visualizer import Visualizer 26 from eac_physical import ueac26 from eac_physical import PinGrid 27 27 import pygame 28 28 import random … … 31 31 import sys; sys.path.insert(0, ".") 32 32 from pgu import gui 33 from controlpanel import EacPanel, TableBorder33 from controlpanel import EacPanel, ButtonPanel 34 34 from raw_display import RawDisplay 35 35 36 phyeac = ueac(ueac_device='/dev/ttyUSB0') # Connect to the uEAC device 37 phyeac.reset() # Reset the board to clear any previous config 38 phyeac.lof() # turn off the board Leds 39 phyeac.lla_add(3,3) # Instantiate an lla at position (3,3). 40 phyeac.write_i(1,1,100) # write pin (1,1) as current source 41 phyeac.write_i(5,5,100) # write pin (5,5) as current source 36 37 pg = PinGrid(ueac_device='/dev/ttyUSB0') 38 39 # phyeac = ueac(ueac_device='/dev/ttyUSB0') # Connect to the uEAC device 40 # phyeac.reset() # Reset the board to clear any previous config 41 # phyeac.lof() # turn off the board Leds 42 # phyeac.lla_add(3,3,1) # Instantiate an lla at position (3,3). 43 # phyeac.write_i(1,1,100) # write pin (1,1) as current source 44 # phyeac.write_i(5,5,100) # write pin (5,5) as current source 42 45 43 46 pygame.init() … … 49 52 50 53 phyeac_vis = Visualizer(absolute=True) 51 phyeac_vis.update(p hyeac.voltage_values)54 phyeac_vis.update(pg) 52 55 phyeac_raw = RawDisplay() 53 phyeac_raw.update(phyeac.voltage_values) 54 56 phyeac_raw.update(pg) 55 57 56 58 form = gui.Form() 57 59 app = gui.App() 58 60 ecc = EacPanel() 61 bcc = ButtonPanel(pg.reset, pg.lon, pg.lof) 62 59 63 c = gui.Container(align=-1,valign=-1) 60 64 c.add(ecc,0,325) 65 # c.add(bcc,720,100) 66 c.add(bcc,650,100) 67 61 68 app.init(c) 62 69 … … 64 71 _quit = 0 65 72 66 tb = TableBorder()73 # tb = TableBorder() 67 74 68 75 clock = pygame.time.Clock() … … 72 79 changes = diff_dict(_form_last,_form) 73 80 if changes != None: 74 p hyeac.update(changes,_form)81 pg.update(changes,_form) 75 82 76 83 for event in pygame.event.get(): … … 79 86 app.event(event) 80 87 81 phyeac.read_v() 82 phyeac_vis.update(phyeac.voltage_values) 88 pg.get_data() 83 89 84 phyeac_raw.update(phyeac.voltage_values) 90 # phyeac.read_v() 91 phyeac_vis.update(pg) 92 phyeac_raw.update(pg) 93 94 # phyeac.read_i() 95 # print phyeac.current_values 96 # phyeac.lla_report(2) 85 97 86 98 screen.fill((0,0,0)) analog/pyeac/branches/pyeac_pygame/eeepc/raw_display.py
r1092 r1094 43 43 pygame.draw.line(self.master_surface,(255,255,255),(0,240),(300,240),1) 44 44 45 def update(self, vdata):45 def update(self,pg): 46 46 self.clear_surface() 47 47 self.draw_grid() 48 xoffset = 1 549 yoffset = 3048 xoffset = 10 49 yoffset = 5 50 50 for y in range(5): 51 51 for x in range(5): 52 voltage = float(vdata[y][x]) 53 text.write(self.master_surface,self.font,(xoffset+x*60,yoffset+y*60),(255,255,255),"%4.3f" % (voltage)) 54 52 voltage = float(pg.grid[y][x].voltage) 53 text.write(self.master_surface,self.font,(xoffset+x*60,yoffset+y*60),(0,255,0),"V = %4.3f" % (voltage)) 54 if pg.grid[y][x].mode == 'S': 55 loc = ((xoffset)+x*60,(yoffset+10)+y*60) 56 value = int(pg.grid[y][x].current_output) 57 if value >= 0: 58 text.write(self.master_surface,self.font,loc,(255,0,0),"Io = %d" % (value)) 59 else: 60 text.write(self.master_surface,self.font,loc,(0,0,255),"Io = %d" % (value)) 61 if pg.grid[y][x].mode == 'L': 62 loc = ((xoffset)+x*60,(yoffset+10)+y*60) 63 text.write(self.master_surface,self.font,loc,(255,255,0),"LLA") 64 65 55 66 if __name__ == '__main__': 56 67 size = (300,300) analog/pyeac/branches/pyeac_pygame/eeepc/visualizer.py
r1093 r1094 29 29 self.surface.fill(color,fill_window) 30 30 31 def update(self, vdata):31 def update(self,pg): 32 32 if self.absolute == True: 33 33 max = 5.0 … … 35 35 for y in range(5): 36 36 for x in range(5): 37 voltage = float( vdata[y][x])37 voltage = float(pg.grid[y][x].voltage) 38 38 if voltage > max: 39 39 voltage = max … … 47 47 for y in range(5): 48 48 for x in range(5): 49 voltage = float( vdata[y][x])49 voltage = float(pg.grid[y][x].voltage) 50 50 if voltage > max: 51 51 max = voltage … … 57 57 for y in range(5): 58 58 for x in range(5): 59 voltage = float( vdata[y][x])59 voltage = float(pg.grid[y][x].voltage) 60 60 vnorm = (voltage - min)/span 61 61 cdata = self.palette[int(vnorm*255)]
