#!/usr/bin/perl -w use strict; use Gtk2 '-init'; use Glib qw/TRUE FALSE/; use GPS::NMEA; use threads; use threads::shared; my $notebook; my $gps_entry; my $gps_start:shared = 0; my $die:shared = 0; my($ns,$lat,$ew,$lon):shared; my $gps_current; ###################################################################### +############################# #start threads my $thread_gps = threads->new( \&gps); ###################################################################### +############################# #timeouts my $timer_gps = Glib::Timeout->add(100, \&gps_position); ###################################################################### +############################# #create window my $window = Gtk2::Window->new('toplevel'); $window->signal_connect(delete_event=> sub {$die = 1; $thread_gps->joi +n; Gtk2->main_quit}); $window->set_title("GPS Test"); #create notebook $notebook = Gtk2::Notebook->new; $notebook->set_tab_pos('top'); my $gps_table = Gtk2::Table->new(3, 2, FALSE); #GPS Group (for all users) my $gps_instruction = Gtk2::Label->new(); $gps_instruction->set_markup( '<span size="small">Enter the location o +f the GPS device (i.e. "COM4" or "/dev/lao")</span>'); my $gps_label = Gtk2::Label->new( 'Location'); $gps_current = Gtk2::Label->new; $gps_entry = Gtk2::Entry->new(); $gps_entry->set_text("COM4"); my $start_stop = Gtk2::Button->new("Start"); $gps_table->attach_defaults($gps_instruction, 0, 2, 0, 1); $gps_table->attach_defaults($gps_label, 0, 1, 1, 2); $gps_table->attach_defaults($gps_entry, 1, 2, 1, 2); $gps_table->attach_defaults($start_stop, 0, 1, 2, 3); $gps_table->attach_defaults($gps_current, 1, 2, 2, 3); #start and stop GPS device $start_stop->signal_connect('clicked' => sub {if ( $start_stop->get_la +bel eq "Start") {$start_stop->set_label("Stop"); $gps_start = 1; pri +nt "$gps_start\n";} else {$start_stop->set_label("Start"); $gps_start + = 0; print "$gps_start\n";}}); $notebook->append_page($gps_table, "GPS"); #add widgets $window->add($notebook); $window->show_all; Gtk2->main; ###################################################################### +############################## #GPS Thread sub gps{ while (1) { #If program ends stop the loop goto END if $die == 1; if ($gps_start == 1) { #start the GPS Device my $gps_device = GPS::NMEA->new(Port => 'COM4', Baud => 4800); print "$gps_device\n"; #start the loop for (;;) { #stops the warnings in the GPS device module local $^W = 0; ($ns,$lat,$ew,$lon) = $gps_device->get_position; print "$gps_device\n"; goto END if $die == 1; last if $gps_start == 0; sleep 3; } print "$gps_device\n"; #undef $gps_device; } else {sleep 4} } END: } ###################################################################### +############################## #GPS position timeout sub gps_position{ #set the current GPS position $gps_current->set_label("$ns $lat, $ew $lon") if $gps_start == 1 and + defined($ns); $gps_current->set_label("N/A") if $gps_start == 0; return 1; }
In reply to GPS Widget by deadpickle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |