
Originally Posted by
kenneth@hrensberg.dk
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()