Пример #1
0
		static void ShowMainMenu()
		{
			
			List<IMenuItem> items = new List<IMenuItem>();
			items.Add (new MenuItemWithAction("Programs", () => RunPrograms(),MenuItemSymbole.RightArrow));
			items.Add (new MenuItemWithAction("WiFi Connection", () => ShowWiFiMenu(), MenuItemSymbole.RightArrow));
			items.Add (new MenuItemWithAction("WebServer", () => ShowWebServerMenu(), MenuItemSymbole.RightArrow));
			items.Add (new MenuItemWithAction("Settings", () => ShowSettings(), MenuItemSymbole.RightArrow));
			items.Add (new MenuItemWithAction("Information", () => Information()));
			items.Add (new MenuItemWithAction("Check for Updates", () => ShowUpdatesDialogs()));
			items.Add (new MenuItemWithAction("Shutdown", () => Shutdown()));
			Menu m = new Menu("Main menu", items);
			m.Show();
		}
Пример #2
0
		static bool RunPrograms ()
		{
			do
			{
				updateProgramList = false;
				List<MenuItemWithAction> actionList = new List<MenuItemWithAction>();
				List<ProgramInformation> programs = ProgramManager.Instance.GetProgramInformationList();
				foreach(var program in programs)
				{
					actionList.Add( new MenuItemWithAction(program.Name, () => ShowProgramOptions (program)));
				}
				Menu m = new Menu ("Run program:", actionList);
				m.Show ();//block
			}while (updateProgramList); 
			return false;
		}
Пример #3
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;
 }
Пример #4
0
        static bool ShowWebServerMenu()
        {
            List<IMenuItem> items = new List<IMenuItem> ();
            var portItem = new MenuItemWithNumericInput("Port", settings.WebServerSettings.Port, 1, ushort.MaxValue);
            portItem.OnValueChanged+= delegate(int value)
            {
                new Thread(delegate() {
                    settings.WebServerSettings.Port = value;
                    settings.Save();
                }).Start();
            };
            var startItem = new MenuItemWithCheckBox("Start server", WebServer.IsRunning(),
                delegate(bool running)
               	 		{

                    bool isRunning = running;
                    if(running){
                        var step = new StepContainer(
                            delegate()
                            {
                                WebServer.StopAll();
                                System.Threading.Thread.Sleep(2000);
                                return true;
                            },
                            "Stopping", "Failed to stop");
                        var dialog = new ProgressDialog("Web Server",step);
                        dialog.Show();
                        isRunning = WebServer.IsRunning();
                    }
                    else{
                        var step1 = new StepContainer(()=>{return WebServer.StartFastCGI();}, "Init CGI Server", "Failed to start CGI Server");
                        var step2 = new StepContainer(()=>{return WebServer.StartLighttpd();}, "Initializing", "Failed to start server");
                        var step3 = new StepContainer(()=>{return WebServer.LoadPage();}, "Loading page", "Failed to load page");
                        var stepDialog = new StepDialog("Web Server", new List<IStep>{step1,step2,step3}, "Webserver started");
                        isRunning = stepDialog.Show();
                    }
                    return isRunning;
               			}
            );

            //items.Add(portItem);
            items.Add(startItem);
            //Show the menu
            Menu m = new Menu ("Web Server", items);
            m.Show ();
            return false;
        }
Пример #5
0
        static bool ShowSettings()
        {
            //Create the settings items and apply the settings
            List<IMenuItem> items = new List<IMenuItem> ();
            var terminateWithEscapeItem = new MenuItemWithCheckBox("Debug termination",settings.DebugSettings.TerminateWithEscape);
            var debugPortItem = new MenuItemWithNumericInput("Debug port",settings.DebugSettings.Port,1, ushort.MaxValue);
            var checkForUpdate = new MenuItemWithCheckBox("Update check",settings.GeneralSettings.CheckForSwUpdatesAtStartUp);
            var wifiConnect = new MenuItemWithCheckBox("WiFi auto connect",settings.WiFiSettings.ConnectAtStartUp);
            //var soundVolume = new MenuItemWithNumericInput("Volume",settings.SoundSettings.Volume);
            //var enableSound = new MenuItemWithCheckBox("Enable sound", settings.SoundSettings.EnableSound);

            items.Add(wifiConnect);
            items.Add(checkForUpdate);
            items.Add(terminateWithEscapeItem);
            items.Add (debugPortItem);
            //items.Add(soundVolume);
            //items.Add(enableSound);
            //Show the menu

            Menu m = new Menu ("Settings", items);
            m.Show ();
            new Thread(delegate() {
                settings.DebugSettings.TerminateWithEscape = terminateWithEscapeItem.Checked;
                settings.DebugSettings.Port = debugPortItem.Value;
                settings.GeneralSettings.CheckForSwUpdatesAtStartUp = checkForUpdate.Checked;
                settings.WiFiSettings.ConnectAtStartUp = wifiConnect.Checked;
                //settings.SoundSettings.Volume = soundVolume.Value;
                //settings.SoundSettings.EnableSound = enableSound.Checked;
                settings.Save();
            }).Start();
            return false;
        }
Пример #6
0
        static bool RunPrograms()
        {
            do
            {
                updateProgramList = false;
                IEnumerable<MenuItemWithAction> itemsFromEV3 = Directory.EnumerateDirectories(ProgramPathEV3)
                    .Select((programFolder) => new MenuItemWithAction (new DirectoryInfo(programFolder).Name, () => ShowProgramOptions (programFolder)));
                IEnumerable<MenuItemWithAction> itemsFromSD = Directory.EnumerateDirectories(ProgramPathSdCard)
                    .Select ((programFolder) => new MenuItemWithAction (new DirectoryInfo(programFolder).Name, () => ShowProgramOptions (programFolder)));

                Menu m = new Menu ("Run program:", itemsFromEV3.Concat (itemsFromSD));
                m.Show ();//block
            }while (updateProgramList);
            return false;
        }