/* Copyright 2010 GHI Electronics LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using GHIElectronics.NETMF.FEZ; using GHIElectronics.NETMF.USBClient; using System.Collections; using System.Text; using Fez.IO; using System.Reflection; using System.IO.Ports; namespace CdcPlusDebugger { public class Program { static FezTermHost term; static AutoResetEvent are = new AutoResetEvent(false); static FEZ_Components.Piezo speaker = new FEZ_Components.Piezo(FEZ_Pin.PWM.Di5); static readonly byte newLine = 255; static FEZ_Components.Button myButton; public static void Main() { myButton = new FEZ_Components.Button(FEZ_Pin.Interrupt.Di4); myButton.ButtonPressEvent +=new FEZ_Components.Button.ButtonPressEventHandler(myButton_ButtonPressEvent); term = new FezTermHost(newLine); term.MessageReceived += new MessageFunc(term_MessageReceived); term.Stopped += new Action(term_Stopped); term.Start(); // Stopped event will set are. are.WaitOne(); Debug.Print("Main exited."); } static void myButton_ButtonPressEvent(FEZ_Pin.Interrupt pin, FEZ_Components.Button.ButtonState state) { speaker.Play(5000, 300); } static void term_Stopped() { are.Set(); } static void term_MessageReceived(string value) { if (value == null) return; string result = HandleCommands(value); if (result == "bye") { term.WriteMessage("bye"); term.Stop(); return; } else { term.WriteMessage(result); } } static string HandleCommands(string cmd) { string lcmd = cmd.ToLower(); switch (lcmd) { case "exit": return "bye"; case "v": case "ver": return Assembly.GetExecutingAssembly().FullName; case "time": return DateTime.Now.ToString(); case "?": case "h": case "help": return GetHelp(); case "info": return GetSystemInfo(); case "beephigh": speaker.Play(8000, 500); return "OK"; case "beeplow": case "beep": speaker.Play(3000, 500); return "OK"; case "btnleft": speaker.Play(4000, 500); return "OK"; case "btnright": speaker.Play(6000, 500); return "OK"; case "ping": return "reply from FezTermHost."; case "dir": case "ls": return GetDir(); case "xbee": XBeeSend(); return "OK"; default: return "'" + cmd + "' is not recognized as in internal or external command."; } } // Just a simulation listing. static string GetDir() { string list = @" Volume in drive C is OS Volume Serial Number is 3895-9268 Directory of C:\Program Files (x86)\GHI Electronics\GHI NETMF v4.1 SDK 10/15/2010 10:33 PM