public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { if (context != null) { var workflowBuilder = (WorkflowBuilder)context.GetService(typeof(WorkflowBuilder)); if (workflowBuilder != null) { var portNames = (from builder in workflowBuilder.Workflow.Descendants() let createPort = ExpressionBuilder.GetWorkflowElement(builder) as CreateArduino where createPort != null && !string.IsNullOrEmpty(createPort.PortName) select !string.IsNullOrEmpty(createPort.Name) ? createPort.Name : createPort.PortName) .Concat(ArduinoManager.LoadConfiguration().Select(configuration => configuration.PortName)) .Distinct() .ToList(); if (portNames.Count > 0) { return(new StandardValuesCollection(portNames)); } else { return(new StandardValuesCollection(SerialPort.GetPortNames())); } } } return(base.GetStandardValues(context)); }
public static IObservable <bool> DigitalInput(string portName, int pin, PinMode pinMode) { return(Observable.Create <bool>(async observer => { var connection = await ArduinoManager.ReserveConnectionAsync(portName); connection.Arduino.PinMode(pin, pinMode); var port = Arduino.GetPortNumber(pin); EventHandler <DigitalInputReceivedEventArgs> inputReceived; inputReceived = (sender, e) => { if (e.Port == port) { observer.OnNext(connection.Arduino.DigitalRead(pin) != 0); } }; connection.Arduino.ReportDigital(port, true); connection.Arduino.DigitalInputReceived += inputReceived; return Disposable.Create(() => { connection.Arduino.DigitalInputReceived -= inputReceived; connection.Arduino.ReportDigital(port, false); connection.Dispose(); }); })); }
public override IObservable <Arduino> Generate() { return(Observable.Using( () => ArduinoManager.ReserveConnection(Name, configuration), resource => { return Observable.Return(resource.Arduino) .Concat(Observable.Never(resource.Arduino)); })); }
public override IObservable <byte[]> Process(IObservable <byte[]> source) { return(Observable.Using( () => ArduinoManager.ReserveConnection(PortName), connection => source.Do(value => { lock (connection.Arduino) { connection.Arduino.SendSysex((byte)Feature, value); } }))); }
public override IObservable <byte[]> Process(IObservable <byte[]> source) { return(Observable.Using( cancellationToken => ArduinoManager.ReserveConnectionAsync(PortName), (connection, cancellationToken) => Task.FromResult(source.Do(value => { lock (connection.Arduino) { connection.Arduino.SendSysex((byte)Feature, value); } })))); }
public override IObservable <int> Process(IObservable <int> source) { return(Observable.Using( cancellationToken => ArduinoManager.ReserveConnectionAsync(PortName), (connection, cancellationToken) => { var pin = Pin; connection.Arduino.PinMode(pin, PinMode.Servo); return Task.FromResult(source.Do(value => { lock (connection.Arduino) { connection.Arduino.AnalogWrite(pin, value); } })); })); }
public override IObservable <int> Process(IObservable <int> source) { return(Observable.Using( () => ArduinoManager.ReserveConnection(PortName), connection => { var pin = Pin; connection.Arduino.PinMode(pin, PinMode.Pwm); return source.Do(value => { lock (connection.Arduino) { connection.Arduino.AnalogWrite(pin, value); } }); })); }
public override IObservable <byte[]> Generate() { return(Observable.Create <byte[]>(observer => { var connection = ArduinoManager.ReserveConnection(PortName); EventHandler <SysexReceivedEventArgs> sysexReceived; sysexReceived = (sender, e) => { if (e.Feature == Feature) { observer.OnNext(e.Args); } }; connection.Arduino.SysexReceived += sysexReceived; return Disposable.Create(() => { connection.Arduino.SysexReceived -= sysexReceived; connection.Dispose(); }); })); }
public static IObservable <int> AnalogInput(string portName, int pin) { return(Observable.Create <int>(async observer => { var connection = await ArduinoManager.ReserveConnectionAsync(portName); EventHandler <AnalogInputReceivedEventArgs> inputReceived; inputReceived = (sender, e) => { if (e.Pin == pin) { observer.OnNext(e.Value); } }; connection.Arduino.ReportAnalog(pin, true); connection.Arduino.AnalogInputReceived += inputReceived; return Disposable.Create(() => { connection.Arduino.AnalogInputReceived -= inputReceived; connection.Arduino.ReportAnalog(pin, false); connection.Dispose(); }); })); }