예제 #1
0
    def register(self):
        if not self.__is_saved:
            response = tkMessageBox.askokcancel(
                title="Save Setup",
                message="Setup data must be saved before the registration" +
                " process can be completed. Would you like to save now?")

            if response:
                self.saveData()
            else:
                tkMessageBox.showinfo(title="Setup",
                                      message="Registration not completed.")
                return

        if not self.checkData():

            tkMessageBox.showinfo(
                title="Setup",
                message="Registration not complete.\n\nSaved data is " +
                "invalid. Please ensure that there are 3 control points and " +
                "at least 1 parking spaces marked.")
            return

        try:
            import setup_data
            reload(setup_data)
            boxes = setup_data.boxes
            if not isinstance(boxes, list): raise ValueError()
        except:
            print "ERROR: Setup data does not exist. Please run options 1 and 2 first."
            return

        try:
            import senddata
        except:
            print "ERROR: Could not import send data file."
            return

        # start fresh
        out = senddata.deregister_pi()

        try:
            out['error']
            print "ERROR: Error in connecting to server. Please update settings.py."
            return
        except:
            pass

        for box in boxes:
            if box[1] == 0:
                output = senddata.register_area(box[0])
                if "error" in output.keys():
                    if self.__is_verbose: print "ERROR:", output["error"]
                    return
                else:
                    if self.__is_verbose:
                        print "INFO: Registering area", box[0], "on server."

        # print success message
        if self.__is_verbose: print "\nINFO: Server registration successful."
예제 #2
0
    def register(self):
        """Register the Pi with the server. """
        
        # if setup hasn't been saved recently since last change, ask the if 
        # user to save first
        if not self.__is_saved:
            response = tkMessageBox.askokcancel(title = "Save Setup",
                message = "Setup data must be saved before the registration"
                + " process can be completed. Would you like to save now?")
                
            # if user selects 'yes' save the data and continue, else do not 
            # register the pi
            if response: 
                self.saveData()
            else:
                tkMessageBox.showinfo(title = "PiPark Setup",
                    message = "Registration not completed.")
                return
                
        # check that most recent saved data is valid (#CPs == 3, #Spaces > 0)
        if not self.checkData():

            # data invalid, so display message and return
            tkMessageBox.showinfo(
                title = "PiPark Setup",
                message = "Registration not complete.\n\nSaved data is "
                + "invalid. Please ensure that there are 3 control points and "
                + "at least 1 parking spaces marked."
                )
            return
                
        # attempt to import the setup data and ensure 'boxes' is a list
        try:
            import setup_data
            reload(setup_data)
            boxes = setup_data.boxes
            if not isinstance(boxes, list): raise ValueError()
        except:
            print "ERROR: Setup data does not exist. Please run options 1 and 2 first."
            return
            
        # attempt to import the server senddata module
        try:
            import senddata
        except:
            print "ERROR: Could not import send data file."
            return
        

        # deregister all areas associated with this pi (start fresh)
        out = senddata.deregister_pi()
        
        try:
            out['error']
            print "ERROR: Error in connecting to server. Please update settings.py."
            return
        except:
            pass
        
        # register each box on the server
        for box in boxes:
            if box[1] == 0:
                output = senddata.register_area(box[0])
                if "error" in output.keys():
                    if self.__is_verbose: print "ERROR:", output["error"]
                    return
                else:
                    if self.__is_verbose:
                        print "INFO: Registering area", box[0], "on server."
         
        # print success message if verbose        
        if self.__is_verbose: print "\nINFO: Server registration successful."
예제 #3
0
    def register(self):
        """Register the Pi with the server. """

        # if setup hasn't been saved recently since last change, ask the if
        # user to save first
        if not self.__is_saved:
            response = tkMessageBox.askokcancel(
                title="Save Setup",
                message="Setup data must be saved before the registration" +
                " process can be completed. Would you like to save now?")

            # if user selects 'yes' save the data and continue, else do not
            # register the pi
            if response:
                self.saveData()
            else:
                tkMessageBox.showinfo(title="PiPark Setup",
                                      message="Registration not completed.")
                return

        # check that most recent saved data is valid (#CPs == 3, #Spaces > 0)
        if not self.checkData():

            # data invalid, so display message and return
            tkMessageBox.showinfo(
                title="PiPark Setup",
                message="Registration not complete.\n\nSaved data is " +
                "invalid. Please ensure that there are 3 control points and " +
                "at least 1 parking spaces marked.")
            return

        # attempt to import the setup data and ensure 'boxes' is a list
        try:
            import setup_data
            reload(setup_data)
            boxes = setup_data.boxes
            if not isinstance(boxes, list): raise ValueError()
        except:
            print "ERROR: Setup data does not exist. Please run options 1 and 2 first."
            return

        # attempt to import the server senddata module
        try:
            import senddata
        except:
            print "ERROR: Could not import send data file."
            return

        # deregister all areas associated with this pi (start fresh)
        out = senddata.deregister_pi()

        try:
            out['error']
            print out  #debug
            print "ERROR: Error in connecting to server. Please update settings.py."
            return
        except:
            pass

        # register each box on the server
        for box in boxes:
            if box[1] == 0:
                output = senddata.register_area(box[0])
                if "error" in output.keys():
                    if self.__is_verbose: print "ERROR:", output["error"]
                    return
                else:
                    if self.__is_verbose:
                        print "INFO: Registering area", box[0], "on server."

        # print success message if verbose
        if self.__is_verbose: print "\nINFO: Server registration successful."
예제 #4
0
파일: setup.py 프로젝트: wlstks7/PiPark
def __main():
    """Main function for setup.py. Contains and handles the menu loop."""
    
    print """
--------------------------------------------------------------------------------
    
                             Setup for PiPark, 2014
    
================================================================================
    """
    
    # continually loop menu unitl user chooses 'q' to quit
    setup_image_location = "./images/setup.jpeg"
    while True:
        user_choice = __menu_choice()
        
        if user_choice == '1':
            # initialise camera and start pi camera preview
            camera = imageread.setup_camera()
            camera.start_preview()
            
            print "INFO: Setup image save location:", str(setup_image_location)
            print "INFO: Camera preview initiated."
            print ""
            
            # when user presses enter, take a new setup image. Then ask the user to confirm or
            # reject the image. If image is rejected, take a new image.
            while True:
                raw_input("When ready, press ENTER to capture setup image.")
                camera.capture(setup_image_location)
                user_input = raw_input("Accept image (y/n)? > ")
                
                if user_input.lower() in ('y', "yes"): break
                    
            # picture saved, end preview
            camera.close()
            print ""
            print "INFO: Setup image has been saved to:", str(setup_image_location)
            print "INFO: Camera preview closed."
        
        
        elif user_choice == '2':
            # check setup image exists, if not print error directing to option 1
            try:
                setup_image = Image.open(setup_image_location)
            except:
                print "ERROR: Setup image does not exist. Select option 1 to"
                print "create a new setup image."
            
            # setup image exists, so open GUI window allowing selection of spaces and
            # reference areas
            print """
When the window opens use the mouse to mark parking spaces and 3 reference
areas. Press T to toggle between marking parking spaces and reference areas and
the numbers 1 - 0 to mark new areas.
            """
            raw_input("\nPress ENTER to continue...\n")
            setup_selectarea.main(setup_image)
        
        
        elif user_choice == '3':
            # attempt to import the setup data and ensure 'boxes' is a list. If fail,
            # return to main menu prompt.
            try:
                import setup_data
                boxes = setup_data.boxes
                if not isinstance(boxes, list): raise ValueError()
            except:
                print "ERROR: Setup data does not exist. Please run options 1 and 2 first."
                continue
                
            # attempt to import the server senddata module. If fail, return to main menu
            # prompt.
            try:
                import senddata
            except:
                print "ERROR: Could not import send data file."
                continue
            
            # deregister all areas associated with this pi (start fresh)
            out = senddata.deregister_pi()
            
            try:
                out['error']
                print "ERROR: Error in connecting to server. Please update settings.py."
                continue
            except:
                pass
            
            # register each box on the server
            for box in boxes:
                if box[1] == 0:
                    senddata.register_area(box[0])
                    print "INFO: Registering area", box[0], "on server database."
                    
            print "\nRegistration complete."
        
        
        elif user_choice == '4':
            print "This will complete the setup and run the main PiPark program."
            user_input = raw_input("Continue and run the main program? (y/n) >")
            if user_input.lower in ('y', 'yes'):
                main.run_main()
                break
                                                 
        elif user_choice.lower() in ('h', "help"):
            print """
Welcome to PiPark setup, here's a quick run-through of the steps to successfully
setup your PiPark unit.
            
  1) Ensure that the PiPark unit is mounted suitable above the cark park so that
     the PiPark's camera is able to look down with a clear view upon the spaces
     that are required to be monitored.
            
  2) At the main menu prompt of this setup program enter option '1' to fine tune
     the direction of the camera so that it is clearly able to view the spaces.
     When you have finalised the position of the camera press ENTER to capture a
     setup image. If everything is correct and you do not wish to recapture the
     setup image, type 'y' or 'yes' at the prompt to continue the setup program.
     If you wish to recapture the setup image, type 'n' or 'no' at the prompt.
     
     Note: The setup image does not require the car park to be empty.

  3) Once back at the main menu prompt, enter option '2' to open up the setup
     GUI, which will open a new window allowing you to mark parking space areas
     and reference areas on the setup image that was captures as part of step 2.
     
     When the window has opened use the mouse to mark start and end corners of
     rectangles, which will represent the areas to be processed by the main
     program. To toggle between marking reference areas and parking space areas
     press 'T'. Blue areas represent parking spaces, and red areas represent
     reference areas.
     
     Currently up to ten areas can be marked, using the number keys from 1 - 0.
     There must be exactly 3 reference areas (RED) marked on the setup image
     and at least 1 parking space.
     
     When all areas have been marked on the image press 'O' to output the marked
     areas' co-ordinates to a file and close the window to continue completing
     the setup.
     
     Controls Summary:
       T -- Toggle between reference areas (RED) and parking spaces (BLUE).
       C -- Clear all marked areas.
       O -- Output the reference areas to a file.
       1 to 0 -- Change area ID numbers.

  4) The final step to completing the setup is to choose option '3' from the 
     main menu prompt. When selected the parking spaces will be registered to
     the server, and can now be viewed on the website.

  5) The setup is now complete; at the main menu prompt type 'q' or 'quit' to
     terminate the setup program. Alternatively, choose option 3 to immediately
     run the main PiPark program.
            """
            
            
        elif user_choice.lower() in ('q', "quit"):
            print ""
            break
        
        
        else:
            print "\nERROR: Invalid menu choice.\n"
예제 #5
0
def __main():
    
    
    setup_image_location = "./images/setup.jpeg"
    while True:
        user_choice = __menu_choice()
        
        if user_choice == '1':
            
            camera = imageread.setup_camera()
            camera.start_preview()
            
            print "INFO: Setup image save location:", str(setup_image_location)
            print "INFO: Camera preview initiated."
            print ""
            
            
            while True:
                raw_input("When ready, press ENTER to capture setup image.")
                camera.capture(setup_image_location)
                user_input = raw_input("Accept image (y/n)? > ")
                
                if user_input.lower() in ('y', "yes"): break
                    
            # picture saved, end preview
            camera.close()
            print ""
            print "INFO: Setup image has been saved to:", str(setup_image_location)
            print "INFO: Camera preview closed."
        
        
        elif user_choice == '2':
            
            try:
                setup_image = Image.open(setup_image_location)
            except:
                print "ERROR: Setup image does not exist. Select option 1 to"
                print "create a new setup image."
            
        
            
            raw_input("\nPress ENTER to continue...\n")
            setup_selectarea.main(setup_image)
        
        
        elif user_choice == '3':
           
            try:
                import setup_data
                boxes = setup_data.boxes
                if not isinstance(boxes, list): raise ValueError()
            except:
                print "ERROR: Setup data does not exist. Please run options 1 and 2 first."
                continue
                
            # attempt to import the server senddata module. If fail, return to main menu
            # prompt.
            try:
                import senddata
            except:
                print "ERROR: Could not import send data file."
                continue
            
            # deregister all areas associated with this pi (start fresh)
            out = senddata.deregister_pi()
            
            try:
                out['error']
                print "ERROR: Error in connecting to server. Please update settings.py."
                continue
            except:
                pass
            
            # register each box on the server
            for box in boxes:
                if box[1] == 0:
                    senddata.register_area(box[0])
                    print "INFO: Registering area", box[0], "on server database."
                    
            print "\nRegistration complete."
        
        
        elif user_choice == '4':
            print "This will complete the setup and run the main PiPark program."
            user_input = raw_input("Continue and run the main program? (y/n) >")
            if user_input.lower in ('y', 'yes'):
                main.run_main()
                break
                                                 
        elif user_choice.lower() in ('h', "help"):
        
            
            
        elif user_choice.lower() in ('q', "quit"):
            print ""
            break
        
        
        else:
            print "\nERROR: Invalid menu choice.\n"