public PwmOutputConfigureCommand(DigitalOutputSpec spec, bool enable) { this.PwmDef = new PwmOutputSpec(spec); this.Enable = enable; this.DutyCycle = float.NaN; this.RequestedFrequency = 1000; // default in IOIO is 1Khz for sampling so maybe here too }
public void IOIOImpl_ToggleLED() { IOIOConnection ourConn = this.CreateGoodSerialConnection(false); this.CreateCaptureLogHandlerSet(); // we'll add the handler state on top of the default handlers so we don't have to peek into impl IOIO ourImpl = CreateIOIOImplAndConnect(ourConn, new List <IObserverIOIO>() { this.CapturedConnectionState_, this.CapturedSingleQueueAllType_, this.CapturedLogs_ }); LOG.Debug("Setup Complete"); System.Threading.Thread.Sleep(100); // wait for us to get the hardware ids DigitalOutputSpec ledSpec = new DigitalOutputSpec(Spec.LED_PIN); // SHOULD USE THE FACTORY instead of this lame ... IDigitalOutputConfigureCommand confDigitalOut = new DigitalOutputConfigureCommand( ledSpec); IDigitalOutputValueSetCommand turnItOn = new DigitalOutputSetValueCommand(ledSpec, true); IDigitalOutputValueSetCommand turnItOff = new DigitalOutputSetValueCommand(ledSpec, false); ourImpl.PostMessage(confDigitalOut); for (int i = 0; i < 8; i++) { System.Threading.Thread.Sleep(150); ourImpl.PostMessage(turnItOn); System.Threading.Thread.Sleep(150); ourImpl.PostMessage(turnItOff); } // this test can fail if we can't connect to the device but otherwise no way to read pin 1 values Assert.IsTrue(true, "there is no status to check"); }
public void CreateDigitalOutputTo_ToggleLED() { IOIOConnection ourConn = this.CreateGoodSerialConnection(); this.CreateCaptureLogHandlerSet(); // add our handlers on to p of default so we don't have to grovel around in the internal variables IOIOProtocolIncoming fooIn = new IOIOProtocolIncoming(ourConn.GetInputStream(), HandlerObservable_); IOIOProtocolOutgoing fooOut = new IOIOProtocolOutgoing(ourConn.GetOutputStream()); System.Threading.Thread.Sleep(100); // wait for us to get the hardware ids DigitalOutputSpec ledSpec = new DigitalOutputSpec(Spec.LED_PIN); IDigitalOutputConfigureCommand commandSetup = new DigitalOutputConfigureCommand( ledSpec, false); IDigitalOutputValueSetCommand commandOn = new DigitalOutputSetValueCommand(ledSpec, true); IDigitalOutputValueSetCommand commandOff = new DigitalOutputSetValueCommand(ledSpec, false); //// TODO should use the hardware from the captured connection IResourceManager rManager = new ResourceManager(Hardware.IOIO0003); commandSetup.Alloc(rManager); commandOn.Alloc(rManager); commandOff.Alloc(rManager); commandSetup.ExecuteMessage(fooOut); for (int i = 0; i < 8; i++) { System.Threading.Thread.Sleep(200); commandOn.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(200); commandOff.ExecuteMessage(fooOut); } Assert.IsTrue(true, "there is no status to check"); }
/// <summary> /// TODO add PeriodUSec to this constructor /// </summary> /// <param name="spec"></param> /// <param name="freqHz"></param> /// <param name="dutyCycle"></param> public PwmOutputConfigureCommand(DigitalOutputSpec spec, int freqHz, float dutyCycle) { this.PwmDef = new PwmOutputSpec(spec); this.Enable = true; this.DutyCycle = dutyCycle; this.RequestedFrequency = freqHz; }
private void ConfigureLed(IOIOMessageCommandFactory commandFactory) { LedPinSpec_ = new DigitalOutputSpec(Spec.LED_PIN); IDigitalOutputConfigureCommand createLED = commandFactory.CreateDigitalOutputConfigure(LedPinSpec_, LEDValueForState(false)); OurImpl_.PostMessage(createLED); }
/// <summary> /// Do we even need all these parameters? Isn't there only one SpiMaster on the board /// </summary> /// <param name="miso"></param> /// <param name="mosi"></param> /// <param name="clock"></param> /// <param name="slaveSelect"></param> /// <param name="rate"></param> internal SpiMasterConfigureCommand(DigitalInputSpec miso, DigitalOutputSpec mosi, DigitalOutputSpec clock, DigitalOutputSpec[] slaveSelect, SpiMasterConfig rate) { this.Miso = miso; this.Mosi = mosi; this.Clock = Clock; this.SlaveSelect = slaveSelect; this.Rate = rate; throw new NotImplementedException("Post(IOpenSpiMasterTo) not tied together in outgoing protocol"); }
public void ServoTest_SimpleServoTest() { //// TODO should use the hardware from the captured connection IResourceManager rManager = new ResourceManager(Hardware.IOIO0003); IOIOConnection ourConn = this.CreateGoodSerialConnection(); this.CreateCaptureLogHandlerSet(); IOIOProtocolIncoming fooIn = new IOIOProtocolIncoming(ourConn.GetInputStream(), HandlerObservable_); IOIOProtocolOutgoing fooOut = new IOIOProtocolOutgoing(ourConn.GetOutputStream()); System.Threading.Thread.Sleep(20); // wait for us to get the hardware ids int pwmFrequency = 100; DigitalOutputSpec pwmPinSpec = new DigitalOutputSpec(3, DigitalOutputSpecMode.NORMAL); // configure for servo PwmOutputConfigureCommand commandCreatePWM = new PwmOutputConfigureCommand(pwmPinSpec, pwmFrequency); commandCreatePWM.Alloc(rManager); commandCreatePWM.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(100); for (int i = 0; i < 4; i++) { // change it after settling PwmOutputUpdateCommand lowValue = new PwmOutputUpdatePulseWidthCommand(commandCreatePWM.PwmDef, 600); lowValue.Alloc(rManager); lowValue.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(500); // change it after settling PwmOutputUpdateCommand highValue = new PwmOutputUpdatePulseWidthCommand(commandCreatePWM.PwmDef, 2000); highValue.Alloc(rManager); highValue.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(500); } PwmOutputCloseCommand commandReleasePwm = new PwmOutputCloseCommand(commandCreatePWM.PwmDef); commandReleasePwm.Alloc(rManager); commandReleasePwm.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(500); //IEnumerable<IReportAnalogPinValuesFrom> readValues = this.HandlerSingleQueueAllType_.CapturedMessages_ // .OfType<IReportAnalogPinValuesFrom>(); //Assert.IsTrue(readValues.Count() >= 1, "Didn't find the number of expected IReportAnalogPinValuesFrom: " + readValues.Count()); // logging the messages with any other string doesn't show the messages themselves !? LOG.Debug("Captured " + +this.CapturedSingleQueueAllType_.Count()); LOG.Debug(this.CapturedSingleQueueAllType_.GetEnumerator()); // should verify close command }
public void CreateAnalogInputOutputTo_AnalogLoopbackOut31In32() { //// TODO should use the hardware from the captured connection IResourceManager rManager = new ResourceManager(Hardware.IOIO0003); IOIOConnection ourConn = this.CreateGoodSerialConnection(); this.CreateCaptureLogHandlerSet(); IOIOProtocolIncoming fooIn = new IOIOProtocolIncoming(ourConn.GetInputStream(), HandlerObservable_); IOIOProtocolOutgoing fooOut = new IOIOProtocolOutgoing(ourConn.GetOutputStream()); System.Threading.Thread.Sleep(100); // wait for us to get the hardware ids AnalogInputConfigureCommand commandCreateIn = new AnalogInputConfigureCommand(31, true); commandCreateIn.Alloc(rManager); commandCreateIn.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(10); DigitalOutputSpec pwmPinSpec = new DigitalOutputSpec(32, DigitalOutputSpecMode.NORMAL); // set analog "voltage" PwmOutputConfigureCommand commandCreatePWM = new PwmOutputConfigureCommand(pwmPinSpec, 1000, 0.3f); commandCreatePWM.Alloc(rManager); commandCreatePWM.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(100); // change it after settling PwmOutputUpdateCommand commandChangePWM = new PwmOutputUpdateDutyCycleCommand(commandCreatePWM.PwmDef, 0.7f); commandChangePWM.Alloc(rManager); commandChangePWM.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(100); PwmOutputCloseCommand commandReleasePwm = new PwmOutputCloseCommand(commandCreatePWM.PwmDef); commandReleasePwm.Alloc(rManager); commandReleasePwm.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(50); IEnumerable <IReportAnalogPinValuesFrom> readValues = this.CapturedSingleQueueAllType_ .OfType <IReportAnalogPinValuesFrom>(); Assert.IsTrue(readValues.Count() >= 1, "Didn't find the number of expected IReportAnalogPinValuesFrom: " + readValues.Count()); // logging the messages with any other string doesn't show the messages themselves !? LOG.Debug("Captured " + this.CapturedSingleQueueAllType_.Count()); LOG.Debug(this.CapturedSingleQueueAllType_.GetEnumerator()); // should verify close command }
private void ConfigurePwm(IOIOMessageCommandFactory commandFactory) { DigitalOutputSpec pwmPinSpec = new DigitalOutputSpec(SERVO_PIN, DigitalOutputSpecMode.NORMAL); IPwmOutputConfigureCommand createPwm = commandFactory.CreatePwmOutputConfigure(pwmPinSpec, 100); OurImpl_.PostMessage(createPwm); // message post fills in pin def so pick that up. runs in a thread so wait until command completes // have to capture the PwmDef to get the frequencey while (createPwm.PwmDef.Frequency < 0) { System.Threading.Thread.Sleep(10); } this.ServoPinDef_ = createPwm.PwmDef; // value should match minimum of the slider IPwmOutputUpdatePulseWidthCommand command = new IOIOMessageCommandFactory().CreatePwmPulseWithOutputUpdate(this.ServoPinDef_, 600.0f); OurImpl_.PostMessage(command); }
public ISpiMasterConfigureCommand CreateSpiMasterOpen(int miso, int mosi, int clk, int slaveSelect, Component.Types.SpiMasterRate rate) { DigitalOutputSpec[] slaveSelectCalc = new DigitalOutputSpec[1]; slaveSelectCalc[0] = new DigitalOutputSpec(slaveSelect); return(new SpiMasterConfigureCommand(new DigitalInputSpec(miso), new DigitalOutputSpec(mosi), new DigitalOutputSpec(clk), slaveSelectCalc, new SpiMasterConfig(rate))); }
public IDigitalOutputValueSetCommand CreateDigitalOutputCommandSet(DigitalOutputSpec spec, bool level) { return(new DigitalOutputSetValueCommand(spec, level)); }
internal DigitalOutputSetValueCommand(DigitalOutputSpec pinDef, bool level) { // TODO: Complete member initialization this.PinDef = pinDef; this.Level = level; }
public IPwmOutputConfigureCommand CreatePwmOutputConfigure(DigitalOutputSpec spec, int freqHz, float dutyCycle) { return(new PwmOutputConfigureCommand(spec, freqHz, dutyCycle)); }
public IPwmOutputConfigureCommand CreatePwmOutputConfigure(DigitalOutputSpec spec, int freqHz) { return(new PwmOutputConfigureCommand(spec, freqHz)); }
public IPwmOutputConfigureCommand CreatePwmOutputConfigure(DigitalOutputSpec spec, bool enable) { return(new PwmOutputConfigureCommand(spec, enable)); }
public DigitalOutputCloseCommand(DigitalOutputSpec spec) { this.PinDef = spec; }
public IDigitalOutputCloseCommand CreateDigitalOutputCommandClose(DigitalOutputSpec spec) { return(new DigitalOutputCloseCommand(spec)); }