Windows Marketplace for Windows Mobile users

Marat Bakirov already wrote in his blog about Windows Marketplact for Mobile users. Till now over Windows Marketplace the curtain of secret kept and it was not clear as this direction will develop. And here recently, at WPC some details Windows Marketplace for mobile devices became known.

Some facts about Windows Marketplace for Windows Mobile users (some of them already have been sounded earlier):

  • For application placing on Windows Marketplace it is required to pay $99 per year. Thus it will be possible to place five applications. For each additional application it is required to pay $99 per a year.
  • The developer will receive 70% from application cost. 30% will leave in favour of Windows Marketplace.
  • Before placing in Windows Marketplace all application should pass certification.
  • The applications placed in Windows Marketplace can be bought conveniently and safely directly from the mobile device. Application for Windows Marketplace will be accessible to these purposes in Windows Mobile 6.5 out of the box, and for versions 6.0 and 6.1 it it will be possible to install in addition in the end of 2009.
  • On 27th of July, 2009 Windows Marketplace it will be accessible to a wide range of users and developers. Subsequently applications from Windows Marketplace can be downloaded from 30 million mobile devices worldwide. The list of the countries in which works Windows Marketplace:
    • Australia
    • Austria
    • Belgium
    • Brazil
    • Canada
    • Denmark
    • Finland
    • France
    • Germany
    • Greece
    • Hong Kong SAR
    • India
    • Ireland
    • Italy
    • Japan
    • Luxembourg
    • Mexico
    • New Zealand
    • Netherlands
    • Norway
    • Poland
    • Portugal
    • Singapore
    • Spain
    • Sweden
    • Switzerland
    • Taiwan
    • United Kingdom
    • United States

What does it mean for us, developers? It means, that in the near future there will be a platform which for small money will allow to place easily and simply our applications in the global market and to earn on it.

References:

Windows 7 Sensor and Location platform: Implementation of own sensor (Part 3/3)

Windows 7 +1Recently I have told about use Sensor and Location platform in the applications. We have seen, that use of this component set can be very convenient for the application and do not demand many efforts. Also we have an opportunity to work with set of devices in the unified style. Problem of use of this platform there is a presence of drivers for Windows 7 and presence of wrappers for Sensor API. Development of the driver for the device – a task of the manufacturer. And implementation of support in Sensor API can be made own forces.

As I already spoke an entry point is SensorManager class . By means of this class it is possible to get access to the necessary sensor controls and to work with them. This class has methods of getting of the list of all sensors, sensor getting by ID or on type, request to sensor use, and also event of change of quantity of sensors in system.

SensorManager

Each sensor has two main types of identifiers – SensorId and TypeId. TypeId identifies a separate class of devices. For example, by it it is possible to get all sensors of light in system, or any other types of devices. SensorId it is given it is unique to each device. For example, if in system three same sensors of movements everyone will have the unique identifier. Is also CategoryId which unites sensors in a category.

Each identifier represents GUID. They are set by manufacturers by developing of the device and drivers. Thus, it is possible to get a concrete sensor only knowing it ID. Each sensor is presented by Sensor class. It has the general information about a sensor and methods which data from the generalised collections in not typified kind allow to obtain. It is clear, that such data presentation is not so convenient for our applications. Therefore for each sensor it is accepted to implement a class-wrapper within Sensor API. It is implemented by inheritance from general class Sensor. In demonstration examples already there are two such realisations – for 3D accelerometer and for light sensor. However, at the device which we considered earlier there are also touch buttons which also can be used. Therefore let’s implement such class for this sensor.

We will define a new class which will be the inheritor of Sensor class. That it was recognised in Sensor API it it is necessary to mark with SensorDescription attribute in which to specify TypeId for this type of sensors. In base class Sensor there are two important things for us – DataReport property and DataReportChanged event. This property contains data from a sensor, and event fires at their change. The task of our class – to take advantage of these data and to deliver to their user of our class in a convenient kind. For this purpose we will create one more small class which will be engaged in analysis of the information from DataReport.

Experimental by we will find out, that by pressing of the button 1 the code 1 is generated, by pressing 2 – the code 2 is generated, by pressing 3 – the code 4 is generated, and by pressing 4 – the code 8 is generated. It is visible, that binary bits here are used. Also the code 0 in a case unpress of all buttons is generated. Thus, we can write the following code.

[SensorDescription("545C8BA5-B143-4545-868F-CA7FD986B4F6")]


public class SwitchArraySensor : Sensor


{


    public class SwitchArraySensorData


    {


        private static Guid KeyStateProperyId = new Guid(@"38564a7c-f2f2-49bb-9b2b-ba60f66a58df");


 


        public SwitchArraySensorData(SensorReport report)


        {


            uint state = (uint) report.Values[KeyStateProperyId][0];


            Button1Pressed = (state & 0x01) != 0;


            Button2Pressed = (state & 0x02) != 0;


            Button3Pressed = (state & 0x04) != 0;


            Button4Pressed = (state & 0x08) != 0;


        }


 


        public bool Button1Pressed { get; private set; }


        public bool Button2Pressed { get; private set; }


        public bool Button3Pressed { get; private set; }


        public bool Button4Pressed { get; private set; }


    }


 


    public SwitchArraySensorData Current


    {


        get { return new SwitchArraySensorData(DataReport); }


    }


 


    public event EventHandler StateChanged;


 


    public SwitchArraySensor()


    {


        DataReportChanged += SwitchArraySensor_DataReportChanged;


    }


 


    void SwitchArraySensor_DataReportChanged(Sensor sender, EventArgs e)


    {


        if (StateChanged != null)


        {


            StateChanged.Invoke(sender, e);


        }


    }


}

Actually, this class is a wrapper in Sensor API for the sensor necessary to us. For its use I should subscribe for StateChanged event and receive the information through Current property.

For getting of the list of accessible sensor of the some type it is possible to use GetSensorsByTypeId method of SensorManager class. Thus TypeId these sensor it will be defined on the basis of set SensorDescription attribute. Now, using these sensors we can subscribe on necessary event and obtain data in a kind convenient for the application. For example, we can display on the form a state of pressing of buttons.

private void Window_Loaded(object sender, RoutedEventArgs e)


{


    var sensors = SensorManager.GetSensorsByTypeId<SwitchArraySensor>();


    foreach (SwitchArraySensor sensor in sensors)


    {


        switch (sensor.FriendlyName)


        {


            case "Left Switch Array Sensor":


                sensor.StateChanged += delegate(object leftSensor, EventArgs arg)


                {


                    var buttons = ((SwitchArraySensor)leftSensor).Current;


                    SwitchState(LeftButton1, buttons.Button1Pressed);


                    SwitchState(LeftButton2, buttons.Button2Pressed);


                    SwitchState(LeftButton3, buttons.Button3Pressed);


                    SwitchState(LeftButton4, buttons.Button4Pressed);


                };


                break;


            case "Right Switch Array Sensor":


                sensor.StateChanged += delegate(object rightSensor, EventArgs arg)


                {


                    var buttons = ((SwitchArraySensor)rightSensor).Current;


                    SwitchState(RightButton1, buttons.Button1Pressed);


                    SwitchState(RightButton2, buttons.Button2Pressed);


                    SwitchState(RightButton3, buttons.Button3Pressed);


                    SwitchState(RightButton4, buttons.Button4Pressed);


                };


                break;


        }


 


    }


}





As a result we will receive the application which looks as follows.





Certainly, an example with realisation of a similar sensor synthetic enough. However, it obviously shows process of connection of the sensor to Sensor API.



I wish successes to you in creation of your context-aware applications!



Sample application:



Windows 7 Sensor and Location platform: Sensors programming (Part 2/3)

Windows 7 +1 Recently I wrote about Sensor and Location platform in Windows 7 and for what purposes it is necessary. Now we will talk about how this platform can be used in the applications.

To make experiments with not virtual sensors, but with something more approached to a reality, we will use the device from Freescale semiconductor, constructed on the basis of JMBADGE2008-B microcontroller. This device represents the small circuit board on which also there are some sensors – 3D accelerometer, ambient light and buttons.

Freescale

This device is developed specially for demonstration of possibilities of Sensor and Location platform in Windows 7. Actually, everyone can buy it. Thus, this device is good for using for demonstration of this possibility Windows 7.

Before to consider concrete applications, let’s look inside Sensor and Location platform. Before creation of Windows 7 and Sensor&Location platform the connection of various sensors was reduced to implementation of driver and software for it.

 

At such organisation of a task of interaction with external sensors it is possible, but it is heavy. For this purpose each application should interact with that API which will be offered by the vendor of a sensor and a software which serves this sensor. The problem is especially unpleasant in case when the application should use set of the same sensors from different vendors. How Sensor&Location platform suggests to solve this problem?

At level of operational system there are mechanisms of work with sensors. There is a standard unified program interface for work with sensors – Sensor API. Thus all interactions occur to the sensor through Sensor API. It is important, that interactions with all sensors occurs in uniform style. Now you do not need to be integrated with native API through p/invoke.

To work with Sensor and Location API it is necessary to download corresponding library “.NET Interop Sample Library“. In it there are.NET-wrappers for work with Sensor API. In it there are some classes with which help it is possible to work with sensors.

Class SensorManager is an entry point. Through it it is possible to receive the information of sensor controls, and also to work with them. For example, by means of GetSensorBySensorId <> method it is possible to get access to the sensor which interested us. Each sensor should have a class-wrapper which is inherited from base class Sensor. In NET Interop Sample Library already there are such three realisations – AmbientLightSensor, Accelerometer3D, UnknownSensor.

Sensor API

The main idea at work with sensors consists in the following. At change of a state of the sensor (connected/disconnected/active/etc) StateChanged event is throwed. This event is necessary to begin with or end of work with sensors. After communication with the sensor is adjusted, the DataReportChanged event is generated at receiving of new data . This event will be generated how much often depends on sensor and driver. At processing of this event it is possible to read a state of sensors and somehow to change work of application. For these purposes GetProperty method is used. In parameters of this method the identifier of property as which it is necessary to read from the sensor is transferred. As a rule, details of calls of this method disappear in classes which are implements for the specific sensor.

Besides, each sensor has own identifier (GUID) on which it is possible to identify the device. At implementation of a class-wrapper for the sensor this ID is set by means of attribute. Thus, the sensor can be accessed  as obviously having specified the identifier of this sensor, or having referred on this class-wrapper.

/// <summary>
/// Represents a generic ambient light sensor
/// </summary>
[SensorDescription( "97F115C8-599A-4153-8894-D2D12899918A" )]
public class AmbientLightSensor : Sensor
{
 
// .....
// .....
// .....
 
var sensors = SensorManager.GetSensorsByTypeId<AmbientLightSensor>();

Let’s try implement some examples of work with sensors which are accessible in the device from Freescale. We will work with two types of sensors – accelerometer (allows to measure a corner of an inclination of the device) and light (measures light exposure level indoors).

The first application which we implement will display level of light exposure in the form of a burning bulb on the form. To begin with we will subscribe to event of change of a state in Sensor API. It is necessary that the application has started to work, if the sensor is connected in a hot mode. In the handler of this event we will receive the list of all sensors of the necessary type and we will subscribe at them for DataReportChanged event.In the handler of this event we will read value from the sensor of light exposure and to write it in TextBox at the form. Because event is generated in an additional thread, also it is required to make a call of method Dispatcher.Invoke that processing went in the main thread and we could co-operate with elements on the form. Thus we will get the following code.

 
private void Window_Loaded(object sender, RoutedEventArgs e)
{
    SensorManager.SensorsChanged += SensorManagerSensorsChanged;
}
 
void SensorManagerSensorsChanged(SensorsChangedEventArgs change)
{
    Dispatcher.Invoke((System.Threading.ThreadStart)(UpdateSensorsList));
}
 
private void UpdateSensorsList()
{
    var sensors = SensorManager.GetSensorsByTypeId<AmbientLightSensor>();
    foreach (var sensor in sensors)
        sensor.DataReportChanged += delegate(Sensor sender, EventArgs e)
                                        {
                                            Dispatcher.Invoke((System.Threading.ThreadStart)(delegate
                                            {
                                                if (ActiveSensorsListBox.SelectedItem == sender)
                                                {
                                                    CurrentValue.Text =
                                                        ((AmbientLightSensor)sender).CurrentLuminousIntensity.Intensity.ToString();
                                                }
                                            }));
};
}

Now in TextBox on the form current value of light exposure is displayed. Now it is easy to implement any visualisation for it. By means of bindings in WPF we will display degree of light exposure in the form of bulbs. As a result we will receive the following application.

As on a photo it is very difficult to see application work, I have recordered short video in which how the sensor reacts to light exposure degree is well visible.

Other sensor is more interesting – he allows to define degree of an inclination of the device on different axes. For demonstration of degree of an inclination we take 3D model of the airplane for WPF application and we will rotate it in space depending on sensor indicators. The principle of this application is similar previous – we find the necessary sensors, we subscribe for events and at their processing we write down co-ordinates in entry fields on the form. After that we bind model’s coordinates to values of these TextBoxs.

private void UpdateSensorsList()
{
    foreach (var sensor in SensorManager.GetSensorsByTypeId<Accelerometer3D>())
    {
        sensor.DataReportChanged += delegate(Sensor sender, EventArgs e)
                                        {
                                            Dispatcher.Invoke((System.Threading.ThreadStart)(delegate
                                            {
                                                    if (UseXCoordinate.IsChecked == true)
                                                        CurrentXValue.Text = ((Accelerometer3D)sender).CurrentAcceleration[Accelerometer3D.AccelerationAxis.X].ToString();
                                                    if (UseYCoordinate.IsChecked == true)
                                                        CurrentYValue.Text = ((Accelerometer3D)sender).CurrentAcceleration[Accelerometer3D.AccelerationAxis.Y].ToString();
                                                    if (UseZCoordinate.IsChecked == true)
                                                        CurrentZValue.Text = ((Accelerometer3D)sender).CurrentAcceleration[Accelerometer3D.AccelerationAxis.Z].ToString();
                                            }));
};
    }
 
}

Apparently from this example, the code for work with sensors has changed not so strongly. Actually, the code of data acquisition from sensors has changed only, and the rest remains invariable.



Apparently from a photo at a device inclination, the sensor transfers the information to the application and model coordinates change. Thus, we can see effect of an inclination of three-dimensional model.



That is interesting, these sensors can use some applications simultaneously. Also in one application it is possible to use some sensors. Let’s combine application of rotation of three-dimensional model with light sensor. In this case except turn of model we will show the sun. If light exposure indoors decreases, also the sun will disappear. The more illumination indoors, the the sun will shine more intensively. Accordingly in this application the code from two previous examples is used. Therefore I will not bring a code, and at once I will show result.



Also it is possible to look this application in dynamics.



On these examples it is well visible, that work with sensors in Windows 7 is very simple. However, for this purpose it is necessary to have the driver for Windows 7 and a class-wrapper for Sensor&Location platform. As a rule, the driver are delivered by the vendor of a hardware platform, and the class-wrapper can be implemented independently. Next time we will talk just on this theme.


Sample applications: