changeset 120:b75bfbcf5979

new modules: dmxclient provides a very convenient way for clients to talk to the new modules: dmxclient provides a very convenient way for clients to talk to the dmxserver; updatefreq stores event times and computes a report about how frequently they occur
author drewp
date Fri, 13 Jun 2003 14:00:36 +0000
parents 6f9898f00c9c
children 2f48cb9219ed
files light8/dmxclient.py light8/updatefreq.py
diffstat 2 files changed, 13 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/light8/dmxclient.py	Fri Jun 13 13:59:32 2003 +0000
+++ b/light8/dmxclient.py	Fri Jun 13 14:00:36 2003 +0000
@@ -5,12 +5,11 @@
 client id is formed from sys.argv[0] and the PID.  """
 
 import xmlrpclib,os,sys,socket,time
-from twisted.web.xmlrpc import Proxy
 _dmx=None
 
 _id="%s-%s" % (sys.argv[0].replace('.py','').replace('./',''),os.getpid())
 
-def outputlevels(levellist,twisted=0):
+def outputlevels(levellist):
     """present a list of dmx channel levels, each scaled from
     0..1. list can be any length- it will apply to the first len() dmx
     channels.
@@ -21,33 +20,14 @@
     global _dmx,_id
 
     if _dmx is None:
-        host = os.getenv('DMXHOST', 'localhost')
-        url = "http://%s:8030" % host
-        if not twisted:
-            _dmx=xmlrpclib.Server(url)
-        else:
-            _dmx = Proxy(url)
+        _dmx=xmlrpclib.Server("http://localhost:8030")
 
-    if not twisted:
-        try:
-            _dmx.outputlevels(_id,levellist)
-        except socket.error,e:
-            print "dmx server error %s, waiting"%e
-            time.sleep(1)
-        except xmlrpclib.Fault,e:
-            print "outputlevels had xml fault: %s" % e
-            time.sleep(1)
-    else:
-        def err(error):
-            print "dmx server error",error
-            time.sleep(1)
-        d = _dmx.callRemote('outputlevels',_id,levellist)
-        d.addErrback(err)
-
+    try:
+        _dmx.outputlevels(_id,levellist)
+    except socket.error,e:
+        print "dmx server error %r, waiting"%e
+        time.sleep(1)
+    except xmlrpclib.Fault,e:
+        print "outputlevels had xml fault: %s" % e
+        time.sleep(1)
     
-dummy = os.getenv('DMXDUMMY')
-if dummy:
-    print "dmxclient: DMX is in dummy mode."
-    def bogus(*args):
-        pass
-    outputlevels = bogus
--- a/light8/updatefreq.py	Fri Jun 13 13:59:32 2003 +0000
+++ b/light8/updatefreq.py	Fri Jun 13 14:00:36 2003 +0000
@@ -9,7 +9,7 @@
     the samples param to __init__ specifies how many past updates will
     be stored.  """
     
-    def __init__(self,samples=20):
+    def __init__(self,samples=40):
         self.times=[0]
         self.samples=samples
 
@@ -24,10 +24,7 @@
         """a cheap algorithm, for now, which looks at the first and
         last times only"""
 
-        try:
-            hz=len(self.times)/(self.times[-1]-self.times[0])
-        except ZeroDivisionError:
-            return 0
+        hz=len(self.times)/(self.times[-1]-self.times[0])
         return hz
     def __str__(self):
-        return "%.2fHz"%float(self)
+        return "%.1fHz"%float(self)