From aeb8efc56ad4f2819dc319f8a1bb127a77bb890e Mon Sep 17 00:00:00 2001 From: javiplx Date: Sat, 30 Apr 2011 08:39:41 +0000 Subject: [PATCH] Global renaming and simplification, adding testing codeblock git-svn-id: file:///svnroot/wifihood/branches/cleaning@85 c51dfc6a-5949-4919-9c8e-f207a149c383 --- wifimap/gps.py | 88 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/wifimap/gps.py b/wifimap/gps.py index e83e7b1..0965bfd 100644 --- a/wifimap/gps.py +++ b/wifimap/gps.py @@ -1,22 +1,23 @@ - import location + import gobject class GPSObject ( gobject.GObject ) : - def __init__ ( self , widget=None ) : + def __init__ ( self ) : gobject.GObject.__init__( self ) - self._parent = widget - self._debug = False + self.control = location.GPSDControl.get_default() + self.control.set_properties(preferred_method=location.METHOD_GNSS, + preferred_interval=location.INTERVAL_DEFAULT) self.device = location.GPSDevice() - # properties : maincontext_pointer preferred_interval preferred_method - self.method = location.METHOD_GNSS + self.device.connect_object("changed", GPSObject.update , self) + + # Values to be set by GPSDevice changed events self.gps_state = False self.gps_info = "NO_FIX 0 0 NaN NaN NaN NaN NaN NaN NaN" - self.update_handler = None self.satellites = None self.cell_info = None self.ngps = 0 @@ -24,48 +25,43 @@ class GPSObject ( gobject.GObject ) : def set_method ( self , method="gps" ) : if method == "agps" : - self.method = location.METHOD_GNSS | location.METHOD_AGNSS + self.control.set_properties(preferred_method=location.METHOD_GNSS|location.METHOD_AGNSS) else : - self.method = location.METHOD_GNSS - - def set_interval ( self , interval="1" ) : - if interval == "1" : - self.interval = location.INTERVAL_1S - elif interval == "2" : - self.interval = location.INTERVAL_2S - elif interval == "5" : - self.interval = location.INTERVAL_5S - elif interval == "10" : - self.interval = location.INTERVAL_10S - elif interval == "20" : - self.interval = location.INTERVAL_20S - elif interval == "30" : - self.interval = location.INTERVAL_30S - elif interval == "60" : - self.interval = location.INTERVAL_60S - elif interval == "120" : - self.interval = location.INTERVAL_120S + control.set_properties(preferred_method=location.METHOD_GNSS) + + def set_interval ( self , interval=0 ) : + if interval <= 0 : + self.control.set_properties(preferred_interval=location.INTERVAL_DEFAULT) + elif interval <= 1 : + self.control.set_properties(preferred_interval=location.INTERVAL_1S) + elif interval <= 2 : + self.control.set_properties(preferred_interval=location.INTERVAL_2S) + elif interval <= 5 : + self.control.set_properties(preferred_interval=location.INTERVAL_5S) + elif interval <= 10 : + self.control.set_properties(preferred_interval=location.INTERVAL_10S) + elif interval <= 20 : + self.control.set_properties(preferred_interval=location.INTERVAL_20S) + elif interval <= 30 : + self.control.set_properties(preferred_interval=location.INTERVAL_30S) + elif interval <= 60 : + self.control.set_properties(preferred_interval=location.INTERVAL_60S) else : - self.interval = location.INTERVAL_DEFAULT + self.control.set_properties(preferred_interval=location.INTERVAL_120S) - def do_start ( self ) : - self.control.set_properties(preferred_method=self.method, - preferred_interval=self.interval) - if not self.update_handler : - self.update_handler = self.device.connect_object("changed", GPSObject.do_update , self) + def start ( self ) : + if not self.device.online : self.control.start() # FIXME : Stopping does not work, at least while getting fix - def do_stop ( self ) : - if self.update_handler : - # FIXME : Is this removal OK? - del self.update_handler - self.update_handler = None - self.control.stop() + def stop ( self ) : + if self.device.online : + self.control.stop() - def do_update ( self ) : + def update ( self ) : - if self.device : + self.state = None + if self.device.online : if self.device.status == location.GPS_DEVICE_STATUS_NO_FIX : self.gps_state = "NO_FIX" elif self.device.status == location.GPS_DEVICE_STATUS_FIX : @@ -109,3 +105,13 @@ class GPSObject ( gobject.GObject ) : gobject.type_register(GPSObject) +if __name__ == "__main__" : + loop = gobject.MainLoop() + sample = GPSObject() + print dir(sample) + def on_stop(control, mainloop): + mainloop.quit() + sample.control.connect("gpsd-stopped", on_stop, loop) + sample.start() + loop.run() + sample.stop() -- 1.7.9.5