/// <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(); }
public int AnalogWrite(AnalogPins pin, int pinValue) { return(ExecuteFunctionReturnValue("analogwrite", pin.ToString(), pinValue.ToString())); }
public int AnalogRead(AnalogPins pin) { return(ExecuteFunctionReturnValue("analogread", pin.ToString())); }
public int AnalogWrite(AnalogPins pin, int pinValue) { return ExecuteFunctionReturnValue("analogwrite", pin.ToString(), pinValue.ToString()); }
public int AnalogRead(AnalogPins pin) { return ExecuteFunctionReturnValue("analogread", pin.ToString()); }
/// <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++; } }
/// <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; }