Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simenkid/tri-state
A status manager
https://github.com/simenkid/tri-state
Last synced: about 1 month ago
JSON representation
A status manager
- Host: GitHub
- URL: https://github.com/simenkid/tri-state
- Owner: simenkid
- License: mit
- Created: 2016-08-04T05:56:45.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-01-24T03:15:08.000Z (almost 8 years ago)
- Last Synced: 2024-04-20T13:57:32.935Z (7 months ago)
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tri-state
A status manager```js
var exec = require('child_process').exec;// ...
// 假設 gpio 已經 export 出來, direction 也設定好了
// 以下程式碼沒有測試過, 寫個大概
// 它在 /app/model/model.js 裡面第 24 行附近so3.init('lightCtrl', 0, {
onOff: {
read: function (cb) {
exec('cat /sys/class/gpio/gpioXX/value', function (err, stdout, stderr) {
if (err) {
cb(err);
} else {
// stdout is result, I think its a string '0' or '1',
// we can use parseInt() to make it a number. 這個請自己確定一下囉
cb(null, parseInt(stdout);
}
});
},
write: function (val, cb) {
var valWritten = val ? 1 : 0;
exec('echo ' + valWritten + ' > /sys/class/gpio/gpioXX/value', function (err, stdout, stderr) {
if (err)
cb(err);
else
cb(null, val);
});
}
}
});
```