Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Threading;
- using Microsoft.SPOT;
- using Microsoft.SPOT.Presentation;
- using Microsoft.SPOT.Presentation.Controls;
- using Microsoft.SPOT.Presentation.Media;
- using Microsoft.SPOT.Touch;
- using Gadgeteer.Networking;
- using GT = Gadgeteer;
- using GTM = Gadgeteer.Modules;
- using Gadgeteer.Modules.GHIElectronics;
- using Gadgeteer.Modules.Seeed;
- namespace Gadgeteer_DD02_Oled_GPS_01
- {
- public partial class Program
- {
- // create a program wide variable switch
- // has the gps worked out the position yet?
- bool postionCalculated = false;
- // create a font that we can use on the oled display screen
- Font displayFont = Resources.GetFont(Resources.FontResources.NinaB);
- // This method is run when the mainboard is powered up or reset.
- void ProgramStarted()
- {
- /*******************************************************************************************
- Modules added in the Program.gadgeteer designer view are used by typing
- their name followed by a period, e.g. button. or camera.
- Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
- button.ButtonPressed +=<tab><tab>
- If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
- GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
- timer.Tick +=<tab><tab>
- timer.Start();
- *******************************************************************************************/
- // create a gps new postion recieved event handling robot
- gps.PositionReceived += new GPS.PositionReceivedHandler(gps_PositionReceived);
- // create a gps new NMEA signal recieved event handling robot
- gps.NMEASentenceReceived += new GPS.NMEASentenceReceivedHandler(gps_NMEASentenceReceived);
- // stop the oled display redrawing every time we add a graphic element to the screen memory
- oledDisplay.SimpleGraphics.AutoRedraw = false;
- // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
- Debug.Print("Program Started");
- }
- void gps_NMEASentenceReceived(GPS sender, string nmeaSentence)
- {
- // the gps has recieved another message from a satellite! (or maybe it is a nearby ship?)
- // have we calculated the postion yet?
- // if we have then stop printing the NMEA messages
- if (postionCalculated == false)
- {
- // print the NMEA message just for fun
- Debug.Print(nmeaSentence);
- // jump out of the event handler to free it up
- // print the message to the oled display
- processNMEAMessage(nmeaSentence);
- }
- }
- void gps_PositionReceived(GPS sender, GPS.Position position)
- {
- // the gps has recieved enough information and the first position has been calculated!
- Debug.Print(position);
- // flick the switch to note that the position has now been calculated and to stop showing NMEA messages
- postionCalculated = true;
- // jump out of the event handler to free it up
- // send the message to be processed and sent to the oled display screen
- processGPSMessage(position);
- }
- void processNMEAMessage(string recievedMessage)
- {
- // clear the oled display screen memory of graphics
- oledDisplay.SimpleGraphics.Clear();
- // write the message to the display screen
- printOledDisplay(1, recievedMessage);
- // write part of the message to the the next line on the screen?
- // careful as it will crash if the message is shorter than you think
- //printOledDisplay(2, recievedMessage.Substring(15, 15));
- // redraw the screen with all new graphics
- oledDisplay.SimpleGraphics.Redraw();
- }
- void processGPSMessage(string recievedMessage)
- {
- // clear the oled display screen memory of graphics
- oledDisplay.SimpleGraphics.Clear();
- // write the message to the display screen
- // cut out the first part of the message
- // Indexof give the position of a word and Substring gives the letters between two numbers from a text string
- printOledDisplay(1, recievedMessage.Substring(0, recievedMessage.IndexOf("Long ")));
- // cut out the second part of the message
- printOledDisplay(2, recievedMessage.Substring(recievedMessage.IndexOf("Long "), recievedMessage.IndexOf("Speed ") - recievedMessage.IndexOf("Long ")));
- // cut out the third part of the message
- printOledDisplay(3, recievedMessage.Substring(recievedMessage.IndexOf("Speed "), recievedMessage.IndexOf("Course ") - recievedMessage.IndexOf("Speed ")));
- // leave out the forth part of the message
- // cut out the ast part if the fifth part of the message
- printOledDisplay(4, recievedMessage.Substring(recievedMessage.IndexOf("2013 ") + 5));
- // redraw the screen with all new graphics
- oledDisplay.SimpleGraphics.Redraw();
- }
- // a custom method for printing text to the OLED screen
- // input a line number and the text to be printed as a text string
- void printOledDisplay(uint lineNumber, string displayMessage)
- {
- uint xPos = 0;
- oledDisplay.SimpleGraphics.DisplayText(displayMessage, displayFont, GT.Color.White, xPos, lineNumber * 12);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment