Example #1
0
 def handle_barcode(self, str):
     putil.trace("ding")
     item = Products.get_from_barcode(str)
     if item == None:
         GUI.warn("Unknown product cannot buy here")
         return
     GUI.info("Added {} - \"{}\"".format(item.name, item.text))
     Foodputer.add_item(item)
Example #2
0
    def handle_hal(self, json_data):
        """handles the dict generated from parsing the json data

        fields:
        status: Hal.ACCEPT ect as int REQUIRED
        """
        
        status = int(json_data['status'])
        print "status: ", status

        if status == Hal.ACCEPT:
            Foodputer.set_state(start)
            GUI.accepted_order()
        elif status == Hal.DENY:
            if Pin_check.tries_left == 0:
                self.handle_abort()
            else:
                Foodputer.set_state(ordering)
                GUI.wrong_pin(Pin_check.tries_left)
                Pin_check.tries_left -= 1;
        elif status == Hal.NOFUNDS:
            Foodputer.set_state(ordering)
            GUI.not_enough_money();
        else:
            putil.trace("no such return is nice {}".format(status));
            self.handle_abort()
Example #3
0
    def handle_hal(self, resp):
        putil.trace("rfid check data: \"{}\"".format(resp))
        if not resp or len(resp) < 2:
            putil.trace("HAL doesnt know user or no contact")
            Foodputer.set_state(start)
            GUI.no_rfid()
            return

        Foodputer.new_order( resp['user'], resp['token']) 
        Foodputer.set_state(ordering)
        Pin_check.tries_left = 3;
        GUI.valid_rfid()
Example #4
0
    def run(self):
        pin = self.pincheck.pin
        
        #for debugging and mocking
        if (LOCAL):
            data = ACCEPT
            if pin == "p4":
                data = DENY
            elif pin == "p3":
                data =  NOFUNDS
            time.sleep(1)
            if self.alive:
                self.pincheck.handle_hal(data)
            return
        
        data = Foodputer.get_order()

        #remove token from data, but use it in sha1-digest
        msg = "{}{}{}{}".format(data['name'], data['total'],data['token'], pin)
        digest = hashlib.sha512(msg).hexdigest()
        data['signature'] = digest
        

        payload = json.dumps(data)
        ret = None
        try:
            print "PAYLOAD is: ", payload
            resp = urllib2.urlopen(URL, payload)
            print "resp info", resp.info()
            txt = resp.read()
            print "JSON is: ", txt
            ret = json.loads(txt)
            
        except (urllib2.URLError, urllib2.HTTPError), e:
            putil.trace("could not contact hal!!")
            self.alive = False
            self.pincheck.handle_fail(e)
Example #5
0
    def draw_cart(self, surface):
        yoffset = 200
        xoffset = 250
        self.large_txt(surface, "Cart:", (xoffset, yoffset))
        yoffset += self.large_font.get_linesize()
        cart = Foodputer.get_cart()
        if not cart:
            return
        total = 0
        xoffset2 = 450
        for k in cart.keys():
            tup = cart[k]
            item = tup[0]
            cnt = tup[1]
            total += cnt * item.price
            txt = "{} stk {} a".format(cnt, item.name)           
            self.small_txt(surface, txt, (xoffset, yoffset))
            txt = "{}{}".format(" " if item.price < 10 else "", "%0.2f" % item.price)
            self.small_txt(surface, txt , (xoffset2, yoffset))
            yoffset += self.small_line


        line = self.large_font.render("TOTAL        %0.2f" % total, 1, green)
        surface.blit(line, (xoffset, 500))
Example #6
0
# SETTINGS
# TODO FULLSCREEN = 0
W = 800
H = 600

BG = (0, 0, 0)

pygame.init()

# vars
surface = pygame.display.set_mode((W, H))
clock = pygame.time.Clock()


Foodputer.set_state(State.start)
GUI.set_state(GUI.start)


def valid_id_char(s):
    return s.isalnum() or "-" in s


def quit():
    print "bye bye"
    sys.exit(0)


walltime = 0
strbuf = ""
running = 1
Example #7
0
 def handle_pin(self, str):
     putil.trace("shop smart, shop k-mart")
     Pin_check.pin = str
     Foodputer.set_state(pin_check)
Example #8
0
 def handle_fail(self, e):
     GUI.hal_error(e)
     Foodputer.set_state(start)
Example #9
0
 def handle_rfid(self, str):
     putil.trace("Velcome user")
     rfid_check.nr = str
     Foodputer.set_state(rfid_check)
Example #10
0
 def handle_abort(self):
     Foodputer.set_state(start)
     GUI.abort()
Example #11
0
 def handle_undo(self):
     Foodputer.undo()