Beispiel #1
0
 static bool ShowUpdatesDialogs()
 {
     if (WiFiDevice.IsLinkUp())
     {
         var step = new StepContainer(
             delegate()
         {
             try{
                 return(UpdateAvailable());
             }
             catch
             {
                 return(false);
             }
         },
             "Checking server", "No software updates available", "Software update available. Visit monobrick.dk");
         var dialog = new ProgressDialog("Updates", step);
         dialog.Show();
     }
     else
     {
         var dialog = new InfoDialog("WiFi device is not pressent", true);
         dialog.Show();
     }
     return(false);
 }
Beispiel #2
0
        static bool Information()
        {
            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);
                }
            }
            string monoCLR = System.Reflection.Assembly.GetExecutingAssembly().ImageRuntimeVersion;

            Point offset   = new Point(0, (int)Font.MediumFont.maxHeight);
            Point startPos = new Point(0, 0);

            Lcd.Instance.Clear();
            Lcd.Instance.WriteText(Font.MediumFont, startPos + offset * 0, "Firmware: " + firmwareVersion, true);
            Lcd.Instance.WriteText(Font.MediumFont, startPos + offset * 1, "Image: " + VersionHelper.CurrentImageVersion(), true);
            Lcd.Instance.WriteText(Font.MediumFont, startPos + offset * 2, "Mono version: " + monoVersion.Substring(0, 7), true);
            Lcd.Instance.WriteText(Font.MediumFont, startPos + offset * 3, "Mono CLR: " + monoCLR, true);
            Lcd.Instance.WriteText(Font.MediumFont, startPos + offset * 4, "IP: " + WiFiDevice.GetIpAddress(), true);

            Lcd.Instance.Update();
            Buttons.Instance.GetKeypress();
            return(false);
        }
Beispiel #3
0
        public override void OnDrawContent()
        {
            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);
                }
            }
            string monoCLR        = System.Reflection.Assembly.GetExecutingAssembly().ImageRuntimeVersion;
            var    currentVersion = UpdateHelper.InstalledVersion();

            Point offset   = new Point(0, (int)Font.MediumFont.maxHeight);
            Point startPos = new Point(0, 0);

            Lcd.Clear();
            Lcd.WriteText(Font.MediumFont, startPos + offset * 0, "Firmware: " + currentVersion.Firmware, true);
            Lcd.WriteText(Font.MediumFont, startPos + offset * 1, "Image: " + currentVersion.Image, true);
            Lcd.WriteText(Font.MediumFont, startPos + offset * 2, "Mono version: " + monoVersion.Substring(0, 7), true);
            Lcd.WriteText(Font.MediumFont, startPos + offset * 3, "Mono CLR: " + monoCLR, true);
            Lcd.WriteText(Font.MediumFont, startPos + offset * 4, "IP: " + WiFiDevice.GetIpAddress(), true);
            Lcd.Update();
        }
Beispiel #4
0
        private bool LoadSettings()
        {
            bool ok = true;

            try
            {
                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);
                    }
                }
                string monoCLR        = System.Reflection.Assembly.GetExecutingAssembly().ImageRuntimeVersion;
                var    currentVersion = UpdateHelper.InstalledVersion();
                string ip             = WiFiDevice.GetIpAddress();
                information = new Information();
                information.FirmwareVersion = currentVersion.Firmware;
                information.ImageVersion    = currentVersion.Image;
                information.IpAddress       = ip;
                information.MonoCLRVersion  = monoCLR;
                information.MonoVersion     = monoVersion;
            }
            catch
            {
                ok = false;
            }
            return(ok);
        }
Beispiel #5
0
 static bool ShowUpdatesDialogs(Lcd lcd, Buttons btns, bool showDescriptionDialog)
 {
     if (WiFiDevice.IsLinkUp())
     {
         try {
             InfoDialog dialog = null;
             if (showDescriptionDialog)
             {
                 dialog = new InfoDialog(font, lcd, btns, "Checking for updates. Please wait", false);
                 dialog.Show();
             }
             if (UpdateAvailable())
             {
                 dialog = new InfoDialog(font, lcd, btns, "Software update available. Visit monobrick.dk", true);
             }
             else
             {
                 dialog = new InfoDialog(font, lcd, btns, "No software updates available", true);
             }
             dialog.Show();
         }
         catch {
             InfoDialog dialog = new InfoDialog(font, lcd, btns, "Failed to check for updates", true);
             dialog.Show();
         }
     }
     else
     {
         var dialog = new InfoDialog(font, lcd, btns, "WiFi device is not pressent", true);
         dialog.Show();
     }
     return(false);
 }
Beispiel #6
0
        static bool Information(Lcd lcd, Buttons btns)
        {
            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);
                }
            }
            string monoCLR = System.Reflection.Assembly.GetExecutingAssembly().ImageRuntimeVersion;

            Point offset   = new Point(0, (int)font.maxHeight);
            Point startPos = new Point(0, 0);

            lcd.Clear();
            lcd.WriteText(font, startPos + offset * 0, versionString, true);
            lcd.WriteText(font, startPos + offset * 1, "Mono version: " + monoVersion.Substring(0, 7), true);
            lcd.WriteText(font, startPos + offset * 2, "Mono CLR: " + monoCLR, true);
            lcd.WriteText(font, startPos + offset * 3, "IP: " + WiFiDevice.GetIpAddress(), true);
            lcd.Update();
            btns.GetKeypress();
            return(false);
        }
Beispiel #7
0
 static bool ShowUpdatesDialogs()
 {
     if (WiFiDevice.IsLinkUp())
     {
         bool        newImage       = false;
         bool        newFirmwareApp = false;
         bool        newAddin       = false;
         VersionInfo versionInfo    = null;
         var         step           = new StepContainer(
             delegate() {
             try {
                 versionInfo         = VersionHelper.AvailableVersions();
                 newImage            = versionInfo.Image != VersionHelper.CurrentImageVersion();
                 newFirmwareApp      = versionInfo.Fimrware != firmwareVersion;
                 string addInVersion = VersionHelper.CurrentAddInVersion();
                 if (addInVersion != null)
                 {
                     newAddin = versionInfo.AddIn != VersionHelper.CurrentAddInVersion();
                 }
             } catch {
                 return(false);
             }
             return(true);
         },
             "Checking server", "Failed to check for Updates");
         var dialog = new ProgressDialog("Updates", step);
         dialog.Show();
         if (newImage)
         {
             var visitWebsiteDialog = new InfoDialog("New image available. Download it at monobrick.dk", true);
             visitWebsiteDialog.Show();
         }
         else
         {
             if (newFirmwareApp)
             {
                 var updateQuestion = new QuestionDialog("New firmware available. Update?", "New Fiwmware");
                 if (updateQuestion.Show())
                 {
                     var          updateHelper = new UpdateHelper(versionInfo.Fimrware);
                     List <IStep> steps        = new List <IStep> ();
                     steps.Add(new StepContainer(updateHelper.DownloadFirmware, "Downloading...", "Failed to download files"));
                     steps.Add(new StepContainer(updateHelper.UpdateBootFile, "Updating system", "Failed to update boot file"));
                     var updateDialog = new StepDialog("Updating", steps);
                     if (updateDialog.Show())
                     {
                         for (int seconds = 10; seconds > 0; seconds--)
                         {
                             var rebootDialog = new InfoDialog("Update completed. Rebooting in  " + seconds, false);
                             rebootDialog.Show();
                             System.Threading.Thread.Sleep(1000);
                         }
                         ProcessHelper.RunAndWaitForProcess("/sbin/shutdown", "-h now");
                         Thread.Sleep(120000);
                         var whyAreYouHereDialog = new InfoDialog("Cut the power", false, "Reboot failed");
                         whyAreYouHereDialog.Show();
                         new ManualResetEvent(false).WaitOne();
                     }
                 }
             }
             else
             {
                 if (newAddin)
                 {
                     var visitWebsiteDialog = new InfoDialog("New Xamarin Add-in. Download it at monobrick.dk", true);
                     visitWebsiteDialog.Show();
                 }
                 else
                 {
                     var noUpdateDialog = new InfoDialog("No updates available", true);
                     noUpdateDialog.Show();
                 }
             }
         }
     }
     else
     {
         var dialog = new InfoDialog("WiFi device is not pressent", true);
         dialog.Show();
     }
     return(false);
 }
Beispiel #8
0
        static bool ShowWiFiMenu()
        {
            List <IMenuItem> items = new List <IMenuItem> ();
            var ssidItem           = new MenuItemWithCharacterInput("SSID", "Enter SSID", settings.WiFiSettings.SSID);

            ssidItem.OnDialogExit += delegate(string text) {
                new Thread(delegate() {
                    settings.WiFiSettings.SSID = text;
                    settings.Save();
                }).Start();
            };
            var passwordItem = new MenuItemWithCharacterInput("Password", "Password", settings.WiFiSettings.Password, true);

            passwordItem.OnDialogExit += delegate(string text) {
                new Thread(delegate() {
                    settings.WiFiSettings.Password = text;
                    settings.Save();
                }).Start();
            };
            var encryptionItem = new MenuItemWithOptions <string>("Encryption", new string[] { "None", "WPA/2" }, settings.WiFiSettings.Encryption ? 1 : 0);

            encryptionItem.OnOptionChanged += delegate(string newOpstion) {
                new Thread(delegate() {
                    if (newOpstion == "None")
                    {
                        settings.WiFiSettings.Encryption = false;
                    }
                    else
                    {
                        settings.WiFiSettings.Encryption = true;
                    }
                    settings.Save();
                }).Start();
            };
            var connectItem = new MenuItemWithCheckBox("Connect", WiFiDevice.IsLinkUp(),
                                                       delegate(bool WiFiOn)
            {
                bool isOn          = WiFiOn;
                var createFileStep = new StepContainer
                                     (
                    delegate()
                {
                    WriteWpaSupplicantConfiguration(settings.WiFiSettings.SSID, settings.WiFiSettings.Password, settings.WiFiSettings.Encryption);
                    return(true);
                },
                    "Creating file", "Error creating WPA file"
                                     );
                var progressDialog = new ProgressDialog("WiFi", createFileStep);
                progressDialog.Show();
                if (WiFiOn)
                {
                    var turnOffStep = new StepContainer(
                        delegate()
                    {
                        WiFiDevice.TurnOff();
                        return(true);
                    },
                        "Turning Off", "Error turning off WiFi", "WiFi Disabled");
                    var dialog = new ProgressDialog("WiFi", turnOffStep);
                    dialog.Show();
                    isOn = false;
                }
                else
                {
                    var turnOnStep = new StepContainer(
                        delegate()
                    {
                        return(WiFiDevice.TurnOn(60000));
                    },
                        "Connecting", "Failed to connect");
                    Dialog dialog = new ProgressDialog("WiFi", turnOnStep);
                    if (dialog.Show())
                    {
                        if (settings.WiFiSettings.ConnectAtStartUp == false)
                        {
                            var question = new QuestionDialog("Do you want to connect at start-up?", "Settings");
                            if (question.Show())
                            {
                                new Thread(delegate() {
                                    settings.WiFiSettings.ConnectAtStartUp = true;
                                    settings.Save();
                                }).Start();
                            }
                        }
                        dialog = new InfoDialog("Connected Successfully " + WiFiDevice.GetIpAddress(), true, "WiFi");
                        dialog.Show();
                        isOn = true;
                    }
                    else
                    {
                        isOn = false;
                    }
                }
                return(isOn);
            }
                                                       );

            items.Add(ssidItem);
            items.Add(passwordItem);
            items.Add(encryptionItem);
            items.Add(connectItem);
            //Show the menu
            Menu m = new Menu("WiFi Connection", items);

            m.Show();
            return(false);
        }
Beispiel #9
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();
            }
        }
Beispiel #10
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();
        }
Beispiel #11
0
        static bool ShowWiFiMenu(Lcd lcd, Buttons btns)
        {
            List <IMenuItem> items = new List <IMenuItem> ();
            var ssidItem           = new MenuItemWithCharacterInput(lcd, btns, "SSID", "Enter SSID", settings.WiFiSettings.SSID);

            ssidItem.OnDialogExit += delegate(string text) {
                new Thread(delegate() {
                    settings.WiFiSettings.SSID = text;
                    settings.Save();
                }).Start();
            };
            var passwordItem = new MenuItemWithCharacterInput(lcd, btns, "Password", "Password", settings.WiFiSettings.Password, true);

            passwordItem.OnDialogExit += delegate(string text) {
                new Thread(delegate() {
                    settings.WiFiSettings.Password = text;
                    settings.Save();
                }).Start();
            };
            var encryptionItem = new MenuItemWithOptions <string>(lcd, "Encryption", new string[] { "None", "WPA/2" }, settings.WiFiSettings.Encryption ? 1 : 0);

            encryptionItem.OnOptionChanged += delegate(string newOpstion) {
                new Thread(delegate() {
                    if (newOpstion == "None")
                    {
                        settings.WiFiSettings.Encryption = false;
                    }
                    else
                    {
                        settings.WiFiSettings.Encryption = true;
                    }
                    settings.Save();
                }).Start();
            };
            var connectItem = new MenuItemWithCheckBox(lcd, "Connect", WiFiDevice.IsLinkUp(),
                                                       delegate(bool WiFiOn)
            {
                bool isOn      = WiFiOn;
                var infoDialog = new InfoDialog(font, lcd, btns, "Creating Configuration file", false);
                infoDialog.Show();
                WriteWpaSupplicantConfiguration(settings.WiFiSettings.SSID, settings.WiFiSettings.Password, settings.WiFiSettings.Encryption);
                if (WiFiOn)
                {
                    var dialog = new InfoDialog(font, lcd, btns, "Shutting down WiFi", false);
                    dialog.Show();
                    WiFiDevice.TurnOff();
                    dialog = new InfoDialog(font, lcd, btns, "WiFi Disabled!!", true);
                    dialog.Show();
                    isOn = false;
                }
                else
                {
                    var dialog = new InfoDialog(font, lcd, btns, "Connecting to WiFi Network Please Wait", false);
                    dialog.Show();
                    if (WiFiDevice.TurnOn(60000))
                    {
                        if (settings.WiFiSettings.ConnectAtStartUp == false)
                        {
                            var question = new QuestionDialog(font, lcd, btns, "Do you want to connect at start-up?", "Settings");
                            question.Show();
                            if (question.IsPositiveSelected)
                            {
                                new Thread(delegate() {
                                    settings.WiFiSettings.ConnectAtStartUp = true;
                                    settings.Save();
                                }).Start();
                            }
                        }
                        dialog = new InfoDialog(font, lcd, btns, "Connected Successfully " + WiFiDevice.GetIpAddress(), true);
                        dialog.Show();
                        isOn = true;
                    }
                    else
                    {
                        dialog = new InfoDialog(font, lcd, btns, "Failed to connect to WiFI Network", true);
                        dialog.Show();
                        isOn = false;
                    }
                }
                return(isOn);
            }
                                                       );

            items.Add(ssidItem);
            items.Add(passwordItem);
            items.Add(encryptionItem);
            items.Add(connectItem);
            //Show the menu
            Menu m = new Menu(font, lcd, btns, "WiFi Connection", items);

            m.Show();
            return(false);
        }
 private static bool OnTurnWiFiOff()
 {
     WiFiDevice.TurnOff();
     return(true);
 }
 private static bool OnTurnWiFiOn()
 {
     return(WiFiDevice.TurnOn(FirmwareSettings.WiFiSettings.SSID, FirmwareSettings.WiFiSettings.Password, FirmwareSettings.WiFiSettings.Encryption, ConnectTimeout));
 }
 public TurnWiFiOnOffCheckBox() : base("Connected", WiFiDevice.IsLinkUp(), "WiFi", new CheckBoxStep(new StepContainer(OnTurnWiFiOn, "Connecting", "Failed to connect"), new StepContainer(OnTurnWiFiOff, "Disconnecting", "Error disconnecting")), null)
 {
 }