master
David Kebler 2017-01-12 19:50:06 -08:00
commit 29503c31af
10 changed files with 240 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/node_modules/
/coverage/

13
.jshglobals Normal file
View File

@ -0,0 +1,13 @@
{
"globals": {
"Debug" : true,
/* MOCHA */
"describe" : false,
"it" : false,
"xit" : false,
"before" : false,
"beforeEach" : false,
"after" : false,
"afterEach" : false
}
}

70
.jshintrc Normal file
View File

@ -0,0 +1,70 @@
{
// https://gist.github.com/connor/1597131
// Globals - import repo spectific globals
"extends": "./.jshglobals",
// Settings
"passfail" : false, // Stop on first error.
"maxerr" : 100, // Maximum error before stopping.
// Predefined globals whom JSHint will ignore.
"browser" : true, // Standard browser globals e.g. `window`, `document`.
"node" : true,
"rhino" : false,
"couch" : false,
"wsh" : true, // Windows Scripting Host.
"jquery" : true,
"prototypejs" : false,
"mootools" : false,
"dojo" : false,
// Development.
"debug" : false, // Allow debugger statements e.g. browser breakpoints.
"devel" : true, // Allow developments statements e.g. `console.log();`.
// ECMAScript
"esversion" : 6, //use this in new version of jshint
"strict" : false, // Require `use strict` pragma in every file.
"globalstrict" : false, // Allow global "use strict" (also enables 'strict').
// The Good Parts.
"asi" : true, // Tolerate Automatic Semicolon Insertion (no semicolons).
"laxbreak" : true, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
"bitwise" : true, // Allow bitwise operators (&, |, ^, etc.).
"boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
"curly" : true, // Require {} for every new block or scope.
"eqeqeq" : true, // Require triple equals i.e. `===`.
"eqnull" : false, // Tolerate use of `== null`.
"evil" : false, // Tolerate use of `eval`.
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
"forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`.
"immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
"latedef" : false, // Prohipit variable use before definition.
"loopfunc" : false, // Allow functions to be defined within loops.
"noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
"regexp" : true, // Prohibit `.` and `[^...]` in regular expressions.
"regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`.
"scripturl" : true, // Tolerate script-targeted URLs.
"shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
"supernew" : false, // Tolerate `new function () { ... };` and `new Object;`.
"undef" : true, // Require all non-global variables be declared before they are used.
// Personal styling preferences.
"newcap" : false, // Require capitalization of all constructor functions e.g. `new F()`.
"noempty" : true, // Prohibit use of empty blocks.
"nonew" : true, // Prohibit use of constructors for side-effects.
"nomen" : true, // Prohibit use of initial or trailing underbars in names.
"onevar" : false, // Allow only one `var` statement per function.
"plusplus" : false, // Prohibit use of `++` & `--`.
"sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
"trailing" : true, // Prohibit trailing whitespaces.
"white" : false, // Check against strict whitespace and indentation rules.
"indent" : 2 // Specify indentation spacing
}

4
.npmignore Normal file
View File

@ -0,0 +1,4 @@
tests/
test/
*.test.js
testing/

14
.travis.yml Normal file
View File

@ -0,0 +1,14 @@
language: node_js
node_js:
- '4.0'
- '5.0'
- '6.0'
- 'node'
sudo: false
script: npm test
after_success:
- bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"

8
index.js Normal file
View File

@ -0,0 +1,8 @@
let opts = {
dirname: __dirname + '/lib',
// http://stackoverflow.com/questions/2078915/a-regular-expression-to-exclude-a-word-string
filter: /^(?!index)([^\.].*)\.js?$/,
recursive: false,
merge: true // remove or comment to have each file in /lib be a prop/key in library...see node-require-all
}
module.exports = require('require-all')(opts);

21
lib/bus.js Normal file
View File

@ -0,0 +1,21 @@
'use strict'
const i2c = require('i2c-bus'),
pA = require('bluebird').promisifyAll,
PQ = require('promisqueue')
class Bus {
constructor(busnum) {
this.methods = pA(i2c.open(busnum,()=>{}),{suffix: "_p" }) //,multiArgs: true})
this.q = new PQ({ limit: 1})
}
scan(){ return this.bus.scan_p()}
close(){ return this.bus.close_p()}
qAdd(job){this.q.add(() => job)}
} // end of Bus Class
module.exports = Bus;

50
lib/device.js Normal file
View File

@ -0,0 +1,50 @@
'use strict'
// **********************************
class Device {
// bus is i2c-bus bus object
constructor(bus, address, opts) {
this.bus = bus.methods // artifact of adapting ic2-bus to class format
this.address = address
if (opts){
this.id = opts.id // must be unique within a bus
this.desc = opts.desc
}
}
readRaw(length,buffer) {
return this.bus.i2cRead_p(this.address, length, buffer)
}
writeRaw(length,buffer) {
return this.bus.i2cWrite_p(this.address, length, buffer)
}
read(cmd) {
return this.bus.readByte_p(this.address, cmd)
}
write(cmd, byte) {
return this.bus.writeByte_p(this.address, cmd, byte)
}
read2(cmd) {
return this.bus.readWord_p(this.address, cmd)
}
write2(cmd, bytes) {
return this.bus.writeWord_p(this.address, cmd, bytes)
}
// command with more than two bytes following
readBytes(){}
writeBytes(){}
}
module.exports = Device;

36
package.json Normal file
View File

@ -0,0 +1,36 @@
{
"name": "uci-template-changeme",
"version": "0.0.1",
"description": "A template for a starting a uci package",
"main": "index.js",
"scripts": {
"testw": "./node_modules/.bin/mocha --reporter list --recursive --watch",
"test": "istanbul cover ./node_modules/.bin/_mocha test/ --report lcovonly -- -R spec --recursive && codecov || true"
},
"author": "David Kebler",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/uCOMmandIt/uci-pkg-template.git"
},
"keywords": [
"node.js",
"communication",
"serial",
"utilities",
"helpers"
],
"bugs": {
"url": "https://github.com/uCOMmandIt/utilities/issues"
},
"homepage": "https://github.com/uCOMmandIt/utilities#readme",
"dependencies": {
"require-all": "git+https://github.com/dkebler/node-require-all.git#merge"
},
"devDependencies": {
"chai": "^3.5.0",
"codecov": "^1.0.1",
"istanbul": "^0.4.5",
"mocha": "^3.2.0"
}
}

22
readme.md Normal file
View File

@ -0,0 +1,22 @@
# uCOMmandIt Template Package Repository
<!-- find and replace the package name to match -->
[![Build Status](https://img.shields.io/travis/uCOMmandIt/uci-pkg-template.svg?branch=master)](https://travis-ci.org/uCOMmandIt/uci-pkg-template)
[![Inline docs](http://inch-ci.org/github/uCOMmandIt/uci-pkg-template.svg?branch=master)](http://inch-ci.org/github/uCOMmandIt/uci-pkg-template)
[![Dependencies](https://img.shields.io/david/uCOMmandIt/uci-pkg-template.svg)](https://david-dm.org/uCOMmandIt/uci-pkg-template)
[![devDependencies](https://img.shields.io/david/dev/uCOMmandIt/uci-pkg-template.svg)](https://david-dm.org/uCOMmandIt/uci-pkg-template?type=dev)
[![codecov](https://img.shields.io/codecov/c/github/uCOMmandIt/uci-pkg-template/master.svg)](https://codecov.io/gh/uCOMmandIt/uci-pkg-template)
Clone this to get a quick start on a new uci package. It has all the testing ready to go with Travis-CI and code coverage. All the readme badges are included as well
Clone it for as a starting place for your own package!
You'll need codecov and travis-ci accounts
##Steps
1. Clone repo
2. Edit package.json
3. Edit badge urls changing to your repo path
4. Run npm install
5. Open a github