8 class GPSObject ( gobject.GObject ) :
10 def __init__ ( self , widget=None ) :
11 gobject.GObject.__init__( self )
14 self.control = location.GPSDControl.get_default()
15 # properties : maincontext_pointer preferred_interval preferred_method
16 self.method = location.METHOD_GNSS
18 self.gps_state = False
20 self.update_handler = None
21 self.satellites = None
26 def set_method ( self , method="gps" ) :
28 self.method = location.METHOD_GNSS | location.METHOD_AGNSS
30 self.method = location.METHOD_GNSS
32 def set_interval ( self , interval="1" ) :
34 self.interval = location.INTERVAL_1S
35 elif interval == "2" :
36 self.interval = location.INTERVAL_2S
37 elif interval == "5" :
38 self.interval = location.INTERVAL_5S
39 elif interval == "10" :
40 self.interval = location.INTERVAL_10S
41 elif interval == "20" :
42 self.interval = location.INTERVAL_20S
43 elif interval == "30" :
44 self.interval = location.INTERVAL_30S
45 elif interval == "60" :
46 self.interval = location.INTERVAL_60S
47 elif interval == "120" :
48 self.interval = location.INTERVAL_120S
50 def do_start ( self ) :
52 self.control.set_properties(preferred_method=self.method)
53 self.device = location.GPSDevice()
54 if self.update_handler :
55 hildon.hildon_banner_show_information( self._parent , "icon_path" , "GPS already started" )
57 self.update_handler = self.device.connect_object("changed", GPSObject.do_update , self)
60 # FIXME : Stopping does not work, at least while getting fix
61 def do_stop ( self ) :
62 if self.update_handler :
63 # FIXME : Is this removal OK?
64 del self.update_handler
65 self.update_handler = None
69 def do_update ( self ) :
72 if self.device.status == location.GPS_DEVICE_STATUS_NO_FIX :
73 # if self.gps_state == "FIX" or self.gps_state == "DGPS" :
74 # banner = hildon.hildon_banner_show_information( self._parent , "icon_path" , "Lost GPS fix" )
75 # banner.set_timeout( 1500 )
76 self.gps_state = "NO_FIX"
77 elif self.device.status == location.GPS_DEVICE_STATUS_FIX :
78 # if self.gps_state == "NO_FIX" :
79 # banner = hildon.hildon_banner_show_information( self._parent , "icon_path" , "Got GPS fix" )
80 # banner.set_timeout( 1500 )
81 self.gps_state = "FIX"
83 self.refresh_infowin()
84 elif self.device.status == location.GPS_DEVICE_STATUS_DGPS_FIX :
85 # if self.gps_state == "NO_FIX" :
86 # banner = hildon.hildon_banner_show_information( self._parent , "icon_path" , "Got differential GPS fix" )
87 # banner.set_timeout( 1500 )
88 self.gps_state = "DGPS"
90 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] )
91 self.satellites = self.device.satellites
92 self.cell_info = self.device.cell_info
95 # banner = hildon.hildon_banner_show_information( self._parent , "icon_path" , "GPS info : %s" % self.gps_info )
96 # banner.set_timeout( 300 )
98 def set_infowin ( self , statuswin ) :
99 self.status = statuswin
101 def refresh_infowin ( self ) :
102 self.status.set_label( "%d gps" % self.ngps )
105 # mode = device.fix[0]
106 # if mode == location.GPS_DEVICE_MODE_NOT_SEEN : # This means ??
107 # print "mode is NOSEEN"
108 # if mode == location.GPS_DEVICE_MODE_NO_FIX : # This implies device.status == location.GPS_DEVICE_STATUS_NO_FIX
109 # # and probably device.fix[1] == location.GPS_DEVICE_NONE_SET
110 # print "mode is NOFIX"
111 # if mode == location.GPS_DEVICE_MODE_2D :
113 # if mode == location.GPS_DEVICE_MODE_3D :
116 # if flags & location.GPS_DEVICE_SPEED_SET :
117 # print "GPS_DEVICE_SPEED_SET"
118 # if flags & location.GPS_DEVICE_TRACK_SET :
119 # print "GPS_DEVICE_TRACK_SET"
120 # if flags & location.GPS_DEVICE_ALTITUDE_SET :
121 # print "GPS_DEVICE_ALTITUDE_SET"
122 # if flags & location.GPS_DEVICE_CLIMB_SET :
123 # print "GPS_DEVICE_CLIMB_SET"
125 gobject.type_register(GPSObject)