Ejemplo n.º 1
0
 public static void Load()
 {
     if (PersistentStorage.DetectSDCard())
     {
         storage = new PersistentStorage("SD");
         storage.MountFileSystem();
         RemovableMedia.Insert += new InsertEventHandler(RemovableMedia_Insert);
     }
 }
Ejemplo n.º 2
0
        private static void SDWatcher()
        {
            const int POLL_TIME = 500; // check every 500 millisecond
            bool      exists;

            while (true)
            {
                try // If SD card was removed while mounting, it may throw exceptions
                {
                    exists = PersistentStorage.DetectSDCard();

                    // make sure it is fully inserted and stable
                    if (exists)
                    {
                        Thread.Sleep(50);
                        exists = PersistentStorage.DetectSDCard();
                    }

                    if (exists && sdCard == null)
                    {
                        sdCard = new PersistentStorage("SD");
                        sdCard.MountFileSystem();
                    }
                    else if (!exists && sdCard != null)
                    {
                        sdCard.UnmountFileSystem();
                        sdCard.Dispose();
                        sdCard = null;
                    }
                }
                catch
                {
                    if (sdCard != null)
                    {
                        sdCard.Dispose();
                        sdCard = null;
                    }
                }

                Thread.Sleep(POLL_TIME);
            }
        }
Ejemplo n.º 3
0
 private bool MountCardStorage()
 {
     if (PersistentStorage.DetectSDCard())
     {
         try
         {
             lock (this)
             {
                 _cardStorage = new PersistentStorage("SD");
                 _cardStorage.MountFileSystem();
             }
             return(true);
         }
         catch (Exception)
         {
             ReleaseCardStorage();
             return(false);
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
        public Storage(string storageType)
        {
            try
            {
                if (PersistentStorage.DetectSDCard())
                {
                    ps = new PersistentStorage(storageType);
                    ps.MountFileSystem();
                    Debug.Print("SD Card found and mounted.");
                }

                if (!VolumeInfo.GetVolumes()[0].IsFormatted)
                {
                    Debug.Print("SD Card not formatted.");
                    throw new HomeMonitorException("SD Card not formatted.");
                }
            }
            catch (Exception e)
            {
                Debug.Print("Error: No SD Card Found!");
                //throw new HomeMonitorException("Error: No SD Card Found!", e);
            }
        }
Ejemplo n.º 5
0
        public Storage(string storageType, Microsoft.SPOT.Hardware.Cpu.Pin _detectPin)
        {
            cardDetectPin = new InputPort(_detectPin, false, Port.ResistorMode.PullUp);
            try
            {
                if (PersistentStorage.DetectSDCard())
                {
                    ps = new PersistentStorage(storageType);
                    ps.MountFileSystem();
                    Debug.Print("SD Card found and mounted.");
                }

                if (!VolumeInfo.GetVolumes()[0].IsFormatted)
                {
                    Debug.Print("SD Card not formatted.");
                    throw new HomeMonitorException("SD Card not formatted.");
                }
            }
            catch (Exception e)
            {
                Debug.Print("Error: No SD Card Found!");
                //throw new HomeMonitorException("Error: No SD Card Found!", e);
            }
        }
Ejemplo n.º 6
0
        private void ProgramStarted()
        {
            relayX1Plus = new RelayX1Plus(1);


            //gasSense.SetHeatingElement(true);
            //new Thread(() =>
            //{
            //    while (true)
            //    {
            //        Thread.Sleep(10000);
            //        Trace.TraceInformation("Gas Sensor: {0}", gasSense.ReadVoltage());
            //    }
            //}).Start();


            //temperatureHumidity.MeasurementComplete +=
            //    (sender, temp, humid) =>
            //        {
            //            Trace.TraceInformation("Temp Sensor T: {0}", temp);
            //            Trace.TraceInformation("Temp Sensor H: {0}", humid);
            //        };
            //new Thread(() =>
            //{
            //    while (true)
            //    {
            //        Thread.Sleep(10000);
            //        temperatureHumidity.RequestMeasurement();
            //    }
            //}).Start();


            //new Thread(() =>
            //{
            //    while (true)
            //    {
            //        Thread.Sleep(10000);
            //        Trace.TraceInformation("Light Sensor: {0}", lightSensor.ReadLightSensorPercentage());
            //    }
            //}).Start();



            RemovableMedia.Insert +=
                (o, e) =>
            {
                if (e.Volume.Name == SDCardVolumeName)
                {
                    Trace.TraceInformation("SD card inserted");

                    BootApplication();
                }
            };

            RemovableMedia.Eject +=
                (o, e) =>
            {
                if (e.Volume.Name == SDCardVolumeName)
                {
                    Trace.TraceInformation("SD card removed");

                    // TODO: what else?
                }
            };

            if (!PersistentStorage.DetectSDCard())
            {
                Trace.TraceInformation("Insert SD card to boot");
            }
            else
            {
                SetupStorage();
            }

            // Start auto mounting thread
            new Thread(SDMountThread).Start();
        }