public MeadowApp()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            rtc = new Ds1307(Device.CreateI2cBus());
            // Uncomment only when setting the time
            // rtc.SetTime(new DateTime(2019, 11, 23, 22, 55, 20));

            display = new CharacterDisplay
                      (
                device: Device,
                pinRS: Device.Pins.D15,
                pinE: Device.Pins.D14,
                pinD4: Device.Pins.D13,
                pinD5: Device.Pins.D12,
                pinD6: Device.Pins.D11,
                pinD7: Device.Pins.D10
                      );

            led.SetColor(RgbLed.Colors.Green);

            StartCountdown();
        }
Example #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, Realtime Clock DS1307!");

            I2cConnectionSettings settings = new I2cConnectionSettings(1, Ds1307.DefaultI2cAddress);
            I2cDevice             device   = I2cDevice.Create(settings);

            using (Ds1307 rtc = new Ds1307(device))
            {
                // set DS1307 time
                rtc.DateTime = DateTime.Now;

                // loop
                while (true)
                {
                    // read time
                    DateTime dt = rtc.DateTime;

                    Console.WriteLine($"Time: {dt.ToString("yyyy/MM/dd HH:mm:ss")}");
                    Console.WriteLine();

                    // wait for a second
                    Thread.Sleep(1000);
                }
            }
        }
Example #3
0
        private async Task TestClock()
        {
            // ***
            // *** Clock
            // ***
            Ds1307 dtc = new Ds1307();
            await dtc.InitializeAsync();

            // ***
            // *** Get the date and time from the clock
            // ***
            DateTimeOffset dt = await dtc.GetAsync();

            // ***
            // *** Create an NTP client and get the date and time
            // ***
            NtpClient      ntp = new NtpClient();
            DateTimeOffset?ndt = await ntp.GetAsync("0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org", "3.pool.ntp.org");

            // ***
            // *** Update the clock if we have a result from the servers
            // ***
            if (ndt.HasValue)
            {
                await dtc.SetAsync(ndt.Value);
            }
        }
Example #4
0
        public static void Main()
        {
            Debug.Print("mem: " + Debug.GC(false));

            I2CDevice i2cDevice = new I2CDevice(null);
            Ds1307    ds1307    = new Ds1307(200);

            ds1307.Test(i2cDevice);

            Thread.Sleep(1000);

            OutputPort uLcd144_reset = new OutputPort(Pins.GPIO_PIN_D13, true);
            ULcd144    uLcd144       = new ULcd144();

            uLcd144.Test(uLcd144_reset);
            Thread.Sleep(1000);

            _serialBridge           = new SerialBridge(Serial.COM1);
            _serialBridge.ReadLine += new ThreadedSerialDevice.ReadHandler(_serialBridge_ReadLine);

            while (true)
            {
                Thread.Sleep(100);
            }
        }
Example #5
0
        private async void Button_ClickAsync(object sender, RoutedEventArgs e)
        {
            Ds1307    ds  = new Ds1307();
            NtpClient ntp = new NtpClient();

            try
            {
                // await ds.InitializeAsync();
                // Debug.Write(ds.DeviceAddress);
                // //////     DateTime? dt = await ntp.GetAsync(@"europe.pool.ntp.org");
                // if (ds.IsInitialized)
                //     Debug.WriteLine("zains");

                // var dto = new DateTimeOffset(DateTime.Now);
                // await ds.SetAsync(dto);

                //// var dtoa = await ds.GetAsync();
                //// Debug.WriteLine(dtoa.DateTime.ToLocalTime());



                await LoadChartContents();
            }

            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                ds.Dispose();
            }
        }
Example #6
0
        public MeadowApp()
        {
            Console.WriteLine("Initializing...");

            rtc = new Ds1307(Device.CreateI2cBus());

            DS1307Test();
        }
Example #7
0
        private async Task Test()
        {
            Ds1307    dtc = new Ds1307();
            NtpClient ntp = new NtpClient();

            try
            {
                await dtc.InitializeAsync();

                // ***
                // *** Create an NTP client and get the date and time
                // ***

                var ndt = await ntp.GetAsync("0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org", "3.pool.ntp.org");

                // ***
                // *** Update the clock if we have a result from the servers
                // ***
                if (ndt.HasValue)
                {
                    await dtc.SetAsync(ndt.Value);
                }
                // ***
                // *** Get the date and time from the clock
                // ***
                if (!dtc.IsInitialized)
                {
                    return;
                }
                DateTimeOffset dt = await dtc.GetAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                dtc.Dispose();
            }
        }
Example #8
0
        public static void Main()
        {
            Debug.Print("mem: " + Debug.GC(false));

            I2CDevice i2cDevice = new I2CDevice(null);
            Ds1307 ds1307 = new Ds1307(200);
            ds1307.Test(i2cDevice);

            Thread.Sleep(1000);

            OutputPort uLcd144_reset = new OutputPort(Pins.GPIO_PIN_D13, true);
            ULcd144 uLcd144 = new ULcd144();
            uLcd144.Test(uLcd144_reset);
            Thread.Sleep(1000);

            _serialBridge = new SerialBridge(Serial.COM1);
            _serialBridge.ReadLine += new ThreadedSerialDevice.ReadHandler(_serialBridge_ReadLine);

            while (true)
            {
                Thread.Sleep(100);
            }
        }
Example #9
0
 public Rtc(II2cBus bus)
 {
     clock = new Ds1307(bus);
 }