/* diversity-nmea-backend - * * Copyright 2008 OpenMoko, Inc. * Authored by Chia-I Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include "diversity-nmea-backend.h" #include "diversity-nmea.h" static struct { DiversityWorld *world; DiversityNmea *nmea; gboolean fix; } nmea; static void on_gprmc(DiversityNmea *dnmea, gboolean fix, gdouble lon, gdouble lat) { DiversityBard *self; self = diversity_world_get_self(nmea.world); if (fix) { diversity_object_geometry_set(DIVERSITY_OBJECT(self), lon, lat, 0.0, 0.0); if (!nmea.fix) { nmea.fix = TRUE; diversity_object_set_accuracy(DIVERSITY_OBJECT(self), DIVERSITY_OBJECT_ACCURACY_DIRECT); } } else if (nmea.fix) { nmea.fix = FALSE; diversity_object_set_accuracy(DIVERSITY_OBJECT(self), DIVERSITY_OBJECT_ACCURACY_NONE); } } int nmea_init(DiversityWorld *world, GError **error) { DiversityBard *self; if (!g_thread_supported()) g_thread_init(NULL); nmea.world = world; g_object_ref(world); self = diversity_world_get_self(world); nmea.fix = FALSE; nmea.nmea = diversity_nmea_new(); g_signal_connect(nmea.nmea, "gprmc", G_CALLBACK(on_gprmc), NULL); diversity_bard_add_equipment(self, DIVERSITY_EQUIPMENT(nmea.nmea)); return TRUE; } void nmea_fini(void) { if (nmea.nmea) { g_object_unref(G_OBJECT(nmea.nmea)); nmea.nmea = NULL; } if (nmea.world) { g_object_unref(G_OBJECT(nmea.world)); nmea.world = NULL; } }