Ejemplo n.º 1
0
        void Initialize()
        {
            var onboardLed = new RgbPwmLed(
                device: Device,
                redPwmPin: Device.Pins.OnboardLedRed,
                greenPwmPin: Device.Pins.OnboardLedGreen,
                bluePwmPin: Device.Pins.OnboardLedBlue);

            onboardLed.SetColor(Color.Red);

            mcp = new Mcp23x08(Device.CreateI2cBus(), true, true, true);

            IDigitalOutputPort[] ports =
            {
                Device.CreateDigitalOutputPort(Device.Pins.D01),
                Device.CreateDigitalOutputPort(Device.Pins.D00),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP7,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP6,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP5,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP4,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP3,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP2,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP1,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP0,       false,  OutputType.PushPull),
            };

            ledBarGraph = new LedBarGraph(ports);

            onboardLed.SetColor(Color.Green);
        }
Ejemplo n.º 2
0
        public MeadowApp()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            mcp = new Mcp23x08(Device.CreateI2cBus(), true, true, true);

            IDigitalOutputPort[] ports =
            {
                Device.CreateDigitalOutputPort(Device.Pins.D01),
                Device.CreateDigitalOutputPort(Device.Pins.D00),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP7,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP6,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP5,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP4,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP3,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP2,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP1,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP0,       false,  OutputType.PushPull),
            };

            ledBarGraph = new LedBarGraph(ports);

            led.SetColor(RgbLed.Colors.Green);

            ledBarGraph.Percentage = 1;
            //CycleLeds();
        }
Ejemplo n.º 3
0
        void TestDigitalOutputPorts(int loopCount)
        {
            var out00 = _mcp.CreateDigitalOutputPort(_mcp.Pins.GP0);
            var out01 = _mcp.CreateDigitalOutputPort(_mcp.Pins.GP1);
            var out02 = _mcp.CreateDigitalOutputPort(_mcp.Pins.GP2);
            var out03 = _mcp.CreateDigitalOutputPort(_mcp.Pins.GP3);
            var out04 = _mcp.CreateDigitalOutputPort(_mcp.Pins.GP4);
            var out05 = _mcp.CreateDigitalOutputPort(_mcp.Pins.GP5);
            var out06 = _mcp.CreateDigitalOutputPort(_mcp.Pins.GP6);
            var out07 = _mcp.CreateDigitalOutputPort(_mcp.Pins.GP7);

            var outs = new List <IDigitalOutputPort>()
            {
                out00, out01, out02, out03, out04, out05, out06, out07
            };

            foreach (var outie in outs)
            {
                outie.State = true;
            }

            for (int l = 0; l < loopCount; l++)
            {
                // loop through all the outputs
                for (int i = 0; i < outs.Count; i++)
                {
                    // turn them all off
                    foreach (var outie in outs)
                    {
                        outie.State = false;
                    }

                    // turn on just one
                    outs[i].State = true;
                    Thread.Sleep(250);
                }
            }

            // cleanup
            for (int i = 0; i < outs.Count; i++)
            {
                outs[i].Dispose();
            }
        }
Ejemplo n.º 4
0
        public MeadowApp()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            mcp = new Mcp23x08(Device.CreateI2cBus(), true, true, true);

            leds = new List <Led>();
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP0)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP1)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP2)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP3)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP4)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP5)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP6)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP7)));

            led.SetColor(RgbLed.Colors.Green);

            CycleLeds();
        }
        void Initialize()
        {
            var onboardLed = new RgbPwmLed(
                device: Device,
                redPwmPin: Device.Pins.OnboardLedRed,
                greenPwmPin: Device.Pins.OnboardLedGreen,
                bluePwmPin: Device.Pins.OnboardLedBlue);

            onboardLed.SetColor(Color.Red);

            mcp = new Mcp23x08(Device.CreateI2cBus(), true, true, true);

            leds = new List <Led>();
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP0)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP1)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP2)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP3)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP4)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP5)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP6)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP7)));

            onboardLed.SetColor(Color.Green);
        }
Ejemplo n.º 6
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
        }