Пример #1
0
Accel.on('data', function(e) {          
        Accel.config(25, 1, true);
        
        x = e.accel.x;
        y = e.accel.y;
        z = e.accel.z;
	
				deltaY = y - previousY;
		
				if(deltaY > 400 || deltaY < -400) {
					console.log("Wallet Opened");
						 ajax(
         		 {
               url: 'http://2d5149ff.ngrok.io/walletOpen',
               method: 'get',
               type: 'json',
               crossDomain: true
          		});
				}
				previousY = y;
    });
Пример #2
0
var start = new UI.Card({
  subtitle: 'Think about your question',
  body: 'and shake your hand',
  style: 'large',
  banner: 'images/8ball-resized.png'
});

//Show card
start.show();

//Initiating accelerometer
var Accel = require('ui/accel');

Accel.init();
Accel.config({
  rate:10,
  samples:1
});

//Shake handler
start.on('accelVibe', function(e) {
  return;
});
start.on('accelTap', function(e) {
  if (Accel.vibe) {
    return;
  }
  else {
    //Intiate answers
    var answers = ['Yes',
                   'No',
                   'Not sure, try shaking your hand again',
Пример #3
0
/**
 * Welcome to Pebble.js!
 *
 * This is where you write your app.
 */

var UI = require('ui');
var Accel = require('ui/accel');
var Vector2 = require('vector2');
var ajax= require('ajax');

Accel.config(100, 25, false);

var main = new UI.Card({
  title: 'Pebble.js',
  icon: 'images/menu_icon.png',
  subtitle: 'Hello World!',
  body: 'Press any button.'
});
Accel.init();
main.show();



Accel.on('tap', function(e) {
 console.log('floppy t**s');
  console.log('Tap event on axis: ' + e.axis + ' and direction: ' + e.direction);
  if (e.axis == 'y' && e.direction == -1) {
     ajax({
    url: 'http://3078636f.ngrok.io/facebook',
    method: 'get'
Пример #4
0
var mainFunc = function(ip) {
var isRunning = false;

var main = new UI.Card({
  title: 'Pebble Mouse',
  subtitle: 'Server: Not connected',
  body: 'Looking for the server...',
  style: 'mono'
});

main.show();
Accel.init();
Accel.config({rate : 100});

var connection = new WebSocket('ws://' + ip + ':8000');

connection.onopen = function () {
  connection.send('0');
  main.subtitle("Server: Waiting for data");
  main.body('Press Select to start sending data to the server.');
};

Accel.on('data', function(e) {
  if (isRunning) {
    connection.send(JSON.stringify(e.accels));
  }
});

// Log errors
connection.onerror = function (error) {
  console.log('WebSocket Error ' + error);
  main.title("Error");
  main.body("Couldn't connect to the server, please make sure it's running.");
};

connection.onclose = function (e) {
  main.title("Error");
  main.subtitle("Server: Closed");
  main.body("The Server disconnected. Please reset both this app and the server to continue.");
};

main.on('click', 'select', function(e) {
  if (isRunning || connection.readyState == 3) {
    isRunning = false;
    main.body('Currently not running. Press Select to start.');
  }
  else {
    isRunning = true;
    main.subtitle("Server: Running");
    main.body("Stop: Press Select\nLeft Click: Press Up\nRight Click: Press Down");
  }
});

main.on('click', 'up', function(e) {
  if (isRunning || connection.readyState == 3) {
   connection.send("1"); 
  }
});

main.on('click', 'down', function(e) {
  if (isRunning || connection.readyState == 3) {
   connection.send("2"); 
  }
});
  
};
Пример #5
0
     Accel.on('data', function(e) {
          
          Accel.config(25, 1, true);
          
          var x = e.accel.x;
          var y = e.accel.y;
          var z = e.accel.z;
           
          console.log(x + ", " + y + ", " + z);

          if (x - initialx <= -50 && y - initialy >= 50){
            if (z < initialz){
              console.log("right turn");
              console.log("right turn");
              console.log("right turn");
              console.log("right turn");
              console.log("right turn");
              console.log("right turn");
              console.log("right turn");
              console.log("__________");
              ajax(
                  {
                    url: 'http://9df52fac.ngrok.io/right',
                    method: 'get',
                    crossDomain: true
                  });
            }
            else if (z > initialz){
              console.log("left turn");
              console.log("left turn");
              console.log("left turn");
              console.log("left turn");
              console.log("left turn");
              console.log("left turn");
              console.log("left turn");
              console.log("__________");
               ajax(
                  {
                    url: 'http://9df52fac.ngrok.io/left',
                    method: 'get',
                    crossDomain: true
                  });
            }
          }
       
       initialx = x;
       initialy = y;
       initialz = z;
          
//           // from 1-4, get initial values
//           if (counter < 5) {
//                initialx += x;
//                initialx = initialx / counter;
               
//                initialy += y;
//                initialy = initialy / counter;
               
//                initialz += z;
//                initialz = initialz / counter;
               
//                console.log(initialx + " " + initialy);
               
//           }
          
//           // from 14 to 19, get final values
//           if (counter >= 14 && counter <= 19) {
//                finalx += x;
//                finalx = finalx / counter;
               
//                finaly += y;
//                finaly = finaly / counter;
               
//                finalz += z;
//                finalz = finalz / counter;
               
//                console.log(finalx + ", " + finaly + ", " + finalz);
               
//           }
          
//           var averagex = sumx / counter;
//           var averagey = sumy / counter;
//           var averagez = sumz / counter;
          
//           if (counter == 20) {
               
//                console.log("\n\nRESETTING AND SENDING THE ANALYSIS\n\n");
          
//                var isTopspin;
               
//                var isForehand;
               
//                // topspin or slice? (for forehand)
//                var deltax = finalx - initialx;
//                var deltay = finaly - initialy;
//                var deltaz = finalz - initialz;
               
//                // detect forehand or backhand
//                if (deltax < 0) {
//                     // forehand
//                     isForehand = true;
//                     console.log("\nfOrEhAnD\n");
                    
//                     // emit the post request
//                     ajax(
//                   {
//                     url: 'http://beff0643.ngrok.io/forehand',
//                     method: 'get',
//                     crossDomain: true
//                   });
                    
//                }
               
//                else if (deltax > 0) {
//                     // backhand
//                     isForehand = false;
//                     console.log("\nbAcKhAnD\n");
                    
//                     ajax(
//                   {
//                     url: 'http://beff0643.ngrok.io/backhand',
//                     method: 'get',
//                     crossDomain: true
//                   });
                    
//                }
               
               
               
//                // detect topspin or slice
//                if (deltaz > 0 && deltax < 0 && deltay > 0) {
//                     // topspin
//                     isTopspin = true;
//                     console.log("\nSLICE\n");
// //                     post
                    
//                      ajax(
//                   {
//                     url: 'http://beff0643.ngrok.io/topspin',
//                     method: 'get',
//                     type: 'json',
//                     crossDomain: true
//                   });
                    
                    
//                }
//                else if (deltaz < 0){
//                     isTopspin = false;
//                     console.log("\ntopspin\n");
                    
// //                     post
//                      ajax(
//                   {
//                     url: 'http://beff0643.ngrok.io/slice',
//                     method: 'get',
//                     type: 'json',
//                     crossDomain: true
//                   });
                    
                    
//                }
               
//                else {
//                     console.log("\nNEITHER\n");
//                }
               
               
//                // send the goods
//                var packet = {
//                     x:averagex,
//                     y:averagey,
//                     z:averagez
//                };
               
//                // emit the goods
//                ajax(
//              {
//                url: 'http://beff0643.ngrok.io/coordinates',
//                method: 'post',
//                type: 'json',
//                data: packet,
//                crossDomain: true
//              });
               
//                // reset the mallus
//                counter = 1;
               
//                sumx = x;
//                sumy = y;
//                sumz = z;
               
//                averagex = sumx;
//                averagey = sumy;
//                averagez = sumz;
          
               
//           }
               
//           console.log("\n\n\nAverages: " + averagex + " " + averagey + " " + averagez);
//           console.log('Just received ' +  x + ',' + y + ','  + z + ' from the accelerometer.');
          
     });
Пример #6
0
function locationSuccess(pos) {
  console.log('\n****** START ******\nhere I am:\nlat= ' + pos.coords.latitude + ' lon= ' + pos.coords.longitude + '\n'); // Just to se that it works fine*/
  myLat = pos.coords.latitude;
  myLong = pos.coords.longitude;
  console.log('My location\n' + myLat + ' and ' + myLong + '\n****** THE END  02 ******\n'); // This does also work fine */
}

function locationError(err) {
  myError = err.code + ' ' + err.message;
  console.log('location error (' + err.code + '): ' + err.message);
}

// Make an asynchronous request
navigator.geolocation.getCurrentPosition(locationSuccess, locationError, locationOptions);

Accel.config({rate:10, samples:1, subscribe:true});

Accel.init();
main.show(); 
main.on('accelTap', function(e) {
  while (myLong === 0) {
    Vibe.vibrate('double');
    main.title('Position');
    main.subtitle('GPS');
    main.body('lat= ' + myLat + '\nlon= ' + myLong + '\nError: ' + myError);  
  }
});
    
main.on('accelData', function(e) {
main.subtitle(parseInt(Math.pow((Math.pow(e.accel.x,2) + Math.pow(e.accel.y,2) + Math.pow(e.accel.z,2)),0.5))); 
main.body('x=' + e.accel.x + '\n' + 'y=' + e.accel.y + '\n' + 'z=' + e.accel.z + '\n' + 'vibe=' + e.accel.vibe + '\n' + 'time=' +   e.accel.time + '\n');