Door works!
authorBernard Blackham <dagobah@ucc.gu.uwa.edu.au>
Sun, 27 Jun 2004 19:48:15 +0000 (19:48 +0000)
committerBernard Blackham <dagobah@ucc.gu.uwa.edu.au>
Sun, 27 Jun 2004 19:48:15 +0000 (19:48 +0000)
virtualvend/vvend.py

index e395589..c06970d 100644 (file)
@@ -24,6 +24,18 @@ except:
 
 import pango
 
+class Switches:
+    def __init__(self):
+       self.misc_input = 0xff
+       self.switch_input = 0x3f
+    def door_open(self):
+       return self.switch_input & 0x20
+    def set_door_open(self, open = True):
+       if open:
+           self.switch_input |= 0x20
+       else:
+           self.switch_input &= ~0x20
+
 #now we have both gtk and gtk.glade imported
 #Also, we know we are running GTK v2
 
@@ -82,6 +94,7 @@ class appgui:
     self.vendpw = "AAAAAAAAAAAAAAAA"
 
     self.messageid = None
+    self.switches = Switches()
 
     #s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     #s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
@@ -117,8 +130,11 @@ class appgui:
     self.do_send('2'+key+' keypress\n')
 
   def door_changed(self, widget):
-    print 'Door changed to', widget.pressed()
-    pass
+    self.switches.set_door_open(not widget.get_active())
+    if widget.get_active():
+       self.do_send('401 door closed\n')
+    else:
+       self.do_send('400 door open\n')
 
   def handleNewConnection(self,source,condition):
     #source is a socket in GTK v 1 and a fd in version 2
@@ -220,6 +236,7 @@ class appgui:
             gtk.input_remove(tag)
             conn.close()
      self.sock.close()
+     self.sock.shutdown()
 
      gtk.mainquit()
      sys.stdout.write("quit!\n")

UCC git Repository :: git.ucc.asn.au