Ejemplo n.º 1
0
        private void DoUpdateLcd()
        {
            Lcd.Clear();
            if (!Lcd.IsKey3Pressed)
            {
                Lcd.LcdWriteTime();

                List <CalendarItem> CalenderItems = DataManager.GetCalenderItems();

                Int32 LineCount = 0;
                for (int i = 0; i < 4; i++)
                {
                    if (CalenderItems.Count > i)
                    {
                        Lcd.LcdWrite(LineCount++, CalenderItems[i]);
                    }
                }

                List <EmailItem> EmailItems = DataManager.GetEmailItems();

                if (EmailItems.Count > 0)
                {
                    Lcd.LcdWrite(EmailItems[0]);
                }
                Lcd.Update();
            }
            NextUpdateLcd = DateTime.Now.AddMilliseconds(100);
        }
Ejemplo n.º 2
0
 static void Shutdown(Motor motorR, Motor motorL)
 {
     motorR.Off();                                                                                                                                                                       //voor de zekerheid dat alle motoren stoppen met draaien na het afsluiten
     motorL.Off();
     Lcd.Clear();                                                                                                                                                                        //het lcd scherm vrijmaken van de text en het vrijgemaakte scherm tonen
     Lcd.Update();
 }
Ejemplo n.º 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();
        }
 //public static LiquidCrystalI2C Lcd;
 private static void LCDFinish(Lcd lcd, string message)
 {
     lcd.SetCursorPosition(0, 1);
     lcd.Write(message);
     Thread.Sleep(600);
     lcd.Clear();
 }
Ejemplo n.º 5
0
        private void DrawItemList()
        {
            if (!isItemSizeCalculated)
            {
                CalculateItemSize();
                isItemSizeCalculated = true;
            }
            Lcd.Clear();
            Rectangle currentPos = new Rectangle(new Point(0, 0), itemSize);
            Rectangle arrowRect  = new Rectangle(new Point(Lcd.Width / 2 - arrowWidth / 2, Lcd.Height - arrowHeight), new Point(Lcd.Width / 2 + arrowWidth / 2, Lcd.Height - 1));

            Lcd.WriteTextBox(font, currentPos, title, true, Lcd.Alignment.Center);
            int i = 0;

            while (i != itemsOnScreen)
            {
                if (i + scrollPos >= items.Count)
                {
                    break;
                }
                items [i + scrollPos].OnDrawTitle(font, currentPos + itemHeight * (i + 1), i != cursorPos);
                i++;
            }
            Lcd.DrawArrow(arrowRect, Lcd.ArrowOrientation.Down, scrollPos + itemsOnScreen < items.Count);
            Lcd.Update();
        }
Ejemplo n.º 6
0
 private void DisplayInputMessage(DisplayPiInputMessage message, TimeSpan?endDelay = null)
 {
     Lcd.Clear();
     Lcd.SendMessage($"{message.Author}\n{message.Message}");
     Debug.WriteLine(message.ToString());
     Task.Delay(endDelay ?? TimeSpan.FromSeconds(3)).Wait();
 }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        public LCDTest()
        {
            // RS,RW,E,D4,D5,D6,D7
            RaspPiGPIOMemLcdTransferProvider lcdProvider = new RaspPiGPIOMemLcdTransferProvider(
                GPIOPins.Pin_P1_07,
                GPIOPins.Pin_P1_22,
                GPIOPins.Pin_P1_11,
                GPIOPins.Pin_P1_12,
                GPIOPins.Pin_P1_15,
                GPIOPins.Pin_P1_16,
                GPIOPins.Pin_P1_18);

            string meintext = "Hello World, how are you?";
            Lcd    lcd      = new Lcd(lcdProvider);

            lcd.Begin(16, 2);
            lcd.Clear();
            lcd.Backlight = false;
            lcd.SetCursorPosition(0, 0);
            lcd.Write(meintext);
            //System.Threading.Thread.Sleep (3);
            //lcd.Clear();
            //lcd.Write("Ahoj Bernie?!");
            System.Threading.Thread.Sleep(2000);
            int anzahl = meintext.Length;

            while (anzahl > 0)
            {
                lcd.ScrollDisplayLeft();
                System.Threading.Thread.Sleep(200);
                anzahl--;
            }
        }
Ejemplo n.º 9
0
        public static void Main()
        {
            var lcdProvider = new GpioLcdTransferProvider(Stm32F4Discovery.Pins.PD1, Stm32F4Discovery.Pins.PD2,
                                                          Stm32F4Discovery.Pins.PD9, Stm32F4Discovery.Pins.PD11,
                                                          Stm32F4Discovery.Pins.PD10, Stm32F4Discovery.Pins.PD8);

            var lcd = new Lcd(lcdProvider);

            lcd.Begin(16, 2); //columns, rows

            //znaki specjalne
            //http://www.quinapalus.com/hd44780udg.html
            var customCharacters = new[]
            {
                new byte[] { 0x00, 0x0a, 0x15, 0x11, 0x11, 0x0a, 0x04, 0x00 },                         //serce
                new byte[] { 0x04, 0x02, 0x01, 0x1f, 0x01, 0x02, 0x04, 0x00 }                          //strzalka
            };

            //ladowanie znakow specjalnych
            for (int i = 0; i < customCharacters.Length; i++)
            {
                lcd.CreateChar(i, customCharacters[i]);
            }

            lcd.Clear();
            lcd.Write("* Hello World! *");
            Thread.Sleep(3000);

//            lcd.Clear();
//            lcd.Encoding = Encoding.UTF8;
//            lcd.Write("ĄąĆćĘꣳŃńÓ󌜯ż");
//            Thread.Sleep(3000);

            lcd.Clear();
            lcd.WriteByte(0); //pierwszy znak specjalny
            Thread.Sleep(2000);
            lcd.WriteByte(1); //drugi znak specjalny
            Thread.Sleep(3000);

            //nastepna linia
            lcd.SetCursorPosition(0, 1);
            lcd.Write("#     Bye...   #");
        }
Ejemplo n.º 10
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();
        }
        private void UpdateCalib()
        {
            var time = Clock.Instance.ElapsedMilliseconds / 1000;
            var test = _bno.GetCalibration();

            _lcd.Clear();
            _lcd.Write("S:" + test[0] + " G:" + test[1] + " A:" + test[2] + " M:" + test[3]);
            _lcd.SetCursorPosition(0, 1);
            _lcd.Write("T+ " + time + " s");
            Thread.Sleep(_delay);
        }
Ejemplo n.º 12
0
        private void OnExit(QuestionDialog dialog)
        {
            if (dialog.IsPositiveSelected)
            {
                Parent.SuspendButtonEvents();
                Lcd.Clear();
                Lcd.WriteText(Font.MediumFont, new Point(0, 0), "Shutting down...", true);
                Lcd.Update();

                Buttons.LedPattern(LedColor.Red, LedEffect.Normal);
                Brick.TurnOff();
            }
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
 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();
     }
 }
Ejemplo n.º 15
0
        private static void initializeLCD(I2CBus bus)
        {
            // Use I2C provider
            // Default configuration coresponds to Adafruit's LCD backpack
            // Initialize provider (multiple devices can be attached to same bus)
            var lcdProvider = new MCP23008LcdTransferProvider(_bus);

            // Create the LCD interface
            LCD = new Lcd(lcdProvider);
            // Set the LCD Color property = Led.  This is for cleaner code only.
            //LCD.Color = Led;
            // Set up the LCD's number of columns and rows:
            LCD.Begin(20, 4);
            // Clear the LCD
            LCD.Clear();
        }
Ejemplo n.º 16
0
        /// <summary>
        /// LCD Thread
        /// </summary>
        private void LCDThread()
        {
            Thread.CurrentThread.IsBackground = true;
            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);

            while (!stopLCDThread.WaitOne(lCDThreadSampleTime))
            {
                Lcd.Clear();
                Lcd.WriteTextBox(f, box, "Light = " + reflectedLight, true);
                Lcd.WriteTextBox(f, box + offset, "Steer " + currentSteeringAngle, false);
                Lcd.Update();
            }
        }
Ejemplo n.º 17
0
 private void StartProgram()
 {
     if (ProgramManager.RunningProgram == null)
     {
         if (!useEscToStop)
         {
             Parent.SuspendButtonEvents();
         }
         Lcd.Clear();
         Lcd.Update();
         ProgramManager.StartProgram(program, inAot, OnDone);
     }
     else
     {
         //Show some dialog
     }
 }
Ejemplo n.º 18
0
        public static void Main(string[] args)
        {
            EventWaitHandle stopped     = new ManualResetEvent(false);
            int             centerX     = Lcd.Width / 2;
            int             centerY     = Lcd.Height / 2;
            Point           center      = new Point(centerX, centerY);
            int             refreshRate = 100;
            bool            run         = true;
            ButtonEvents    buts        = new ButtonEvents();

            buts.EscapePressed += () => {
                stopped.Set();
                run = false;
            };

            while (run)
            {
                for (int k = 0; k < 4; k++)
                {
                    for (int i = 1; i < centerY; i++)
                    {
                        Lcd.Clear();
                        Lcd.DrawCircle(center, (ushort)i, true, true);
                        Lcd.Update();
                        stopped.WaitOne(refreshRate);
                    }
                    for (int i = centerY - 1; i > 0; i--)
                    {
                        Lcd.Clear();
                        Lcd.DrawCircle(center, (ushort)i, true, true);
                        Lcd.Update();
                        stopped.WaitOne(refreshRate);
                    }
                }

                for (int k = 0; k < 20; k++)
                {
                    Lcd.Clear();
                    Lcd.DrawHLine(center, centerX / 2, true);
                    stopped.WaitOne(refreshRate);
                    Lcd.Clear();
                    Lcd.DrawVLine(center, centerY / 2, true);
                }
            }
        }
Ejemplo n.º 19
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メインメニューへ戻る
            }
        }
Ejemplo n.º 20
0
        public void ShowError(string message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            bool split = message.Length > Columns;

            string line1 = split ? message.Substring(0, Columns) : message;

            _lcd.Clear();
            _lcd.Write(line1);

            if (split)
            {
                string line2 = message.Substring(Columns, message.Length - Columns);
                _lcd.SetCursorPosition(0, 1);
                _lcd.Write(line2);
            }
        }
Ejemplo n.º 21
0
        static bool Shutdown(Lcd lcd, Buttons btns)
        {
            var dialog = new QuestionDialog(Font.MediumFont, lcd, btns, "Are you sure?", "Shutdown EV3");

            dialog.Show();
            if (dialog.IsPositiveSelected)
            {
                lcd.Clear();
                lcd.WriteText(font, new Point(0, 0), "Shutting down...", true);
                lcd.Update();

                using (UnixDevice dev = new UnixDevice("/dev/lms_power"))
                {
                    dev.IoCtl(0, new byte[0]);
                }
                btns.LedPattern(2);
                MenuAction = () => ProcessHelper.RunAndWaitForProcess("/lejos/bin/exit");
                return(true);
            }
            return(false);
        }
Ejemplo n.º 22
0
        private void RedrawMenu()
        {
            lcd.Clear();
            Rectangle currentPos = new Rectangle(new Point(0, 0), itemSize);
            Rectangle arrowRect  = new Rectangle(new Point(Lcd.Width / 2 - arrowWidth / 2, Lcd.Height - arrowHeight), new Point(Lcd.Width / 2 + arrowWidth / 2, Lcd.Height - 1));

            lcd.WriteTextBox(font, currentPos, title, true, Lcd.Alignment.Center);
            int i = 0;

            while (i != itemsOnScreen)
            {
                if (i + scrollPos >= menuItems.Length)
                {
                    break;
                }
                menuItems [i + scrollPos].Draw(font, currentPos + itemHeight * (i + 1), i != cursorPos);
                i++;
            }
            lcd.DrawArrow(arrowRect, Lcd.ArrowOrientation.Down, scrollPos + itemsOnScreen < menuItems.Length);
            lcd.Update();
        }
Ejemplo n.º 23
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();
        }
Ejemplo n.º 24
0
        public static void Main(string[] args)
        {
            ManualResetEvent terminateProgram = new ManualResetEvent(false);
            string           fbToken          = "CAACpSl1Qm3cBAHAMyZAY...";//This is not valied
            var          fb          = new FacebookClient(fbToken);
            Lcd          lcd         = new Lcd();
            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);
            var          colorSensor = new ColorSensor(SensorPort.In1);
            ButtonEvents buts        = new ButtonEvents();

            LcdConsole.WriteLine("Use color on port1");
            LcdConsole.WriteLine("Enter post value");
            LcdConsole.WriteLine("Esc. terminate");
            buts.EscapePressed += () => {
                terminateProgram.Set();
            };

            buts.EnterPressed += () => {
                Color color = colorSensor.ReadColor();
                lcd.Clear();
                lcd.WriteTextBox(f, box + offset * 0, "Color: " + color, true);
                lcd.WriteTextBox(f, box + offset * 1, "Send to Facebook" + color, true);
                lcd.Update();
                colorSensor.ReadColor();
                var    me      = fb.Get("monobrick.dk") as JsonObject;
                var    uid     = me["id"];
                string url     = string.Format("{0}/{1}", uid, "feed");
                var    argList = new Dictionary <string, object>();
                argList["message"] = "A program running MonoBrick Firmware was aked to read the color sensor. Color read: " + colorSensor.ReadColor().ToString();
                fb.Post(url, argList);
            };
            terminateProgram.WaitOne();
        }
        public static void Main()
        {
            var bus = new I2CBus();

            var lcdProvider = new MCP23008LcdTransferProvider(bus);
            var lcd         = new Lcd(lcdProvider);

            lcd.Begin(16, 2);
            lcd.Backlight = true;
            lcd.Write("Payload McPayload Face v1.0");
            for (int i = 0; i < 12; i++)
            {
                lcd.ScrollDisplayLeft();
                Thread.Sleep(200);
            }
            Thread.Sleep(1000);
            lcd.Clear();
            LCDFinish(lcd, "ACC DemoSat 2016");

            //THIS SECTION CREATES / INITIALIZES THE SERIAL LOGGER
            Debug.Print("Flight computer started successfully. Beginning INIT.");

            //Lcd = new LiquidCrystalI2C(0x01, 16, 2);
            //Lcd.write("Testing!");
            lcd.Write("Starting logger.");
            var logger = new Logger();

            Debug.Print("Starting logger.");
            logger.Start();
            LCDFinish(lcd, "Done.");


            lcd.Write("Starting clock...");
            Rebug.Print("Starting clock.");
            Clock.Instance.Start();
            LCDFinish(lcd, "Done.");

            //THIS SECTION CREATES/INITIALIZES THE PRESSURE SENSOR
            //lcd.Write("Init BMP sensor.");
            //Rebug.Print("Initializing BMP Sensor ");
            //var bmploop = new PressureTempAltitudeUpdater(bus, delay: 1000);
            //LCDFinish(lcd);

            //THIS SECTION CREATES/INITIALIZES THE SERIAL BNO 100HZ UPDATER
            lcd.Write("Init BNO sensor...");
            Rebug.Print("Initializing BNO Sensor ");
            var bno     = new SerialBno(SerialPorts.COM1, 5000, 5000, SerialBno.Bno055OpMode.OperationModeNdof);
            var bnoloop = new SerialBnoUpdater(bno, delay: 1000);

            LCDFinish(lcd, "Done.");

            ////Starts up the expensive mag
            lcd.Write("Init exp. mag...");
            Rebug.Print("Initializing expensive magnetometer on com3");
            var expensiveMagLoop = new ExpensiveMagUpdater(delay: 1000);

            LCDFinish(lcd, "Done.");

            lcd.Write("Init calib disp.");
            Rebug.Print("Initializing BNO calibration display loop");
            var printBnoCalib = new BNOCalibUpdate(bno, lcd, delay: 1000);

            LCDFinish(lcd, "Done.");

            //////THIS SECTION CREATES/INITIALIZES THE MAGNETOMETER UPDATER
            var mag_dump_size = 18432;

            lcd.Write("Init fast mag...");
            Rebug.Print("Initializing fast mag dump collector with a size of " + mag_dump_size + "bytes.");
            var customMagLoop = new CustomMagUpdater(mag_dump_size, AnalogChannels.ANALOG_PIN_A0);

            LCDFinish(lcd, "Done.");

            //Thread.Sleep(5000);
            lcd.Write("Init complete...");
            Rebug.Print("Flight computer INIT Complete. Continuing with boot.");
            LCDFinish(lcd, "Continuing boot.");

            //THIS SECTION INITIALIZES AND STARTS THE MEMORY MONITOR
            lcd.Write("Start memory monitor...");
            Rebug.Print("Starting memory monitor...");
            MemoryMonitor.Instance.Start(ref logger);
            LCDFinish(lcd, "Done.");

            ////THIS STARTS THE Mag dump update
            lcd.Write("Start f.mag loop...");
            Rebug.Print("Starting fast mag dump...");
            customMagLoop.Start();
            LCDFinish(lcd, "Done.");

            ////THIS STARTS THE BNO SENSOR UPDATE
            lcd.Write("Start bno loop...");
            Rebug.Print("Starting bno sensor updates...");
            bnoloop.Start();
            LCDFinish(lcd, "Done.");

            //THIS STARTS THE BNO SENSOR UPDATE
            //lcd.Write("Start bmp loop");
            //Rebug.Print("Starting bmp sensor updates...");
            //bmploop.Start();
            //LCDFinish(lcd);

            //THIS STARTS THE EXPENSIVE MAG UPDATE
            lcd.Write("Start e.mag loop...");
            Rebug.Print("Starting expensive mag updates...");
            expensiveMagLoop.Start();
            LCDFinish(lcd, "Done.");

            lcd.Write("Boot successful!");
            LCDFinish(lcd, "Entering run state.");

            Rebug.Print("Flight computer boot successful.");
            printBnoCalib.Start();
        }
Ejemplo n.º 26
0
        static void Main(string[] args)
        {
            ButtonEvents buttons = new ButtonEvents();
            TcpListener  server  = null;
            TcpClient    client  = null;
            bool         run     = true;

            buttons.EscapePressed += () =>
            {
                if (server != null)
                {
                    server.Stop();
                }
                if (client != null)
                {
                    client.Close();
                }

                run = false;
            };

            Log("KinematicServer 1.5");

            float mainRatio      = 46.667f;
            float secondaryRatio = 40.0f;
            float handRatio      = 8f;

#if DUMPLOGS
            StringBuilder logs = new StringBuilder();
#endif
            using (RobotMotors motors = new RobotMotors(MotorPort.OutA, MotorPort.OutB, MotorPort.OutC)
            {
                MainMotorRatio = mainRatio, SecondaryMotorRatio = secondaryRatio, HandMotorRatio = handRatio
            })
            {
                EV3TouchSensor sensor1 = new EV3TouchSensor(SensorPort.In1);
                EV3ColorSensor sensor2 = new EV3ColorSensor(SensorPort.In2);
                sensor2.Mode = ColorMode.Reflection;

                int sensor2max = -1;
                int pause      = 0;
                buttons.EnterReleased += () =>
                {
                    pause++;
                };
                int currentPause = 0;
                motors.Calibrate((RobotMotors.CalibrationSteps step) =>
                {
                    if (!run)
                    {
                        return(true);
                    }
                    switch (step)
                    {
                    case RobotMotors.CalibrationSteps.Main:
                        if (sensor1.IsPressed())
                        {
                            return(true);
                        }
                        break;

                    case RobotMotors.CalibrationSteps.Pause:
                        if (currentPause != pause)
                        {
                            currentPause = pause;
                            return(true);
                        }
                        break;

                    case RobotMotors.CalibrationSteps.Secondary:
                        int sensor2reading = sensor2.ReadRaw();
                        if (sensor2reading > 19 &&
                            sensor2reading < sensor2max)     // moving away from sweet spot (but remove noise)
                        {
#if DUMPLOGS
                            logs.Append(string.Format("{0}:{1}:{2}\n\n", motors.GetRawTacho(MotorPort.OutB), sensor2reading, sensor2max));
                            logs.Append("-----------------\n\n");
#endif
                            return(true);
                        }
                        else if (sensor2reading > sensor2max)
                        {
                            sensor2max = sensor2reading;      // keep going when it increases
                        }
#if DUMPLOGS
                        logs.Append(string.Format("{0}:{1}:{2}\n\n", motors.GetRawTacho(MotorPort.OutB), sensor2reading, sensor2max));
#endif
                        break;

                    case RobotMotors.CalibrationSteps.SecondaryReset:
                        sensor2max = -1;
#if DUMPLOGS
                        logs.Append("***********************\n\n");
#endif
                        break;
                    }

                    /*
                     * Lcd.Clear();
                     * int line = 0;
                     * Lcd.WriteText(Font.MediumFont, new Point(0, line), "Calibrating...", true);
                     * line += (int)(Font.MediumFont.maxHeight);
                     * Lcd.WriteText(Font.MediumFont, new Point(0, line), string.Format("Refl.: {0} / {1}", sensor2.ReadRaw(), sensor2max), true);
                     * line += (int)(Font.MediumFont.maxHeight);
                     * Lcd.WriteText(Font.MediumFont, new Point(0, line), string.Format("A: {0}", motors.GetRawTacho(MotorPort.OutA)), true);
                     * line += (int)(Font.MediumFont.maxHeight);
                     * Lcd.WriteText(Font.MediumFont, new Point(0, line), string.Format("B: {0}", motors.GetRawTacho(MotorPort.OutB)), true);
                     * line += (int)(Font.MediumFont.maxHeight);
                     * Lcd.Update();
                     */

                    return(false);
                });
            }
            // stop here
            if (!run)
            {
                return;
            }

            // main loop
            Lcd.Clear();
            Lcd.Update();
            Log("Starting...");
            try
            {
                using (RobotMotors motors = new RobotMotors(MotorPort.OutA, MotorPort.OutB, MotorPort.OutC)
                {
                    MainMotorRatio = mainRatio, SecondaryMotorRatio = secondaryRatio, HandMotorRatio = handRatio
                })
                {
                    // Set the TcpListener on port 13000.
                    Int32 port = 13000;

                    // TcpListener server = new TcpListener(port);
                    server = new TcpListener(IPAddress.Any, port);

                    // Start listening for client requests.
                    server.Start();

                    // Buffer for reading data
                    Byte[] bytes = new Byte[256];
                    String data  = null;

                    // Enter the listening loop.
                    while (run)
                    {
                        Log("Waiting for a connection... ");

                        // Perform a blocking call to accept requests.
                        // You could also user server.AcceptSocket() here.
                        client = server.AcceptTcpClient();
                        Log("Connected!");

#if DUMPLOGS
                        // DEBUG
                        byte[] logBuffer = Encoding.ASCII.GetBytes(logs.ToString());
                        client.GetStream().Write(logBuffer, 0, logBuffer.Length);
#endif
                        motors.MainMotorSpeed      = 64;
                        motors.SecondaryMotorSpeed = 64;
                        motors.HandMotorSpeed      = 127;
                        data = null;

                        // Get a stream object for reading and writing
                        NetworkStream stream = client.GetStream();

                        int    read;
                        string message = "";
                        // Loop to receive all the data sent by the client.
                        int commandCount = 0;
                        while (run && (read = stream.Read(bytes, 0, bytes.Length)) != 0)
                        {
                            // Translate data bytes to a ASCII string.
                            data = System.Text.Encoding.ASCII.GetString(bytes, 0, read);
                            for (int i = 0; i < read; i++)
                            {
                                char c = data[i];
                                if (c != '\0')
                                {
                                    message += c;
                                }
                                else
                                {
                                    String[] rawCommand = message.Split(';');
                                    // get message type
                                    switch (rawCommand[0])
                                    {
                                    case "UP":
                                        motors.Queue(new HandCommand(true));
                                        commandCount = 0;
                                        break;

                                    case "DWN":
                                        motors.Queue(new HandCommand(false));
                                        commandCount = 0;
                                        break;

                                    case "MOV":
                                        commandCount++;
                                        float mainRotation      = float.Parse(rawCommand[1]);
                                        float secondaryRotation = float.Parse(rawCommand[2]);

                                        motors.Queue(
                                            new MoveCommand {
                                            MainRotation      = (int)Math.Round(mainRotation, MidpointRounding.AwayFromZero),
                                            SecondaryRotation = (int)Math.Round(secondaryRotation, MidpointRounding.AwayFromZero)
                                        });
                                        break;
                                    }

                                    //
                                    Lcd.Clear();
                                    int line = 0;
                                    Lcd.WriteText(Font.MediumFont, new Point(0, line), string.Format("Count: {0}", commandCount), true);
                                    line += (int)(Font.MediumFont.maxHeight);
                                    Lcd.WriteText(Font.MediumFont, new Point(0, line), string.Format("Last: {0}", message), true);
                                    line += (int)(Font.MediumFont.maxHeight);
                                    Lcd.Update();

                                    //
                                    message = "";
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log(ex.Message);
                if (client.Connected)
                {
                    byte[] buffer = Encoding.ASCII.GetBytes(ex.Message);
                    client.GetStream().Write(buffer, 0, buffer.Length);
                }
                throw;
            }
            finally
            {
                // Stop listening for new clients.
                server.Stop();
            }
        }
Ejemplo n.º 27
0
        public static void Main()
        {
            serialPort.ReadTimeout = 0;

            string InitMessage = "Initializing...";

            // set up the LCD's number of columns and rows:
            lcd.Begin(columns: 16, lines: 2);
            lcd.Backlight = true;
            lcd.Clear();
            lcd.Clear();
            lcd.SetCursorPosition(0, 0);

            // Print a message to the LCD.
            lcd.Write(" *** ARMING ***");
            Thread.Sleep(250);

            lcd.SetCursorPosition(column: 0, row: 1);
            lcd.Write("HomeAlarmPlus Pi");
            Thread.Sleep(1600);
            lcd.Clear();
            lcd.SetCursorPosition(column: 0, row: 0);
            lcd.Write(InitMessage);
            Thread.Sleep(1600);

            for (int i = 0; i < InitMessage.Length; i++)
            {
                lcd.ScrollDisplayLeft();
                Thread.Sleep(85);
            }

            lcd.Clear();
            lcd.SetCursorPosition(column: 0, row: 0);
            lcd.Write("HomeAlarmPlus Pi");

            MonitorZonesDelegate monitorZones = new MonitorZonesDelegate(MonitorZones);

            MonitorMotionSensorDelegate monitorMotion = new MonitorMotionSensorDelegate(MonitorSensors);

            SdCardEventLogger.parseConfigFileContents(Alarm.User_Definitions.Constants.ALARM_CONFIG_FILE_PATH);
            syncHttpEvents = Stopwatch.StartNew();

            InitArrays();
            IPAddress = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress;
            Console.DEBUG_ACTIVITY(IPAddress);
            lcd.SetCursorPosition(column: 0, row: 1);
            lcd.Write("IP: " + IPAddress + "       ");

            Thread.Sleep(1000);
            SdCardEventLogger.SDCardAccess();

            lcd.SetCursorPosition(column: 0, row: 1);
            lcd.Write("Port: " + Alarm.ConfigDefault.Data.Http_port + "        ");
            Thread.Sleep(1000);

            new Thread(Alarm.WebServer.startHttp).Start();

            //Time from Raspberry Pi
            Debug.Print("Setting Date and Time from Network");
            lcd.SetCursorPosition(column: 0, row: 1);
            lcd.Write("Finding RPi-srvr");
            Notification.PushingBox.Connect("vPUSHINGBOX");

            //Let's notify Pushover
            //With extension.replace spaces are replaced with %20 so that is recognized by PHP when posting parameters.
            string time  = DateTime.Now.ToString();
            string ttime = Extension.Replace(time, " ", "%20");

            Notification.Pushover.Connect(ttime, Extension.Replace("Netduino Plus Time set", " ", "%20"), Extension.Replace("Time set from Raspberry Pi", " ", "%20"), false);

            LastResetCycle  = DateTime.Now.ToString("ddd, d MMM yyyy hh:mm:ss tt\r\n");
            dLastResetCycle = DateTime.Now;
            Thread.Sleep(2000);

            lcd.SetCursorPosition(column: 0, row: 0);
            lcd.Write("Syncing data           ");
            lcd.SetCursorPosition(column: 0, row: 1);
            lcd.Write("Wunderground       ");
            parseWeatherData(ttime);
            Thread.Sleep(2000);

            lcd.Clear();
            lcd.SetCursorPosition(column: 0, row: 0);
            lcd.Write("HomeAlarmPlus Pi");
            lcd.SetCursorPosition(column: 0, row: 1);
            lcd.Write("Temp: " + Alarm.Common.Weather_Info.current_temperature + "      ");
            Thread.Sleep(2000);

            lcd.SetCursorPosition(column: 0, row: 1);
            lcd.Write("SYSTEM READY           ");
            Debug.Print("ARMED!");
            Thread.Sleep(560);
            ATTINYx5.Write(true);

            lcd.Clear();

            int count = 0, sub_count = 0;

            while (true)
            {
                Console.DEBUG_ACTIVITY("Main Method - Memory available: " + Debug.GC(true));
                monitorZones();
                //monitorMotion();

                lcd.Clear();
                if (count % 2 == 0)
                {
                    lcd.SetCursorPosition(column: 0, row: 0);
                    lcd.Write("  Date    Time");
                    lcd.SetCursorPosition(column: 0, row: 1);
                    lcd.Write(DateTime.Now.ToString("MMM dd/yy h:mmtt ").ToUpper());
                }
                else
                {
                    lcd.SetCursorPosition(column: 0, row: 0);
                    lcd.Write("  Current Temp");

                    lcd.SetCursorPosition(column: 0, row: 1);

                    if (sub_count % 2 == 0)
                    {
                        lcd.Write(Alarm.Common.Weather_Info.current_temperature + " " + Alarm.Common.Weather_Info.current_conditions);
                    }
                    else
                    {
                        lcd.Write("Hi: " + Alarm.Common.Weather_Info.today_high + " Lo: " + Alarm.Common.Weather_Info.today_low);
                    }

                    sub_count++;
                }

                Thread.Sleep(Alarm.Common.Alarm_Constants.ALARM_DELAY_TIME);

                double eHours = syncHttpEvents.ElapsedHours;
                if (eHours >= Alarm.ConfigDefault.Data.WUNDERGROUND_SYNC_FREQUENCY)
                {
                    parseWeatherData(Extension.Replace(DateTime.Now.ToString(), " ", "%20"));
                    syncHttpEvents = Stopwatch.StartNew();
                }

                count++;
            }
        }
Ejemplo n.º 28
0
 public void Clear()
 {
     lcd.Clear();
 }
Ejemplo n.º 29
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);
        }
Ejemplo n.º 30
0
 private static bool Exit(Lcd lcd, Buttons btns)
 {
     lcd.Clear();
     exit = true;
     return(true);
 }