main.js 12/11(最終)
'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);
var alertCount = 0; /*転倒検知用カウント*/
setInterval(function(){
SRF02.read(port0,0x70).then(value0 => {
SRF02.read(port2,0x70).then(value2 => {
navigator.setGpioPort(198,"out").then( portl=>{
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 = "転倒?";
alertCount += 1; /*センサーの数値が7回連続でこの条件に当てはまった場合*/
if(alertCount >= 7){/*転倒とみなしアクションを起こす*/
portl.write(1);
alert("アラート");
portl.write(0);
alertCount = 0;
}
}else{
document.getElementById("test").innerHTML = "立っている?";
alertCount = 0;
}
}else{
if(value0 > 100){
document.getElementById("test").innerHTML = "いない";
alertCount = 0;
}else{
document.getElementById("test").innerHTML = "浮いてる?";
alertCount = 0;
}
}
if(value0 >= 1000000){
if(value2 >= 1000000){
document.getElementById("test").innerHTML = "上段下段エラー";
portl.write(1);
}else{
document.getElementById("test").innerHTML = "上段エラー";
portl.write(1);
}
}else if(value2 >= 1000000){
document.getElementById("test").innerHTML = "下段エラー";
portl.write(1);
}else{
portl.write(0);
}
});
});
});
},500);
},
function(error) {
console.log(error.message);
}
);
}, false);
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);
var alertCount = 0; /*転倒検知用カウント*/
setInterval(function(){
SRF02.read(port0,0x70).then(value0 => {
SRF02.read(port2,0x70).then(value2 => {
navigator.setGpioPort(198,"out").then( portl=>{
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 = "転倒?";
alertCount += 1; /*センサーの数値が7回連続でこの条件に当てはまった場合*/
if(alertCount >= 7){/*転倒とみなしアクションを起こす*/
portl.write(1);
alert("アラート");
portl.write(0);
alertCount = 0;
}
}else{
document.getElementById("test").innerHTML = "立っている?";
alertCount = 0;
}
}else{
if(value0 > 100){
document.getElementById("test").innerHTML = "いない";
alertCount = 0;
}else{
document.getElementById("test").innerHTML = "浮いてる?";
alertCount = 0;
}
}
if(value0 >= 1000000){
if(value2 >= 1000000){
document.getElementById("test").innerHTML = "上段下段エラー";
portl.write(1);
}else{
document.getElementById("test").innerHTML = "上段エラー";
portl.write(1);
}
}else if(value2 >= 1000000){
document.getElementById("test").innerHTML = "下段エラー";
portl.write(1);
}else{
portl.write(0);
}
});
});
});
},500);
},
function(error) {
console.log(error.message);
}
);
}, false);