Skip to content

Instantly share code, notes, and snippets.

@NekoTashi
Last active October 21, 2015 07:46
Show Gist options
  • Select an option

  • Save NekoTashi/01770990ea413e933514 to your computer and use it in GitHub Desktop.

Select an option

Save NekoTashi/01770990ea413e933514 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<!-- compiled css output -->
<link href="css/ionic.app.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/style.css">
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<!--<script src="lib/ngCordova/dist/ng-cordova.js"></script>-->
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>
<script type="text/javascript" src="/plugins/cordova-plugin-ble-central/www/ble.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="starter">
<ion-pane ng-controller="MainCtrl">
<ion-header-bar class="bar-positive">
<h1 class="title">Eli-Batt</h1>
</ion-header-bar>
<ion-content>
<div class="card">
<img class="full-image" src="img/elibatt.png">
<div class="item item-text-wrap">
<ul class="list">
<ion-toggle ng-model="batterySwitch.checked" ng-change="changeState()" toggle-class="toggle-balanced">
<h1 class="toggle_status">Switch</h1>
</ion-toggle>
</ul>
</div>
<div class="item item-text-wrap">
<button class="button button-block button-positive" onclick="window.open('http://iongroup.cl/myelihome/mybatteries.php', '_blank', 'location=no'); return false;">Dashboard</button>
</div>
</div>
</ion-content>
<ion-footer-bar class="bar-stable">
<div class="tabs tabs-icon-top">
<a class="tab-item" ng-click="openSearch()">
<i class="icon ion-bluetooth"></i>
Search Battery
</a>
</div>
</ion-footer-bar>
<script id="baterias.html" type="text/ng-template">
<ion-modal-view>
<ion-header-bar class="bar-positive">
<h1 class="title">Battery</h1>
<div class="buttons">
<button class="button button-clear" ng-click="closeSearch()">Cerrar</button>
</div>
</ion-header-bar>
<ion-content class="content_page">
<ion-refresher pulling-text="Pull to refresh" on-refresh="searchBat()">
</ion-refresher>
<ion-list>
<ion-item ng-repeat="battery in batteries" ng-click="selectedBattery(battery)">
{{battery.name}}
</ion-item>
</ion-list>
</ion-content>
</ion-modal-view>
</script>
</ion-pane>
</body>
</html>
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
StatusBar.style(1);
}
});
})
.controller('MainCtrl', function($scope, $ionicModal) {
$ionicModal.fromTemplateUrl('baterias.html', {
scope: $scope
}).then(function(modal) {
$scope.modal = modal;
});
$scope.closeSearch = function() {
$scope.modal.hide();
ble.stopScan();
};
$scope.openSearch = function() {
$scope.modal.show();
$scope.searchBat();
};
$scope.batteries = [];
$scope.searchBat = function() {
if ($scope.battery !== null) {
ble.disconnect($scope.battery.id);
}
batteries = [];
ble.startScan([], function(device) {
if ("name" in device) {
batteries.push(device);
}
}, function() {
console.log('fuckbitches'); // TODO: Por cambiar
});
$scope.$broadcast('scroll.refreshComplete');
$scope.batteries = batteries;
};
$scope.battery = null;
$scope.selectedBattery = function(battery) {
$scope.battery = battery;
$scope.modal.hide();
ble.stopScan();
ble.connect($scope.battery.id, function(device) {
console.log(JSON.stringify(device));
$scope.battery = device; // TODO: Precaucion
}, function() {
console.log('Device disconnected');
});
};
$scope.batterySwitch = {
checked: true
};
$scope.changeState = function() {
if ($scope.batterySwitch.checked === true) {
var string = "R1\n";
// function (x) {return x.charCodeAt(0);}
// array = string.split('').map(s);
//var characteristic = "713D0003-503E-4C75-BA94-3148F18d941E";
//var service = "713D0000-503E-4C75-BA94-3148F18D941E";
ble.writeWithoutResponse(
$scope.battery.id,
$scope.battery.characteristics[1].service,
$scope.battery.characteristics[1].characteristic,
string,
function(){
console.log('Data Sended');
},
function() {
console.log('ERROR!');
}
);
} else {
// Battery OFF
//ble.write();
}
};
$scope.goBrowser = function() {
var options = {
location: 'no',
clearcache: 'no',
toolbar: 'no'
};
//$cordovaInAppBrowser.open('http://iongroup.cl/myelihome/mybatteries.php', '_blank', options)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment