public int ResolutionOfCapability(PinModes mode) { if (HasPinCapability(mode)) { return(Capabilities[mode]); } return(-1); }
public InvalidPinModeException(PinModes mode, List<PinModes> availableModes ) { this.mode = mode; var sb = new StringBuilder(); foreach (var availableMode in availableModes) { sb.Append(availableMode); } this.availableModes = sb.ToString(); }
public InvalidPinModeException(PinModes mode, List <PinModes> availableModes) { this.mode = mode; var sb = new StringBuilder(); foreach (var availableMode in availableModes) { sb.Append(availableMode); } this.availableModes = sb.ToString(); }
protected override bool HandleByte(byte messageByte) { switch (currentState) { case HandlerState.StartEnd: currentState = HandlerState.SysexCommand; return(true); case HandlerState.SysexCommand: currentState = HandlerState.PinMode; return(true); case HandlerState.PinMode: // If the message has finished Reset and return that we won't handle other bytes if (messageByte == MessageConstants.SYSEX_END) { Reset(); messageBroker.CreateEvent(new CapabilitiesFinishedMessage()); return(false); } // We finished with a pin so create a capability message for this pin // we don't change the currentState because the next byte could be // a mode byte, or a finish message byte if (messageByte == MessageConstants.FINISHED_PIN_CAPABILITIES) { message.PinNo = currentPin++; messageBroker.CreateEvent(message); message = new CapabilityMessage(); return(true); } // Some assurance that we get an actual mode if (messageByte > Enum.GetValues(typeof(PinModes)).Length) { Reset(); throw new MessageHandlerException(BaseExceptionMessage + "There is no such pin mode"); } currentMode = (PinModes)messageByte; currentState = HandlerState.PinResolution; return(true); case HandlerState.PinResolution: message.Modes[currentMode] = messageByte; currentState = HandlerState.PinMode; return(true); default: throw new ArgumentOutOfRangeException(); } }
public void SetPinMode(ArduinoUnoPins pin, PinModes mode) { if (firmata.IsInitialized == false) { return; } var currentPin = firmata.Pins[(int)pin]; // Throw an exception if the pin doesn't have this capability if (!currentPin.HasPinCapability(mode)) { throw new InvalidPinModeException(PinModes.Servo, currentPin.Capabilities.Keys.ToList()); } switch (mode) { case PinModes.I2C: // TODO : Special case for I2C message... throw new NotImplementedException(); case PinModes.Servo: // Special case for servo message... firmata.SendMessage(new ServoConfigMessage() { Pin = (byte)pin }); break; default: firmata.SendMessage(new PinModeMessage { Mode = mode, Pin = (byte)pin }); break; } // TODO : see if we need this or the next way //firmata.Pins[(byte) pin].CurrentMode = mode; // Update the pin state firmata.SendMessage(new PinStateQueryMessage() { Pin = (byte)pin }); }
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!_loaded) { return; } if (PinModeChanged == null) { return; } switch (PinModeSelect.SelectedIndex) { case 0: PinModeChanged(this, new PinModeChangedArgs() { Pincap = PinModes.Analog }); _pincap = PinModes.Analog; break; case 1: PinModeChanged(this, new PinModeChangedArgs() { Pincap = PinModes.Input }); _pincap = PinModes.Input; break; case 2: PinModeChanged(this, new PinModeChangedArgs() { Pincap = PinModes.Output }); _pincap = PinModes.Output; break; case 3: PinModeChanged(this, new PinModeChangedArgs() { Pincap = PinModes.PWM }); _pincap = PinModes.PWM; break; } }
public void SetPinMode(ArduinoMegaPins pin, PinModes mode) { if ( firmata.IsInitialized == false ) return; // Throw an exception if the pin doesn't have this capability if (!firmata.Pins[(int)pin].Capabilities.Keys.Contains(mode)) throw new InvalidPinModeException(PinModes.Servo, firmata.Pins[(int)pin].Capabilities.Keys.ToList()); switch (mode) { case PinModes.I2C: // TODO : Special case for I2C message... throw new NotImplementedException(); case PinModes.Servo: // Special case for servo message... firmata.SendMessage(new ServoConfigMessage() { Pin = (byte)pin }); break; default: firmata.SendMessage(new PinModeMessage { Mode = mode, Pin = (byte)pin }); break; } // Update the pin state firmata.SendMessage(new PinStateQueryMessage(){Pin = (byte) pin}); }
public bool HasPinCapability(PinModes mode) { return Capabilities.ContainsKey(mode); }
public int ResolutionOfCapability(PinModes mode) { if (HasPinCapability(mode)) { return Capabilities[mode]; } return -1; }
static string SetPinModeCommand(PinModes mode, int pin) { byte[] cmd = { FirmataCommands.SETPINMODE, (byte) pin, (byte) mode }; return Encode(cmd); }
public PinControl() { InitializeComponent(); _pincap = PinModes.Output; }
public bool HasPinCapability(PinModes mode) { return(Capabilities.ContainsKey(mode)); }