Esempio n. 1
0
 def main(self):
     if GPIO.input(
             self.doorbutton
     ):  #if door closed button is pressed, switches off green LED and switches on red LED
         GPIO.output(self.openlight, 0)
         GPIO.output(self.closelight, 1)
         putState(self.machine, door=0)
     if GPIO.input(self.washbutton) and GPIO.input(
             self.washlight
     ):  #if it was washing finished washing button is pressed, switches off amber LED and informs firebase wash is done
         GPIO.output(self.washlight, 0)
         putState(self.machine, state=-2)
         self.washing = False
     if not self.washing:  #if its not washing, it will check firebase if door should open
         if getState(self.machine, 'door') != 0:
             GPIO.output(self.closelight, 0)
             GPIO.output(self.openlight, 1)
         else:  #check firebase if washing should begin and updates wash time to users
             GPIO.output(self.openlight, 0)
             GPIO.output(self.closelight, 1)
             if getState(self.machine, 'state') == -1:
                 GPIO.output(self.washlight, 1)
                 for student in getState(self.machine, 'studentid'):
                     machineid, endtime = getData(student,
                                                  ['machineid', 'endtime'])
                     for machine in range(len(machineid)):
                         if machineid[machine] == self.machine:
                             endtime[machine] = time() + washTime
                     putData(student, endtime=endtime)
                     self.washing = True
Esempio n. 2
0
 def checks(
     self, instance
 ):  #checks if all doors are closed (if not, go to the close door screen) and checks if pooling time does not exceed timeOut (start wash once exceeds)
     if getWash(timeOut) != None:
         putState(getWash(timeOut), state=-1)
     if getDoor() != None:
         return self.door(instance)
     else:
         return self.closed(instance)
Esempio n. 3
0
 def login(self, instance):
     if verify(self.ut.text,
               Hash(self.pt.text)):  #if userID and passwords match
         weight, machineid, endtime = getData(
             self.ut.text, ['weight', 'machineid', 'endtime'
                            ])  #gets current wash info of the user
         timing, studentid = getState(
             globalMachine,
             ['state', 'studentid'
              ])  #gets current userids and state of washing machine
         if weight == None:  #if user has no current washes
             weight = [globalWeight]
             machineid = [globalMachine]
             if timing == 0:  #of no laudry in the machine, puts time of putting laundry
                 endtime = [time() + washTime + timeOut]
             else:  #uses the first user's time of putting laundry
                 endtime = [timing + washTime + timeOut]
         else:  #adds new wash info to current washes
             weight += [globalWeight]
             machineid += [globalMachine]
             if timing == 0:
                 endtime += [time() + washTime + timeOut]
             else:
                 endtime += [timing + washTime + timeOut]
         if studentid == None:  #if machine is empty, create the user list
             studentid = [self.ut.text]
         else:  #add user info to user list
             studentid += [self.ut.text]
         putData(self.ut.text,
                 weight=weight,
                 machineid=machineid,
                 endtime=endtime,
                 debt=globalCost,
                 pmstate=0)  #updates users data to firebase
         if globalState == -1:  #if last user (washing machine starts wash immediately after this user), updates info accordingly
             putState(globalMachine,
                      door=1,
                      state=-1,
                      weight=globalWeight,
                      studentid=studentid)
         elif getState(
                 globalMachine, 'state'
         ) == 0:  #if first user, puts time of putting laundry and updates info accordingly
             putState(globalMachine,
                      door=1,
                      state=time(),
                      weight=globalWeight,
                      studentid=studentid)
         else:  #if neither, keeps first user timing and updates rest of info accordingly
             putState(globalMachine,
                      door=1,
                      weight=globalWeight,
                      studentid=studentid)
         global globalState
         globalState = timing
         self.manager.current = 'wash'
     else:
         self.ut.text = ''
         self.pt.text = ''
         self.fail.text = 'Incorrect User ID or Password'
Esempio n. 4
0
 def signup(self, instance):
     if not (self.ut.text.isdigit()
             and len(self.ut.text) == 7):  #checks validity of student ID
         self.fail.text = 'Invalid Student ID'
         self.ut.text = ''
         self.ut.focus = True
     elif self.ut.text in getUsers(
     ):  #checks if student ID is already in system
         self.fail.text = 'Student ID already in use, please choose another'
         self.ut.text = ''
         self.ut.focus = True
     elif self.pt.text != self.cpt.text:  #checks for matching passwords
         self.fail.text = 'Passwords do not match'
         self.pt.text = ''
         self.cpt.text = ''
         self.pt.focus = True
     elif not (self.ct.text.isdigit()
               and len(self.ct.text) == 8):  #checks validity of hp number
         self.fail.text = 'Invalid Handphone Number'
         self.ct.focus = True
     elif self.ct.text == '':  #checks for empty fields
         self.fail.text = 'Please key in your Handphone Number\nso we can contact you for laundry collection'
         self.ct.focus = True
     elif self.ut.text == '':
         self.fail.text = 'Please key in your User ID'
         self.ut.focus = True
     elif self.pt.text == '':
         self.fail.text = 'Please key in your password'
         self.pt.focus = True
     else:
         createUser(self.ut.text, Hash(self.pt.text),
                    int(self.ct.text))  #creates the user on firebase
         timing, studentid = getState(globalMachine, ['state', 'studentid'])
         weight = [globalWeight]
         machineid = [globalMachine]
         if timing == 0:
             endtime = [time() + washTime + timeOut]
         else:
             endtime = [timing + washTime + timeOut]
         if studentid == None:
             studentid = [self.ut.text]
         else:
             studentid += [self.ut.text]
         putData(self.ut.text,
                 weight=weight,
                 machineid=machineid,
                 endtime=endtime,
                 debt=globalCost)
         if globalState == -1:
             putState(globalMachine,
                      door=1,
                      state=-1,
                      weight=globalWeight,
                      studentid=studentid)
         elif getState(globalMachine, 'state') == 0:
             putState(globalMachine,
                      door=1,
                      state=time(),
                      weight=globalWeight,
                      studentid=studentid)
         else:
             putState(globalMachine,
                      door=1,
                      weight=globalWeight,
                      studentid=studentid)
         self.manager.current = 'contactbot'
Esempio n. 5
0
 def login(self, instance):
     if verify(self.ut.text, Hash(self.pt.text)):
         weight, machineid, endtime = getData(
             self.ut.text, ['weight', 'machineid', 'endtime'])
         if weight == None:  #if wash info is empty
             global globalState
             globalState = 'You do not have any laundry to collect'
             self.manager.current = 'nocollect'
             return None
         else:
             machinels = []
             for machine in range(len(machineid)):
                 if getState(machineid[machine], 'state') == -2:
                     machinels.append(machine)
             if machinels == []:  #if none of the washing machines the user has laundry in is ready
                 global globalState
                 globalState = 'Your laundry is not ready for collection'
                 self.manager.current = 'nocollect'
                 return None
             weightls = []
             machineidls = []
             for machine in sorted(
                     machinels, reverse=True
             ):  #removed ready wash data and puts it into new lists
                 weightls.append(weight.pop(machine))
                 machineidls.append(machineid.pop(machine))
                 endtime.pop(machine)
             putData(self.ut.text,
                     machineid=machineid,
                     weight=weight,
                     endtime=endtime
                     )  #returns not ready wash data back to firebase
             for machine in range(
                     len(machineidls)
             ):  #uses ready wash data to update washing machine status
                 studentid = getState(machineidls[machine], 'studentid')
                 try:
                     studentid.remove(self.ut.text)
                 except ValueError:
                     pass
                 if getState(machineidls[machine],
                             'weight') - weightls[machine] < 0.001:
                     putState(machineidls[machine],
                              door=1,
                              state=0,
                              weight=-weightls[machine],
                              studentid=studentid)
                 else:
                     putState(machineidls[machine],
                              door=1,
                              weight=-weightls[machine],
                              studentid=studentid)
             global globalMachine
             globalMachine = list(
                 set(machineidls)
             )  #puts list of washing machines with user's laundry ready for collection
             self.manager.current = 'collect'
     else:
         self.ut.text = ''
         self.pt.text = ''
         self.fail.text = 'Incorrect User ID or Password'