예제 #1
0
        /// <summary>
        /// Handle the Analog Mapping Message. This is used to find out which pins have
        /// analog input capabilities and fill the AnalogPins list
        /// </summary>
        public void Handle(AnalogMappingMessage message)
        {
            if (IsInitialized)
            {
                return;
            }

            for (int i = 0; i < message.PinMappings.Count; i++)
            {
                // If we have an analog pin
                if (message.PinMappings[i] != 127)
                {
                    // Put the corresponding pin to the analog pins dictionary
                    // this is a reference, so any changes to the primary object
                    // will be reflected here too.
                    AnalogPins.Add(Pins[i]);
                }
            }
            AdvanceInitialization();
        }
예제 #2
0
 public int AnalogWrite(AnalogPins pin, int pinValue)
 {
     return(ExecuteFunctionReturnValue("analogwrite", pin.ToString(), pinValue.ToString()));
 }
예제 #3
0
 public int AnalogRead(AnalogPins pin)
 {
     return(ExecuteFunctionReturnValue("analogread", pin.ToString()));
 }
예제 #4
0
 public int AnalogWrite(AnalogPins pin, int pinValue)
 {
     return ExecuteFunctionReturnValue("analogwrite", pin.ToString(), pinValue.ToString());
 }
예제 #5
0
 public int AnalogRead(AnalogPins pin)
 {
     return ExecuteFunctionReturnValue("analogread", pin.ToString());
 }
예제 #6
0
        /// <summary>
        /// Go through the initialization procedure
        /// </summary>
        private void AdvanceInitialization()
        {
            // Do nothing if we are initialized
            if (currentInitState == InitializationStages.FullyInitialized)
            {
                return;
            }

            switch (currentInitState)
            {
            case InitializationStages.QueryProtocolVersion:
                // This is the first inistialization stage
                // Stop any previous reports
                StopReports();
                base.SendMessage(new ProtocolVersionRequestMessage());
                break;

            case InitializationStages.QueryFirmwareVersion:
                base.SendMessage(new QueryFirmwareMessage());
                break;

            case InitializationStages.QueryCapabilities:
                // Clear the pins, as we will be receiving new ones
                Pins.Clear();
                AnalogPins.Clear();
                // Send the message to get the capabilities
                base.SendMessage(new QueryCapabilityMessage());
                break;

            case InitializationStages.QueryAnalogMappings:
                base.SendMessage(new AnalogMappingQueryMessage());
                break;

            case InitializationStages.QueryPinStates:
                for (int i = 0; i < Pins.Count; i++)
                {
                    base.SendMessage(new PinStateQueryMessage {
                        Pin = (byte)i
                    });
                }
                break;

            case InitializationStages.StartReports:
                var portsCount = (byte)Math.Ceiling(Pins.Count / 8.0);
                for (byte i = 0; i < portsCount; i++)
                {
                    base.SendMessage(new ToggleDigitalReportMessage()
                    {
                        Port = i, ShouldBeEnabled = true
                    });
                }

                for (byte i = 0; i < AnalogPins.Count; i++)
                {
                    base.SendMessage(new ToggleAnalogReportMessage()
                    {
                        Pin = i, ShouldBeEnabled = true
                    });
                }

                // There is no callback for the above messages so advance anyway
                OnInitialized();
                break;

            case InitializationStages.FullyInitialized:
                // Do nothing we are finished with the initialization
                break;

            default:
                throw new ArgumentOutOfRangeException("stage");
            }

            // Go to the next state
            if (!IsInitialized)
            {
                currentInitState++;
            }
        }
예제 #7
0
 /// <summary>
 /// Creats the event and initializes all its properties
 /// </summary>
 /// <param name="inPinToQuery">The pin to query</param>
 public QueryAnalogInputEvent(AnalogPins inPinToQuery)
 {
     _pinToQuery = inPinToQuery;
     identifier  = EventIdentifier.AnalogPinQueryRequest;
 }