For whatever reason, using GPS is a pain. The real breakthrough was in having the app catch exceptions and then trow them away and try again. I blame the poor implementation of serial port over bluetooth as well as the inexcusable lack of a working Bluetooth intermediate driver for smartphones. There are only a few things you cannot do without a stylus, and there is no need to require those sorts of things to change system settings.
Anyway, here's a small app that gives you lat/lon when you run it and hit the right soft key. status is a label covering the whole screen.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace GPSmkII
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public bool Parse(string sentence)
{
switch(sentence.Split(',')[0]) {
case "$GPRMC":
return parseLocation(sentence);
default:
return false;
}
}
public bool parseLocation(string sentence)
{
string[] words = sentence.Split(',');
if ((words[3] != "" && words[4] != "") && (words[5] != "" && words[6] != ""))
{
double lat = Convert.ToDouble(words[3].Substring(0, 2));
lat += Convert.ToDouble(words[3].Substring(2)) / 60.0;
double lon = Convert.ToDouble(words[5].Substring(0, 3));
lon += Convert.ToDouble(words[5].Substring(3)) / 60.0;
status.Text += "Lat: " + lat + '\n';
status.Text += "Lon: " + lon + '\n';
return true;
}
return false;
}
private void menuItem2_Click(object sender, EventArgs e)
{
while (true)
{
try
{
SerialPort sp1 = new SerialPort("COM8");
sp1.Open();
sp1.ReadTimeout = 2000;
while (!Parse(sp1.ReadLine()))
{ }
return;
}
catch (Exception ex)
{
status.Text += ex.Message + '\n';
}
}
}
private void menuItem1_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
Showing posts with label mobilelab. Show all posts
Showing posts with label mobilelab. Show all posts
Saturday, February 16, 2008
Tuesday, February 5, 2008
Useful Linkage
For Paparazzi and anyone using the camera (including QR codes):
http://blogs.msdn.com/marcpe/archive/2006/03/03/542941.aspx
It successfully operates in the background. The next step is to wire it into a communication server so that it will take pictures on demand.
http://www.flash.0tutor.com/archive/128/Actionscript-dynamic-load-image-into-flash.shtml
A tutorial on dynamically loading images into Flash. Flash Lite supports this as of 2.0, and I suspect the functions are all the same.
I dare y'all to beat me to a Flash camera app
Edit: Too late! Sorta. I cut out the uploading portion of the TimedCamera app and set the interval to 1sec. Then I made a Flash file a second long with a couple lines of script
http://blogs.msdn.com/marcpe/archive/2006/03/03/542941.aspx
It successfully operates in the background. The next step is to wire it into a communication server so that it will take pictures on demand.
http://www.flash.0tutor.com/archive/128/Actionscript-dynamic-load-image-into-flash.shtml
A tutorial on dynamically loading images into Flash. Flash Lite supports this as of 2.0, and I suspect the functions are all the same.
I dare y'all to beat me to a Flash camera app
Edit: Too late! Sorta. I cut out the uploading portion of the TimedCamera app and set the interval to 1sec. Then I made a Flash file a second long with a couple lines of script
this.createEmptyMovieClip("canvas_mc", 10);
canvas_mc.loadMovie("flowers.jpg");
Wednesday, January 23, 2008
First of many
In class, I started a small Flash chat client and C# chat server.
It serves as a quick intro to Flash textfields, buttons, and XML sockets. It also brings up the issue that sometimes Flash Lite handles UI elements differently from desktop Flash. On the phone and in Device Central, the input text fields only send out "onChanged" events when you hit enter. On the desktop flash player, that same text field "changes" after every character you type.
As an added bonus, it's also an introduction to socket communication and threading in C#. The server runs on either the phone or the computer (M$ can do some things right). The server doesn't really do much when someone leaves the chat, but I "handle" the exception. Also, it will screw up if the incoming message (the whole XML doc) is larger than 256 bytes. Be terse.
Click here for the file.
It serves as a quick intro to Flash textfields, buttons, and XML sockets. It also brings up the issue that sometimes Flash Lite handles UI elements differently from desktop Flash. On the phone and in Device Central, the input text fields only send out "onChanged" events when you hit enter
As an added bonus, it's also an introduction to socket communication and threading in C#. The server runs on either the phone or the computer (M$ can do some things right). The server doesn't really do much when someone leaves the chat, but I "handle" the exception. Also, it will screw up if the incoming message (the whole XML doc) is larger than 256 bytes. Be terse.
Click here for the file.
Subscribe to:
Posts (Atom)