diff --git a/Netduino.Core/EmulatorBootstrapper.cs b/Netduino.Core/EmulatorBootstrapper.cs index 3a49747..053bd32 100644 --- a/Netduino.Core/EmulatorBootstrapper.cs +++ b/Netduino.Core/EmulatorBootstrapper.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using Caliburn.Micro; using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting; @@ -10,9 +9,6 @@ using Netduino.Core.ViewModels; using Netduino.Core.Services; using System.IO; -using Microsoft.SPOT.Tasks; -using System.Xml; -using Netduino.Core.Service; namespace Netduino.Core { @@ -21,11 +17,11 @@ namespace Netduino.Core /// public class EmulatorBootstrapper : Bootstrapper { - private CompositionContainer container; + private CompositionContainer _container; static EmulatorBootstrapper() { - LogManager.GetLog = type => new Log4netLogger(type); + LogManager.GetLog = type => new Log4NetLogger(type); } /// @@ -34,25 +30,25 @@ static EmulatorBootstrapper() protected override void Configure() { - AggregateCatalog catalog = new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType()); - container = new CompositionContainer(catalog); + var catalog = new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType()); + _container = new CompositionContainer(catalog); var batch = new CompositionBatch(); batch.AddExportedValue(new WindowManager()); IEventAggregator aggregator = new EventAggregator(); - batch.AddExportedValue(aggregator); + batch.AddExportedValue(aggregator); - EmulatorService service = new EmulatorService(aggregator); - batch.AddExportedValue(service); + var emulatorService = new EmulatorService(aggregator); + batch.AddExportedValue(emulatorService); - batch.AddExportedValue(container); + batch.AddExportedValue(_container); - container.Compose(batch); + _container.Compose(batch); // Start the emulator - service.StartEmulator(); + emulatorService.StartEmulator(); } /// @@ -64,7 +60,7 @@ protected override void Configure() protected override object GetInstance(Type serviceType, string key) { string contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(serviceType) : key; - var exports = container.GetExportedValues(contract); + var exports = _container.GetExportedValues(contract); if (exports.Count() > 0) return exports.First(); @@ -74,12 +70,12 @@ protected override object GetInstance(Type serviceType, string key) protected override IEnumerable GetAllInstances(Type serviceType) { - return container.GetExportedValues(AttributedModelServices.GetContractName(serviceType)); + return _container.GetExportedValues(AttributedModelServices.GetContractName(serviceType)); } protected override void BuildUp(object instance) { - container.SatisfyImportsOnce(instance); + _container.SatisfyImportsOnce(instance); } /// @@ -88,7 +84,7 @@ protected override void BuildUp(object instance) /// protected override IEnumerable SelectAssemblies() { - return new Assembly[] { Assembly.GetExecutingAssembly(), Assembly.LoadFrom(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Extensions\NetduinoEmulator.dll")) }; + return new[] { Assembly.GetExecutingAssembly(), Assembly.LoadFrom(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Extensions\NetduinoEmulator.dll")) }; } /// diff --git a/Netduino.Core/InputGpioEventArgs.cs b/Netduino.Core/InputGpioEventArgs.cs index 1192826..d076d93 100644 --- a/Netduino.Core/InputGpioEventArgs.cs +++ b/Netduino.Core/InputGpioEventArgs.cs @@ -1,41 +1,25 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.SPOT.Emulator.Gpio; - -namespace Netduino.Core +namespace Netduino.Core { /// /// A simple DTO that represents the state of an input pin on the netduino /// public class InputGpioEventArgs { - private int _pin; - private bool _edge; public InputGpioEventArgs(int pin, bool edge) { - _pin = pin; - _edge = edge; + Pin = pin; + Edge = edge; } /// /// What pin this event is for /// - public int Pin - { - get { return _pin; } - set { _pin = value; } - } + public int Pin { get; set; } /// /// What state the pin transitioned to /// - public bool Edge - { - get { return _edge; } - set { _edge = value; } - } + public bool Edge { get; set; } } } diff --git a/Netduino.Core/Netduino.Core.csproj b/Netduino.Core/Netduino.Core.csproj index 15162eb..4c92ea0 100644 --- a/Netduino.Core/Netduino.Core.csproj +++ b/Netduino.Core/Netduino.Core.csproj @@ -70,12 +70,12 @@ - - - - - - + + + + + + diff --git a/Netduino.Core/OutputGpioEventArgs.cs b/Netduino.Core/OutputGpioEventArgs.cs index fec4e82..8cc0634 100644 --- a/Netduino.Core/OutputGpioEventArgs.cs +++ b/Netduino.Core/OutputGpioEventArgs.cs @@ -1,44 +1,27 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.SPOT.Emulator.Gpio; - -namespace Netduino.Core +namespace Netduino.Core { public class OutputGpioEventArgs { - private int _pin; - private bool _edge; - - /// + /// /// A simple DTO that represents the state of an output pin on the netduino /// /// /// public OutputGpioEventArgs(int pin, bool edge) { - _pin = pin; - _edge = edge; + Pin = pin; + Edge = edge; } - /// - /// The pin this event belongs to - /// - public int Pin - { - get { return _pin; } - set { _pin = value; } - } + /// + /// The pin this event belongs to + /// + public int Pin { get; set; } - /// - /// The state the pin should transition to - /// - public bool Edge - { - get { return _edge; } - set { _edge = value; } - } + /// + /// The state the pin should transition to + /// + public bool Edge { get; set; } } } diff --git a/Netduino.Core/Service/EmulatorService.cs b/Netduino.Core/Service/EmulatorService.cs deleted file mode 100644 index e04b319..0000000 --- a/Netduino.Core/Service/EmulatorService.cs +++ /dev/null @@ -1,201 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.SPOT.Emulator; -using Microsoft.SPOT.Emulator.Gpio; -using Microsoft.SPOT.Hardware; -using Caliburn.Micro; -using System.ComponentModel.Composition; -using Netduino.Core; - -namespace Netduino.Core.Services -{ - [Export(typeof(IEmulatorService))] - public class EmulatorService:Emulator2,IEmulatorService,IHandle,IHandle - { - //private readonly Emulator _emulator; - private GpioPort _onBoardLedPort; - private GpioPort _onBoardSwitch1; - private GpioPort _gpio_d0Port; - private GpioPort _gpio_d1Port; - private GpioPort _gpio_d2Port; - private GpioPort _gpio_d3Port; - private GpioPort _gpio_d4Port; - private GpioPort _gpio_d5Port; - private GpioPort _gpio_d6Port; - private GpioPort _gpio_d7Port; - private GpioPort _gpio_d8Port; - private GpioPort _gpio_d9Port; - private GpioPort _gpio_d10Port; - private GpioPort _gpio_d11Port; - private GpioPort _gpio_d12Port; - private GpioPort _gpio_d13Port; - //private GpioPort _gpio_a0Port; - private readonly IEventAggregator _eventAggregator; - private readonly ILog _log = LogManager.GetLog(typeof(EmulatorService)); - - - public EmulatorService(IEventAggregator eventAggregator) - { - _eventAggregator = eventAggregator; - } - - public override void Configure(System.Xml.XmlReader reader) - { - try - { - base.Configure(reader); - } - catch (Exception ex) - { - _log.Error(ex); - } - } - - public override void Run() - { - base.Run(); - - } - - /// Registers default components and settings for this emulator - protected override void LoadDefaultComponents() - { - base.LoadDefaultComponents(); - - } - - public override void SetupComponent() - { - base.SetupComponent(); - } - - public override void InitializeComponent() - { - base.InitializeComponent(); - _gpio_d0Port = RegisterOutput("GPIO_PIN_D0"); - _gpio_d1Port = RegisterOutput("GPIO_PIN_D1"); - _gpio_d2Port = RegisterOutput("GPIO_PIN_D2"); - _gpio_d3Port = RegisterOutput("GPIO_PIN_D3"); - _gpio_d4Port = RegisterOutput("GPIO_PIN_D4"); - _gpio_d5Port = RegisterOutput("GPIO_PIN_D5"); - _gpio_d6Port = RegisterOutput("GPIO_PIN_D6"); - _gpio_d7Port = RegisterOutput("GPIO_PIN_D7"); - _gpio_d8Port = RegisterOutput("GPIO_PIN_D8"); - _gpio_d9Port = RegisterOutput("GPIO_PIN_D9"); - _gpio_d10Port = RegisterOutput("GPIO_PIN_D10"); - _gpio_d11Port = RegisterOutput("GPIO_PIN_D11"); - _gpio_d12Port = RegisterOutput("GPIO_PIN_D12"); - _gpio_d13Port = RegisterOutput("GPIO_PIN_D13"); - _onBoardLedPort = RegisterOutput("ONBOARD_LED"); - _onBoardSwitch1 = this.FindComponentById("ONBOARD_SW1") as GpioPort; - - _eventAggregator.Subscribe(this); - } - - private GpioPort RegisterOutput(string id) - { - GpioPort port = this.FindComponentById(id) as GpioPort; - if (port != null) - { - if (port.ModesAllowed == GpioPortMode.InputOutputPort || port.ModesAllowed == GpioPortMode.OutputPort) - { - _log.Info("Id={0} is an output pin so register it for events", id); - port.OnGpioActivity += new GpioActivity(Port_OnGpioActivity); - } - else - { - _log.Warn("Id={0} must not be an output pin", id); - } - } - else - { - _log.Warn("Output was not registered Id={0}", id); - } - return port; - } - - public override void UninitializeComponent() - { - base.UninitializeComponent(); - } - - void Port_OnGpioActivity(GpioPort sender, bool edge) - { - _log.Info("Emulator Service GpioPort Fired {0} {1}",sender.Pin,edge); - _eventAggregator.Publish(new OutputGpioEventArgs((int)sender.Pin, edge)); - } - - public void Handle(InputGpioEventArgs message) - { - - if (message != null) - { - _log.Info("Emulator Service: Handle Input {0} {1}",message.Pin,message.Edge); - if (message.Pin == Pins.ONBOARD_SW1 && _onBoardSwitch1 != null) - { - _onBoardSwitch1.Write(message.Edge); - } - if (message.Pin == Pins.GPIO_PIN_D1 && _gpio_d1Port != null) - { - _gpio_d1Port.Write(message.Edge); - } - if (message.Pin == Pins.GPIO_PIN_D2 && _gpio_d2Port != null) - { - _gpio_d2Port.Write(message.Edge); - } - if (message.Pin == Pins.GPIO_PIN_D3 && _gpio_d3Port != null) - { - _gpio_d3Port.Write(message.Edge); - } - if (message.Pin == Pins.GPIO_PIN_D4 && _gpio_d4Port != null) - { - _gpio_d4Port.Write(message.Edge); - } - if (message.Pin == Pins.GPIO_PIN_D5 && _gpio_d5Port != null) - { - _gpio_d5Port.Write(message.Edge); - } - if (message.Pin == Pins.GPIO_PIN_D6 && _gpio_d6Port != null) - { - _gpio_d6Port.Write(message.Edge); - } - if (message.Pin == Pins.GPIO_PIN_D7 && _gpio_d7Port != null) - { - _gpio_d7Port.Write(message.Edge); - } - if (message.Pin == Pins.GPIO_PIN_D8 && _gpio_d8Port != null) - { - _gpio_d8Port.Write(message.Edge); - } - if (message.Pin == Pins.GPIO_PIN_D9 && _gpio_d9Port != null) - { - _gpio_d9Port.Write(message.Edge); - } - if (message.Pin == Pins.GPIO_PIN_D10 && _gpio_d10Port != null) - { - _gpio_d10Port.Write(message.Edge); - } - if (message.Pin == Pins.GPIO_PIN_D11 && _gpio_d11Port != null) - { - _gpio_d11Port.Write(message.Edge); - } - if (message.Pin == Pins.GPIO_PIN_D12 && _gpio_d12Port != null) - { - _gpio_d12Port.Write(message.Edge); - } - if (message.Pin == Pins.GPIO_PIN_D13 && _gpio_d13Port != null) - { - _gpio_d13Port.Write(message.Edge); - } - } - } - - public void Handle(OutputGpioEventArgs message) - { - _log.Info("Emulator Service Handle Output "); - - } - } -} diff --git a/Netduino.Core/Service/IEmulatorService.cs b/Netduino.Core/Service/IEmulatorService.cs deleted file mode 100644 index ebc5da6..0000000 --- a/Netduino.Core/Service/IEmulatorService.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Netduino.Core.Services -{ - public interface IEmulatorService - { - } -} diff --git a/Netduino.Core/Service/DebugLogger.cs b/Netduino.Core/Services/DebugLogger.cs similarity index 85% rename from Netduino.Core/Service/DebugLogger.cs rename to Netduino.Core/Services/DebugLogger.cs index 56a8ce3..e59805c 100644 --- a/Netduino.Core/Service/DebugLogger.cs +++ b/Netduino.Core/Services/DebugLogger.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using Caliburn.Micro; using System.Diagnostics; @@ -21,7 +18,7 @@ public DebugLogger(Type type) #endregion #region Helper Methods - private string CreateLogMessage(string format, params object[] args) + private static string CreateLogMessage(string format, params object[] args) { return string.Format("[{0}] {1}", DateTime.Now.ToString("o"), diff --git a/Netduino.Core/Service/Emulator2.cs b/Netduino.Core/Services/Emulator2.cs similarity index 60% rename from Netduino.Core/Service/Emulator2.cs rename to Netduino.Core/Services/Emulator2.cs index f32c07b..03c1513 100644 --- a/Netduino.Core/Service/Emulator2.cs +++ b/Netduino.Core/Services/Emulator2.cs @@ -1,16 +1,13 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.SPOT.Emulator; using System.Threading; +using Microsoft.SPOT.Emulator; using Microsoft.SPOT.Emulator.Gpio; using Microsoft.SPOT.Hardware; namespace Netduino.Core.Services { /// Extension of standard Emulator to provide events for key state changes - /// The standard and derived classes go through + /// The standard and derived classes go through /// several stages of initialization. However, external classes, like a view model /// don't get to participate in the "notification" of state changes. Thus it is difficult /// for a view model to know when it is safe to attach to the emulators LCD changed event. @@ -24,16 +21,16 @@ public Emulator2( ) { } - /// Creates a new instance of an - /// Custom emulator HAL built from the .NET Micro Framework Porting kit - /// - /// This overload of the constructor allows setting the HAL/CLR implementation for the emulator. - /// You can create custom HAL/CLR configurations using the .NET Micro Framework Porting kit. - /// - //public Emulator2(IEmulator Hal) - // : base( Hal ) - //{ - //} + ///// Creates a new instance of an + ///// Custom emulator HAL built from the .NET Micro Framework Porting kit + ///// + ///// This overload of the constructor allows setting the HAL/CLR implementation for the emulator. + ///// You can create custom HAL/CLR configurations using the .NET Micro Framework Porting kit. + ///// + ////public Emulator2(IEmulator Hal) + //// : base( Hal ) + ////{ + ////} #region Emulator Thread /// Start the emulator engine on a new thread @@ -44,10 +41,10 @@ public void StartEmulator( ) } /// Start the emulator engine on a new thread - /// Command line arguments - public void StartEmulator( string[ ] Args ) + /// Command line arguments + public void StartEmulator( string[ ] args ) { - new Thread( Start ).Start( Args ); + new Thread( Start ).Start( args ); } #endregion @@ -85,56 +82,52 @@ public override void UninitializeComponent() #region GPIO Pins /// Registers a GPIO pin in the system - /// Pin number - /// Name for the pin + /// Pin number + /// Name for the pin /// /// Useful method for registering a pin - /// NOTE: This should only be called from an overload of the - /// Method + /// NOTE: This should only be called from an overload of the + /// Method /// - protected GpioPort RegisterPin(string Name, Cpu.Pin Pin) + protected GpioPort RegisterPin(string name, Cpu.Pin pin) { - return RegisterPin(Name, Pin, GpioPortMode.InputOutputPort, GpioPortMode.InputOutputPort); + return RegisterPin(name, pin, GpioPortMode.InputOutputPort, GpioPortMode.InputOutputPort); } /// Registers a GPIO pin in the system - /// Pin number - /// Name for the pin - /// Virtual Key to attach to the pin + /// Pin number + /// Name for the pin + /// Virtual Key to attach to the pin /// /// Useful method for registering a pin that acts as a button - /// NOTE: This should only be called from an overload of the - /// Method + /// NOTE: This should only be called from an overload of the + /// Method /// - protected GpioPort RegisterPin(string Name, Cpu.Pin Pin, VirtualKey Key) + protected GpioPort RegisterPin(string name, Cpu.Pin pin, VirtualKey key) { - GpioPort retVal = RegisterPin(Name, Pin); - retVal.VirtualKey = Key; + GpioPort retVal = RegisterPin(name, pin); + retVal.VirtualKey = key; return retVal; } /// Registers a GPIO pin in the system - /// Name for the pin - /// Pin number - /// Expected mode for the pin - /// Allowed modes for the pin + /// Name for the pin + /// Pin number + /// Expected mode for the pin + /// Allowed modes for the pin /// /// Useful method for registering a pin - /// NOTE: This should only be called from an overload of the - /// Method + /// NOTE: This should only be called from an overload of the + /// Method /// - protected GpioPort RegisterPin(string Name, Cpu.Pin Pin, GpioPortMode ExpectedMode, GpioPortMode AllowedMode) + protected GpioPort RegisterPin(string name, Cpu.Pin pin, GpioPortMode expectedMode, GpioPortMode allowedMode) { - if (this.State != EmulatorState.Configuration) + if (State != EmulatorState.Configuration) throw new InvalidOperationException( "Cannot register GPIO Pins unless emulator is in the Configuration state"); - GpioPort port = new GpioPort(); - port.Pin = Pin; - port.ModesAllowed = AllowedMode; - port.ModesExpected = ExpectedMode; - port.ComponentId = Name; - RegisterComponent(port); + var port = new GpioPort {Pin = pin, ModesAllowed = allowedMode, ModesExpected = expectedMode, ComponentId = name}; + RegisterComponent(port); return port; } #endregion diff --git a/Netduino.Core/Services/EmulatorService.cs b/Netduino.Core/Services/EmulatorService.cs new file mode 100644 index 0000000..33f73af --- /dev/null +++ b/Netduino.Core/Services/EmulatorService.cs @@ -0,0 +1,179 @@ +using System; +using System.ComponentModel.Composition; +using Caliburn.Micro; +using Microsoft.SPOT.Emulator.Gpio; + +namespace Netduino.Core.Services +{ + [Export(typeof(IEmulatorService))] + public class EmulatorService:Emulator2,IEmulatorService,IHandle,IHandle + { + //private readonly Emulator _emulator; + private GpioPort _onBoardLedPort; + private GpioPort _onBoardSwitch1; + private GpioPort _gpioD0Port; + private GpioPort _gpioD1Port; + private GpioPort _gpioD2Port; + private GpioPort _gpioD3Port; + private GpioPort _gpioD4Port; + private GpioPort _gpioD5Port; + private GpioPort _gpioD6Port; + private GpioPort _gpioD7Port; + private GpioPort _gpioD8Port; + private GpioPort _gpioD9Port; + private GpioPort _gpioD10Port; + private GpioPort _gpioD11Port; + private GpioPort _gpioD12Port; + private GpioPort _gpioD13Port; + //private GpioPort _gpio_a0Port; + private readonly IEventAggregator _eventAggregator; + private readonly ILog _log = LogManager.GetLog(typeof(EmulatorService)); + + + public EmulatorService(IEventAggregator eventAggregator) + { + _eventAggregator = eventAggregator; + } + + public override void Configure(System.Xml.XmlReader reader) + { + try + { + base.Configure(reader); + } + catch (Exception ex) + { + _log.Error(ex); + } + } + + /// Registers default components and settings for this emulator + protected override void LoadDefaultComponents() + { + base.LoadDefaultComponents(); + + } + + public override void InitializeComponent() + { + base.InitializeComponent(); + _gpioD0Port = RegisterOutput("GPIO_PIN_D0"); + _gpioD1Port = RegisterOutput("GPIO_PIN_D1"); + _gpioD2Port = RegisterOutput("GPIO_PIN_D2"); + _gpioD3Port = RegisterOutput("GPIO_PIN_D3"); + _gpioD4Port = RegisterOutput("GPIO_PIN_D4"); + _gpioD5Port = RegisterOutput("GPIO_PIN_D5"); + _gpioD6Port = RegisterOutput("GPIO_PIN_D6"); + _gpioD7Port = RegisterOutput("GPIO_PIN_D7"); + _gpioD8Port = RegisterOutput("GPIO_PIN_D8"); + _gpioD9Port = RegisterOutput("GPIO_PIN_D9"); + _gpioD10Port = RegisterOutput("GPIO_PIN_D10"); + _gpioD11Port = RegisterOutput("GPIO_PIN_D11"); + _gpioD12Port = RegisterOutput("GPIO_PIN_D12"); + _gpioD13Port = RegisterOutput("GPIO_PIN_D13"); + _onBoardLedPort = RegisterOutput("ONBOARD_LED"); + _onBoardSwitch1 = FindComponentById("ONBOARD_SW1") as GpioPort; + + _eventAggregator.Subscribe(this); + } + + private GpioPort RegisterOutput(string id) + { + var gpioPort = FindComponentById(id) as GpioPort; + if (gpioPort != null) + { + if (gpioPort.ModesAllowed == GpioPortMode.InputOutputPort || gpioPort.ModesAllowed == GpioPortMode.OutputPort) + { + _log.Info("Id={0} is an output pin so register it for events", id); + gpioPort.OnGpioActivity += Port_OnGpioActivity; + } + else + { + _log.Warn("Id={0} must not be an output pin", id); + } + } + else + { + _log.Warn("Output was not registered Id={0}", id); + } + return gpioPort; + } + + void Port_OnGpioActivity(GpioPort sender, bool edge) + { + _log.Info("Emulator Service GpioPort Fired {0} {1}",sender.Pin,edge); + _eventAggregator.Publish(new OutputGpioEventArgs((int)sender.Pin, edge)); + } + + public void Handle(InputGpioEventArgs message) + { + + if (message != null) + { + _log.Info("Emulator Service: Handle Input {0} {1}",message.Pin,message.Edge); + if (message.Pin == Pins.ONBOARD_SW1 && _onBoardSwitch1 != null) + { + _onBoardSwitch1.Write(message.Edge); + } + if (message.Pin == Pins.GPIO_PIN_D1 && _gpioD1Port != null) + { + _gpioD1Port.Write(message.Edge); + } + if (message.Pin == Pins.GPIO_PIN_D2 && _gpioD2Port != null) + { + _gpioD2Port.Write(message.Edge); + } + if (message.Pin == Pins.GPIO_PIN_D3 && _gpioD3Port != null) + { + _gpioD3Port.Write(message.Edge); + } + if (message.Pin == Pins.GPIO_PIN_D4 && _gpioD4Port != null) + { + _gpioD4Port.Write(message.Edge); + } + if (message.Pin == Pins.GPIO_PIN_D5 && _gpioD5Port != null) + { + _gpioD5Port.Write(message.Edge); + } + if (message.Pin == Pins.GPIO_PIN_D6 && _gpioD6Port != null) + { + _gpioD6Port.Write(message.Edge); + } + if (message.Pin == Pins.GPIO_PIN_D7 && _gpioD7Port != null) + { + _gpioD7Port.Write(message.Edge); + } + if (message.Pin == Pins.GPIO_PIN_D8 && _gpioD8Port != null) + { + _gpioD8Port.Write(message.Edge); + } + if (message.Pin == Pins.GPIO_PIN_D9 && _gpioD9Port != null) + { + _gpioD9Port.Write(message.Edge); + } + if (message.Pin == Pins.GPIO_PIN_D10 && _gpioD10Port != null) + { + _gpioD10Port.Write(message.Edge); + } + if (message.Pin == Pins.GPIO_PIN_D11 && _gpioD11Port != null) + { + _gpioD11Port.Write(message.Edge); + } + if (message.Pin == Pins.GPIO_PIN_D12 && _gpioD12Port != null) + { + _gpioD12Port.Write(message.Edge); + } + if (message.Pin == Pins.GPIO_PIN_D13 && _gpioD13Port != null) + { + _gpioD13Port.Write(message.Edge); + } + } + } + + public void Handle(OutputGpioEventArgs message) + { + _log.Info("Emulator Service Handle Output "); + + } + } +} diff --git a/Netduino.Core/Services/IEmulatorService.cs b/Netduino.Core/Services/IEmulatorService.cs new file mode 100644 index 0000000..a88df69 --- /dev/null +++ b/Netduino.Core/Services/IEmulatorService.cs @@ -0,0 +1,6 @@ +namespace Netduino.Core.Services +{ + public interface IEmulatorService + { + } +} diff --git a/Netduino.Core/Service/Log4NetLogger.cs b/Netduino.Core/Services/Log4NetLogger.cs similarity index 86% rename from Netduino.Core/Service/Log4NetLogger.cs rename to Netduino.Core/Services/Log4NetLogger.cs index ed1632b..699ee16 100644 --- a/Netduino.Core/Service/Log4NetLogger.cs +++ b/Netduino.Core/Services/Log4NetLogger.cs @@ -1,19 +1,16 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using Caliburn.Micro; namespace Netduino.Core.Services { - public class Log4netLogger : ILog + public class Log4NetLogger : ILog { #region Fields private readonly log4net.ILog _innerLogger; #endregion #region Constructors - public Log4netLogger(Type type) + public Log4NetLogger(Type type) { //_innerLogger = log4net.LogManager.GetLogger(type); log4net.ILog[] loggers = log4net.LogManager.GetCurrentLoggers(); diff --git a/Netduino.Core/Service/TextFileLogger.cs b/Netduino.Core/Services/TextFileLogger.cs similarity index 86% rename from Netduino.Core/Service/TextFileLogger.cs rename to Netduino.Core/Services/TextFileLogger.cs index 042a58b..ee11833 100644 --- a/Netduino.Core/Service/TextFileLogger.cs +++ b/Netduino.Core/Services/TextFileLogger.cs @@ -1,11 +1,8 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Caliburn.Micro; using System.IO; +using Caliburn.Micro; -namespace Netduino.Core.Service +namespace Netduino.Core.Services { public class TextFileLogger : ILog { diff --git a/Netduino.Core/ViewModels/IEmulatorViewModel.cs b/Netduino.Core/ViewModels/IEmulatorViewModel.cs index bc069b7..618809f 100644 --- a/Netduino.Core/ViewModels/IEmulatorViewModel.cs +++ b/Netduino.Core/ViewModels/IEmulatorViewModel.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Netduino.Core.ViewModels +namespace Netduino.Core.ViewModels { /// /// All emulators need to implement this interface diff --git a/Netduino.Core/ViewModels/IShellViewModel.cs b/Netduino.Core/ViewModels/IShellViewModel.cs index 2e5e350..ffd8e5b 100644 --- a/Netduino.Core/ViewModels/IShellViewModel.cs +++ b/Netduino.Core/ViewModels/IShellViewModel.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Netduino.Core.ViewModels +namespace Netduino.Core.ViewModels { /// /// The shell marker interface diff --git a/Netduino.Core/ViewModels/ShellViewModel.cs b/Netduino.Core/ViewModels/ShellViewModel.cs index c40bb05..6b1f122 100644 --- a/Netduino.Core/ViewModels/ShellViewModel.cs +++ b/Netduino.Core/ViewModels/ShellViewModel.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Caliburn.Micro; -using System.ComponentModel.Composition; +using System.ComponentModel.Composition; using System.IO; +using Caliburn.Micro; namespace Netduino.Core.ViewModels { @@ -15,7 +11,7 @@ namespace Netduino.Core.ViewModels public class ShellViewModel :Conductor,IShellViewModel { private string _emulatorName; - private string _keyBase = @"HKEY_CURRENT_USER\Software\Microsoft\.NETMicroFramework\v4.1\Emulators\{45D406A2-51DD-4662-ABDD-499BD9589AF1}"; + private const string KeyBase = @"HKEY_CURRENT_USER\Software\Microsoft\.NETMicroFramework\v4.1\Emulators\{45D406A2-51DD-4662-ABDD-499BD9589AF1}"; private IWindowManager _windowManager; private IEmulatorViewModel _emulatorViewModel; private readonly ILog _log = LogManager.GetLog(typeof(ShellViewModel)); @@ -26,8 +22,7 @@ public ShellViewModel(IWindowManager windowManager,IEmulatorViewModel viewModel) _log.Info("ShellViewModel Constructor"); _windowManager = windowManager; _emulatorViewModel = viewModel; - this.DisplayName = "Netduino Emulator"; - + DisplayName = "Netduino Emulator"; } public string EmulatorName @@ -69,15 +64,15 @@ public void WriteRegistry() { string path = Path.Combine(Directory.GetCurrentDirectory(), "Netduino.Shell.exe"); ; - Microsoft.Win32.Registry.SetValue(_keyBase, "Name", EmulatorName); - Microsoft.Win32.Registry.SetValue(_keyBase, "Path", path); + Microsoft.Win32.Registry.SetValue(KeyBase, "Name", EmulatorName); + Microsoft.Win32.Registry.SetValue(KeyBase, "Path", path); } protected override void OnActivate() { base.OnActivate(); - Screen view = (Screen)IoC.Get(); + var view = (Screen)IoC.Get(); ChangeActiveItem(view, true); } } diff --git a/Netduino.Core/Views/ShellView.xaml.cs b/Netduino.Core/Views/ShellView.xaml.cs index 8d9f9a4..6e34356 100644 --- a/Netduino.Core/Views/ShellView.xaml.cs +++ b/Netduino.Core/Views/ShellView.xaml.cs @@ -17,7 +17,7 @@ namespace Netduino.Core.Views /// /// Interaction logic for ShellView.xaml /// - public partial class ShellView : UserControl + public partial class ShellView { public ShellView() { diff --git a/Netduino.SimpleEmulator/Converters/BoolToBrushConverter.cs b/Netduino.SimpleEmulator/Converters/BoolToBrushConverter.cs index 50e6463..9efca36 100644 --- a/Netduino.SimpleEmulator/Converters/BoolToBrushConverter.cs +++ b/Netduino.SimpleEmulator/Converters/BoolToBrushConverter.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Windows.Data; using System.Windows.Media; @@ -12,6 +9,7 @@ public class BoolToBrushConverter : IValueConverter { private Brush _falseBrush = Brushes.Red; private Brush _trueBrush = Brushes.Green; + #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) @@ -22,7 +20,6 @@ public object Convert(object value, Type targetType, return _falseBrush; default: return _trueBrush; - break; } } public object ConvertBack(object value, Type targetType, diff --git a/Netduino.SimpleEmulator/Images/netduino.gif b/Netduino.SimpleEmulator/Images/netduino.gif new file mode 100644 index 0000000..b2eab59 Binary files /dev/null and b/Netduino.SimpleEmulator/Images/netduino.gif differ diff --git a/Netduino.SimpleEmulator/Netduino.SimpleEmulator.csproj b/Netduino.SimpleEmulator/Netduino.SimpleEmulator.csproj index 68e4a63..3ee8490 100644 --- a/Netduino.SimpleEmulator/Netduino.SimpleEmulator.csproj +++ b/Netduino.SimpleEmulator/Netduino.SimpleEmulator.csproj @@ -71,8 +71,13 @@ MSBuild:Compile - + + + + + copy "$(TargetDir)$(TargetFileName)" "$(TargetDir)..\Shell\Extensions\" /y +