From a5882a36f51fafb0a641a3591094e7aa5b864649 Mon Sep 17 00:00:00 2001 From: Bernard Blackham Date: Sun, 27 Jun 2004 19:48:15 +0000 Subject: [PATCH] Door works! --- virtualvend/vvend.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/virtualvend/vvend.py b/virtualvend/vvend.py index e395589..c06970d 100644 --- a/virtualvend/vvend.py +++ b/virtualvend/vvend.py @@ -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") -- 2.20.1