示例#1
0
        public static void Main(string[] args)
        {
            using (var i2cBus = new I2CBusPI("/dev/i2c-1"))
            {
                var i2cDevice = new I2CDevicePI(i2cBus, Display.DefaultI2CAddress);

                display = new SSD1306.Display(i2cDevice, 128, 32);
                display.Init();

                var Tahmona8       = new Tahmona8();
                var tahmona10      = new Tahmona10();
                var tahmona12      = new Tahmona12();
                var tahmona14      = new Tahmona14();
                var dinerRegular24 = new DinerRegular24();

                display.WriteLineBuffProportional(dinerRegular24, "192.168.0.5");
                display.DisplayUpdate();

                while (true)
                {
                    foreach (var dfont in new IFont[] { dinerRegular24, Tahmona8, tahmona10, tahmona12, tahmona14 })
                    {
                        display.WriteLineBuff(dfont, "Hello World 123456", dfont.GetType().Name);
                        display.DisplayUpdate();
                        Console.ReadLine();
                    }
                }
            }
        }
示例#2
0
            public SSD1306Driver(I2CBusPI bus)
            {
                var i2cDevice = new I2CDevicePI(bus, SSD1306.Display.DefaultI2CAddress);

                display = new SSD1306.Display(i2cDevice, 128, 64, true);
                display.Init();
            }
示例#3
0
            public BME280Sensor(I2CBusPI bus, IObservable <Unit> pollingTrigger)
            {
                var sensor = new BoschDevices.BME280Sensor(bus, 1014);
                var delay  = TimeSpan.FromMilliseconds(500);

                CurrentTemperature = pollingTrigger.Buffer(delay).Select(_ => (double)sensor.ReadTemperature().Result);
            }
示例#4
0
        static void Main(string[] args)
        {
            MMALCamera cam = MMALCamera.Instance;

            // Create observable that will generate an incrementing number every second
            var observable = Observable.Generate(1, x => true, x => x + 1, x => x, x => TimeSpan.FromSeconds(1));

            var relay  = OutputPort.Create(17, OutputPort.InitialValue.Low).Result;
            var light1 = OutputPort.Create(27, OutputPort.InitialValue.Low).Result;
            var light2 = OutputPort.Create(22, OutputPort.InitialValue.Low).Result;
            var button = InputPort.Create(24, GpioEdge.Both).Result;

            // Write true whenever the number is even and odd when the number is odd
            using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/", "jpg"))
                using (observable.Select(x => x % 2 == 0).Subscribe(relay))
                    using (observable.Select(x => x % 2 == 0).Subscribe(light1))
                        //using (observable.Select(x => x % 2 != 0).Subscribe(light2))
                        //using (button.Do(pressed => Console.WriteLine(pressed)).Subscribe())
                        using (button.Subscribe(light2))
                            using (var i2cBus = new I2CBusPI("/dev/i2c-1"))
                            {
                                var takePictureTask = cam.TakePicture(imgCaptureHandler, MMALEncoding.JPEG, MMALEncoding.I420);

                                var i2cDevice = new I2CDevicePI(i2cBus, Display.DefaultI2CAddress);

                                var sensor = new BME280Sensor(i2cBus, 1014);

                                var display = new SSD1306.Display(i2cDevice, 128, 64);
                                display.Init();

                                var dfont = new AdafruitSinglePageFont();

                                for (int i = 0; i < 100; i++)
                                {
                                    display.WriteLineBuff(dfont, $"Temperature: {sensor.ReadTemperature().Result} °C", $"Pressure: {sensor.ReadPressure().Result} Pa", $"Humidity: {sensor.ReadHumidity().Result} %", $"Altitude: {sensor.ReadAltitude().Result} m", "Line 5", "Line 6", "Line 7", "Line 8");
                                    display.DisplayUpdate();
                                }

                                //for (int i = 0; i < 100; i++)
                                //    display.DrawPixel(i, i);

                                takePictureTask.Wait();
                                display.ClearDisplay();
                            }
            // releasing relay
            relay.Write(true);
            // turning of light
            light1.Write(false);
            light2.Write(false);
            // Cleanup disposes all unmanaged resources and unloads Broadcom library. To be called when no more processing is to be done
            // on the camera.
            cam.Cleanup();
        }
 public BME280Sensor(I2CBusPI bus, float localSeaLevelPressureHectopascal)
 {
     this.bus         = bus;
     seaLevelPressure = localSeaLevelPressureHectopascal;
 }
示例#6
0
 public I2CBus(IObservable <Unit> pollingTrigger)
 {
     bus = new I2CBusPI(1);
     this.pollingTrigger = pollingTrigger;
 }
示例#7
0
        public static void Main(string[] args)
        {
            IFont font = null;

            bool flip         = false;
            bool ipwait       = false;
            bool proportional = false;
            var  lines        = new List <string>();

            if (args.Length == 0)
            {
                DisplayHelp();
                return;
            }

            for (int i = 0; i < args.Length; i++)
            {
                var argLow = args[i].ToLower();
                switch (argLow)
                {
                case "--flip":
                    flip = true;
                    break;

                case "--ip":
                case "-i":
                    lines.Add(getIPAddress());
                    break;

                case "--proportional":
                case "-p":
                    proportional = true;
                    break;

                case "-f":
                case "--font":
                    i++;
                    foreach (var fontType in GetFonts())
                    {
                        if (fontType.ToString().ToLower().Contains(args[i]))
                        {
                            font = (IFont)Activator.CreateInstance(fontType);
                            continue;
                        }
                    }
                    break;

                case "--ipwait":
                    ipwait = true;
                    break;

                case "--help":
                case "-h":
                    DisplayHelp();
                    return;

                default:
                    lines.Add(args[i]);
                    break;
                }
            }

            while (ipwait)
            {
                var ip = getIPAddress();
                if (!ip.StartsWith("0.") && !ip.StartsWith("127"))
                {
                    lines.Add(ip);
                    ipwait = false;
                    break;
                }
                Thread.Sleep(500);
            }

            if (lines.Count == 0)
            {
                lines.Add(getIPAddress());
            }

            if (font == null && lines.Count == 1)
            {
                Match match = Regex.Match(lines[0], @"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}");
                if (match.Success)
                {
                    font         = new DinerRegular24();
                    proportional = true;
                }
            }

            if (font == null)
            {
                font = new Tahmona10();
            }


            using (var i2cBus = new I2CBusPI("/dev/i2c-1"))
            {
                var i2cDevice = new I2CDevicePI(i2cBus, Display.DefaultI2CAddress);

                var display = new SSD1306.Display(i2cDevice, 128, 32, flip);
                display.Init();

                if (proportional)
                {
                    display.WriteLineBuffProportional(font, lines[0]);
                }
                else
                {
                    display.WriteLineBuff(font, lines.ToArray());
                }
                display.DisplayUpdate();
            }
        }