예제 #1
0
 public Ammeter(WirekiteDevice device, int i2cPort)
 {
     this.device  = device;
     this.i2cPort = i2cPort;
     releasePort  = false;
     InitSensor();
 }
예제 #2
0
 public GyroMPU6050(WirekiteDevice device, I2CPins i2cPins)
 {
     this.device = device;
     i2cPort     = device.ConfigureI2CMaster(i2cPins, 100000);
     releasePort = true;
     InitSensor();
 }
예제 #3
0
 public void OnDeviceDisconnected(WirekiteDevice device)
 {
     timer.Dispose();
     servo.Port = 0;
     servo      = null;
     device     = null;
 }
예제 #4
0
 public GyroMPU6050(WirekiteDevice device, int i2cPort)
 {
     this.device  = device;
     this.i2cPort = i2cPort;
     releasePort  = false;
     InitSensor();
 }
예제 #5
0
 public RF24Radio(WirekiteDevice device, int spiPort, int cePin, int csnPin)
 {
     this.device  = device;
     this.spiPort = spiPort;
     cePort       = device.ConfigureDigitalOutputPin(cePin, DigitalOutputPinAttributes.Default, false);
     csnPort      = device.ConfigureDigitalOutputPin(csnPin, DigitalOutputPinAttributes.Default, true);
 }
예제 #6
0
 public ColorTFT(WirekiteDevice device, int spiPort, int csPin, int dcPin, int resetPin)
 {
     this.device = device;
     spi         = spiPort;
     csPort      = device.ConfigureDigitalOutputPin(csPin, DigitalOutputPinAttributes.Default, true);
     dcPort      = device.ConfigureDigitalOutputPin(dcPin, DigitalOutputPinAttributes.Default, true);
     resetPort   = device.ConfigureDigitalOutputPin(resetPin, DigitalOutputPinAttributes.Default, true);
 }
예제 #7
0
        public void OnDeviceConnected(WirekiteDevice device)
        {
            _device = device;
            _device.ResetConfiguration();

            _builtinLED = device.ConfigureDigitalOutputPin(13, DigitalOutputPinAttributes.Default);
            _ledTimer   = new Timer(Blink, null, 300, 500);
        }
예제 #8
0
        public void OnDeviceConnected(WirekiteDevice device)
        {
            this.device = device;
            device.ResetConfiguration();

            i2cPort  = device.ConfigureI2CMaster(I2CPins.I2CPinsSCL19_SDA18, 100000);
            nunchuck = new NunchuckController(device, i2cPort);
            timer    = new Timer(ReadNunchuck, null, 0, 100);
        }
예제 #9
0
        public void OnDeviceConnected(WirekiteDevice device)
        {
            this.device = device;
            device.ResetConfiguration();

            device.ConfigurePWMTimer(0, 100, PWMTimerAttributes.Default);
            servo = new ServoController(device, 10);
            servo.TurnOn(0);
            timer = new Timer(MoveServo, null, 0, 1000);
        }
예제 #10
0
        public void OnDeviceConnected(WirekiteDevice device)
        {
            this.device = device;
            device.ResetConfiguration();

            redLight    = device.ConfigureDigitalOutputPin(16, DigitalOutputPinAttributes.HighCurrent);
            orangeLight = device.ConfigureDigitalOutputPin(17, DigitalOutputPinAttributes.HighCurrent);
            greenLight  = device.ConfigureDigitalOutputPin(21, DigitalOutputPinAttributes.HighCurrent);
            timer       = new Timer(SwichTrafficLight, null, 0, 500);
        }
예제 #11
0
        public void OnDeviceDisconnected(WirekiteDevice device)
        {
            DisposeTimers();

            _device = null;

            redCheckBox.IsChecked    = false;
            orangeCheckBox.IsChecked = false;
            greenCheckBox.IsChecked  = false;
            SetSwitchDisplay(false);
        }
예제 #12
0
        public void OnDeviceConnected(WirekiteDevice device)
        {
            this.device = device;
            device.ResetConfiguration();

            greenButton = device.ConfigureDigitalInputPin(14, DigitalInputPinAttributes.Pullup | DigitalInputPinAttributes.TriggerFalling, (port, value) =>
            {
                PlaySound("ding_dong");
            });
            redButton = device.ConfigureDigitalInputPin(20, DigitalInputPinAttributes.Pullup | DigitalInputPinAttributes.TriggerFalling, (port, value) =>
            {
                PlaySound("gliss");
            });
        }
예제 #13
0
        public void OnDeviceConnected(WirekiteDevice device)
        {
            this.device = device;
            device.ResetConfiguration();

            analogInput = device.ConfigureAnalogInputPin(AnalogPin.A1, 100, (port, value) =>
            {
                Dispatcher.Invoke(() =>
                {
                    double voltage       = value / bandgap;
                    string text          = String.Format("{0:0.000} V", voltage);
                    voltageLabel.Content = text;
                });
            });

            bandgapReference = device.ConfigureAnalogInputPin(AnalogPin.BandGap, 990, (port, value) =>
            {
                bandgap = value;
            });
        }
예제 #14
0
 public ServoController(WirekiteDevice device, int pin)
 {
     Device = device;
     Pin    = pin;
 }
예제 #15
0
 public void OnDeviceDisconnected(WirekiteDevice device)
 {
     device = null;
 }
예제 #16
0
 public OLEDDisplay(WirekiteDevice device, I2CPins i2cPins)
 {
     this.device = device;
     i2cPort     = device.ConfigureI2CMaster(i2cPins, 400000);
     releasePort = true;
 }
예제 #17
0
        public void OnDeviceConnected(WirekiteDevice device)
        {
            _device = device;
            _device.ResetConfiguration();

            if (hasBuiltInLED)
            {
                _builtinLED = device.ConfigureDigitalOutputPin(13, DigitalOutputPinAttributes.Default);

                _ledTimer = new Timer(Blink, null, 300, 500);
            }

            if (useLEDBoard)
            {
                _redLED    = device.ConfigureDigitalOutputPin(16, DigitalOutputPinAttributes.HighCurrent);
                _orangeLED = device.ConfigureDigitalOutputPin(17, DigitalOutputPinAttributes.HighCurrent);
                _greenLED  = device.ConfigureDigitalOutputPin(21, DigitalOutputPinAttributes.HighCurrent);

                _switchPort = device.ConfigureDigitalInputPin(12, DigitalInputPinAttributes.Pullup | DigitalInputPinAttributes.TriggerRaising | DigitalInputPinAttributes.TriggerFalling, (port, value) =>
                {
                    Dispatcher.Invoke(new Action(() =>
                    {
                        SetSwitchDisplay(value);
                    }));
                });
                SetSwitchDisplay(device.ReadDigitalPin(_switchPort));

                _dutyCyclePin = device.ConfigureAnalogInputPin(AnalogPin.A4, 127, (port, value) =>
                {
                    device.WritePWMPin(_pwmOutputPin, value);
                    Dispatcher.Invoke(new Action(() =>
                    {
                        string text = String.Format("{0:##0.0} %", value * 100);
                        dutyCycleValueLabel.Content = text;
                    }));
                });

                _frequencyPin = device.ConfigureAnalogInputPin(AnalogPin.A1, 149, (port, value) =>
                {
                    if (Math.Abs(value - _prevFrequencyValue) > 0.01)
                    {
                        _prevFrequencyValue = value;
                        int frequency       = (int)((Math.Exp(Math.Exp(value)) - Math.Exp(1)) * 900 + 10);
                        _device.ConfigurePWMTimer(0, frequency, PWMTimerAttributes.Default);
                        Dispatcher.Invoke(new Action(() =>
                        {
                            string text = String.Format("{0} Hz", frequency);
                            frequencyValueLabel.Content = text;
                        }));
                    }
                });

                _voltageXPin = device.ConfigureAnalogInputPin(AnalogPin.A8, 137, (port, value) =>
                {
                    Dispatcher.Invoke(new Action(() =>
                    {
                        analogStick.XDirection = 1.0 - value * 2;
                    }));
                });
                _voltageYPin = device.ConfigureAnalogInputPin(AnalogPin.A9, 139, (port, value) =>
                {
                    Dispatcher.Invoke(new Action(() =>
                    {
                        analogStick.YDirection = 1.0 - value * 2;
                    }));
                });

                _stickSwitchPin = device.ConfigureDigitalInputPin(20,
                                                                  DigitalInputPinAttributes.TriggerRaising | DigitalInputPinAttributes.TriggerFalling | DigitalInputPinAttributes.Pullup,
                                                                  (port, value) =>
                {
                    Dispatcher.Invoke(new Action(() =>
                    {
                        analogStick.Foreground = value ? _stickReleasedColor : _stickPressedColor;
                    }));
                });
                analogStick.Foreground = device.ReadDigitalPin(_stickSwitchPin) ? _stickReleasedColor : _stickPressedColor;

                _pwmOutputPin = device.ConfigurePWMOutputPin(10);
            }

            if (useI2CBoard)
            {
                _i2cPort = _device.ConfigureI2CMaster(I2CPins.I2CPinsSCL16_SDA17, 400000);
                _gyro    = new GyroMPU6050(_device, _i2cPort);
                _gyro.StartCalibration();
                _gyroTimer = new Timer(ReadGyro, null, 400, 400);

                _ammeter      = new Ammeter(_device, _i2cPort);
                _ammeterTimer = new Timer(ReadAmmeter, null, 300, 350);

                _display = new OLEDDisplay(_device, _i2cPort)
                {
                    DisplayOffset = 2
                };
                StartOLEDShow();
            }

            if (useSpiTFTBoard)
            {
                if (_device.GetBoardInfo(BoardInfo.Board) == WirekiteDevice.BoardTeensyLC)
                {
                    _spiPort = _device.ConfigureSPIMaster(14, 11, WirekiteDevice.InvalidPortId, 16000000, SPIAttributes.Default);
                }
                else
                {
                    _device.ConfigureFlowControl(memorySize: 20000, maxOutstandingRequests: 100);
                    _spiPort = _device.ConfigureSPIMaster(14, 11, WirekiteDevice.InvalidPortId, 18000000, SPIAttributes.Default);
                }
                _colorTFT = new ColorTFT(_device, _spiPort, 6, 4, 5);

                StartColorShow();
            }

            if (useSpiRFBoard)
            {
                if (_device.GetBoardInfo(BoardInfo.Board) == WirekiteDevice.BoardTeensy3_2)
                {
                    _device.ConfigureFlowControl(memorySize: 20000, maxOutstandingRequests: 100);
                }
                _spiPort = _device.ConfigureSPIMaster(14, 11, 12, 10000000, SPIAttributes.Default);
                _radio   = new RF24Radio(_device, _spiPort, 18, 19);
                _radio.InitModule();
                _radio.RFChannel   = 0x52;
                _radio.AutoAck     = false;
                _radio.OutputPower = RF24Radio.RFOutputPower.Low;

                _radio.ConfigureIRQPin(10, 10, PacketReceived);

                _radio.OpenTransmitPipe(0x389f30cc1b);
                _radio.OpenReceivePipe(1, 0x38a8bb7201);
                _radio.StartListening();

                _radioThread = new Thread(SendTime);
                _radioThread.Start();
            }
        }
예제 #18
0
 public OLEDDisplay(WirekiteDevice device, int i2cPort)
 {
     this.device  = device;
     this.i2cPort = i2cPort;
     releasePort  = false;
 }
예제 #19
0
 public NunchuckController(WirekiteDevice device, int i2cPort)
 {
     Device  = device;
     I2CPort = i2cPort;
     InitController();
 }
예제 #20
0
 public void OnDeviceDisconnected(WirekiteDevice device)
 {
     timer.Dispose();
     device = null;
 }