Editing PyMaemo/Python-GPSbt
Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 11: | Line 11: | ||
API | API | ||
- | * | + | * gpsbt.start - establishes a new GPS connection and returns a context. This one is is used to inform stop method what connection to be ended. |
- | + | ||
- | context = gps.start() | + | context = gps.start() |
- | + | ||
- | * | + | * gpsbt.stop - ends an active connection, passed through the context. gps.stop(context) |
- | * | + | * gpsbt.gps() - the class that gets information from GPS. Through it its possible to query, get_fix, get_position, etc. |
- | * | + | * gpsbt.gps.get_fix() - fills in the 'fix' structure with GPS data. The fields are: mode, time, ept, latitude, longitude, eph, altitude (meters), epv, track (degrees from true north), speed (knots), climb (meters per second), epd, eps and epc. |
- | * | + | * gpsbt.gps.get_position() - its a shortcut to return (latitude, longitude) info. |
- | * | + | * gpsbt.gps.query() - allows user to send one letter commands to the GPS device. Its possible to group a sequence of commands to send, e.g.: |
- | ** | + | ** gpsbt.gps.query('a') fills in the altitude field of 'fix' structure |
- | ** | + | ** gpsbt.gps.query('as') fills in the altitude and speed fields |
- | * | + | * gpsbt.gps.satellites - contains a list of detected satellites, including information about usage and quality. |
== Example == | == Example == | ||
The code below shows how to connect with a GPS device, get data and close this connection: | The code below shows how to connect with a GPS device, get data and close this connection: | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | main() | + | import gpsbt |
- | + | import time | |
+ | |||
+ | def main(): | ||
+ | context = gpsbt.start() | ||
+ | |||
+ | if context == None: | ||
+ | print 'Problem while connecting!' | ||
+ | return | ||
+ | |||
+ | # ensure that GPS device is ready to connect and to receive commands | ||
+ | time.sleep(2) | ||
+ | gpsdevice = gpsbt.gps() | ||
+ | |||
+ | # read 3 times and show information | ||
+ | for a in range(4): | ||
+ | gpsdevice.get_fix() | ||
+ | time.sleep(2) | ||
+ | |||
+ | # print information stored under 'fix' variable | ||
+ | print 'Altitude: %.3f'%gpsdevice.fix.altitude | ||
+ | # dump all information available | ||
+ | print gpsdevice | ||
+ | |||
+ | # ends Bluetooth connection | ||
+ | gpsbt.stop(context) | ||
+ | |||
+ | main() | ||
+ | |||
Download source code [http://pymaemo.garage.maemo.org/documentation/python_gps_examples/gpsbt-example.py here]. | Download source code [http://pymaemo.garage.maemo.org/documentation/python_gps_examples/gpsbt-example.py here]. | ||
[[Category:Python]] | [[Category:Python]] |
Learn more about Contributing to the wiki.