Simple services for Windows 8 Bluetooth

Source: Internet
Author: User
The Bluetooth simple key service example demonstrates how to access Bluetooth Low-energy Ti simple key services from Metro applications by using Windows portable devices (WPD) drivers and WPD automated APIs.

(Function(){

VaR Simplekeyservice = Null ;

function outputstatus (Message) {
var statuselement = document. getelementbyid ("statusmessage");
If (statuselement) {
statuselement. innertext = message;
}< BR >}

function applicationactivated () {
try {< br> If (tempservice! = null ) {
tempservice. applicationactivated ();
}< BR >}< span style = "color: # 0000ff;"> catch (exception) {
sdksample. displayerror (exception. tostring ();
}< BR >}

function applicationsuspended () {
try {< br> If (tempservice! = null ) {
tempservice. applicationsuincluded ();
}< BR >}< span style = "color: # 0000ff;"> catch (exception) {
sdksample. displayerror (exception. tostring ();
}< BR >}

Winjs. namespace. Define ('tikeyfobsample. descrithcontroller ',{
Applicationactivated: applicationactivated,
Applicationsuspended: applicationsuspended,
Initializecontrollerdevices: Function (){
Outputstatus ("looking for Bluetooth controllers ...");
// Use WPD automation to query for devices that implement the simple key service
Windows. devices. enumeration. deviceinformation. findallasync ("system. devices. interfaceclassguid: = \" "+ tikeyfobsample. constants. simplekeydeviceuuid + "\"",
Null ).
Then ( Function (Devices ){
If (Devices. length> 0 ){
Outputstatus ("found a Bluetooth controller ...");
Try {
VaR Devicefactory = New Activexobject ("portabledeviceautomation. Factory ");
VaR Device = devicefactory. getdevicefromid (devices [0]. ID );
// Make sure that gdevservice is instantiated as a global to ensure it doesn' t get garbage collected
Simplekeyservice = device. Services [0];

// Register for custom onkeypressed event
Simplekeyservice. onkeypressed = Function (Keypressvalue ){
VaR Leftbutton = Document. getelementbyid ("leftbutton ");
VaR Rightbutton = Document. getelementbyid ("rightbutton ");
Outputstatus ("received a value of:" + keypressvalue. tostring ());
Switch (Keypressvalue ){
// No button is pressed
Case 0:
Leftbutton. style. Background = "red ";
Rightbutton. style. Background = "red ";
Break ;
// Left button is pressed
Case 1:
Leftbutton. style. Background = "green ";
Rightbutton. style. Background = "red ";
Break ;
// Right button is pressed
Case 2:
Leftbutton. style. Background = "red ";
Rightbutton. style. Background = "green ";
Break ;
// Both buttons are pressed
Case 3:
Leftbutton. style. Background = "green ";
Rightbutton. style. Background = "green ";
Break ;
Default :
Break ;
};
};
Simplekeyservice. applicationactivated ();
}Catch (E ){
Outputstatus ("error locating a Bluetooth Controller:" + E. Message );
}

}Else{
Outputstatus ("no Bluetooth controller found ");
}
});
}
});
})();

 

Complete example/files/risk/windows8/simple master service sample.rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.