main.js 12/04
'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);
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);