@ -0,0 +1,132 @@ | |||
# Please take extra care not to add rules that will make tracked files ignored. | |||
# To test that, run `git ls-files -i --exclude-standard`. | |||
# To check why a specific file is ignored, run `git check-ignore -v <filepath>`. | |||
# === Rule for dotfiles === | |||
# Ignore all dotfiles. | |||
.* | |||
# Exclude specific dotfiles that we want to track. | |||
!deps/**/.* | |||
!test/fixtures/**/.* | |||
!.clang-format | |||
!.editorconfig | |||
!.eslintignore | |||
!.eslintrc.js | |||
!.flake8 | |||
!.gitattributes | |||
!.github | |||
!.gitignore | |||
!.gitkeep | |||
!.mailmap | |||
!.nycrc | |||
!.travis.yml | |||
!.eslintrc.yaml | |||
!.cpplint | |||
# === Rules for root dir === | |||
/core | |||
/vgcore.* | |||
/v8*.log | |||
/perf.data | |||
/perf.data.old | |||
/tags | |||
/doc/api.xml | |||
/node | |||
/node_g | |||
/*.exe | |||
/*.swp | |||
/out | |||
/*.txt | |||
# === Rules for artifacts of `./configure` === | |||
/icu_config.gypi | |||
/config.gypi | |||
/config.status | |||
/config_fips.gypi | |||
# === Rules for MSVS artifacts === | |||
/Debug | |||
/Release | |||
*.sln | |||
*.suo | |||
*.vcxproj* | |||
UpgradeLog*.XML | |||
_UpgradeReport_Files/ | |||
*.sdf | |||
*.opensdf | |||
*.VC.* | |||
*.wixobj | |||
/tools/msvs/genfiles/ | |||
/npm.wxs | |||
# Exclude MSVS files used for .msi file generation | |||
!tools/msvs/msi/custom_actions.vcxproj | |||
!tools/msvs/msi/nodemsi.sln | |||
# === Rules for GYP artifacts === | |||
*-nodegyp* | |||
/gyp-*-tool | |||
/test/addons/??_*/ | |||
/*.mk | |||
# === Rules for other build artifacts === | |||
/email.md | |||
/deps/v8-* | |||
/deps/icu | |||
/deps/icu*.zip | |||
/deps/icu*.tgz | |||
/deps/icu-tmp | |||
./node_modules | |||
/android-toolchain/ | |||
# generated by gyp on Windows | |||
/deps/openssl/openssl.props | |||
/deps/openssl/openssl.targets | |||
/deps/openssl/openssl.xml | |||
# generated by gyp on android | |||
/*.target.mk | |||
/*.host.mk | |||
/deps/openssl/openssl.target.mk | |||
/deps/zlib/zlib.target.mk | |||
# === Rules for release artifacts === | |||
/*.tar.* | |||
/*.pkg | |||
/SHASUMS*.txt* | |||
# === Rules for `node_modules` === | |||
!**/node_modules/** | |||
/node_modules | |||
/tools/doc/node_modules | |||
/tools/clang-format/node_modules | |||
# === Rules for test artifacts === | |||
/*.tap | |||
/*.xml | |||
/node_trace.*.log | |||
# coverage related | |||
/gcovr | |||
/build | |||
# === Rules for XCode artifacts === | |||
*.xcodeproj | |||
*.xcworkspace | |||
*.pbxproj | |||
# === Rules for files in `/deps` === | |||
# Exclude all files in the vendored `npm`. | |||
!/deps/npm/node_modules | |||
# These are not needed and causes issues for distro packagers. | |||
/deps/npm/node_modules/.bin/ | |||
# Respect V8's .gitignore | |||
!deps/v8/** | |||
# Ignore the libuv book and GitHub templates | |||
/deps/uv/.github/ | |||
/deps/uv/docs/code/ | |||
/deps/uv/docs/src/guide/ | |||
# Ignore dependencies fetched by deps/v8/tools/node/fetch_deps.py | |||
/deps/.cipd | |||
# === Global Rules === | |||
# Keep last to avoid being excluded | |||
*.pyc | |||
__pycache__ | |||
.DS_Store |
@ -0,0 +1,39 @@ | |||
var i2cBus = require("i2c-bus"); | |||
var Pca9685Driver = require("pca9685").Pca9685Driver; | |||
var options = { | |||
i2c: i2cBus.openSync(1), | |||
address: 0x70, | |||
frequency: 50, | |||
debug: false | |||
}; | |||
var ledConfig = [ | |||
{r: 0, g: 1, b: 2} | |||
] | |||
class LED { | |||
constructor(){ | |||
this.pwm = new Pca9685Driver(options, function(err) { | |||
if (err) { | |||
console.error("Error initializing PCA9685"); | |||
process.exit(-1); | |||
} | |||
console.log("Initialization done"); | |||
}); | |||
} | |||
setColor(stripe, r, g, b){ | |||
this.pwm.setPulseRange(ledConfig[stripe].r,0,r*16) | |||
this.pwm.setPulseRange(ledConfig[stripe].g,0,g*16) | |||
this.pwm.setPulseRange(ledConfig[stripe].b,0,b*16) | |||
} | |||
} | |||
module.exports = new LED() |
@ -0,0 +1,67 @@ | |||
var express = require('express'); | |||
var bodyParser = require('body-parser') | |||
var app = express(); | |||
var cors = require('cors') | |||
var i2cBus = require("i2c-bus"); | |||
var Pca9685Driver = require("pca9685").Pca9685Driver; | |||
var LED = require("./LED.js"); | |||
var state = { | |||
"led": [ | |||
{ "color": {"r": 255, "g": 255, "b": 255}, | |||
"position": { | |||
"description":"front left", | |||
"block":1, | |||
"direction": "left" | |||
}, | |||
"channels": { | |||
"type": "rgb" | |||
"device": 0, | |||
"r": 0, | |||
"g": 1, | |||
"b": 2 | |||
} | |||
}] | |||
} | |||
// parse application/x-www-form-urlencoded | |||
app.use(bodyParser.urlencoded({ extended: false })) | |||
// parse application/json | |||
app.use(bodyParser.json()) | |||
app.use(cors()) | |||
app.get('/get', (req, res) => { | |||
if(req.query.led === undefined){ | |||
res.send(state.led) | |||
} else if(req.query.led >= state.led.length){ | |||
res.sendStatus(400) | |||
}else{ | |||
res.send(state.led[req.query.led]) | |||
} | |||
}) | |||
app.post('/set', (req, res) => { | |||
let id = req.body.id | |||
state.led[id].color.r = req.body.r; | |||
state.led[id].color.g = req.body.g; | |||
state.led[id].color.b = req.body.b; | |||
console.log(state.led) | |||
LED.setColor(req.body.id,state.led[0].r,state.led[0].g,state.led[0].b); | |||
res.sendStatus(200) | |||
}) | |||
app.post('setAll', (req, res) => { | |||
} | |||
app.listen(3002, ()=>{ | |||
console.log('Server running on port 3002') | |||
}) | |||
@ -0,0 +1,25 @@ | |||
{ | |||
"name": "ledpi", | |||
"version": "1.0.0", | |||
"description": "", | |||
"main": "index.js", | |||
"watch": { | |||
"start": "index.js" | |||
}, | |||
"scripts": { | |||
"start": "node .", | |||
"test": "echo \"Error: no test specified\" && exit 1", | |||
"watch": "npm-watch" | |||
}, | |||
"author": "", | |||
"license": "ISC", | |||
"dependencies": { | |||
"body-parser": "^1.18.3", | |||
"cors": "^2.8.5", | |||
"express": "^4.16.4", | |||
"i2c-bus": "^4.0.10", | |||
"johnny-five": "^1.1.0", | |||
"npm-watch": "^0.6.0", | |||
"pca9685": "^4.0.3" | |||
} | |||
} |
@ -0,0 +1,30 @@ | |||
var i2cBus = require("i2c-bus"); | |||
var Pca9685Driver = require("pca9685").Pca9685Driver; | |||
var options = { | |||
i2c: i2cBus.openSync(1), | |||
address: 0x70, | |||
frequency: 50, | |||
debug: false | |||
}; | |||
class PWM { | |||
var pwm; | |||
constructor(){ | |||
pwm = new Pca9685Driver(options, function(err) { | |||
if (err) { | |||
console.error("Error initializing PCA9685"); | |||
process.exit(-1); | |||
} | |||
console.log("Initialization done"); | |||
}); | |||
} | |||
} | |||
module.exports = new PWM() |
@ -0,0 +1,18 @@ | |||
var i2cBus = require("i2c-bus"); | |||
var Pca9685Driver = require("pca9685").Pca9685Driver; | |||
var options = { | |||
i2c: i2cBus.openSync(1), | |||
address: 0x70, | |||
frequency: 50, | |||
debug: false | |||
}; | |||
pwm = new Pca9685Driver(options, function(err) { | |||
if (err) { | |||
console.error("Error initializing PCA9685"); | |||
process.exit(-1); | |||
} | |||
console.log("Initialization done"); | |||
}); | |||
module.exports.pwm |