Ejemplo n.º 1
0
        public Window CreateWindow()
        {
            // Create a window object and set its size to the
            // size of the display.
            mainWindow = new Window();
            mainWindow.Height = SystemMetrics.ScreenHeight;
            mainWindow.Width = SystemMetrics.ScreenWidth;

            Text help = new Text();
            help.Font = Resources.GetFont(Resources.FontResources.nina14);
            help.TextContent = "Buttons: UP resets, SEL Syncs, DOWN schedules";
            help.HorizontalAlignment = HorizontalAlignment.Center;
            help.VerticalAlignment = VerticalAlignment.Top;

            time.Font = Resources.GetFont(Resources.FontResources.small);
            time.TextContent = "Initializing...";
            time.HorizontalAlignment = Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
            time.VerticalAlignment = Microsoft.SPOT.Presentation.VerticalAlignment.Center;

            // Add the text controls to the window.
            Panel panel = new Panel();
            panel.Children.Add(help);
            panel.Children.Add(time);
            mainWindow.Child = panel;

            // Connect the button handler to all of the buttons.
            mainWindow.AddHandler(Buttons.ButtonUpEvent, new RoutedEventHandler(OnButtonUp), false);

            // Set the window visibility to visible.
            mainWindow.Visibility = Visibility.Visible;

            clockTimer = new DispatcherTimer(mainWindow.Dispatcher);
            clockTimer.Interval = new TimeSpan(0, 0, 0, 1, 0);
            clockTimer.Tick += new EventHandler(ClockTimer_Tick);

            // Attach the button focus to the window.
            Buttons.Focus(mainWindow);

            TimeService.SystemTimeChanged += new SystemTimeChangedEventHandler(TimeService_SystemTimeChanged);
            TimeService.TimeSyncFailed += new TimeSyncFailedEventHandler(TimeService_TimeSyncFailed);

            clockTimer.Start();

            return mainWindow;
        }
Ejemplo n.º 2
0
        long uploadIntervalMSec = 60000;  // upload interval 1000 msec

        private void Initialize()
        {
            InitializeUpload();

            measureTimer = new DispatcherTimer();
            measureTimer.Interval = TimeSpan.FromTicks(measureIntervalMSec * TimeSpan.TicksPerMillisecond);
            measureTimer.Tick += MeasureTimer_Tick;
            measureTimer.Start();

            uploadTimer = new DispatcherTimer();
            uploadTimer.Interval = TimeSpan.FromTicks(uploadIntervalMSec * TimeSpan.TicksPerMillisecond);
            uploadTimer.Tick += UploadTimer_Tick;
            uploadTimer.Start();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates the main window.
        /// </summary>
        /// <returns>The main window.</returns>
        public Window CreateWindow()
        {
            // Create a window object and set its size to the size of the 
            // display.
            mainWindow = new Window();
            mainWindow.Width = SystemMetrics.ScreenWidth;
            mainWindow.Height = SystemMetrics.ScreenHeight;

            // Detect landscape or portrait so the program can adjust its 
            // layout.
            bool portrait =
                SystemMetrics.ScreenWidth < SystemMetrics.ScreenHeight;

            // Create the main stack panel.
            StackPanel stack = new StackPanel(portrait ?
                Orientation.Vertical : Orientation.Horizontal);

            // Create stack panels for the current temperature and target 
            // temperature.
            StackPanel stack1 = new StackPanel(Orientation.Vertical);
            StackPanel stack2 = new StackPanel(Orientation.Vertical);

            // Create border panels for the current temperature and target 
            // temperature.
            BorderPanel panel1;
            BorderPanel panel2;

            // Detect portrait or landscape orientation.
            if (portrait)
            {

                // If in portrait mode, set the width to the screen width and 
                // height to 1/4 and 3/4.
                panel1 = new BorderPanel(SystemMetrics.ScreenWidth,
                    (int)(SystemMetrics.ScreenHeight * .25));
                panel2 = new BorderPanel(SystemMetrics.ScreenWidth,
                    (int)(SystemMetrics.ScreenHeight * .75));
            }
            else
            {
                // Otherwise, set the width and height to 1/2 and 1/2, 
                // respectively.
                panel1 = new BorderPanel(SystemMetrics.ScreenWidth / 2,
                    SystemMetrics.ScreenHeight);
                panel2 = new BorderPanel(SystemMetrics.ScreenWidth / 2,
                    SystemMetrics.ScreenHeight);
            }

            // Add the border panels to the panels containing the current 
            // temperature and target temperature.
            panel1.Children.Add(stack1);
            panel2.Children.Add(stack2);

            // Add the stack panels to the border panels.
            stack.Children.Add(panel1);
            stack.Children.Add(panel2);

            // Create text controls for the current temperature.
            _textCurrentTemp = new Text();
            _textCurrentTemp.Font =
                Resources.GetFont(Resources.FontResources.nina48);
            _textCurrentTemp.TextContent =
                Resources.GetString(Resources.StringResources.InitialTemp);
            _textCurrentTemp.HorizontalAlignment =
                Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
            _textCurrentTemp.VerticalAlignment =
                Microsoft.SPOT.Presentation.VerticalAlignment.Center;

            Text currentLabel = new Text();
            currentLabel.Font =
                Resources.GetFont(Resources.FontResources.nina14);
            currentLabel.TextContent =
                Resources.GetString(Resources.StringResources.CurrentTemp);
            currentLabel.HorizontalAlignment =
                Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
            currentLabel.VerticalAlignment =
                Microsoft.SPOT.Presentation.VerticalAlignment.Center;

            // Add the text controls to the current temperature stack panel.
            stack1.Children.Add(currentLabel);
            stack1.Children.Add(_textCurrentTemp);

            // Create controls for the target temperature.
            _textTargetTemp = new Text();
            _textTargetTemp.Font =
                Resources.GetFont(Resources.FontResources.nina48);
            _textTargetTemp.TextContent =
                Resources.GetString(Resources.StringResources.InitialTemp);
            _textTargetTemp.HorizontalAlignment =
                HorizontalAlignment.Center;
            _textTargetTemp.VerticalAlignment =
                VerticalAlignment.Center;

            Text targetLabel = new Text();
            targetLabel.Font =
                Resources.GetFont(Resources.FontResources.nina14);
            targetLabel.TextContent =
                Resources.GetString(Resources.StringResources.TargetTemp);
            targetLabel.HorizontalAlignment = HorizontalAlignment.Center;
            targetLabel.VerticalAlignment = VerticalAlignment.Center;

            // Create the air conditioner or heater status indicator.
            _statusIndicator = new StatusIndicator();

            // Add the controls to the target temperature stack panel.
            stack2.Children.Add(targetLabel);
            stack2.Children.Add(_textTargetTemp);
            stack2.Children.Add(_statusIndicator);

            // Add instructions to the target temperature stack panel.
            TextFlow instructions = new TextFlow();
            instructions.HorizontalAlignment = HorizontalAlignment.Center;
            instructions.VerticalAlignment = VerticalAlignment.Center;
            instructions.TextAlignment = TextAlignment.Center;
            instructions.TextRuns.Add(new TextRun("Up Button to Increase",
                Resources.GetFont(Resources.FontResources.nina14), Color.Black));
            instructions.TextRuns.Add(TextRun.EndOfLine);
            instructions.TextRuns.Add(new TextRun("Down Button to Decrease",
                Resources.GetFont(Resources.FontResources.nina14), Color.Black));
            instructions.TextRuns.Add(TextRun.EndOfLine);
            instructions.TextRuns.Add(new TextRun(
                "Select Button to Toggle Celsius / Fahrenheit",
                Resources.GetFont(Resources.FontResources.nina14), Color.Black));
            stack2.Children.Add(instructions);

            // Set the main window child to the main horizontal stack panel.
            mainWindow.Child = stack;

            // Connect the button handler to all of the buttons.
            mainWindow.AddHandler(Buttons.ButtonUpEvent,
                new RoutedEventHandler(OnButtonUp), false);

            // Set the window visibility to Visible.
            mainWindow.Visibility = Visibility.Visible;

            // Attach the button focus to the window.
            Buttons.Focus(mainWindow);

            // Create the timer that will check the current temperature.
            _timer = new DispatcherTimer(mainWindow.Dispatcher);
            _timer.Interval = new TimeSpan(0, 0, 0, 0, 50);
            _timer.Tick += new EventHandler(OnTimer);
            _timer.Start();

            return mainWindow;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Starts game on specified level
        /// </summary>
        /// <param name="startLevel">Leve to start game</param>
        public void StartGame(int startLevel)
        {
            // Prepare universe
            gameUniverse.Init();
            gameUniverse.StartLevel(startLevel);
            gameUniverse.StepUniverse();

            // Start tick timer
            gameTimer = new DispatcherTimer(this.Dispatcher);
            gameTimer.Interval = new TimeSpan(0, 0, 0, 0, gameUniverse.Statistics.Interval);
            gameTimer.Tick += new EventHandler(GameTimer_Tick);
            gameTimer.Start();
        }
Ejemplo n.º 5
0
            // Constructor
            public MyWindow()
            {
                time.Font = Resources.GetFont(Resources.FontResources.nina48);
                time.TextContent = DateTime.Now.ToString("hh:mm:ss");
                time.HorizontalAlignment = HorizontalAlignment.Center;
                time.VerticalAlignment = VerticalAlignment.Center;

                dayofWeek.Font = Resources.GetFont(Resources.FontResources.nina14);
                dayofWeek.TextContent = days[(int)DateTime.Now.DayOfWeek];
                dayofWeek.HorizontalAlignment = HorizontalAlignment.Left;
                dayofWeek.VerticalAlignment = VerticalAlignment.Bottom;
                dayofWeek.ForeColor = Colors.Red;

                date.Font = Resources.GetFont(Resources.FontResources.nina14);
                date.TextContent = DateTime.Now.ToString("MM/dd/yyyy");
                date.HorizontalAlignment = HorizontalAlignment.Right;
                date.VerticalAlignment = VerticalAlignment.Bottom;
                date.ForeColor = Colors.Red;

                ip.Font = Resources.GetFont(Resources.FontResources.nina14);
                ip.TextContent = str;
                ip.HorizontalAlignment = HorizontalAlignment.Center;
                ip.VerticalAlignment = VerticalAlignment.Bottom;

                help.Font = Resources.GetFont(Resources.FontResources.nina14);
                help.TextContent = "Buttons: UP resets, SEL Syncs, DOWN schedules";
                help.HorizontalAlignment = HorizontalAlignment.Center;
                help.VerticalAlignment = VerticalAlignment.Top;

                clockTimer = new DispatcherTimer(this.Dispatcher);
                clockTimer.Interval = new TimeSpan(0, 0, 0, 1, 0);
                clockTimer.Tick += new EventHandler(ClockTimer_Tick);

                // Add the time control to the window.
                this.Child = panel;
                panel.Children.Add(time);
                panel.Children.Add(dayofWeek);
                panel.Children.Add(date);
                panel.Children.Add(ip);
                panel.Children.Add(help);

                clockTimer.Start();
            }