From 7c2c54dfa01135eff003f1ad65d339c2679c46d5 Mon Sep 17 00:00:00 2001
From: Mitchell Pomery <bob_george33@hotmail.com>
Date: Wed, 18 Mar 2015 00:51:14 +0800
Subject: [PATCH 2/2] Add virtual vending machine

---
 virtualsnack.py | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/virtualsnack.py b/virtualsnack.py
index 66e16c8..7e467c5 100755
--- a/virtualsnack.py
+++ b/virtualsnack.py
@@ -10,6 +10,7 @@ import socket, select, errno
 # for emulator code
 import sys
 import string
+import time
 
 class ContainedMultiSelect(npyscreen.BoxTitle):
     _contained_widget = npyscreen.TitleMultiSelect
@@ -84,6 +85,26 @@ class VirtualSnack(npyscreen.Form):
         self.date_widget = self.add(npyscreen.FixedText, value=datetime.now().ctime(), editable=False, rely=18)
         self.date_widget.value = "Hello"
 
+        self.slots = []
+        slotx = 0
+        sloty = 0
+
+        # The Virtual Vending Machine
+        for i in range(10):
+                self.add(npyscreen.FixedText, value=str(i), editable=False, relx=62, rely=4+i)
+        for slx in range(10):
+                self.slots.append([])
+                xpos = 64 + (slx * 2)
+                self.add(npyscreen.FixedText, value=str(slx), editable=False, relx=xpos, rely=3)
+                for sly in range(10):
+                        ypos = 4 + sly
+                        if sly == 5:
+                                self.slots[slx].append(None)
+                        else:
+                                self.slots[slx].append(self.add(npyscreen.FixedText, value="/", editable=False, relx=xpos, rely=ypos))
+
+        self.collectionslot = self.add(npyscreen.FixedText, value="PUSH", editable=False, relx=70, rely=15)
+
         # Ctrl + Q exits the application
 	self.add_handlers({"^Q": self.exit_application})
 	self.add_handlers({"^C": self.exit_application})
@@ -278,10 +299,13 @@ Mark Tearle, October 2014
         self.do_send("102 Vend all motors complete\n")
 
     def do_vend(self,command):
-        fail = None
-	if fail:
+        if self.F.slots[int(command[2])][int(command[1])] == None:            
             self.do_send("153 Home sensors failing\n")
         else:
+            for pos in "-\|/-\|/":
+                self.F.slots[int(command[2])][int(command[1])].value = pos
+                self.F.display()
+                time.sleep(0.5)
             self.do_send("100 Vend successful\n")
 
     def do_display(self,string):
-- 
2.0.1

