コード例 #1
0
ファイル: Main.cs プロジェクト: thaiEv3/monoev3
        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);
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            new Motor(MotorPort.OutA).Off();

            Lcd lcd = new Lcd();

            lcd.ShowPicture(MonoPicture.Picture);
            Font      f       = Font.MediumFont;
            Point     offset  = new Point(0, 25);
            Point     p       = new Point(10, Lcd.Height - 75);
            Point     boxSize = new Point(100, 24);
            Rectangle box     = new Rectangle(p, p + boxSize);

            ButtonEvents buts = new ButtonEvents();
            int          val  = 7;

            buts.EnterPressed += () =>
            {
                lcd.Clear();
                lcd.WriteTextBox(f, box + offset * 0, "Value = " + val.ToString(), true);
                lcd.WriteTextBox(f, box + offset * 1, "Hello World!!", false);
                lcd.WriteTextBox(f, box + offset * 2, "Hello World!!", true);
                lcd.Update();
                val++;
            };
            buts.UpPressed += () =>
            {
                lcd.Clear();
                lcd.DrawBitmap(monoLogo, new Point((int)(Lcd.Width - monoLogo.Width) / 2, 10));
                lcd.Update();
            };
            buts.DownPressed += () =>
            {
                lcd.TakeScreenShot();
                lcd.Clear();
                lcd.WriteTextBox(f, box + offset * 1, "Screen Shot", true);
                lcd.Update();
            };
            buts.EscapePressed += () => stopped.Set();
            stopped.WaitOne();
            lcd.WriteTextBox(f, box + offset * 0, "Done!", true);
            lcd.Update();
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            Bitmap          monoLogo = Bitmap.FromResouce(Assembly.GetExecutingAssembly(), "monologo.bitmap");
            EventWaitHandle stopped  = new ManualResetEvent(false);

            Lcd.ShowPicture(MonoPicture.Picture);
            Font      f       = Font.MediumFont;
            Point     offset  = new Point(0, 25);
            Point     p       = new Point(10, Lcd.Height - 75);
            Point     boxSize = new Point(100, 24);
            Rectangle box     = new Rectangle(p, p + boxSize);

            using (ButtonEvents buts = new ButtonEvents())
            {
                int val = 7;
                buts.EnterPressed += () => {
                    Lcd.Clear();
                    Lcd.WriteTextBox(f, box + offset * 0, "Value = " + val.ToString(), true);
                    Lcd.WriteTextBox(f, box + offset * 1, "Hello EV3!!", false);
                    Lcd.WriteTextBox(f, box + offset * 2, "Hello World!!", true);
                    Lcd.Update();
                    val++;
                };
                buts.UpPressed += () => {
                    Lcd.Clear();
                    Lcd.DrawBitmap(monoLogo, new Point((int)(Lcd.Width - monoLogo.Width) / 2, 10));
                    Lcd.Update();
                };
                buts.DownPressed += () => {
                    Lcd.TakeScreenShot();
                    Lcd.Clear();
                    Lcd.WriteTextBox(f, box + offset * 1, "Screen Shot", true);
                    Lcd.Update();
                };
                buts.EscapePressed += () => stopped.Set();
                stopped.WaitOne();
            }
            Lcd.WriteTextBox(f, box + offset * 0, "Done!", true);
            Lcd.Update();
        }
コード例 #4
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();
        }
コード例 #5
0
ファイル: Main.cs プロジェクト: thaiEv3/monoev3
        public static void Main(string[] args)
        {
            using (Lcd lcd = new Lcd())
                using (Buttons btns = new Buttons()) {
                    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();
                    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.WriteTextBox(Font.SmallFont, textRect, "Checking WiFi...", true, Lcd.Alignment.Center);
                    lcd.Update();
                    //WiFiDevice.IsLinkUp ();
                    lcd.WriteTextBox(Font.SmallFont, textRect, "Starting Mono Runtime...", true, Lcd.Alignment.Center);
                    lcd.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.WriteTextBox(Font.SmallFont, textRect, "Loading settings...", true, Lcd.Alignment.Center);
                    lcd.Update();
                    settings = settings.Load();
                    if (settings != null)
                    {
                        lcd.WriteTextBox(Font.SmallFont, textRect, "Applying settings...", true, Lcd.Alignment.Center);
                        lcd.Update();
                        settings.Save();                // JIT work-around
                        WriteWpaSupplicantConfiguration(settings.WiFiSettings.SSID, settings.WiFiSettings.Password, settings.WiFiSettings.Encryption);
                        if (settings.WiFiSettings.ConnectAtStartUp)
                        {
                            lcd.WriteTextBox(Font.SmallFont, textRect, "Connecting to WiFi...", true, Lcd.Alignment.Center);
                            lcd.Update();
                            if (WiFiDevice.TurnOn(60000))
                            {
                                WiFiDevice.GetIpAddress();                         // JIT work-around
                                if (settings.GeneralSettings.CheckForSwUpdatesAtStartUp)
                                {
                                    ShowUpdatesDialogs(lcd, btns, false);
                                }
                                else
                                {
                                    var dialog = new InfoDialog(font, lcd, btns, "Connected Successfully " + WiFiDevice.GetIpAddress(), true);
                                    dialog.Show();
                                }
                            }
                            else
                            {
                                var dialog = new InfoDialog(font, lcd, btns, "Failed to connect to WiFI Network", true);
                                dialog.Show();
                            }
                        }
                    }
                    else
                    {
                        var dialog = new InfoDialog(font, lcd, btns, "Failed to load settings", true);
                        dialog.Show();
                        settings = new FirmwareSettings();
                    }
                }

            for (;;)
            {
                using (Lcd lcd = new Lcd())
                    using (Buttons btns = new Buttons())
                    {
                        ShowMainMenu(lcd, btns);
                    }
                if (MenuAction != null)
                {
                    Console.WriteLine("Starting application");
                    MenuAction();
                    Console.WriteLine("Done running application");
                    MenuAction = null;
                }
            }
        }