Beispiel #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();
                    }
                }
            }
        }
Beispiel #2
0
            public SSD1306Driver(I2CBusPI bus)
            {
                var i2cDevice = new I2CDevicePI(bus, SSD1306.Display.DefaultI2CAddress);

                display = new SSD1306.Display(i2cDevice, 128, 64, true);
                display.Init();
            }
Beispiel #3
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();
        }
        // Method to initialize the BME280 sensor using the I2C interface
        public async Task InitializeDevice()
        {
            Debug.WriteLine("BME280::Initializing device with I2C interface");

            try
            {
                bme280 = new I2CDevicePI(bus, BME280_Address);

                if (bme280 == null) // Check if a device was found at the slave address provided by BME280_Address
                {
                    Debug.WriteLine("Device not found");
                    return;
                }
                else // Since we found a device, let's verify that it is a BME280 by looking at the signature
                {
                    Debug.WriteLine("BME280::Verifying device signature");
                    var WriteBuffer = new byte[] { (byte)Registers.BME280_REGISTER_CHIPID }; // This register stores the signature value
                    var ReadBuffer  = new byte[] { 0xFF };                                   // Initialized to an arbitrary number

                    bme280.WriteRead(WriteBuffer, ReadBuffer);                               // Read the device signature and store in ReadBuffer[0]

                    if (ReadBuffer[0] != BME280_Signature)                                   // Verify the device signature
                    {
                        Debug.WriteLine("BME280::Signature mismatch");
                        return;
                    }

                    Debug.WriteLine("BME280::Getting device ready");

                    // As per the data sheet's instructions, we need some stuff before we can
                    // start taking measurements using the BME280's registers.
                    await ReadCalibrationCoefficients();  // Read the compensation coefficients from the factory
                    await WriteControlRegister();         // Write to the control register
                    await WriteControlRegisterHumidity(); // Write to the humidity control register

                    Debug.WriteLine("BME280::Device is ready");
                }

                init = true;
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception: " + e.Message + "\n" + e.StackTrace);
                throw;
            }
        }
 public static void WriteRead(this I2CDevicePI device, byte[] writeBuffer, byte[] readBuffer)
 {
     device.Write(writeBuffer);
     device.ReadBytes(writeBuffer[0], (byte)readBuffer.Length, readBuffer);
 }
 public static void Write(this I2CDevicePI device, byte[] data) => device.Write(data.First(), data.Skip(1).ToArray());
Beispiel #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();
            }
        }