Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

A GPS tracer application for Windows Mobile CE 5

, 22 May 2007 CPOL
A simple GPS tracer developed for Windows Mobile 2005 on Compact Framework 2.0 SDK
gpstracer_demo.zip
DeviceApplication2.exe
gpstracer_src.zip
DeviceApplication2
DeviceApplication2
bin
Debug
DeviceApplication2.exe
DeviceApplication2.pdb
Release
DeviceApplication2.exe
DeviceApplication2.pdb
GpsTracer.csproj.user
obj
Debug
DeviceApplication2.csproj.GenerateResource.Cache
DeviceApplication2.exe
DeviceApplication2.Form1.resources
DeviceApplication2.pdb
DeviceApplication2.Properties.Resources.resources
GpsTracer.csproj.GenerateResource.Cache
GpsTracer.Form1.resources
GpsTracer.Properties.Resources.resources
Refactor
ResolveAssemblyReference.cache
TempPE
Properties.Resources.Designer.cs.dll
Release
DeviceApplication2.csproj.GenerateResource.Cache
DeviceApplication2.exe
DeviceApplication2.pdb
GpsTracer.csproj.GenerateResource.Cache
GpsTracer.Form1.resources
GpsTracer.Properties.Resources.resources
Refactor
ResolveAssemblyReference.cache
TempPE
Properties.Resources.Designer.cs.dll
Properties
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Windows;
using System.Threading;
using System.IO.Ports;
using System.IO;
using GpsTracer;


namespace GpsTracer
{

    public partial class Form1 : Form
    {

        private reader m_rTh;
        private Mapper m_mapper;
        private Graphics m_graphics;
        private bool m_isDemoMode = false;
        private String m_port = "COM5";
        private bool m_isRunning = false;
        private bool m_log = false;
        private StreamWriter m_logSW;

        public Form1()
        {
            InitializeComponent();
            m_graphics = this.CreateGraphics();
            m_rTh = new reader(m_port);
            m_mapper = new Mapper(m_graphics, 0, 30, 240, 300);
            m_rTh.dataReceived += new reader.DataReceivedEventHandler(parse);
            m_logSW = File.CreateText("GpsTracer.Log");
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
        }

        public void parse(String readed)
        {

            if (m_log)
            {
                m_logSW.WriteLine(readed);
                m_logSW.Flush();
            }

            m_mapper.parseAndDraw(readed);


        }

        private void menuItemRunStop_Click(object sender, EventArgs e)
        {
            if (m_isRunning)
            {
                m_rTh.stop();
            }
            else
            {
                m_rTh.start(m_isDemoMode);
            }
            menuItemRunStop.Checked = !menuItemRunStop.Checked;
            m_isRunning = !m_isRunning;
        }

        private void menuItem3_Click(object sender, EventArgs e)
        {

        }

        private void menuItem4_Click(object sender, EventArgs e)
        {
            if (m_rTh != null)
            {
                m_rTh.stop();
                Thread.Sleep(1000);
            }

            Application.Exit();
        }

        private void trackBar1_ValueChanged(object sender, EventArgs e)
        {
            if (m_mapper != null)
            {
                m_mapper.Scale = (float)trackBar1.Value;
                m_mapper.clearAndDraw();
            }
        }

        private void menuItemDemo_Click(object sender, EventArgs e)
        {
            m_isDemoMode = !m_isDemoMode;
            ((MenuItem)sender).Checked = !((MenuItem)sender).Checked;
        }

        private void menuItemLog_Click(object sender, EventArgs e)
        {
            m_log = !m_log;
            menuItemLog.Checked = !menuItemLog.Checked;
        }

        #region Panning

        private Point touch;
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (m_mapper != null)
            {
                m_mapper.moveCenter(touch.X - e.X, touch.Y - e.Y);
                m_mapper.draw();
            }
            touch.X = e.X;
            touch.Y = e.Y;
        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            touch.X = e.X;
            touch.Y = e.Y;
        }


        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            Form1_MouseMove(sender, e);
            m_mapper.clearAndDraw();
        }

        #endregion

        #region LoadSaveMenu

        private void menuItemLoadPath_Click(object sender, EventArgs e)
        {
            if (m_isRunning)
            {
                menuItemRunStop_Click(sender, e);
            }

            openFileDialog1.ShowDialog();
            
            if (openFileDialog1.FileName.Length > 0)
            {
                m_mapper.loatPath(openFileDialog1.FileName);
            }
        }

        private void menuItemSavePath_Click(object sender, EventArgs e)
        {
            if (m_isRunning)
            {
                menuItemRunStop_Click(sender, e);
            }

            saveFileDialog1.ShowDialog();
            if (saveFileDialog1.FileName.Length > 0)
            {
                m_mapper.savePath(saveFileDialog1.FileName);
            }
        }

        #endregion

        #region ComPortMenu

        private void menuItemCom1_Click(object sender, EventArgs e)
        {
            m_port = "COM1";
            comMenuItemUnchecker();
            ((MenuItem)(sender)).Checked = true;
        }

        private void menuItemCom2_Click(object sender, EventArgs e)
        {
            m_port = "COM2";
            comMenuItemUnchecker();
            ((MenuItem)(sender)).Checked = true;
        }

        private void menuItemCom3_Click(object sender, EventArgs e)
        {
            m_port = "COM3";
            comMenuItemUnchecker();
            ((MenuItem)(sender)).Checked = true;
        }

        private void menuItemCom4_Click(object sender, EventArgs e)
        {
            m_port = "COM4";
            comMenuItemUnchecker();
            ((MenuItem)(sender)).Checked = true;
        }

        private void menuItemCom5_Click(object sender, EventArgs e)
        {
            m_port = "COM5";
            comMenuItemUnchecker();
            ((MenuItem)(sender)).Checked = true;
        }

        private void comMenuItemUnchecker()
        {
            menuItemCom1.Checked = false;
            menuItemCom2.Checked = false;
            menuItemCom3.Checked = false;
            menuItemCom4.Checked = false;
            menuItemCom5.Checked = false;
        }

        #endregion

        private void menuItemCenter_Click(object sender, EventArgs e)
        {
            m_mapper.centerInTheMiddle();
        }

        }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

leonardosalvatore
Architect Giuneco http://www.giuneco.it
Italy Italy
IT is not only work, it is a hobbie, for that i post here!

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 22 May 2007
Article Copyright 2006 by leonardosalvatore
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid