Exemple #1
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);
 }
Exemple #2
0
        public static void Main(string[] args)
        {
            var dialog = new InfoDialog("Start");

            dialog.Show();
            Motor      motorA = new Motor(MotorPort.OutA);
            Motor      motorD = new Motor(MotorPort.OutD);
            WaitHandle motorWaitHandle;

            motorA.Off();
            motorD.Off();



            IMission[] missions = { new Mission1() };

            foreach (var mission in missions)
            {
                CurrentLogger.Logger.info($"Starting mission {mission.Name}");
                MissionRunner.Run(mission);
            }

            return;

            MissionDevelopment dev = new MissionDevelopment();

            dev.Start();
        }
Exemple #3
0
        static NetworkStream connect()
        {
            // サーバとの接続設定
            NetworkStream connection;
            IPAddress     ipAddr = IPAddress.Parse("10.0.1.1");

            var listener = new TcpListener(ipAddr, SOCKET_PORT);

            listener.Start();             // クライアントからの受信接続要求の待機を開始

            var dialogCON = new InfoDialog("Please connect...", false);

            dialogCON.Show();             // Wait for enter to be pressed

            try {
                Socket sock = listener.AcceptSocket();                 // 接続要求の受け入れ
                connection = new NetworkStream(sock, true);
            } catch (SocketException) {
                var dialogE = new InfoDialog("Connect is Failed.", false);
                dialogE.Show();                 // Wait for enter to be pressed
                connection = null;
            }
            listener.Stop();
            return(connection);
        }
Exemple #4
0
        public static void Main(string[] args)
        {
            ButtonEvents buts        = new ButtonEvents();
            var          tokenSource = new CancellationTokenSource();
            var          token       = tokenSource.Token;

            var dialog = new InfoDialog("Attach distance sensor", false);

            dialog.Show();
            var sensor = SensorAttachment.Wait <MSAngleSensor>(token);           //wait for sensor to attached on any port

            LcdConsole.WriteLine("Up reset angle");
            LcdConsole.WriteLine("Down read RMP");
            LcdConsole.WriteLine("Enter read angle");
            LcdConsole.WriteLine("Left read raw");
            LcdConsole.WriteLine("Esc. terminate");

            buts.EscapePressed += () => {
                tokenSource.Cancel();
            };
            buts.EnterPressed += () => {
                LcdConsole.WriteLine("Angle: " + sensor.ReadAngle().ToString());
            };
            buts.UpPressed += () => {
                LcdConsole.WriteLine("Reset angle");
                sensor.ResetAngle();
            };
            buts.DownPressed += () => {
                LcdConsole.WriteLine("Read RPM: " + sensor.ReadRPM().ToString());
            };
            buts.LeftPressed += () => {
                LcdConsole.WriteLine("Read raw: " + sensor.ReadRAW().ToString());
            };
            token.WaitHandle.WaitOne();
        }
Exemple #5
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);
 }
Exemple #6
0
        const int REMOTE_COMMAND_STOP  = 's';         // 's'

        public static void Main()
        {
            // 構造体の宣言と初期化
            var body = new EV3body();

            EV3body.init(ref body);

            // Bluetooth関係のETロボコン拡張機能を有効にする
            Brick.InstallETRoboExt();

            // リモート接続
            NetworkStream connection = connect();

            // センサーおよびモータに対して初回アクセスをしておく
            body.color.Read();
            body.sonar.Read();
            body.gyro.Read();
            body.motorL.SetPower(0);
            body.motorR.SetPower(0);
            body.motorT.SetPower(0);

            body.motorL.ResetTacho();
            body.motorR.ResetTacho();
            body.motorT.ResetTacho();
            Balancer.init();

            // スタート待ち
            wait_start(body, connection);

            var dialogRun = new InfoDialog("Running", false);

            dialogRun.Show();             //Wait for enter to be pressed

            try{
                run(body, connection);
            }catch (Exception) {
                var dialogE = new InfoDialog("Exception.", false);
                dialogE.Show();                //Wait for enter to be pressed
            }

            body.motorL.Off();
            body.motorR.Off();
            body.motorT.Off();

            // ソケットを閉じる
            if (connection != null)
            {
                connection.Close();
            }

            Lcd.Instance.Clear();
            Lcd.Instance.Update();

            if (Debugger.IsAttached)
            {
                Brick.ExitToMenu();                  // MonoBrickメインメニューへ戻る
            }
        }
Exemple #7
0
        static bool ShowWebServerMenu(Lcd lcd, Buttons btns)
        {
            List <IMenuItem> items = new List <IMenuItem> ();
            var portItem           = new MenuItemWithNumericInput(lcd, "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(lcd, "Start server", WebServer.IsRunning(),
                                                     delegate(bool running)
            {
                webServer      = new WebServer(settings.WebServerSettings.Port);
                bool isRunning = running;
                if (running)
                {
                    var dialog = new InfoDialog(font, lcd, btns, "Shutting down Web-Server", false);
                    dialog.Show();
                    webServer.Stop();
                    dialog = new InfoDialog(font, lcd, btns, "Web-server Stopped!", true);
                    dialog.Show();
                    isRunning = false;
                }
                else
                {
                    var dialog = new InfoDialog(font, lcd, btns, "Starting Web-Server Please Wait", false, "Web-Server");
                    dialog.Show();
                    webServer.CompilingServer += delegate() { dialog.UpdateMessage("Compiling..."); };
                    webServer.LoadingPage     += delegate() { dialog.UpdateMessage("Loading page"); };
                    webServer.StartingServer  += delegate() { dialog.UpdateMessage("Starting server"); };
                    if (webServer.Restart())
                    {
                        dialog = new InfoDialog(font, lcd, btns, "Started successfully at port" + settings.WebServerSettings.Port, true);
                        dialog.Show();
                        isRunning = true;
                    }
                    else
                    {
                        dialog = new InfoDialog(font, lcd, btns, "Failed to start Web-Servers", true);
                        dialog.Show();
                        isRunning = false;
                    }
                }
                return(isRunning);
            }
                                                     );

            items.Add(portItem);
            items.Add(startItem);
            //Show the menu
            Menu m = new Menu(font, lcd, btns, "Web Server", items);

            m.Show();
            return(false);
        }
Exemple #8
0
        public static void Main(string[] args)
        {
            InfoDialog dialog = new InfoDialog("Attach a motor to port A", true);

            dialog.Show();             //Wait for enter to be pressed
            Motor motor = new Motor(MotorPort.OutA);

            motor.SetSpeed(50);
            Thread.Sleep(3000);
            motor.Off();
            Lcd.Instance.Clear();
        }
Exemple #9
0
        static void Main(string[] args)
        {
            var    step   = new StepContainer(StartWebserver, "Starting server", "Failed to start");
            Dialog dialog = new ProgressDialog("Webserver", step);

            if (dialog.Show())
            {
                dialog = new InfoDialog("Press enter to stop", "Webserver");
                dialog.Show();
                StopWebserver();
            }
        }
Exemple #10
0
        static bool ShowProgramOptions(string filename, Lcd lcd, Buttons btns)
        {
            string runString        = "Run Program";
            string runInDebugString = "Debug Program";
            string deleteString     = "Delete Program";
            var    dialog           = new SelectDialog <string> (Font.MediumFont, lcd, btns, new string[] {
                runString,
                runInDebugString,
                deleteString
            }, "Options", true);

            dialog.Show();
            if (!dialog.EscPressed)
            {
                string selection = dialog.GetSelection();
                if (selection == runString)
                {
                    lcd.Clear();
                    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, "Running...", true, Lcd.Alignment.Center);
                    lcd.Update();
                    MenuAction = () => RunAndWaitForProgram(filename, false);
                }
                if (selection == runInDebugString)
                {
                    MenuAction = () => RunAndWaitForProgram(filename, true);
                }
                if (selection == deleteString)
                {
                    var infoDialog = new InfoDialog(font, lcd, btns, "Deleting File. Please wait", false, "Deleting File");
                    infoDialog.Show();
                    if (ProcessHelper.RunAndWaitForProcess("rm", filename) == 0)
                    {
                        infoDialog = new InfoDialog(font, lcd, btns, "Program deleted", true, "Deleting File");
                    }
                    else
                    {
                        infoDialog = new InfoDialog(font, lcd, btns, "Error deleting program", true, "Deleting File");
                    }
                    infoDialog.Show();
                }
            }
            else
            {
                return(false);
            }
            return(true);
        }
Exemple #11
0
        private void TrayNotifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (InfoDialog == null)
            {
                InfoDialog = new InfoDialog();
            }

            if (Main.OpenForm(InfoDialog.Text))
            {
                InfoDialog.ReShow();
            }
            else
            {
                InfoDialog.Show();
            }
        }
Exemple #12
0
 static void Main(string[] args)
 {
     try
     {
         // AOT Compile
         ProcessHelper.RunAndWaitForProcess(monoPath, "--aot=full " + ProgramPathSdCard + "/" + TargetProgramFolder + "/" + TargetProgramNameEXE);
         ProcessHelper.RunAndWaitForProcess(monoPath, "--aot=full " + ProgramPathSdCard + "/" + TargetProgramFolder + "/" + "MonoBrickFirmware.dll");
         var info = new InfoDialog("AOTCompileApp is Success.", true, "Program");
         info.Show();
     }
     catch
     {
         var info = new InfoDialog("AOTCompileApp is Error.", true, "Program");
         info.Show();
     }
 }
Exemple #13
0
 public static bool TurnCheckBoxOnOff(bool isChecked)
 {
     if (isChecked)
     {
         var step           = new StepContainer(DummyStep, "Turning off", "Failed to turn off");
         var progressDialog = new ProgressDialog("Information", step);
         progressDialog.Show();
         return(false);
     }
     else
     {
         var dialog = new InfoDialog("Turning On", true);
         dialog.Show();
         return(true);
     }
 }
 private void OnUpdateCompleted(StepDialog dialog)
 {
     if (dialog.ExecutedOk)
     {
         Parent.SuspendButtonEvents();
         Lcd.Clear();
         Lcd.WriteText(Font.MediumFont, new Point(0, 0), "Shutting down...", true);
         Lcd.Update();
         Buttons.LedPattern(2);
         Brick.TurnOff();
         var whyAreYouHereDialog = new InfoDialog("Cut the power", "Reboot failed");
         whyAreYouHereDialog.Show();
         Lcd.Clear();
         new ManualResetEvent(false).WaitOne();
     }
 }
Exemple #15
0
        public static void Main(string[] args)
        {
            using (ButtonEvents buts = new ButtonEvents())
            {
                var tokenSource = new CancellationTokenSource();
                var token       = tokenSource.Token;
                buts.EscapePressed += tokenSource.Cancel;
                var dialog = new InfoDialog("Attach distance sensor");
                dialog.Show();
                var sensor = SensorAttachment.Wait <MSDistanceSensor> (token);               //wait for sensor to attached on any port
                if (!token.IsCancellationRequested)
                {
                    LcdConsole.WriteLine("Up power on");
                    LcdConsole.WriteLine("Down power off");
                    LcdConsole.WriteLine("Enter read sensor");
                    LcdConsole.WriteLine("Left read voltage");
                    LcdConsole.WriteLine("Right read range type");
                    LcdConsole.WriteLine("Esc. terminate");


                    buts.EnterPressed += () =>
                    {
                        LcdConsole.WriteLine("Sensor reading: " + sensor.ReadAsString());
                    };
                    buts.UpPressed += () =>
                    {
                        LcdConsole.WriteLine("Power on");
                        sensor.PowerOn();
                    };
                    buts.DownPressed += () =>
                    {
                        LcdConsole.WriteLine("Power off");
                        sensor.PowerOff();
                    };
                    buts.LeftPressed += () =>
                    {
                        LcdConsole.WriteLine("Voltage: " + sensor.GetVolgage());
                    };
                    buts.RightPressed += () =>
                    {
                        LcdConsole.WriteLine("Sensor range is  : " + sensor.GetRange());
                    };
                }
                token.WaitHandle.WaitOne();
            }
        }
Exemple #16
0
        const int PWM_ABS_MAX         = 60;         //完全停止用モータ制御PWM絶対最大値

        public static void Main()
        {
            // 構造体の宣言と初期化
            var body = new EV3body();

            EV3body.init(ref body);

            // Bluetooth関係のETロボコン拡張機能を有効にする
            Brick.InstallETRoboExt();

            // センサーおよびモータに対して初回アクセスをしておく
            body.color.Read();
            body.gyro.Read();
            body.motorL.SetPower(0);
            body.motorR.SetPower(0);
            body.motorT.SetPower(0);

            body.motorL.ResetTacho();
            body.motorR.ResetTacho();
            body.motorT.ResetTacho();
            Balancer.init();

            // スタート待ち
            wait_start(body);

            try{
                run(body);
            }catch (Exception) {
                var dialogE = new InfoDialog("Exception.");
                dialogE.Show();                //Wait for enter to be pressed
            }

            body.motorL.Off();
            body.motorR.Off();
            body.motorT.Off();

            Lcd.Clear();
            Lcd.Update();

            if (Debugger.IsAttached)
            {
                Brick.ExitToMenu();                  // MonoBrickメインメニューへ戻る
            }
        }
Exemple #17
0
        /// <summary>
        /// Applicatoion info example
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btInfo_Click(object sender, RoutedEventArgs e)
        {
            // Get the icon file from the resources
            var _windowIcon = new BitmapImage();

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("WpfExampleApp.Resources.studie.png"))
            {
                _windowIcon.BeginInit();
                _windowIcon.StreamSource = stream;
                _windowIcon.CacheOption  = BitmapCacheOption.OnLoad;
                _windowIcon.EndInit();
                _windowIcon.Freeze();
            }


            // Get the Information text for the dialog
            StringBuilder _infoText = new StringBuilder();

            // Add the debendency information
            _infoText.Append("********************************************************************************\n");
            _infoText.Append("WpfAppLib.dll version: " + WpfAppLib.Version.GetVersion() + "\n");
            _infoText.Append("********************************************************************************\n");

            try
            {
                _infoText.Append("History:\n\n");
                using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("WpfExampleApp.Resources.History.txt"))
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        string result = reader.ReadToEnd();
                        _infoText.Append(result);
                    }
            }
            catch (Exception err)
            {
                Console.WriteLine("Error reading Versio History log. :: " + err.Message);
            }


            InfoDialog _myInfoDialo = new InfoDialog(new Point(), Assembly.GetExecutingAssembly().GetName().Version.ToString(), _infoText.ToString(), "Company", "Eduard Schmidt", "*****@*****.**", null);

            _myInfoDialo.Show();
        }
        public static void Main(string[] args)
        {
            InfoDialog dialog = new InfoDialog("Misie 2 + 3");                                                                          //print iets op het lcd scherm van de brick

            dialog.Show();                                                                                                              //wacht todat op ok is gedrukt



            Motor          motorR     = new Motor(MotorPort.OutB);                                                              //definieeren van de rechtermotor
            Motor          motorL     = new Motor(MotorPort.OutA);                                                              //definieeren van de linkermotor
            Motor          motorU     = new Motor(MotorPort.OutC);                                                              //definieeren van de robot arm motor
            EV3ColorSensor sensor     = new EV3ColorSensor(SensorPort.In4);                                                     //definieeren van de kleurensensor
            EV3GyroSensor  gyroSensor = new EV3GyroSensor(SensorPort.In2, GyroMode.Angle);                                      //definieeren van de gyrosensor



            //ga er vanuit dat deze functies namen logisch genoeg zijn en geen comments nodig hebben
            DriveStraight(4000, 30, motorR, motorL);
            DriveToColor(25, "White", motorR, motorL, sensor);
            Turning(gyroSensor, -86, motorL, motorR);
            DriveStraight(2500, 30, motorR, motorL);
            Turning(gyroSensor, -86, motorL, motorR);
            DriveStraight(2000, 25, motorR, motorL);
            ArmUp(1500, -20, motorU);
            DriveStraight(100, -25, motorR, motorL);
            ArmUp(600, -20, motorU);
            DriveStraight(2000, -25, motorR, motorL);
            Thread.Sleep(2000);
            ArmUp(200, 20, motorU);
            DriveStraight(700, 25, motorR, motorL);
            DriveStraight(700, -25, motorR, motorL);
            Turning(gyroSensor, 86, motorL, motorR);
            DriveStraight(2170, 30, motorL, motorR);
            Turning(gyroSensor, -90, motorL, motorR);
            DriveStraight(5500, 45, motorL, motorR);
            Turning(gyroSensor, -82, motorL, motorR);
            DriveStraight(6000, 30, motorL, motorR);

            LcdConsole.WriteLine("shutdown");
            Shutdown(motorL, motorR);                                                                                                                                           //afsluiten van het programma
        }
Exemple #19
0
        public static void Main(string[] args)
        {
            InfoDialog dialog = new InfoDialog("verbind een motor aan port A B en C");                              //print iets op het lcd scherm van de brick

            dialog.Show();                                                                                          //wacht todat op ok is gedrukt
            sbyte turningSpeed = 30;                                                                                //hoe hoger deze waarden hoe sneller de robot draaid

            Motor motorR = new Motor(MotorPort.OutB);                                                               //definieeren van de rechtermotor
            Motor motorL = new Motor(MotorPort.OutA);                                                               //definieeren van de linkermotor
            Motor motorU = new Motor(MotorPort.OutC);                                                               //definieeren van de robot arm motor

            //ga er vanuit dat deze functies namen logisch genoeg zijn en geen comments nodig hebben
            DriveStraight(2350, 80, motorL, motorR);
            TurnLeft(turningSpeed, 45, motorR, motorL);
            DriveStraight(150, 50, motorL, motorR);
            ArmUp(800, 18, motorU);
            Thread.Sleep(1500);
            ArmUp(800, -18, motorU);

            Shutdown(motorL, motorR);                                                                                                                                                   //afsluiten van het programma
        }
Exemple #20
0
        static void wait_start(EV3body body, NetworkStream connection)
        {
            //スタート待ち
            var dialogSTART = new InfoDialog("Touch to START", false);

            dialogSTART.Show();              // Wait for enter to be pressed

            while (!body.touch.IsPressed())
            {
                tail_control(body, TAIL_ANGLE_STAND_UP);                 //完全停止用角度に制御
                if (checkRemoteCommand(connection, REMOTE_COMMAND_START))
                {
                    break;                      // PC で 'g' キーが押された
                }
                Thread.Sleep(4);
            }

            while (body.touch.IsPressed())
            {
                tail_control(body, TAIL_ANGLE_STAND_UP);                 //完全停止用角度に制御
                Thread.Sleep(4);
            }
        }
Exemple #21
0
        public static void Main(string[] args)
        {
            try {
                ButtonEvents buts = new ButtonEvents();
                buts.EscapePressed += () => {
                    throw new Exception("Escape gumb je stisnut!");
                };

                ArmCalibrate();
                ArmMove(ArmPosition.Closed);
                color.Mode = ColorMode.Reflection;

                while (true)
                {
                    if (Search())
                    {
                        Pickup();
                        Carry();
                        Dropoff();
                    }
                    else
                    {
                        LcdConsole.WriteLine("Ceo sto je ociscen!");
                        Carry();
                        break;
                    }
                }
            } catch (Exception ex) {
                InfoDialog d = new InfoDialog(ex.Message, "Exception");
                d.Show();
                Thread.Sleep(2000);
            } finally {
                motors.Off();
                armMotor.Off();
                Thread.Sleep(500);
            }
        }
Exemple #22
0
        static bool ShowProgramOptions(string programFolder)
        {
            string fileName = "";

            try {
                fileName = Directory.EnumerateFiles(programFolder, "*.exe").First();
            } catch {
                var info = new InfoDialog(programFolder + "is not executable", true, "Program");
                info.Show();
                Directory.Delete(programFolder, true);
                updateProgramList = true;
                return(true);
            }

            var dialog = new SelectDialog <string> (new string[] {
                "Run Program",
                "Debug Program",
                "Run In AOT",
                "AOT Compile",
                "Delete Program",
            }, "Options", true);

            dialog.Show();
            if (!dialog.EscPressed)
            {
                Action programAction = null;
                switch (dialog.GetSelectionIndex())
                {
                case 0:
                    Lcd.Instance.Clear();
                    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, "Running...", true, Lcd.Alignment.Center);
                    Lcd.Instance.Update();
                    programAction = () => RunAndWaitForProgram(fileName, ExecutionMode.Normal);
                    break;

                case 1:
                    programAction = () => RunAndWaitForProgram(fileName, ExecutionMode.Debug);
                    break;

                case 2:
                    if (!AOTHelper.IsFileCompiled(fileName))
                    {
                        if (AOTCompileAndShowDialog(programFolder))
                        {
                            programAction = () => RunAndWaitForProgram(fileName, ExecutionMode.AOT);
                        }
                    }
                    else
                    {
                        programAction = () => RunAndWaitForProgram(fileName, ExecutionMode.AOT);
                    }
                    break;

                case 3:

                    if (AOTHelper.IsFileCompiled(fileName))
                    {
                        var questionDialog = new QuestionDialog("Progran already compiled. Recompile?", "AOT recompile");
                        if (questionDialog.Show())
                        {
                            AOTCompileAndShowDialog(programFolder);
                        }
                    }
                    else
                    {
                        AOTCompileAndShowDialog(programFolder);
                    }
                    break;

                case 4:
                    var question = new QuestionDialog("Are you sure?", "Delete");
                    if (question.Show())
                    {
                        var step = new StepContainer(() => {
                            Directory.Delete(programFolder, true);
                            return(true);
                        }, "Deleting ", "Error deleting program");
                        var progressDialog = new ProgressDialog("Program", step);
                        progressDialog.Show();
                        updateProgramList = true;
                    }
                    break;
                }
                if (programAction != null)
                {
                    Console.WriteLine("Starting application");
                    programAction();
                    Console.WriteLine("Done running application");
                }
                return(updateProgramList);
            }
            return(false);
        }
Exemple #23
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);
 }
Exemple #24
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);
        }
Exemple #25
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();
            }
        }
Exemple #26
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();
        }
 protected virtual void OnShowClicked(object sender, System.EventArgs e)
 {
     InfoDialog dialog = new InfoDialog();
     dialog.Title = "Contents of the Business Object";
     dialog.Message = _bindable.Data.BusinessObj.Username + "," +
                      _bindable.Data.BusinessObj.Password + "," +
                      _bindable.Data.BusinessObj.Email + "," +
                      _bindable.Data.BusinessObj.Desk;
     dialog.Show();
 }
Exemple #28
0
        private static bool Start(Lcd lcd, Buttons btns)
        {
            if (taskID == taskFind)
            {
                t = new Find();
            }
            else if (taskID == taskEscape)
            {
                t = new Escape();
            }
            else
            {
                //unknown task ID
                return(false);
            }

            //clear previous log messages
            LcdConsole.Clear();

            //set enemy color
            t.enemyColor = enemyColor;

            //init
            int oldLog = Log.level;

            Log.level = Log.LEVEL_ERROR;

            lcd.Clear();
            Rectangle textRect = new Rectangle(new Point(0, Lcd.Height - (int)font.maxHeight - 2), new Point(Lcd.Width, Lcd.Height - 2));

            lcd.WriteTextBox(font, textRect, "initializing...", true, Lcd.Alignment.Center);
            lcd.Update();

            t.Init();

            InfoDialog InitFinishedDialog = new InfoDialog(font, lcd, btns, "Press ENTER to start", true, "Init finished");

            InitFinishedDialog.Show();

            Log.level = oldLog;
            running   = true;

            ButtonEvents be = new ButtonEvents();

            be.EscapePressed += Stop;

            try {
                t.Start();
            }
            catch (Exception e) {
                InfoDialog dialog = new InfoDialog(font, lcd, btns, e + " Exception caught.", true, "Init finished");
                dialog.Show();
                return(false);
            }

            //wait for task to finish
            while (running)
            {
                Thread.Sleep(50);
            }

            be.EscapePressed -= delegate() {
                t.Stop();
                running = false;
            };

            //unregister event
            be.EscapePressed -= Stop;
            //let the GC free the memory
            t = null;

            return(true);
        }
Exemple #29
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);
        }