private static void LoadAppSettings() { Debug.Print(""); Debug.Print(constAppName + " : Loading application settings..."); bool restoreDefSettings = false; InputPort button = new InputPort((Cpu.Pin)FEZ_Pin.Digital.Di11, false, Port.ResistorMode.PullUp); if (button.Read() == false) { Debug.Print(constAppName + " : Reset settings button is pressed."); restoreDefSettings = true; } else if (appSettings.LoadFromFlash() == false) { Debug.Print(constAppName + " : Error loading settings: " + appSettings.LastErrorMsg); restoreDefSettings = true; } if (restoreDefSettings == true) { Debug.Print(constAppName + " : Restoring default settings..."); appSettings = GetDefaultSettings(); if (appSettings.SaveToFlash() == true) { Debug.Print(constAppName + " : Application settings saved."); } else { Debug.Print(constAppName + " : Error saving settings: " + appSettings.LastErrorMsg); } } else { Debug.Print(constAppName + " : Application settings loaded."); } button.Dispose(); button = null; }
private static SerialPort UART4 = new SerialPort("COM4", 9600); //Sump #endregion Fields #region Methods public static void Main() { Debug.EnableGCMessages(false); Debug.Print(""); Debug.Print(""); Debug.Print(constAppName + " : Startup..."); Debug.Print("Free mem : " + Debug.GC(false).ToString()); // set system time SetSystemTime(); Debug.GC(true); Debug.Print("Free mem : " + Debug.GC(false).ToString()); // initialize and mount SD card MountSDCard(); Debug.GC(true); Debug.Print("Free mem : " + Debug.GC(false).ToString()); // load appSettings appSettings = new AppSettings(); LoadAppSettings(); Debug.GC(true); Debug.Print("Free mem : " + Debug.GC(false).ToString()); // initialize fezConnect fezConnect = new FEZConnect(); InitializeFezConnect(); Debug.GC(true); Debug.Print("Free mem : " + Debug.GC(false).ToString()); // initialize network if (fezConnect.DeviceStatus == FEZConnect.DevStatus.Ready) { InitializeNetwork(); Debug.GC(true); Debug.Print("Free mem : " + Debug.GC(false).ToString()); } // set clock from NTP server if (fezConnect.NetworkStatus == FEZConnect.NetStatus.Ready && appSettings.NTPEnabled) { SetClockFromNTPTime(); Debug.GC(true); Debug.Print("Free mem : " + Debug.GC(false).ToString()); } // start http server if (fezConnect.NetworkStatus == FEZConnect.NetStatus.Ready && appSettings.HTTPEnabled) { httpServer = new HTTPServer(); httpServer.HttpStatusChanged += new HTTPServer.HttpStatusChangedHandler(httpServer_HttpStatusChanged); RegisterHTTPEventHandlers(); Debug.GC(true); Debug.Print("Free mem : " + Debug.GC(false).ToString()); StartHTTPServer(); Debug.GC(true); } // run application //readOWbus(); Thread Timer = new Thread(CheckTime); Timer.Start(); Debug.GC(true); Thread Temps = new Thread(Temp); Temps.Start(); Debug.GC(true); // this is the main program loop rebootTime = DateTime.MaxValue; while (true) { // check for reboot if (DateTime.Now >= rebootTime) { rebootTime = DateTime.MaxValue; ; RebootDevice(); Debug.GC(true); } // your application code goes here // sleep 1 sec Thread.Sleep(1000); } }
private static AppSettings GetDefaultSettings() { AppSettings settings = new AppSettings(); // network appSettings settings.HostName = "FishyBrains"; settings.MACAddress = "00-EF-18-84-E8-BE"; settings.DHCPEnabled = false; settings.IPAddress = "192.168.100.15"; settings.IPMask = "255.255.255.0"; settings.IPGateway = "192.168.100.2"; settings.DNSAddress = "75.75.75.75"; settings.NTPEnabled = true; settings.NTPServer = "us.pool.ntp.org"; settings.NTPOffset = "-300"; settings.HTTPEnabled = true; settings.HTTPPrefix = "http"; settings.HTTPPort = "80"; // appSettings settings.Password = "******"; settings.wStartH = "11"; settings.wStartM = "00"; settings.wEndH = "21"; settings.wEndM = "00"; settings.wMax = "80"; settings.wRamp = "120"; settings.bStartH = "10"; settings.bStartM = "00"; settings.bEndH = "22"; settings.bEndM = "00"; settings.bMax1 = "80"; settings.bMax2 = "80"; settings.bRamp = "120"; settings.rStartH = "20"; settings.rStartM = "00"; settings.rEndH = "12"; settings.rEndM = "00"; return settings; }