Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            Lcd.Instance.DrawBitmap(monoLogo, new Point((int)(Lcd.Width - monoLogo.Width) / 2, 5));
            Rectangle textRect = new Rectangle(new Point(0, Lcd.Height - (int)Font.SmallFont.maxHeight - 2), new Point(Lcd.Width, Lcd.Height - 2));

            Lcd.Instance.WriteTextBox(Font.SmallFont, textRect, "Initializing...", true, Lcd.Alignment.Center);
            Lcd.Instance.Update();
            WiFiDevice.TurnOff();
            if (!Directory.Exists(ProgramPathSdCard))
            {
                Directory.CreateDirectory(ProgramPathSdCard);
            }

            // JIT work-around remove when JIT problem is fixed
            System.Threading.Thread.Sleep(10);
            Console.WriteLine("JIT workaround - please remove!!!");
            Lcd.Instance.WriteTextBox(Font.SmallFont, textRect, "Checking WiFi...", true, Lcd.Alignment.Center);
            Lcd.Instance.Update();
            //WiFiDevice.IsLinkUp ();
            Lcd.Instance.WriteTextBox(Font.SmallFont, textRect, "Starting Mono Runtime...", true, Lcd.Alignment.Center);
            Lcd.Instance.Update();
            string monoVersion = "Unknown";
            Type   type        = Type.GetType("Mono.Runtime");

            if (type != null)
            {
                MethodInfo displayName = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
                if (displayName != null)
                {
                    monoVersion = (string)displayName.Invoke(null, null);
                }
                Console.WriteLine("Mono Version" + monoVersion);
            }
            string monoCLR = System.Reflection.Assembly.GetExecutingAssembly().ImageRuntimeVersion;

            // JIT work-around end but look for more below

            //Load settings
            Lcd.Instance.WriteTextBox(Font.SmallFont, textRect, "Loading settings...", true, Lcd.Alignment.Center);
            Lcd.Instance.Update();
            settings = settings.Load();
            if (settings != null)
            {
                Lcd.Instance.WriteTextBox(Font.SmallFont, textRect, "Applying settings...", true, Lcd.Alignment.Center);
                Lcd.Instance.Update();
                settings.Save();                // JIT work-around
                WriteWpaSupplicantConfiguration(settings.WiFiSettings.SSID, settings.WiFiSettings.Password, settings.WiFiSettings.Encryption);
                if (settings.WiFiSettings.ConnectAtStartUp)
                {
                    Lcd.Instance.WriteTextBox(Font.SmallFont, textRect, "Connecting to WiFi...", true, Lcd.Alignment.Center);
                    Lcd.Instance.Update();
                    if (WiFiDevice.TurnOn(60000))
                    {
                        WiFiDevice.GetIpAddress();                         // JIT work-around
                        if (settings.GeneralSettings.CheckForSwUpdatesAtStartUp)
                        {
                            ShowUpdatesDialogs();
                        }
                        else
                        {
                            var dialog = new InfoDialog("Connected Successfully " + WiFiDevice.GetIpAddress(), true);
                            dialog.Show();
                        }
                    }
                    else
                    {
                        var dialog = new InfoDialog("Failed to connect to WiFI Network", true);
                        dialog.Show();
                    }
                }
            }
            else
            {
                var dialog = new InfoDialog("Failed to load settings", true);
                dialog.Show();
                settings = new FirmwareSettings();
            }

            //Keep showing the menu even if user press esc
            while (true)
            {
                ShowMainMenu();
            }
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            if (!File.Exists(SuspendFile))
            {
                File.Create(SuspendFile);
            }
            FileSystemWatcher watcher = new FileSystemWatcher();

            watcher.Path                = Path.GetDirectoryName(SuspendFile);
            watcher.NotifyFilter        = NotifyFilters.LastWrite;
            watcher.Filter              = Path.GetFileName(SuspendFile);
            watcher.Changed            += OnSuspendFileChanged;
            watcher.EnableRaisingEvents = true;

            Menu menu = new Menu("Main Menu");

            menu.AddItem(new ItemWithProgramList("Programs", false));
            menu.AddItem(new ItemWiFiOptions());
            menu.AddItem(new ItemWithSettings());
            menu.AddItem(new ItemWithUpdateDialog());
            //menu.AddItem(new ItemWithWebserver ());
            menu.AddItem(new ItemWithBrickInfo());
            menu.AddItem(new ItemWithTurnOff());

            container = new FirmwareMenuContainer(menu);

            Bitmap monoLogo = Bitmap.FromResouce(Assembly.GetExecutingAssembly(), "monologo.bitmap");

            Lcd.DrawBitmap(monoLogo, new Point((int)(Lcd.Width - monoLogo.Width) / 2, 5));
            Rectangle textRect = new Rectangle(new Point(0, Lcd.Height - (int)Font.SmallFont.maxHeight - 2), new Point(Lcd.Width, Lcd.Height - 2));

            Lcd.WriteTextBox(Font.SmallFont, textRect, "Initializing...", true, Lcd.Alignment.Center);
            Lcd.Update();
            WiFiDevice.TurnOff();
            ProgramManager.CreateSDCardFolder();
            Lcd.WriteTextBox(Font.SmallFont, textRect, "Loading settings...", true, Lcd.Alignment.Center);
            Lcd.Update();
            FirmwareSettings.Load();
            Lcd.WriteTextBox(Font.SmallFont, textRect, "Applying settings...", true, Lcd.Alignment.Center);
            Lcd.Update();
            if (FirmwareSettings.GeneralSettings.ConnectToWiFiAtStartUp)
            {
                Lcd.WriteTextBox(Font.SmallFont, textRect, "Connecting to WiFi...", true, Lcd.Alignment.Center);
                Lcd.Update();
                if (WiFiDevice.TurnOn(FirmwareSettings.WiFiSettings.SSID, FirmwareSettings.WiFiSettings.Password, FirmwareSettings.WiFiSettings.Encryption, 40000))
                {
                    if (FirmwareSettings.GeneralSettings.CheckForSwUpdatesAtStartUp)
                    {
                        container.Show(3);                          //show the menu container with the update dialog
                        return;
                    }
                    else
                    {
                        var dialog = new InfoDialog("Connected Successfully " + WiFiDevice.GetIpAddress());
                        dialog.Show();
                    }
                }
                else
                {
                    var dialog = new InfoDialog("Failed to connect to WiFI Network");
                    dialog.Show();
                }
            }
            container.Show();
        }