11 class GPSObject ( gobject.GObject ) :
13 def __init__ ( self , widget=None ) :
14 gobject.GObject.__init__( self )
17 self.control = location.GPSDControl.get_default()
18 # properties : maincontext_pointer preferred_interval preferred_method
19 self.method = location.METHOD_GNSS
21 self.gps_state = False
22 self.gps_info = "NO_FIX 0 0 NaN NaN NaN NaN NaN NaN NaN"
23 self.update_handler = None
24 self.satellites = None
29 def set_method ( self , method="gps" ) :
31 self.method = location.METHOD_GNSS | location.METHOD_AGNSS
33 self.method = location.METHOD_GNSS
35 def set_interval ( self , interval="1" ) :
37 self.interval = location.INTERVAL_1S
38 elif interval == "2" :
39 self.interval = location.INTERVAL_2S
40 elif interval == "5" :
41 self.interval = location.INTERVAL_5S
42 elif interval == "10" :
43 self.interval = location.INTERVAL_10S
44 elif interval == "20" :
45 self.interval = location.INTERVAL_20S
46 elif interval == "30" :
47 self.interval = location.INTERVAL_30S
48 elif interval == "60" :
49 self.interval = location.INTERVAL_60S
50 elif interval == "120" :
51 self.interval = location.INTERVAL_120S
53 def do_start ( self ) :
55 self.control.set_properties(preferred_method=self.method)
56 self.device = location.GPSDevice()
57 if self.update_handler :
59 hildon.hildon_banner_show_information( self._parent , "icon_path" , "GPS already started" )
61 self.update_handler = self.device.connect_object("changed", GPSObject.do_update , self)
64 # FIXME : Stopping does not work, at least while getting fix
65 def do_stop ( self ) :
66 if self.update_handler :
67 # FIXME : Is this removal OK?
68 del self.update_handler
69 self.update_handler = None
73 def do_update ( self ) :
76 if self.device.status == location.GPS_DEVICE_STATUS_NO_FIX :
77 # if self.gps_state == "FIX" or self.gps_state == "DGPS" :
79 # banner = hildon.hildon_banner_show_information( self._parent , "icon_path" , "Lost GPS fix" )
80 # banner.set_timeout( 1500 )
81 self.gps_state = "NO_FIX"
82 elif self.device.status == location.GPS_DEVICE_STATUS_FIX :
83 # if self.gps_state == "NO_FIX" :
85 # banner = hildon.hildon_banner_show_information( self._parent , "icon_path" , "Got GPS fix" )
86 # banner.set_timeout( 1500 )
87 self.gps_state = "FIX"
89 self.refresh_infowin()
90 elif self.device.status == location.GPS_DEVICE_STATUS_DGPS_FIX :
91 # if self.gps_state == "NO_FIX" :
93 # banner = hildon.hildon_banner_show_information( self._parent , "icon_path" , "Got differential GPS fix" )
94 # banner.set_timeout( 1500 )
95 self.gps_state = "DGPS"
97 self.gps_info = "%s %d %d %s %s %s %s %s %s %s" % ( self.gps_state , self.device.satellites_in_use , self.device.satellites_in_view , self.device.fix[2] , self.device.fix[4] , self.device.fix[5] , self.device.fix[7] , self.device.fix[9] , self.device.fix[11] , self.device.fix[13] )
98 self.satellites = self.device.satellites
99 self.cell_info = self.device.cell_info
103 # banner = hildon.hildon_banner_show_information( self._parent , "icon_path" , "GPS info : %s" % self.gps_info )
104 # banner.set_timeout( 300 )
106 def set_infowin ( self , statuswin ) :
107 self.status = statuswin
109 def refresh_infowin ( self ) :
111 self.status.set_label( "%d gps" % self.ngps )
114 # mode = device.fix[0]
115 # if mode == location.GPS_DEVICE_MODE_NOT_SEEN : # This means ??
116 # print "mode is NOSEEN"
117 # if mode == location.GPS_DEVICE_MODE_NO_FIX : # This implies device.status == location.GPS_DEVICE_STATUS_NO_FIX
118 # # and probably device.fix[1] == location.GPS_DEVICE_NONE_SET
119 # print "mode is NOFIX"
120 # if mode == location.GPS_DEVICE_MODE_2D :
122 # if mode == location.GPS_DEVICE_MODE_3D :
125 # if flags & location.GPS_DEVICE_SPEED_SET :
126 # print "GPS_DEVICE_SPEED_SET"
127 # if flags & location.GPS_DEVICE_TRACK_SET :
128 # print "GPS_DEVICE_TRACK_SET"
129 # if flags & location.GPS_DEVICE_ALTITUDE_SET :
130 # print "GPS_DEVICE_ALTITUDE_SET"
131 # if flags & location.GPS_DEVICE_CLIMB_SET :
132 # print "GPS_DEVICE_CLIMB_SET"
134 gobject.type_register(GPSObject)