転倒検知センサー ISOKS

Created Date: 2015-11-27/ updated date: 2018-03-13
Owner & Collaborators
License
Summary

Memo

main.js 12/04

posted by Yamato-Ikeda on December 04, 2015
'use strict';

window.addEventListener('load', function (){
  function Sleep(millisec) {
    var start = new Date();
    while(new Date() - start < millisec);
  }
 
  navigator.requestI2CAccess().then(
    function(i2cAccess) {
      var port0 = i2cAccess.open(0);
      var port2 = i2cAccess.open(2);
     
      setInterval(function(){
        SRF02.read(port0,0x70).then(value0 => {
          SRF02.read(port2,0x70).then(value2 => {
           console.log(value0);
           console.log(value2);
          
           document.getElementById("debug0").innerHTML = "上段:"+value0;
           document.getElementById("debug2").innerHTML = "下段:"+value2;
            
           if(value2 <= 100){
            if(value0 > 100){
             document.getElementById("test").innerHTML = "転倒?";
            }else{
              document.getElementById("test").innerHTML = "立っている?";
            }
           }else{
              /*document.getElementById("test").innerHTML = "いない";*/
             if(value0 > 100){
             document.getElementById("test").innerHTML = "いない";
            }else{
              document.getElementById("test").innerHTML = "浮いてる?";
            }
           }
          
           if(value0 >= 1000000){
             if(value2 >= 1000000){
              document.getElementById("test").innerHTML = "上段下段エラー";
            }else{
              document.getElementById("test").innerHTML = "上段エラー";
             }
           }else if(value2 >= 1000000){
              document.getElementById("test").innerHTML = "下段エラー";
           }
          
           
          
           /*
           if(value0 <= 100){
             document.getElementById("debug0").innerHTML = "いる:"+value0;
           }else{
             document.getElementById("debug0").innerHTML = "いない:"+value0;
           }
           if(value2 <= 100){
             document.getElementById("debug2").innerHTML = "いる:"+value2;
           }else{
             document.getElementById("debug2").innerHTML = "いない:"+value2;
           }
           */
         });
        });
      },500);
      /*転倒検知プログラム作成中*/
    },
    function(error) {
      console.log(error.message);
    }
  );
}, false);

Comments