Skip to content

Instantly share code, notes, and snippets.

@nazrdogan
Last active December 24, 2015 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nazrdogan/6732035 to your computer and use it in GitHub Desktop.
Save nazrdogan/6732035 to your computer and use it in GitHub Desktop.
Tizen -- Bluetooth (WEB)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="description" content="A single-page template generated by Tizen Web IDE"/>
<title>Tizen Web IDE - Tizen - jQuery Mobile - Single-Page</title>
<link rel="stylesheet" href="./css/jquery.mobile-1.2.0.css"/>
<script type="text/javascript" src="./js/jquery-1.8.2.js"></script>
<script type="text/javascript" src="./js/jquery.mobile-1.2.0.js"></script>
<script type="text/javascript" src="./js/main.js"></script>
<link rel="stylesheet" href="./css/style.css" />
<script type="text/javascript">
var adapter = tizen.bluetooth.getDefaultAdapter();
function powerOn()
{
// Bluetooth kapalı ise
if(!adapter.powered) {
// Bluetooth 'u aç
adapter.setPowered(true, function() {
console.log("Bluetooth powered on success.");
},
function(e) {
console.log("Failed to power on Bluetooth: " + e.message);
});
}
}
function powerOff()
{
// Eğer bluetooth kapalı ise
if(adapter.powered) {
// bluetooth'u kapat
adapter.setPowered(false, function() {
console.log("Bluetooth powered off successfully.");
},
function(e) {
console.log("Failed to power off Bluetooth: " + e.message);
});
}
}
function showMe()
{
if (adapter.visible == false) {
//Cihaz'ı görünür yap
adapter.setVisible(true,
function() { console.log ('Device is visible to other devices for 3 minutes.'); },
function(e) { console.log ('Error: ' + e.message + '(' + e.name + ')'); });
}
else {
console.log("Device is already in discoverable mode.");
}
}
function hideMe()
{
if (adapter.visible) {
// Cihazı gizle
adapter.setVisible(false,
function() { console.log('Device is in-visible now.'); },
function(e) { console.log ('Error: ' + e.message + '(' + e.name + ')'); });
}
else {
console.log("Device is already in invisible mode.");
}
}
function startDiscovery() {
//Cihaz ara
var discoverDevicesSuccessCallback = {
onstarted: function() {
console.log ("Device discovery started...");
},
ondevicefound: function(device) {
console.log("Found device - name: " + device.name + ", Address: "+ device.address);
alert("Found device - name: " + device.name + ", Address: "+ device.address);
},
ondevicedisappeared: function(address) {
console.log("Device disappeared: " + address);
},
onfinished: function(devices) {
console.log("Found Devices");
for (var i = 0; i < devices.length; i++) {
console.log("Name: " + devices[i].name + ", Address: " + devices[i].address);
}
console.log("Total: " + devices.length);
}
};
// Starts searching for nearby devices, for about 10 sec.
adapter.discoverDevices(discoverDevicesSuccessCallback, function(e){
console.log ("Failed to search devices: " + e.message + "(" + e.name + ")");
});
}
function onSetPoweredError(e) {
console.log ("Could not turn on device, reason: " + e.message + "(" + e.name + ")");
}
adapter.setPowered(true, startDiscovery, onSetPoweredError);
</script>
</head>
<body>
<div data-role="page" >
<div data-role="header" data-position="fixed" >
<h1>Bluetooth</h1>
</div><!-- /header -->
<div data-role="content" >
<input type="button" onclick="powerOn()" width="60px" height="60px" value="Bluetooth Aç">
<input type="button" onclick="powerOff()()" width="60px" height="60px" value="Bluetooth Kapa">
<input type="button" onclick="showMe()" width="60px" height="60px" value="Bluetooth'u görünür yap">
<input type="button" onclick="hideMe()" width="60px" height="60px" value="Bluetooth'u gizle">
<input type="button" onclick="startDiscovery()" width="60px" height="60px" value="Bluetooth cihaz bul">
</div><!-- /content -->
<div data-role="footer" data-position="fixed" >
<h4>Footer content</h4>
</div><!-- /footer -->
</div><!-- /page -->
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment