Click here to Skip to main content
15,886,258 members
Articles / Desktop Programming / WPF

Motion adjuster application – using Ultrabook Sensors

Rate me:
Please Sign up or sign in to vote.
4.82/5 (11 votes)
26 May 2013CPOL2 min read 27.1K   262   7  
Using sensors, we can get the change in X and Y direction (i.e. movement), using which we can adjust laptop screen to make it very stable although having jerking motion.
<Page
    x:Class="MotionAdjusterApp.MainPage"
    IsTabStop="false"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MotionAdjusterApp"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" x:Name="samplePage" Loaded="samplePage_Loaded">
    <Page.Resources>
        <Storyboard x:Key="moveContainerBorder" Storyboard.TargetName="containerBorder" RepeatBehavior="Forever">
            <DoubleAnimation Storyboard.TargetProperty="(Canvas.Left)" From="250" To="225" Duration="0:0:0.2" FillBehavior="HoldEnd" AutoReverse="True" />
            <DoubleAnimation Storyboard.TargetProperty="(Canvas.Top)" From="125" To="150" BeginTime="0:0:0.2" Duration="0:0:0.2" FillBehavior="HoldEnd" AutoReverse="True" />
        </Storyboard>
        
        <Storyboard x:Key="moveContainerBorderWithAdjuster" RepeatBehavior="Forever">
            <DoubleAnimation Storyboard.TargetProperty="(Canvas.Left)" From="250" To="225" Duration="0:0:0.2" FillBehavior="HoldEnd" AutoReverse="True" Storyboard.TargetName="containerBorder" />
            <DoubleAnimation Storyboard.TargetProperty="(Canvas.Top)" From="125" To="150" BeginTime="0:0:0.2" Duration="0:0:0.2" FillBehavior="HoldEnd" AutoReverse="True" Storyboard.TargetName="containerBorder" />

            <DoubleAnimation Storyboard.TargetProperty="(Canvas.Left)" From="50" To="75" Duration="0:0:0.2" FillBehavior="HoldEnd" AutoReverse="True" Storyboard.TargetName="txtContent" />
            <DoubleAnimation Storyboard.TargetProperty="(Canvas.Top)" From="50" To="25" BeginTime="0:0:0.2" Duration="0:0:0.2" FillBehavior="HoldEnd" AutoReverse="True" Storyboard.TargetName="txtContent" />
        </Storyboard>
    </Page.Resources>

    <Canvas HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Border x:Name="containerBorder" Canvas.Left="250" Canvas.Top="125" HorizontalAlignment="Center" VerticalAlignment="Center" CornerRadius="5" BorderThickness="20" Background="{StaticResource ApplicationPageBackgroundThemeBrush}" BorderBrush="Silver" Height="350" Width="600">
            <Grid x:Name="containerGrid" Canvas.Left="50" Canvas.Top="50">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="50" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="125" />
                    <ColumnDefinition Width="125" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Canvas Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                    <TextBlock Canvas.Left="50" Canvas.Top="50" x:Name="txtContent" TextWrapping="Wrap" Height="300" Width="450" LineHeight="2" FontSize="13">
                        <TextBlock.Text>
                            "As per latest launch of the 3rd Generation Intel Core Processor, Intel has introduced collection of sensors in Ultrabook. 
                            Collection of sensors includes Global Positioning System (GPS) sensor, Gyroscope, Accelerometer, Ambient Light Sensor, 
                            Compass, etc. Creative applications based on these sensors may affect our day to day life style. There are many sources 
                            which helps developer community to make usage of these sensors. Using that we can find some solution for traditional 
                            issues. Here, I am trying to get solution for following problem. Laptop users are facing problem to use it while 
                            travelling in Car, Train, Bus, etc. The problem is jerking motion. To focus on screen our eyes are trying to focus on 
                            screen, which is in motion. Frequently changing the focus is making our eyes tired and finally to us. 
                            Sometimes it causes motion sickness, too. And hence it is sensible to not to read anything while travelling."
                        </TextBlock.Text>
                    </TextBlock>
                </Canvas>

                <Button x:Name="startMotionButton" Grid.Row="1" Grid.Column="0" Content="Start Motion" Click="startMotionButton_Click"></Button>
                <Button x:Name="stopMotionButton" Grid.Row="1" Grid.Column="1" Content="Stop Motion" Click="stopMotionButton_Click" ></Button>
                <Button x:Name="adjustMotionButton" Grid.Row="1" Grid.Column="2" Content="Motion with Motion Adjuster" Click="motionAdjusterButton_Click" ></Button>
            </Grid>
        </Border>
    </Canvas>

</Page>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) iGATE Computer Systems Ltd.
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions