コード例 #1
0
        public int ResolutionOfCapability(PinModes mode)
        {
            if (HasPinCapability(mode))
            {
                return(Capabilities[mode]);
            }

            return(-1);
        }
コード例 #2
0
 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();
 }
コード例 #3
0
        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();
        }
コード例 #4
0
        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();
            }
        }
コード例 #5
0
        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
            });
        }
コード例 #6
0
        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;
            }
        }
コード例 #7
0
ファイル: ArduinoMega.cs プロジェクト: tasosval/sharpduino
        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});
        }
コード例 #8
0
ファイル: Pin.cs プロジェクト: Deerap/sharpduino
 public bool HasPinCapability(PinModes mode)
 {
     return Capabilities.ContainsKey(mode);
 }
コード例 #9
0
ファイル: Pin.cs プロジェクト: Deerap/sharpduino
        public int ResolutionOfCapability(PinModes mode)
        {
            if (HasPinCapability(mode))
            {
                return Capabilities[mode];
            }

            return -1;
        }
コード例 #10
0
 static string SetPinModeCommand(PinModes mode, int pin)
 {
     byte[] cmd = {
         FirmataCommands.SETPINMODE,
         (byte) pin,
         (byte) mode
     };
     return Encode(cmd);
 }
コード例 #11
0
 public PinControl()
 {
     InitializeComponent();
     _pincap = PinModes.Output;
 }
コード例 #12
0
 public bool HasPinCapability(PinModes mode)
 {
     return(Capabilities.ContainsKey(mode));
 }