Commits

Alex Hixon  committed ec58987

Keep track of timing, send noops as required.

  • Participants
  • Parent commits ed3fd90

Comments (0)

Files changed (2)

 
 COM_PORT = "/dev/ttyUSB0"
 SIMULATE = True
+NOOP_DELAY = 5
 
 class Interface ():
     def __init__ (self, resolution, colors, aspect=45, title="flymote"):
             self.acc_cal = self.wiimote.get_acc_cal(ACCEL_DEVICE)
             self.connected = True
         
-        #print 'info: %d' % (self.wiimote.state['acc'][cwiid.Y])
         prev_updating = self.update_axes
         self.update_axes = (self.wiimote.state['buttons'] == 4)
         
                 rudder_deg = (self/cube.axes[2] + 360) / 4
                 self.wireless.send ((wireless.MessageType.MOVE_RUDDER, rudder_deg)
         else:
-            pass
-            # FIXME: send noop polls to the controller every x seconds
+            if (int(time.time()) - self.wireless.last_timestamp) > NOOP_DELAY:
+                self.wireless.send (wireless.MessageType.NOOP)
         
         glutSwapBuffers()
     
 import serial
 import struct
+import time
 
 class MessageType:
     MOVE_THROTTLE = 1
         self.port = port
         self.baud = baud
         self.version = -1
+        self.last_timestamp = 0
         
         self.device = serial.Serial (port, baud)
+        self.version = int(self.read_string())
+        self.motd = self.read_string()  # silly catface
+        
+        self.last_timestamp = int(time.time())
     
     def send (self, msg, args=None):
         if args is None:
                 raise ValueError, "argument must be between 0 and 180."
             
             a = struct.pack('<BB', msg, args)
-            print "Writing:", a, "; length=", len(a)
-            print "===="
-            i = 0
-            for char in a:
-                print "0x%d\t%d" % (i, ord(char))
-                i += 1
-            print "===="
             self.device.write (a)
+
+        self.last_timestamp = int(time.time())
     
     @property
     def response (self):