Esempio n. 1
0
 def testConvertRotation(self):
     out = toOutputAttrs(L9['Mini15'], {L9['rx']: Literal(90), L9['ry']: Literal(45)})
     self.assertEqual(42, out[L9['xRotation']])
     self.assertEqual(127, out[L9['xFine']])
     self.assertEqual(47, out[L9['yRotation']])
     self.assertEqual(207, out[L9['yFine']])
     self.assertEqual(0, out[L9['rotationSpeed']])
Esempio n. 2
0
 def testConvertDeviceToOutputAttrs(self):
     out = toOutputAttrs(L9['ChauvetColorStrip'],
                         {L9['color']: Literal('#ff0000')})
     self.assertEqual({L9['mode']: 215,
                       L9['red']: 255,
                       L9['green']: 0,
                       L9['blue']: 0
                   }, out)
Esempio n. 3
0
    def setAttrs(self, client, clientSession, settings, sendTime):
        """
        settings is a list of (device, attr, value). These attrs are
        device attrs. We resolve conflicting values, process them into
        output attrs, and call Output.update/Output.flush to send the
        new outputs.

        client is a string naming the type of client. (client,
        clientSession) is a unique client instance.

        Each client session's last settings will be forgotten after
        clientTimeoutSec.
        """
        now = time.time()
        self._warnOnLateRequests(client, now, sendTime)

        self._forgetStaleClients(now)

        uniqueSettings = self.resolvedSettingsDict(settings)
        self.lastRequest[(client, clientSession)] = (now, uniqueSettings)

        deviceAttrs = self._merge(self.lastRequest.itervalues())
        
        outputAttrs = {} # device: {outputAttr: value}
        for d in self.allDevices:
            try:
                devType = self.deviceType[d]
            except KeyError:
                log.warn("request for output to unconfigured device %s" % d)
                continue
            try:
                outputAttrs[d] = toOutputAttrs(devType, deviceAttrs.get(d, {}))
                if self.listeners:
                    self.listeners.outputAttrsSet(d, outputAttrs[d], self.outputMap)
            except Exception as e:
                log.error('failing toOutputAttrs on %s: %r', d, e)
        
        pendingOut = {} # output : values
        for out in self.outputs:
            pendingOut[out] = [0] * out.numChannels

        for device, attrs in outputAttrs.iteritems():
            for outputAttr, value in attrs.iteritems():
                self.setAttr(device, outputAttr, value, pendingOut)

        dt1 = 1000 * (time.time() - now)
        self.flush(pendingOut)
        dt2 = 1000 * (time.time() - now)
        if dt1 > 30:
            log.warn("slow setAttrs: %.1fms -> flush -> %.1fms. lr %s da %s oa %s" % (
                dt1, dt2, len(self.lastRequest), len(deviceAttrs), len(outputAttrs)
            ))
Esempio n. 4
0
    def setAttrs(self, client, clientSession, settings, sendTime):
        """
        settings is a list of (device, attr, value). These attrs are
        device attrs. We resolve conflicting values, process them into
        output attrs, and call Output.update/Output.flush to send the
        new outputs.

        Call with settings=[] to ping us that your session isn't dead.
        """
        now = time.time()
        requestLag = now - sendTime
        if requestLag > .1:
            log.warn('collector.setAttrs from %s is running %.1fms after the request was made',
                     client, requestLag * 1000)

        self._forgetStaleClients(now)

        uniqueSettings = self.resolvedSettingsDict(settings)
        self.lastRequest[client] = (clientSession, now, uniqueSettings)

        deviceAttrs = {} # device: {deviceAttr: value}       
        for _, _, lastSettings in self.lastRequest.itervalues():
            for (device, deviceAttr), value in lastSettings.iteritems():
                if (device, deviceAttr) in self.remapOut:
                    start, end = self.remapOut[(device, deviceAttr)]
                    value = Literal(start + float(value) * (end - start))

                attrs = deviceAttrs.setdefault(device, {})
                if deviceAttr in attrs:
                    value = resolve(device, deviceAttr, [attrs[deviceAttr], value])
                attrs[deviceAttr] = value
                # list should come from the graph. these are attrs
                # that should default to holding the last position,
                # not going to 0.
                if deviceAttr in [L9['rx'], L9['ry'], L9['zoom'], L9['focus']]:
                    self.stickyAttrs[(device, deviceAttr)] = value

        
        # e.g. don't let an unspecified rotation go to 0
        for (d, da), v in self.stickyAttrs.iteritems():
            daDict = deviceAttrs.setdefault(d, {})
            if da not in daDict:
                daDict[da] = v
                    
        outputAttrs = {} # device: {outputAttr: value}
        for d in deviceAttrs:
            try:
                devType = self.deviceType[d]
            except KeyError:
                log.warn("request for output to unconfigured device %s" % d)
                continue
            outputAttrs[d] = toOutputAttrs(devType, deviceAttrs[d])
        
        pendingOut = {} # output : values
        for out in self.outputs:
            pendingOut[out] = [0] * out.numChannels
        for device, attrs in outputAttrs.iteritems():
            for outputAttr, value in attrs.iteritems():
                self.setAttr(device, outputAttr, value, pendingOut)

        dt1 = 1000 * (time.time() - now)
        self.flush(pendingOut)
        dt2 = 1000 * (time.time() - now)
        if dt1 > 10:
            print "slow setAttrs: %.1fms -> flush -> %.1fms. lr %s da %s oa %s" % (
                dt1, dt2, len(self.lastRequest), len(deviceAttrs), len(outputAttrs)
            )
Esempio n. 5
0
 def testConvertColor(self):
     out = toOutputAttrs(L9['Mini15'], {L9['color']: '#010203'})
     self.assertEqual(255, out[L9['dimmer']])
     self.assertEqual(1, out[L9['red']])
     self.assertEqual(2, out[L9['green']])
     self.assertEqual(3, out[L9['blue']])
Esempio n. 6
0
 def testConvert(self):
     self.assertEqual({L9['level']: 127},
                      toOutputAttrs(L9['SimpleDimmer'], {L9['brightness']: .5}))