service | status |
---|---|
Build Status | |
Dependency Status | |
Code Covoiturage |
WebGPIO and WebI2C API polyfill (Chirimen dedicated)
- interface
bower install --save webgpio-polyfill
<script src="[bower_components path]/webgpio/dist/webgpio.min.js"></script>
chirimen CN1.2pin (pullup) connected
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>Test LED</title>
<script src="[bower_components path]/webgpio/dist/webgpio.min.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>
./js/main.js
'use strict';
window.addEventListener('load', function (){
var head = document.querySelector('#head');
navigator.requestGPIOAccess().then(
function(gpioAccess) {
console.log("GPIO ready!");
return gpioAccess;
}).then(gpio=>{
var port = gpio.ports.get(256);
var v = 0;
return port.export("out").then(()=>{
setInterval(function(){
v = v ? 0 : 1;
port.write(v);
head.style.color = v ? 'red' : 'green' ;
},500);
});
}).catch(error=>{
console.log("Failed to get GPIO access catch: " + error.message);
});
}, false);
bower install --save webgpio-polyfill
<script src="[bower_components path]/webgpio/dist/webi2c.min.js"></script>
SRF02(ultrasonic ranging module )
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>Test SRF02</title>
<script src="[bower_components path]/webgpio/dist/webi2c.min.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>
./js/main.js
'use strict';
window.addEventListener('load', function (){
var head = document.querySelector('#head');
// WebI2C Initialized
navigator.requestI2CAccess()
.then(i2cAccess=>i2cAccess.ports)
.then(ports=> ports.get(0))
.then(port=> port.open(0x70))
.then(I2CSlave=>{
setInterval(() => SRF02.read(I2CSlave, 0x70).then(value => {
console.log('value:', value);
head.innerHTML = value ? value : head.innerHTML;
}), 1000);
}).catch(e=> console.error('error', e));
// SRF02 Initialized
var SRF02 = {
sleep: (ms, generator)=> setTimeout(() => generator.next(), ms),
read: (I2CSlave, address)=> {
return new Promise((resolve, reject)=> {
var thread = (function* () {
I2CSlave.write8(0x00, 0x00);
yield SRF02.sleep(1, thread);
I2CSlave.write8(0x00, 0x51);
yield SRF02.sleep(70, thread);
// get distance value
Promise.all([
I2CSlave.read8(0x02, true),
I2CSlave.read8(0x03, true),
]).then(function(v){
var dist = ((v[0] << 8) + v[1]);
resolve(dist);
}).catch(reject);
})();
thread.next();
});
}
};
}, false);
In the following command, concatenated file is output to the ./dist
directory.
gulp build
# live watch test
gulp dev
# single run testing
gulp test
# live reload testing
gulp test:watch
# building webgpio and webi2c
gulp build
# open demo application
gulp demo
- Fork it!
- Create your feature branch: git checkout -b my-new-feature
- Commit your changes: git commit -am 'Add some feature'
- Push to the branch: git push origin my-new-feature
- Submit a pull request :D
Copyright (c) 2016 club-wot team and chirimen-oh team , other contributors
Licensed under the MIT License