03743cdb0ba24f7cf64060b64c96b6b56f71a709
[wifihood] / wifiscanner / wifimap / gps.py
1
2
3 import location
4
5 import hildon
6 import gobject
7
8 class GPSObject ( gobject.GObject ) :
9
10     def __init__ ( self , widget=None ) :
11         gobject.GObject.__init__( self )
12         self._parent = widget
13         self._debug = False
14         self.control = location.GPSDControl.get_default()
15         # properties : maincontext_pointer preferred_interval preferred_method
16         self.method = location.METHOD_GNSS
17         self.device = None
18         self.gps_state = False
19         self.gps_info = None
20         self.update_handler = None
21         self.satellites = None
22         self.cell_info = None
23         self.ngps = 0
24         self.status = None
25
26     def set_method ( self , method="gps" ) :
27         if method == "agps" :
28             self.method = location.METHOD_GNSS | location.METHOD_AGNSS
29         else :
30             self.method = location.METHOD_GNSS
31
32     def set_interval ( self , interval="1" ) :
33         if 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
49
50     def do_start ( self ) :
51         if not self.device :
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" )
56         else :
57             self.update_handler = self.device.connect_object("changed", GPSObject.do_update , self)
58             self.control.start()
59
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
66         self.device.stop()
67         self.control.stop()
68
69     def do_update ( self ) :
70
71         if self.device :
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"
82                 self.ngps += 1
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"
89
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
93
94         #    if self._debug :
95         #        banner = hildon.hildon_banner_show_information( self._parent , "icon_path" , "GPS info : %s" % self.gps_info )
96         #        banner.set_timeout( 300 )
97
98     def set_infowin ( self , statuswin ) :
99         self.status = statuswin
100
101     def refresh_infowin ( self ) :
102         if self.status :
103             self.status.set_label( "%d gps" % self.ngps )
104
105
106 #    mode = device.fix[0]
107 #    if mode == location.GPS_DEVICE_MODE_NOT_SEEN : # This means ??
108 #        print "mode is NOSEEN"
109 #    if mode == location.GPS_DEVICE_MODE_NO_FIX : # This implies device.status == location.GPS_DEVICE_STATUS_NO_FIX
110 #                                                 # and probably device.fix[1] == location.GPS_DEVICE_NONE_SET
111 #        print "mode is NOFIX"
112 #    if mode == location.GPS_DEVICE_MODE_2D :
113 #        print "mode is 2D"
114 #    if mode == location.GPS_DEVICE_MODE_3D :
115 #        print "mode is 3D"
116
117 #    if flags & location.GPS_DEVICE_SPEED_SET :
118 #        print "GPS_DEVICE_SPEED_SET"
119 #    if flags & location.GPS_DEVICE_TRACK_SET :
120 #        print "GPS_DEVICE_TRACK_SET"
121 #    if flags & location.GPS_DEVICE_ALTITUDE_SET :
122 #        print "GPS_DEVICE_ALTITUDE_SET"
123 #    if flags & location.GPS_DEVICE_CLIMB_SET :
124 #        print "GPS_DEVICE_CLIMB_SET"
125
126 gobject.type_register(GPSObject)
127