Skip to content

Commit

Permalink
svelt, functional zooming with axis rescale FTW
Browse files Browse the repository at this point in the history
  • Loading branch information
itdaniher authored and meeg committed Nov 20, 2011
1 parent 374943d commit 617fd4f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
8 changes: 2 additions & 6 deletions cee.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ def b12unpack(self, s):
"Turn a 3-byte string containing 2 12-bit values into two ints"
return s[0]|((s[1]&0x0f)<<8), ((s[1]&0xf0) >> 4)|(s[2]<<4)

closest=lambda self,a,l:min(l,key=lambda x:abs(x-a))

def readADC(self):
data = self.dev.ctrl_transfer(0x40|0x80, 0xA0, 0, 0, 6)
l = self.b12unpack(data[0:3]) + self.b12unpack(data[3:6])
Expand All @@ -42,10 +40,8 @@ def set(self, chan, v=None, i=None, x=None):
dacval = int((2**12*(1.25+(45*.07*i)))/2.5)
self.dev.ctrl_transfer(0x40|0x80, cmd, dacval, MODE_SIMV, 0)
elif x is not None:
gain = self.closest(x[1], gainMapping.keys())
gainval = gainMapping[gain]
self.gains[x[0]] = gain
self.dev.ctrl_transfer(0x40|0x80, 0x65, gainval, x[0], 0)
self.gains[x[0]] = x[1]
self.dev.ctrl_transfer(0x40|0x80, 0x65, gainMapping[x[1]], x[0], 0)
else:
self.dev.ctrl_transfer(0x40|0x80, cmd, 0, MODE_DISABLED, 0)

Expand Down
12 changes: 10 additions & 2 deletions ceeVendorReq.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,28 @@ def getChanData(self, replypkt):
(self.currentChan, replypkt[self.name.lower()+'_i']*1000),
(self.gainChan, self.getGain(self.name.lower()))]

closest=lambda self,a,l:min(l,key=lambda x:abs(x-a))

def getGain(self, name):
name = self.name.lower()
driving = self.driving
mapping = {'a':{'v':1, 'i':0}, 'b':{'v':2,'i':3}}
return self.cee.gains[mapping[name][driving]]

def setGain(self, chan, gain, state=None):
gains = [16, 1, 2, 4, 0.5, 32, 8, 64]
gain = self.closest(gain, gains)
name = self.name.lower()
driving = self.driving
mapping = {'a':{'v':1, 'i':0}, 'b':{'v':2,'i':3}}
chan = mapping[name][driving]
print (chan, gain)
oldGain = self.cee.gains[mapping[name][driving]]
if driving == 'v':
self.voltageChan.max = float(self.voltageChan.max) * oldGain / gain
elif driving == 'i':
self.currentChan.max = float(self.currentChan.max) * oldGain / gain
self.cee.set(0, x=(chan, gain))

server.updateConfig()

class CEE_vendor_req(pixelpulse.Device):
def __init__(self):
Expand Down
2 changes: 2 additions & 0 deletions client/app.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Pixelpulse browser UI
# Distributed under the terms of the BSD License
# (C) 2011 Kevin Mehall (Nonolith Labs) <[email protected]>
# (C) 2011 Ian Daniher (Nonolith Labs) <[email protected]>

class PixelpulseApp
constructor: ->
Expand Down Expand Up @@ -67,6 +68,7 @@ class PixelpulseApp
$('.dnd-oldpos').show().removeClass('dnd-oldpos')

onConfig: (o) ->
$('.analog').remove()
$('#meters, #meters-side').empty()
@channels = {}
self = this
Expand Down
3 changes: 3 additions & 0 deletions pixelpulse.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def _formJSON(self, action, message):
message = json.dumps(message)+'\n'
return message

def updateConfig(self):
self._sendToAll(self._formJSON('config', self.getConfigMessage()))

def data(self, data):
"""Send a new datapoint to connected clients.
Expand Down

0 comments on commit 617fd4f

Please sign in to comment.