Ejemplo n.º 1
0
        public void Save()
        {
            byte[] settings = Reflection.Serialize(this, typeof(AppSettings));
            if (settings.Length > 2044)
            {
                //EMX has 2048 bytes of battery backed-up RAM. 4 bytes are reserved for size
                throw new Exception("Settings size exceed memory limit");
            }

            byte[] settingsSize = new byte[4] {
                (byte)(settings.Length / 256), (byte)(settings.Length % 256), 0, 0
            };
            int pages = settings.Length / 4 + (settings.Length % 4 == 0 ? 0 : 1);

            byte[] settingsPages = new byte[4 * pages];
            Array.Copy(settings, settingsPages, settings.Length);

            try
            {
                BatteryRAM.Write(0, settingsSize, 0, 4);
                BatteryRAM.Write(4, settingsPages, 0, pages * 4);
            }
            catch (Exception)
            {
                //TODO: emulator throws exception
            }
        }
Ejemplo n.º 2
0
        public static void SetDateTime(DateTime newTime)
        {
            var buf = new byte[4];

            Utility.InsertValueIntoArray(buf, 0, 4, RtcValidMagic);
            RealTimeClock.SetTime(newTime);     // Update RTC.
            BatteryRAM.Write(0, buf, 0, 4);     // Mark it valid in BatteryRam.
            RtcIsValid = true;                  // Mark it valid in code.
            Utility.SetLocalTime(newTime);      // Don't forget to update the framework clock too!

            var evt = OnRtcUpdate;

            if (evt != null)
            {
                evt(newTime);
            }
        }