×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    10

    Thread and GPS positioning

    Hi all

    I have made the code below:

    Code:
    import e32
    import thread
    import positioning
    
    def _lighton():
        while 1:
            print u"Thread called"
            e32.ao_sleep(2)
    
    def lighton():
        thread.start_new_thread(_lighton, ())
    
    
    positioning.set_requestors([{"type":"service","format":"application","data":"test_app"}])
    
    def _gps_test():
        while 1:
            gps = (positioning.position(course=1,satellites=1, callback=None, interval=positioning.POSITION_INTERVAL, partial=0))
            pos_thread = gps["position"]
            
            print u"Pos: " + str(pos_thread["latitude"]) + ", " + str(pos_thread["longitude"])
            
            e32.ao_sleep(5)
    
    def gps_test():
        thread.start_new_thread(_gps_test, ())
    
    lighton()
    _gps_test()
    Which work fine, but I also want to have the GPS call in a thread, and for that I thought it would work if i changes the last line from "_gps_test()" to "gps_test()", but it doesn't... Why?!

  2. #2
    Regular Contributor
    Join Date
    Sep 2005
    Location
    Finland, Helsinki
    Posts
    323

    Re: Thread and GPS positioning

    Quote Originally Posted by kenneth@hrensberg.dk View Post
    I have made the code below
    Looks like a mess. Forget about threads when reading gps with positioning.


    Code:
    import positioning
    import appuifw
    import e32
    
    class GpsApp:
        def __init__(self):
            self.lock = e32.Ao_lock()
            self.pos = {} 
            appuifw.app.menu = [
                (u"GPS on",self.start_read_position),
                (u"GPS off",self.stop_read_position),
                (u"print pos",self.print_position),
                (u"Close", self.lock.signal),
            ]
            appuifw.app.exit_key_handler = self.exit_key_handler
    
        def start_read_position(self):
            positioning.set_requestors([{"type":"service", 
                                         "format":"application", 
                                         "data":"test_app"}])
            positioning.position(course=1,satellites=1,
               callback=self.read_position, # <-- !!!
               interval=1000000, partial=1  # <-- !!!
            ) 
            appuifw.note(u"Starting GPS...", 'info')
    
        def stop_read_position(self):
            appuifw.note(u"Stopping GPS...", 'info')
            positioning.stop_position()
    
        def read_position(self, pos):
            """Save the latest position object to the self.pos."""
            self.pos = pos
    
        def print_position(self):
            print "Current position:", self.pos
    
        def run(self):
            self.lock.wait()
            self.exit_key_handler()
    
        def exit_key_handler(self):
            if appuifw.query(u"Quit program", 'query') is True:
                self.running = False
                self.lock.signal()
            print u"Goodbye"
    
    
    myApp = GpsApp()
    myApp.run()
    positioning.stop_position()

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    10

    Re: Thread and GPS positioning

    Oh-yeah... D'OH! Thank you...

Similar Threads

  1. Replies: 3
    Last Post: 2009-09-24, 10:34
  2. thread questions
    By docGroup14 in forum Symbian
    Replies: 11
    Last Post: 2007-10-19, 12:17
  3. Asynchronous Bluetooth GPS reading
    By conos in forum Mobile Java Networking & Messaging & Security
    Replies: 7
    Last Post: 2007-08-21, 12:46

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×