diff bcf2000.py @ 1873:f001d689b3e2

more py3 and typing fixes Ignore-this: 3180bd966cac69de56b86ef6a308cad4
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 27 May 2019 06:20:38 +0000
parents ff9c72cfb023
children 0bb08e887166
line wrap: on
line diff
--- a/bcf2000.py	Mon May 27 06:20:25 2019 +0000
+++ b/bcf2000.py	Mon May 27 06:20:38 2019 +0000
@@ -1,9 +1,10 @@
 #!/usr/bin/python
-from __future__ import division
+
 import math
 import twisted.internet.fdesc
 from twisted.internet import reactor
 from twisted.internet.task import LoopingCall
+from typing import Dict
 
 class BCF2000(object):
 
@@ -35,7 +36,7 @@
         once as C0D0. It should be autodetected"""
         self.devPath = dev
         self.dev = None
-        self.lastValue = {} # control name : value
+        self.lastValue: Dict[str, int] = {} # control name : value
         self.reopen()
         self.packet = ""
         loop = LoopingCall(self.poll)
@@ -47,7 +48,7 @@
         except (IOError, AttributeError):
             return
         if len(bytes) == 0:
-            print "midi stall, reopen slider device"
+            print("midi stall, reopen slider device")
             self.reopen()
             return
         self.packet += bytes
@@ -67,7 +68,7 @@
             self.lastValue[name] = value
             self.valueIn(name, value)
         else:
-            print "unknown control %s to %s" % (which, value)
+            print("unknown control %s to %s" % (which, value))
 
     def reopen(self):
         if self.dev is not None:
@@ -83,7 +84,7 @@
     def valueIn(self, name, value):
         """override this with your handler for when events come in
         from the hardware"""
-        print "slider %s to %s" % (name, value)
+        print("slider %s to %s" % (name, value))
         if name == 'slider1':
             for x in range(2,8+1):
                 v2 = int(64 + 64 * math.sin(x / 3 + value / 10))
@@ -101,7 +102,7 @@
         if self.lastValue.get(name) == value:
             return
         self.lastValue[name] = value
-        which = [k for k,v in self.control.items() if v == name]
+        which = [k for k,v in list(self.control.items()) if v == name]
         assert len(which) == 1, "unknown control name %r" % name
         if name.startswith('button-'):
             value = value * 127