Пример #1
0
 /// <summary>
 /// Instantiates an Mcp23008 on the specified I2C bus using the appropriate
 /// peripheral address based on the pin settings. Use this method if you
 /// don't want to calculate the address.
 /// </summary>
 /// <param name="i2cBus"></param>
 /// <param name="pinA0">Whether or not Address0 pin is pulled high.</param>
 /// <param name="pinA1">Whether or not Address1 pin is pulled high.</param>
 /// <param name="pinA2">Whether or not Address2 pin is pulled high.</param>
 /// <param name="interruptPort">Optional IDigitalInputPort used to support
 /// interrupts. The MCP will notify a single port for an interrupt on
 /// any input configured pin. The driver takes care of looking up which
 /// pin the interrupt occurred on, and will raise it on that port, if a port
 /// is used.</param>
 public Mcp23x08(II2cBus i2cBus, bool pinA0, bool pinA1, bool pinA2,
                 IDigitalInputPort interruptPort = null)
     : this(i2cBus, McpAddressTable.GetAddressFromPins(pinA0, pinA1, pinA2))
 {
     // nothing goes here
 }
Пример #2
0
 public Ina260(II2cBus i2cBus, Addresses address)
     : this(i2cBus, (byte)address)
 {
 }
Пример #3
0
 /// <summary>
 /// Basic constructor
 /// </summary>
 /// <param name="bus">I2C bus</param>
 /// <param name="address">I2C device address</param>
 /// <param name="r">Number of text rows</param>
 /// <param name="c">Number of text columns</param>
 public DisplayLCD(II2cBus bus, byte address, byte r, byte c)
 {
     display = new I2cCharacterDisplay(bus, address, r, c);
     rows    = r;
     columns = c;
 }
Пример #4
0
        /// <summary>
        ///     Create a new TEA5767 object using the default parameters
        /// </summary>
        /// <param name="address">Address of the bus on the I2C display.</param>
        public Tea5767(II2cBus i2cBus, byte address = 0x60)
        {
            _I2cPeripheral = new I2cPeripheral(i2cBus, address);

            InitTEA5767();
        }
Пример #5
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="T:Meadow.Foundation.Sensors.Barometric.BME280" /> class.
 /// </summary>
 /// <param name="i2c">I2C Bus to use for communicating with the sensor</param>
 /// <param name="busAddress">I2C address of the sensor (default = 0x77).</param>
 public Bme280(II2cBus i2c, I2cAddress busAddress = I2cAddress.Adddress0x77)
 {
     _bme280 = new Bme280I2C(i2c, (byte)busAddress);
     Init();
 }
        public override uint Height => 64;         //?

        public SSD1306OLED128x64(II2cBus i2cBus, byte address = 0x3c)
            : base(i2cBus, address)
        {
            this.InitSSD1306();
        }
Пример #7
0
 /// <summary>
 ///     Create a new HIH6130 object using the default parameters for the component.
 /// </summary>
 /// <param name="address">Address of the HIH6130 (default = 0x27).</param>
 /// <param name="i2cBus">I2C bus (default = 100 KHz).</param>
 public Hih6130(II2cBus i2cBus, byte address = 0x27)
 {
     hih6130 = new I2cPeripheral(i2cBus, address);
 }
Пример #8
0
 public Is31fl3731(II2cBus i2cBus, byte address)
 {
     i2cPeripheral = new I2cPeripheral(i2cBus, address);
     Frame         = 0;
 }
Пример #9
0
 /// <summary>
 ///     Create a new GroveTH02 object using the default parameters for the component.
 /// </summary>
 /// <param name="address">Address of the Grove TH02 (default = 0x4-).</param>
 /// <param name="i2cBus">I2C bus (default = 100 KHz).</param>
 public GroveTh02(II2cBus i2cBus, byte address = 0x40)
 {
     groveTH02 = new I2cPeripheral(i2cBus, address);
 }
Пример #10
0
        /// <summary>
        ///     Create a new HT16K33 object using the default parameters
        /// </summary>
        /// <param name="address">Address of the bus on the I2C display.</param>
        /// <param name="i2cBus">I2C bus instance</param>
        public HT16K33(II2cBus i2cBus, byte address = 0x70)
        {
            _I2cPeripheral = new I2cPeripheral(i2cBus, address);

            InitHT16K33();
        }
Пример #11
0
 /// <summary>
 /// Create a new MAG3110 object using the default parameters for the component.
 /// </summary>
 /// <param name="device">IO Device.</param>
 /// <param name="interruptPin">Interrupt pin used to detect end of conversions.</param>
 /// <param name="address">Address of the MAG3110 (default = 0x0e).</param>
 /// <param name="speed">Speed of the I2C bus (default = 400 KHz).</param>
 public MAG3110(IIODevice device, II2cBus i2cBus, IPin interruptPin = null, byte address = 0x0e, ushort speed = 400) :
     this(i2cBus, device.CreateDigitalInputPort(interruptPin, InterruptMode.EdgeRising, ResistorMode.Disabled), address)
 {
 }
Пример #12
0
        /// <summary>
        /// Initializes all hardware and software classes
        /// </summary>
        void Initialize()
        {
            Console.WriteLine("Initialize hardware...");

            onboardLed = new RgbPwmLed(device: Device,
                                       redPwmPin: Device.Pins.OnboardLedRed,
                                       greenPwmPin: Device.Pins.OnboardLedGreen,
                                       bluePwmPin: Device.Pins.OnboardLedBlue,
                                       3.3f, 3.3f, 3.3f,
                                       Meadow.Peripherals.Leds.IRgbLed.CommonType.CommonAnode);

#if DEBUG
            Console.WriteLine("Initializing bus");
#endif
            bus = Device.CreateI2cBus(400000);

#if DEBUG
            Console.WriteLine("Initializing display 1");
#endif
            displaySmall = new DisplayLCD(bus, 0x27, 2, 16);
            displaySmall.Write("I'm alive!");

#if DEBUG
            Console.WriteLine("Initializing display 2");
#endif
            displayBig = new DisplayLCD(bus, 0x23, 4, 20);
            displayBig.Write("I'm alive!");

#if DEBUG
            Console.WriteLine("Initializing hc12");
#endif
            displaySmall.Write("Initializing radio");
            serialCom = new HC12Communication(Device.CreateSerialMessagePort(Device.SerialPortNames.Com4,
                                                                             suffixDelimiter: new byte[] { 10 },
                                                                             preserveDelimiter: true, 115200, 8, Parity.None,
                                                                             StopBits.One));
            com = new CommunicationWrapper(serialCom);

#if DEBUG
            Console.WriteLine("Initializing WiFi");
#endif
            displaySmall.Write("Initializing WiFi");
            ipCom = new WifiUdpCommunication(Device.WiFiAdapter, new Action <string>[] { com.SendMessage, displaySmall.Write });
            //Trying to connect at startup to speed process up, but router might be still booting so in that case will try again when requested
            Task.Run(() =>
            {
                try
                {
                    ConnectToWiFi("");
                }
                catch (Exception e)
                {
                    com.SendMessage(ReturnCommandList.exception + e.Message + ReturnCommandList.exceptionTrace + e.StackTrace);
#if DEBUG
                    Console.WriteLine(e.Message + "/n/n" + e.StackTrace);
#endif
                }
            });

#if DEBUG
            Console.WriteLine("Initializing RTC");
#endif
            displaySmall.Write("Initializing RTC");
            clock = new Rtc(bus, com.SendMessage, SetClock);
            clock.SetClockFromRtc();

#if DEBUG
            Console.WriteLine("Initializing watchdog");
#endif
            displaySmall.Write("Initializing watchdog");
            watchdog = new Watchdog(Watchdog.Type.SerialPort);
            //serialCom.RegisterWatchdog(watchdog.MessageReceived);
            //ipCom.RegisterWatchdog(watchdog.MessageReceived);
            watchdog.RegisterSender(com.SendMessage);
            watchdog.RegisterBlockAction(EmergencyDisable);
            watchdog.RegisterSwitchToSerial(SwitchToSerial);

            dict  = new MethodsDictionary();
            queue = new MethodsQueue(com, dict);
            ipCom.SubscribeToMessages(queue.MessageReceived);
            ipCom.SubscribeToMessages(watchdog.MessageReceived);
            serialCom.SubscribeToMessages(queue.MessageReceived);
            serialCom.SubscribeToMessages(watchdog.MessageReceived);

#if DEBUG
            Console.WriteLine("Initializing pca @1600Hz");
#endif
            displaySmall.Write("Initializing PWM @1600Hz");
            pwm1600 = new Pca9685(bus, 0x61, 1600);
            pwm1600.Initialize();
#if DEBUG
            Console.WriteLine("Initializing pca @50Hz");
#endif
            displaySmall.Write("Initializing PWM @50Hz");
            pwm50 = new Pca9685(bus, 0x60, 50);
            pwm50.Initialize();

#if DEBUG
            Console.WriteLine("Initializing expander 1");
#endif
            displaySmall.Write("Initializing expander 1");
            expander1 = new Mcp23x08(bus, 0x20, Device.CreateDigitalInputPort(Device.Pins.D02, InterruptMode.EdgeBoth));

#if DEBUG
            Console.WriteLine("Initializing expander 2");
#endif
            displaySmall.Write("Initializing expander 2");
            expander2 = new Mcp23x08(bus, 0x21, Device.CreateDigitalInputPort(Device.Pins.D06, InterruptMode.EdgeBoth));

#if DEBUG
            Console.WriteLine("Initializing fans");
#endif
            displaySmall.Write("Initializing fans");
            LEDsFans   = new Fan(expander2.CreateDigitalOutputPort(expander2.Pins.GP4), "LEDs' fans");
            motorsFans = new Fan(expander2.CreateDigitalOutputPort(expander2.Pins.GP5), "Motors' fans");
            inasFan    = new Fan(expander2.CreateDigitalOutputPort(expander2.Pins.GP6), "INAs fan");

#if DEBUG
            Console.WriteLine("Initializing buzzer");
#endif
            displaySmall.Write("Initializing buzzer");
            buzzer = new Buzzer(expander2.CreateDigitalOutputPort(expander2.Pins.GP3, false, OutputType.OpenDrain));
            watchdog.RegisterBuzzer(buzzer.Buzz);
#pragma warning disable CS4014 // To wywołanie nie jest oczekiwane, dlatego wykonywanie bieżącej metody będzie kontynuowane do czasu ukończenia wywołania
            buzzer.Buzz();
#pragma warning restore CS4014 // To wywołanie nie jest oczekiwane, dlatego wykonywanie bieżącej metody będzie kontynuowane do czasu ukończenia wywołania

#if DEBUG
            Console.WriteLine("Initializing power sensors");
#endif
            displaySmall.Write("Initializing power sensors");
            INA219.INA219Configuration config = new INA219.INA219Configuration(INA219.BusVoltageRangeSettings.range32v,
                                                                               INA219.PGASettings.Gain320mV,
                                                                               INA219.ADCsettings.Samples128,
                                                                               INA219.ADCsettings.Samples128,
                                                                               INA219.ModeSettings.ShuntBusContinuous);
            ina219s = new INA219Array(new INA219[]
            {
                new INA219(3.2f, 0.1f, 1, bus, 0x41, config, "C"),
                new INA219(10f, 0.01f, 1, bus, 0x44, config, "L"),
                new INA219(10f, 0.01f, 1, bus, 0x45, config, "R")
            }, buzzer, displayBig, EmergencyDisable);
            ina219s.RegisterSender(com.SendMessage);
            ina219s.RegisterFan(inasFan.SetState);
            ina219s.RegisterFan(motorsFans.SetState);
            ina219s.StartMonitoringVoltage();

            //com = new ComCommunication(Device.CreateSerialMessagePort(Device.SerialPortNames.Com4, suffixDelimiter: new byte[] { 10 }, preserveDelimiter: true, 921600, 8, Parity.None, StopBits.One));

#if DEBUG
            Console.WriteLine("Initializing temperature sensor");
#endif
            displaySmall.Write("Initializing temperature sensor");
            tempPresSensor = new TempPressureSensor(bus);
            tempPresSensor.RegisterSender(com.SendMessage);
#if DEBUG
            Console.WriteLine("Initializing position sensor");
#endif
            displaySmall.Write("Initializing position sensor");
            positionSensor = new BNO055(bus, 0x28);
            positionSensor.RegisterSender(com.SendMessage);
            positionSensor.RegisterScreen(displaySmall.Write);

#if DEBUG
            Console.WriteLine("Initializing motor controller");
#endif
            displaySmall.Write("Initializing motor controller");
            motor = new MotorController(pwm1600.CreatePwmPort(3, 0),
                                        pwm1600.CreatePwmPort(2, 0),
                                        pwm1600.CreatePwmPort(1, 0),
                                        pwm1600.CreatePwmPort(0, 0),
                                        pwm50.CreatePwmPort(0),
                                        Device.CreateDigitalInputPort(Device.Pins.D03, InterruptMode.EdgeRising, ResistorMode.InternalPullDown, 20, 20),
                                        Device.CreateDigitalInputPort(Device.Pins.D04, InterruptMode.EdgeRising, ResistorMode.InternalPullDown, 20, 20),
                                        positionSensor, gimbal, queue.ClearQueue);

#if DEBUG
            Console.WriteLine("Initializing gimbal");
#endif
            displaySmall.Write("Initializing camera gimbal");
            gimbal = new CameraGimbal(pwm50.CreatePwmPort(2), pwm50.CreatePwmPort(1), positionSensor);

#if DEBUG
            Console.WriteLine("Initializing proximity sensors");
#endif
            displaySmall.Write("Initializing proximity sensors");
            proxSensors = new ProximitySensorsArray(new ProximitySensor[]
            {
                new ProximitySensor(expander1.CreateDigitalInputPort(expander1.Pins.GP0, InterruptMode.EdgeRising, ResistorMode.InternalPullUp, 500, 500), Direction.Forward, StopBehavior.Stop, "Front, right", queue, motor),
                new ProximitySensor(expander1.CreateDigitalInputPort(expander1.Pins.GP1, InterruptMode.EdgeRising, ResistorMode.InternalPullUp, 500, 500), Direction.Forward, StopBehavior.Stop, "Front, left", queue, motor),
                new ProximitySensor(expander1.CreateDigitalInputPort(expander1.Pins.GP2, InterruptMode.EdgeRising, ResistorMode.InternalPullUp, 500, 500), Direction.Forward, StopBehavior.Stop, "Front, center", queue, motor),
                new ProximitySensor(expander1.CreateDigitalInputPort(expander1.Pins.GP3, InterruptMode.EdgeRising, ResistorMode.InternalPullUp, 500, 500), Direction.Backward, StopBehavior.Stop, "Back, center", queue, motor)
            });
            proxSensors.Register(com.SendMessage);
            //proxSensors.Register(displaySmall.Write);

#if DEBUG
            Console.WriteLine("Initializing lamps");
#endif
            displaySmall.Write("Initializing lamps");
            narrowLed = new LedLamp(pwm1600.CreatePwmPort(4, 0), LEDsFans, "Front, narrow");
            wideLed   = new LedLamp(pwm1600.CreatePwmPort(5, 0), LEDsFans, "Front, wide");

#if DEBUG
            Console.WriteLine("Initializing cameras");
#endif
            displaySmall.Write("Initializing cameras");
            camera = new Camera(expander2.CreateDigitalOutputPort(expander2.Pins.GP7));
            camera.SetCamera(true);

#if DEBUG
            Console.WriteLine("Finishing initialization");
#endif
            displaySmall.Write("Finishing initialization");
            RegisterMethods();
            //watchdog.StartCheckingMessages();
#if DEBUG
            Console.WriteLine("All hardware initialized!");
#endif
            displaySmall.Clear();
            displaySmall.Write("Ready!");
            com.SendMessage("Ready!");
#pragma warning disable CS4014 // To wywołanie nie jest oczekiwane, dlatego wykonywanie bieżącej metody będzie kontynuowane do czasu ukończenia wywołania
            buzzer.BuzzPulse(100, 100, 3);
#pragma warning restore CS4014 // To wywołanie nie jest oczekiwane, dlatego wykonywanie bieżącej metody będzie kontynuowane do czasu ukończenia wywołania
        }
Пример #13
0
 public Tsl2591(II2cBus bus, byte address = (byte)Addresses.Default)
 {
     i2cBus  = bus;
     Address = address;
 }
Пример #14
0
 public GY521(II2cBus bus, byte address = 0x68)
 {
     Address = address;
     _bus    = bus;
 }
Пример #15
0
        /// <summary>
        ///     Create a new TEA5767 object using the default parameters
        /// </summary>
        /// <param name="address">Address of the bus on the I2C display.</param>
        public Tea5767(II2cBus i2cBus, byte address = TEA5767_ADDRESS)
        {
            i2cPeripheral = new I2cPeripheral(i2cBus, address);

            InitTEA5767();
        }
Пример #16
0
 public Vl53l0x(II2cBus i2cBus, byte address = 0x29, UnitType units = UnitType.mm) : this(i2cBus, null, address, units)
 {
 }
Пример #17
0
 /// <summary>
 ///     Create a new SSD1309 object using the default parameters for
 /// </summary>
 /// <remarks>
 ///     Note that by default, any pixels out of bounds will throw and exception.
 ///     This can be changed by setting the <seealso cref="IgnoreOutOfBoundsPixels" />
 ///     property to true.
 /// </remarks>
 /// <param name="address">Address of the bus on the I2C display.</param>
 public Ssd1309(II2cBus i2cBus, byte address = 0x3c) : base(i2cBus, address, DisplayType.OLED128x64)
 {
 }
Пример #18
0
 /// <summary>
 /// Create a new MAG3110 object using the default parameters for the component.
 /// </summary>
 /// <param name="device"></param>
 /// <param name="interruptPin">Digital pin connected to the alarm interrupt pin on the RTC.</param>
 public Ds3231(IIODevice device, II2cBus i2cBus, IPin interruptPin) :
     this(i2cBus, device.CreateDigitalInputPort(interruptPin))
 {
 }
Пример #19
0
 public LedMatrix8x16Wing(II2cBus i2cBus, byte address = 0x70)
 {
     ht16k33 = new Ht16K33(i2cBus, address);
 }
Пример #20
0
        //private int headingCorrection = 180;

        /// <summary>
        /// Basic constructor
        /// </summary>
        /// <param name="bus">I2C bus</param>
        /// <param name="address">I2C device address</param>
        public BNO055(II2cBus bus, byte address = 40)
        {
            sensor = new Bno055(bus, address);
            sensor.OperatingMode = Bno055.OperatingModes.NINE_DEGREES_OF_FREEDOM;
            bno = new I2cPeripheral(bus, address);
        }
Пример #21
0
        /// <summary>
        ///     Create a new Htu21d temperature and humidity sensor.
        /// </summary>
        /// <param name="address">Sensor address (default to 0x40).</param>
        /// <param name="i2cBus">I2CBus (default to 100 KHz).</param>
        public Htu21d(II2cBus i2cBus, byte address = 0x40)
        {
            htu21d = new I2cPeripheral(i2cBus, address);

            Initialize();
        }
Пример #22
0
 /// <summary>
 /// Constructor with sender action added
 /// </summary>
 /// <param name="sender">Method to send data to control app</param>
 /// <param name="bus">I2C bus</param>
 /// <param name="address">I2C device address</param>
 public BNO055(Action <string> sender, II2cBus bus, byte address = 40) : this(bus, address)
 {
     sendMessage += sender;
 }
Пример #23
0
 public Mpu6050(II2cBus bus, byte address = 0x68)
 {
     Address = address;
     _bus    = bus;
 }
Пример #24
0
 /// <summary>
 /// Basic constructor creating Bme280 object
 /// </summary>
 /// <param name="bus">I2C bus</param>
 /// <param name="address">I2C device address</param>
 public TempPressureSensor(II2cBus bus, byte address = 118)
 {
     sensor = new Bme280(bus, address);
 }
Пример #25
0
 /// <summary>
 ///     Create a new Dht10 object.
 /// </summary>
 /// <param name="address">Address of the Dht12 (default = 0x27).</param>
 /// <param name="i2cBus">I2C bus (default = 100 KHz).</param>
 public Dht10(II2cBus i2cBus, byte address = 0x5C) : base(i2cBus, address)
 {
     _sensor.WriteByte(CMD_SOFTRESET);
     Thread.Sleep(20);
     _sensor.WriteByte(CMD_INIT);
 }
Пример #26
0
 /// <summary>
 /// Constructor creating Bme280 object and assigning communication method
 /// </summary>
 /// <param name="bus">I2C bus</param>
 /// <param name="address">I2C device address</param>
 /// <param name="send">Communication method for sending data to controll app</param>
 public TempPressureSensor(II2cBus bus, Action <string> send, byte address = 118) : this(bus, address)
 {
     sendMessage = send;
 }
Пример #27
0
 internal Ms5611I2c(II2cBus i2c, byte address, Ms5611.Resolution resolution)
     : base(resolution)
 {
     _i2c     = i2c;
     _address = address;
 }
Пример #28
0
 public VEML7700(II2cBus bus)
 {
     Device = bus;
     Initialize((byte)Addresses.Default);
 }
Пример #29
0
        /// <summary>
        ///     Create a new SI7021 temperature and humidity sensor.
        /// </summary>
        /// <param name="address">Sensor address (default to 0x40).</param>
        /// <param name="i2cBus">I2CBus (default to 100 KHz).</param>
        public Si70xx(II2cBus i2cBus, byte address = 0x40)
        {
            si7021 = new I2cPeripheral(i2cBus, address);

            Initialize();
        }
Пример #30
0
 public I2cMcpDeviceComms(II2cBus bus, byte peripheralAddress)
     : base(bus, peripheralAddress)
 {
 }