Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Live example #19

Open
wants to merge 15 commits into
base: forCMN2015-1_B2GOS-20170301
Choose a base branch
from
Empty file modified LEDblink/js/webgpio.js
100644 → 100755
Empty file.
437 changes: 437 additions & 0 deletions LEDblink/js/webi2c.js

Large diffs are not rendered by default.

Empty file modified LEDblink/js/worker.gpio.js
100644 → 100755
Empty file.
134 changes: 134 additions & 0 deletions LEDblink/js/worker.i2c.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
(function(){/* istanbul ignore next */
if (!navigator.mozI2c) {
navigator.mozI2c = new Object();
navigator.mozI2c.open = () => void 0;
navigator.mozI2c.setDeviceAddress = (portNumber, slaveAddress) => {
console.log(`mozI2c.setDeviceAddress portNumber:${portNumber}, slaveAddress:${slaveAddress}`);
if ((portNumber !== 0) && (portNumber !== 2)) {
var err = { message:'portNumber error' };
throw err;
}

if ((slaveAddress > 0x7f) || (slaveAddress < 0)) {
var err = { message:'slaveAddress error' };
throw err;
}

var slaveDevice = { slaveAddress:slaveAddress };
return slaveDevice;
};

navigator.mozI2c.write = (portNumber, slaveAddress, registerNumber, value, aIsOctet) => {
console.log(`mozI2c.write portNumber:${portNumber}, slaveAddress:${slaveAddress}, registerNumber:${registerNumber}, value:${value}, aIsOctet:${aIsOctet}`);
if ((portNumber !== 0) && (portNumber !== 2)) {
var err = { message:'portNumber error' };
throw err;
}

if ((slaveAddress > 0x7f) || (slaveAddress < 0)) {
var err = { message:'slaveAddress error' };
throw err;
}

return 0;
};

navigator.mozI2c.read = (portNumber, slaveAddress, readRegistar, aIsOctet) => {
console.log(`mozI2c.read portNumber:${portNumber}, slaveAddress:${slaveAddress}, readRegistar:${readRegistar}, aIsOctet:${aIsOctet}`);
if ((portNumber !== 0) && (portNumber !== 2)) {
var err = { message:'portNumber error' };
throw err;
}

if ((slaveAddress > 0x7f) || (slaveAddress < 0)) {
var err = { message:'slaveAddress error' };
throw err;
}

return (1);
};

}

onmessage = i2cOnMessage;

function i2cOnMessage(e) {
var data = ab2jsonWorker(e.data);
switch (data.method) {
/********************************/
/** I2C */
/********************************/
case 'i2c.open':
navigator.mozI2c.open(data.portNumber);
break;
case 'i2c.setDeviceAddress':
try {
var slaveDevice = navigator.mozI2c.setDeviceAddress(data.portNumber, data.slaveAddress);
}catch (err) {
postMessage(json2abWorker({
method: `${data.method}.${data.portNumber}`,
portNumber: data.portNumber,
error: { name:err.name, message:err.message },
}));
break;
}

postMessage(json2abWorker({
method: `${data.method}.${data.portNumber}`,
portNumber: data.portNumber,
slaveDevice: slaveDevice,
}));
break;
case 'i2c.write':
try {
var value = navigator.mozI2c.write(data.portNumber, data.slaveAddress, data.registerNumber, data.value, data.aIsOctet);
}catch (err) {
postMessage(json2abWorker({
method: `${data.method}.${data.xid}.${data.portNumber}.${data.slaveAddress}.${data.registerNumber}`,
portNumber: data.portNumber,
error: { name:err.name, message:err.message },
}));
break;
}

postMessage(json2abWorker({
method: `${data.method}.${data.xid}.${data.portNumber}.${data.slaveAddress}.${data.registerNumber}`,
portNumber: data.portNumber,
value: value,
}));
break;
case 'i2c.read':
try {
var value = navigator.mozI2c.read(data.portNumber, data.slaveAddress, data.readRegistar, data.aIsOctet);
}catch (err) {
postMessage(json2abWorker({
method: `${data.method}.${data.xid}.${data.portNumber}.${data.slaveAddress}.${data.readRegistar}`,
portNumber: data.portNumber,
error: { name:err.name, message:err.message },
}));
break;
}

postMessage(json2abWorker({
method: `${data.method}.${data.xid}.${data.portNumber}.${data.slaveAddress}.${data.readRegistar}`,
portNumber: data.portNumber,
value: value,
}));
break;
default:
throw 'Unexpected case to worker method';
}
};

var ab2jsonWorker = (dataBuffer) => JSON.parse(String.fromCharCode.apply(null, new Uint16Array(dataBuffer)));
var json2abWorker = (jsonData) => {
var strJson = JSON.stringify(jsonData);
var buf = new ArrayBuffer(strJson.length * 2);
var uInt8Array = new Uint16Array(buf);
for (var i = 0, strLen = strJson.length; i < strLen; i++) {
uInt8Array[i] = strJson.charCodeAt(i);
}

return uInt8Array;
};
})()
15 changes: 15 additions & 0 deletions LEDblink/live.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>

<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<title>LED Blink</title>
<script src="./js/webgpio.js"></script>
<script src="./js/main.js"></script>
</head>

<body>
</body>

</html>
14 changes: 14 additions & 0 deletions button/live.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>

<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<title>button</title>
<script src="./js/webgpio.js"></script>
<script src="./js/main.js"></script>
</head>
<body>
<h2>push button example</h2>
</body>
</html>
18 changes: 18 additions & 0 deletions i2c-ADT7410/live.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>

<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<title>i2c-ADT7410</title>
<script src="./js/webi2c.js"></script>
<script src="./js/ADT7410.js"></script>
<script src="./js/main.js"></script>
</head>

<body>
<h3 id="head"
style="color:red; text-align: center; font-size: 90px">TEST</h3>
</body>

</html>
12 changes: 12 additions & 0 deletions i2c-ADT7410/live2.webapp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "live-i2c-ADT7410",
"description": "temperature sensor ADT7410 live example",
"launch_path": "/chirimen/live-examples/i2c-ADT7410/live.html",
"developer": {
"name": "CHIRIMEN Open Hardware",
"url": "https://github.com/chirimen-oh/"
},
"icons": {
"128": "/chirimen/live-examples/i2c-ADT7410/style/icons/sensor.png"
}
}
18 changes: 18 additions & 0 deletions i2c-PAJ7620-Gesture/live.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>

<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<title>i2c-PAJ7620 Gesture Sensor</title>
<script src="./js/webi2c.js"></script>
<script src="./js/paj7620.js"></script>
<script src="./js/main.js"></script>
</head>

<body>
<h3 id="head"
style="color:red; text-align: center; font-size: 90px">TEST</h3>
</body>

</html>
18 changes: 18 additions & 0 deletions i2c-PCA9685/live.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>

<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<title>i2c-PCA9685</title>
<script src="./js/webi2c.js"></script>
<script src="./js/PCA9685.js"></script>
<script src="./js/main.js"></script>
</head>

<body>
<h3 id="head"
style="color:red; text-align: center; font-size: 90px">TEST</h3>
</body>

</html>
18 changes: 18 additions & 0 deletions i2c-S11059/live.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>

<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<title>i2c-S11059</title>
<script src="./js/webi2c.js"></script>
<script src="./js/S11059.js"></script>
<script src="./js/main.js"></script>
</head>
<body>
<h1>S11059</h1>
<div id="red"></div>
<div id="green"></div>
<div id="blue"></div>
</body>
</html>
18 changes: 18 additions & 0 deletions i2c-SRF02/live.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>

<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<title>i2c-SRF02</title>
<script src="./js/webi2c.js"></script>
<script src="./js/SRF02.js"></script>
<script src="./js/main.js"></script>
</head>

<body>
<h3 id="head"
style="color:red; text-align: center; font-size: 90px">TEST</h3>
</body>

</html>
17 changes: 17 additions & 0 deletions i2c-VEML6070/live.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>

<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<title>i2c-VEML6070</title>
<script src="./js/webi2c.js"></script>
<script src="./js/VEML6070.js"></script>
<script src="./js/main.js"></script>
</head>

<body>
<h3 id="head" style="color:red; text-align: center; font-size: 90px">TEST</h3>
</body>

</html>
19 changes: 19 additions & 0 deletions i2c-grove-accelerometer/live.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!doctype html>

<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<title>Grove Digital Accelerometer sensor</title>
<script src="./js/webi2c.js"></script>
<script src="./js/i2c-grove-accelerometer.js"></script>
<script src="./js/main.js"></script>
</head>

<body>
<h3 id="ax" style="color:red; text-align: center; font-size: 90px">ax</h3>
<h3 id="ay" style="color:red; text-align: center; font-size: 90px">ay</h3>
<h3 id="az" style="color:red; text-align: center; font-size: 90px">az</h3>
</body>

</html>
12 changes: 12 additions & 0 deletions i2c-grove-accelerometer/live.webapp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "i2c-grove-accelerometer",
"description": "Grove Digital Accelerometer sensor live example",
"launch_path": "/chirimen/live-examples/i2c-grove-accelerometer/live.html",
"developer": {
"name": "CHIRIMEN Open Hardware",
"url": "https://github.com/chirimen-oh/"
},
"icons": {
"128": "/chirimen/live-examples/i2c-grove-accelerometer/style/icons/sensor.png"
}
}
18 changes: 18 additions & 0 deletions i2c-grove-light/live.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>

<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<title>iGrove Digital Light sensor</title>
<script src="./js/webi2c.js"></script>
<script src="./js/i2c-grove-light.js"></script>
<script src="./js/main.js"></script>
</head>

<body>
<h3 id="head"
style="color:red; text-align: center; font-size: 90px">TEST</h3>
</body>

</html>
18 changes: 18 additions & 0 deletions i2c-grove-oledDisplay/live.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>

<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<title>oled-display</title>
<script src="./js/webi2c.js"></script>
<script src="./js/oledDisplay.js"></script>
<script src="./js/main.js"></script>
</head>

<body>
<h3 id="head"
style="color:red; text-align: center; font-size: 90px">TEST</h3>
</body>

</html>
21 changes: 21 additions & 0 deletions i2c-multi-sensors/live.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!doctype html>

<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<title>i2c-multi</title>
<script src="./js/webi2c.js"></script>
<script src="./js/SRF02.js"></script>
<script src="./js/ADT7410.js"></script>
<script src="./js/main.js"></script>
</head>

<body>
<h3 id="head1"
style="color:red; text-align: center; font-size: 90px">TEST</h3>
<h3 id="head2"
style="color:red; text-align: center; font-size: 90px">TEST</h3>
</body>

</html>
Loading