Ejemplo n.º 1
0
        static void Main()
        {
            RtcController rtc = RtcController.GetDefault();

            try
            {
                var t = rtc.GetTime();
                if (t.Year == 1980)
                {
                    rtc.SetTime(RtcDateTime.FromDateTime(new DateTime(2018, 10, 12, 17, 51, 00)));
                }
            }
            catch (Exception)
            {
                rtc.SetTime(RtcDateTime.FromDateTime(new DateTime(2018, 10, 11, 11, 51, 00)));
            }

            //string COM = "GHIElectronics.TinyCLR.NativeApis.STM32F7.UartController\\2";
            UartController ser = UartController.FromName(STM32F7.UartPort.Usart1); // DISCO-F769

            //UartController ser = UartController.FromName(STM32F7.UartPort.Usart3); // NUCLEO-F767
            ser.SetActiveSettings(38400, 8, UartParity.None, UartStopBitCount.One, UartHandshake.None);
            Debug.WriteLine("Starting Program ....");
            BlinkLed blink = new BlinkLed(STM32F7.GpioPin.PJ5, 500); // Disco 769
            //BlinkLed blink = new BlinkLed(STM32F7.GpioPin.PB7, 500); // Nucleo 144 - F767
            Thread run = new Thread(blink.Blink);

            run.Start();
            var r = new HeapAllocTest(10);

            r.Allocate();
            //var d = new DisplayTest();
            string sallocated = "";
            //Debug.WriteLine("Allocated TOTAL Memory:" + GC.GetTotalMemory(false).ToString() + " bytes!");
            //d.DrawSomething("Test String...", 50,50);

            int x = 10, y = 10;

            //SDTest sd = new SDTest();

            sallocated = "Memory:" + GC.GetTotalMemory(true).ToString() + " bytes!";
            while (true)
            {
                x += 2;
                y += 2;
                if (x > (800 - 160) || y > 480 - 160)
                {
                    x = 10;
                    y = 10;
                    GC.Collect();
                }
                Thread.Sleep(1000);
                //d.DrawSomething(sallocated, x, y);
                var    dt = rtc.Now;
                byte[] b  = System.Text.Encoding.UTF8.GetBytes("Program Running !! .." + dt.ToString("dd/MM/yyyy HH:mm:ss") + "\r\n");
                ser.Write(b);
                ser.Flush();
            }
        }
Ejemplo n.º 2
0
        private void toolStripBtnTest_Click(object sender, EventArgs e)
        {
            RtcDateTime rtc = new RtcDateTime();

            byte[] ary_bcd = rtc.GetDateTimeBytesFromNow();

            int x = 0;
        }
Ejemplo n.º 3
0
        private void ThreadTest()
        {
            this.isRunning = true;

            var m = new DateTime(2020, 7, 7, 00, 00, 00);

            if (this.rtc.IsValid && this.rtc.Now >= m)
            {
                while (this.isRunning)
                {
                    var time = this.rtc.Now.ToString();

                    this.UpdateStatusText("RTC is working: " + time, true);
                }
            }
            else
            {
                var newDt = RtcDateTime.FromDateTime(m);

                var charetimeout = 0;

                this.rtc.SetChargeMode(BatteryChargeMode.Fast);

                while (charetimeout < ChargeVbatTimeout)
                {
                    this.UpdateStatusText("Please wait for charing...." + charetimeout + " / " + ChargeVbatTimeout, true);

                    charetimeout++;

                    Thread.Sleep(1000);
                }

                this.rtc.SetChargeMode(BatteryChargeMode.None);

                this.rtc.SetTime(newDt);
                GHIElectronics.TinyCLR.Native.SystemTime.SetTime(m);

                this.UpdateStatusText("Please power off the board for 10 seconds", false);
            }


            this.isRunning = false;

            return;
        }
        private bool DoTestRtc()
        {
            this.UpdateStatusText("Testing real time clock... ", true);
try_again:
            try {
                var rtc = RtcController.GetDefault();

                var m = new DateTime(2020, 7, 7, 00, 00, 00);


                if (rtc.IsValid && rtc.Now >= m)
                {
                    return(true);
                }

                else
                {
                    var newDt = RtcDateTime.FromDateTime(m);

                    rtc.SetTime(newDt);

                    if (rtc.IsValid && rtc.Now >= m)
                    {
                        return(true);
                    }
                }
            }
            catch {
                this.UpdateStatusText("Try Rtc again... ", true);
            }

            if (this.isRunning)
            {
                goto try_again;
            }

            return(false);
        }
Ejemplo n.º 5
0
 public extern void SetTime(RtcDateTime value);