From 29503c31af3d579aff95a732e68da08b286a8913 Mon Sep 17 00:00:00 2001 From: David Kebler Date: Thu, 12 Jan 2017 19:50:06 -0800 Subject: [PATCH] initial --- .gitignore | 2 ++ .jshglobals | 13 ++++++++++ .jshintrc | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ .npmignore | 4 +++ .travis.yml | 14 +++++++++++ index.js | 8 ++++++ lib/bus.js | 21 ++++++++++++++++ lib/device.js | 50 ++++++++++++++++++++++++++++++++++++ package.json | 36 ++++++++++++++++++++++++++ readme.md | 22 ++++++++++++++++ 10 files changed, 240 insertions(+) create mode 100644 .gitignore create mode 100644 .jshglobals create mode 100644 .jshintrc create mode 100644 .npmignore create mode 100644 .travis.yml create mode 100644 index.js create mode 100644 lib/bus.js create mode 100644 lib/device.js create mode 100644 package.json create mode 100644 readme.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e61051f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/node_modules/ +/coverage/ diff --git a/.jshglobals b/.jshglobals new file mode 100644 index 0000000..db4fe74 --- /dev/null +++ b/.jshglobals @@ -0,0 +1,13 @@ +{ +"globals": { + "Debug" : true, + /* MOCHA */ +"describe" : false, +"it" : false, +"xit" : false, +"before" : false, +"beforeEach" : false, +"after" : false, +"afterEach" : false + } +} diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..29bdf7a --- /dev/null +++ b/.jshintrc @@ -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 +} diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..f16fc41 --- /dev/null +++ b/.npmignore @@ -0,0 +1,4 @@ +tests/ +test/ +*.test.js +testing/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8ffd227 --- /dev/null +++ b/.travis.yml @@ -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" diff --git a/index.js b/index.js new file mode 100644 index 0000000..90ae21c --- /dev/null +++ b/index.js @@ -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); diff --git a/lib/bus.js b/lib/bus.js new file mode 100644 index 0000000..05a83e4 --- /dev/null +++ b/lib/bus.js @@ -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; diff --git a/lib/device.js b/lib/device.js new file mode 100644 index 0000000..2517975 --- /dev/null +++ b/lib/device.js @@ -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; diff --git a/package.json b/package.json new file mode 100644 index 0000000..052efb9 --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..5780e89 --- /dev/null +++ b/readme.md @@ -0,0 +1,22 @@ +# uCOMmandIt Template Package Repository + + +[![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