├── .gitignore ├── .npmignore ├── .npmrc ├── CHANGELOG.md ├── LICENSE ├── README.md ├── declarations └── index.d.ts ├── dist ├── index.js └── index.js.map ├── package.json ├── src └── index.ts ├── tsconfig.json └── tslint.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | *.pid.lock 11 | 12 | # Directory for instrumented libs generated by jscoverage/JSCover 13 | lib-cov 14 | 15 | # Coverage directory used by tools like istanbul 16 | coverage 17 | 18 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 19 | .grunt 20 | 21 | # node-waf configuration 22 | .lock-wscript 23 | 24 | # Compiled binary addons (http://nodejs.org/api/addons.html) 25 | build/ 26 | 27 | # Dependency directories 28 | node_modules 29 | 30 | # Optional npm cache directory 31 | .npm 32 | 33 | # Optional REPL history 34 | .node_repl_history 35 | 36 | # Output of 'npm pack' 37 | *.tgz 38 | 39 | # IDE 40 | .vscode 41 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | *.pid.lock 11 | 12 | # Directory for instrumented libs generated by jscoverage/JSCover 13 | lib-cov 14 | 15 | # Coverage directory used by tools like istanbul 16 | coverage 17 | 18 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 19 | .grunt 20 | 21 | # node-waf configuration 22 | .lock-wscript 23 | 24 | # Compiled binary addons (http://nodejs.org/api/addons.html) 25 | build/ 26 | 27 | # Dependency directories 28 | node_modules 29 | 30 | # Optional npm cache directory 31 | .npm 32 | 33 | # Optional REPL history 34 | .node_repl_history 35 | 36 | # Output of 'npm pack' 37 | *.tgz 38 | 39 | # IDE 40 | .vscode 41 | 42 | # package specific 43 | src/ 44 | test/ 45 | tsconfig.json 46 | tslint.json -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 6.0.1 (2019-2-20) 2 | 3 | - Brought in renamed j5-io-types 4 | 5 | ## 6.0.0 (2019-1-10) 6 | 7 | - BREAKING CHANGE: dropped support for Node.js < 6 8 | - Removed the ARM CPU requirement for unit test infrastructure reasons. Don't run this on a not-Raspberry Pi unless you know what you're doing. Doing so is _not_ supported. 9 | 10 | ## 5.3.0 (2019-1-9) 11 | 12 | - Added `getPinNumber` method to the base module to conform to Core IO Types refactor 13 | 14 | ## 5.2.2 (2019-1-8) 15 | 16 | - Ok, fixed those bugs mentioned in 5.2.1 _for realz_ this time. 17 | 18 | ## 5.2.1 (2019-1-8) 19 | 20 | - Fixed a bug where destroying peripherals with more than one pin would cause the `destroy` method to be called more than once. 21 | - Fixed a bug where destroyed peripherals weren't removed from the registry of active pins. 22 | 23 | ## 5.2.0 (2019-1-8) 24 | 25 | - Added `getActivePeripheral`, `setActivePeripheral`, and `getActivePeripherals` methods to the base module. This functionality existed in raspi-peripheral already and was moved here. 26 | 27 | ## 5.1.0 (2017-12-4) 28 | 29 | - Moved dependencies to devDependencies that weren't supposed to be dependencies 30 | - Updated TypeScript to v3 (no compiled output change) 31 | - Added `module` export to conform with Core IO types 32 | 33 | ## 5.0.2 (2017-11-18) 34 | 35 | - Non-ish-code change: Reworked the TypeScript type definition for the signature. It's the same signature, just specified in a way that is easier for DefinitelyTyped to consume. 36 | - Updated the tsconfig.json and tslint.json configuration files to use a newer style, build tools updated 37 | - Note: the compiled output _did not change_ 38 | 39 | ## 5.0.1 (2017-9-11) 40 | 41 | - Non-code change: updated the README and republishing to make sure it's in npm 42 | 43 | ## 5.0.0 (2017-9-11) 44 | 45 | - BREAKING CHANGE: dropped support for Node.js < 4.0.0, and now enforce it via package.json "engines" field. 46 | - SORT OF BREAKING-ISH CHANGE: dropped support for attempting to install on non-arm platforms via package.json's "cpu" field. 47 | - Attempting to install this on a non-Raspberry Pi platform before didn't do much, since most of the Raspi.js suite wouldn't install on non-Raspberry Pi platforms. This module would install, even though you couldn't do anything with it. 48 | 49 | ## 4.0.0 (2017-4-23) 50 | 51 | - Removed Wiring Pi. There _shouldn't_ be any breaking changes, but since this is a large architectural change, I'm doing a major version bump anyways 52 | 53 | ## 3.0.5 (2017-22-1) 54 | 55 | - Publishing a new version to update the README on npmjs.com. No other changes. 56 | 57 | ## 3.0.4 (2016-12-3) 58 | 59 | - Fixed broken publish 60 | 61 | ## 3.0.3 (2016-12-3) 62 | 63 | - Added proper .npmignore 64 | 65 | ## 3.0.2 (2016-12-3) 66 | 67 | - Added types declaration to package.json 68 | 69 | ## 3.0.1 (2016-12-3) 70 | 71 | - Converted the project to TypeScript and cleaned up a bunch of odds and ends 72 | - Note: there is no functionality change or bug fixes with this release 73 | 74 | ## 3.0.0 (2016-11-25) 75 | 76 | - Removed raspi-wiringpi dependency because Raspbian now ships with it by default. 77 | 78 | ## 2.1.0 (2016-6-5) 79 | 80 | - Removed gulp in favor of npm run scripts 81 | - Updated dependencies 82 | 83 | ## 2.0.0 (2015-10-20) 84 | 85 | - Upgraded to NAN 2 86 | - POTENTIAL BREAKING CHANGE 87 | - The API has not changed, but the build requirements have 88 | - Make sure you are running Raspbian Jessie because this module no longer builds on stock Raspbian Wheezy 89 | - See https://github.com/fivdi/onoff/wiki/Node.js-v4-and-native-addons for more information 90 | 91 | ## 1.3.2 (2015-7-16) 92 | 93 | - Updated dependencies 94 | - Updated the repository links to point to their new location 95 | - Added code linter 96 | - Update code style to use newer best practices 97 | 98 | ## 1.3.1 (2015-4-27) 99 | 100 | - Updated dependencies 101 | 102 | ## 1.3.0 (2015-2-21) 103 | 104 | - Switched from traceur to babel for ES6->ES5 compilation 105 | 106 | ## 1.2.0 (2015-2-19) 107 | 108 | - Upgraded NAN to get support for Node.js 0.12 109 | - io.js support is theoretically there, but won't work until https://github.com/TooTallNate/node-gyp/pull/564 is landed 110 | 111 | ## 1.1.6 (2015-2-11) 112 | 113 | - Renamed this package to raspi.js (raspi in NPM) to better reflect the purpose. 114 | 115 | ## 1.1.5 (2015-1-21) 116 | 117 | - Locked down the NAN version for now since code breaks on 1.5 118 | 119 | ## 1.1.4 (2014-12-29) 120 | 121 | - Updated the README 122 | 123 | ## 1.1.3 (2014-12-20) 124 | 125 | - Added a README 126 | - Fixed a script compile issue that prevented 1.1.2 from including the reentrant fix 127 | 128 | ## 1.1.2 (2014-12-3) 129 | 130 | - Made ```init``` properly reentrant 131 | 132 | ## 1.1.1 (2014-12-2) 133 | 134 | - Bug fix in package.json 135 | 136 | ## 1.1.0 (2014-12-2) 137 | 138 | - Switched to ECMAScript 6 139 | - This is a breaking API change! The export structure is slightly different 140 | 141 | ## 1.0.5 (2014-11-27) 142 | 143 | - Fixed a bad NPM publish 144 | 145 | ## 1.0.4 (2014-11-25) 146 | 147 | - Switched to using wiringPiSetup instead of wiringPiSetupGpio 148 | 149 | ## 1.0.0-1.0.3 (2014-11-14) 150 | 151 | - Implemented initial functionality and worked out the kinks in building during ```npm install``` 152 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2017 Bryan Hughes 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Raspi.js 2 | ========== 3 | 4 | **NOTE: This project is in maintenance mode and no longer actively maintained.** 5 | 6 | Raspi.js provides initialization and base support for the Raspberry Pi. This module, along with [Raspi Board](https://github.com/nebrius/raspi-board) and [Raspi Peripheral](https://github.com/nebrius/raspi-peripheral), provide support for various peripherals on the Raspberry Pi. These libraries form the basis for [Raspi IO](https://github.com/nebrius/raspi-io), an IO plugin that adds support for the Raspberry Pi to [Johnny-Five](https://github.com/rwaldron/johnny-five). 7 | 8 | Check out the following peripheral API modules: 9 | 10 | * [Raspi GPIO](https://github.com/nebrius/raspi-gpio) 11 | * [Raspi PWM](https://github.com/nebrius/raspi-pwm) 12 | * [Raspi Software PWM](https://github.com/tralves/raspi-soft-pwm) 13 | * [Raspi I2C](https://github.com/nebrius/raspi-i2c) 14 | * [Raspi LED](https://github.com/nebrius/raspi-led) 15 | * [Raspi Serial](https://github.com/nebrius/raspi-serial) 16 | 17 | If you have a bug report, feature request, or wish to contribute code, please be sure to check out the [Raspi IO Contributing Guide](https://github.com/nebrius/raspi-io/blob/master/CONTRIBUTING.md). 18 | 19 | ## System Requirements 20 | 21 | - Raspberry Pi Model B Rev 1 or newer (sorry Model A users) 22 | - Raspbian Jessie or newer 23 | - [Node-RED](http://nodered.org/) works, but can be finicky and difficult to debug. 24 | - See https://github.com/nebrius/raspi-io/issues/24 for more info about support for other OSes 25 | - Node 4.0.0 or newer 26 | 27 | Detailed instructions for getting a Raspberry Pi ready for NodeBots, including how to install Node.js, can be found in the [wiki](https://github.com/nebrius/raspi-io/wiki/Getting-a-Raspberry-Pi-ready-for-NodeBots) 28 | 29 | **Warning:** when using this module, it MUST be installed with user-level permissions, but run with root permissions (e.g. `sudo node index.js`). 30 | 31 | ## Installation 32 | 33 | Install with npm: 34 | 35 | ```Shell 36 | npm install raspi 37 | ``` 38 | 39 | **Note:** this project is written in [TypeScript](http://www.typescriptlang.org/) and includes type definitions in the package.json file. This means that if you want to use it from TypeScript, you don't need to install a separate @types module. 40 | 41 | ## Example Usage 42 | 43 | In TypeScript/ES6: 44 | 45 | ```TypeScript 46 | import { init } from 'raspi'; 47 | import { DigitalInput, DigitalOutput } from 'raspi-gpio'; 48 | 49 | init(() => { 50 | const input = new DigitalInput('P1-3'); 51 | const output = new DigitalOutput('P1-5'); 52 | output.write(input.read()); 53 | }); 54 | ``` 55 | 56 | in JavaScript: 57 | 58 | ```JavaScript 59 | const raspi = require('raspi'); 60 | const gpio = require('raspi-gpio'); 61 | 62 | raspi.init(() => { 63 | const input = new gpio.DigitalInput('P1-3'); 64 | const output = new gpio.DigitalOutput('P1-5'); 65 | output.write(input.read()); 66 | }); 67 | ``` 68 | 69 | ## API 70 | 71 | ### Module Constants 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 99 | 100 |
ConstantDescription
moduleAn easily consumable object for indirectly passing this module around. Intended specifically for use by Core IO (details coming soon)
87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 |
PropertyTypeDescription
initAlias of the init method
101 | 102 | ### init(cb) 103 | 104 | The ```init``` method initializes the library suite. This method MUST be called before using any peripherals. 105 | 106 | _Arguments_: 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 128 | 129 |
ArgumentTypeDescription
cbFunctionCallback to be called once the board has been initialized. Takes no arguments
124 | 125 | 126 |
Takes no arguments
127 |
130 | 131 | _Returns_: None 132 | 133 | License 134 | ======= 135 | 136 | The MIT License (MIT) 137 | 138 | Copyright (c) 2014-2017 Bryan Hughes 139 | 140 | Permission is hereby granted, free of charge, to any person obtaining a copy 141 | of this software and associated documentation files (the "Software"), to deal 142 | in the Software without restriction, including without limitation the rights 143 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 144 | copies of the Software, and to permit persons to whom the Software is 145 | furnished to do so, subject to the following conditions: 146 | 147 | The above copyright notice and this permission notice shall be included in 148 | all copies or substantial portions of the Software. 149 | 150 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 151 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 152 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 153 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 154 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 155 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 156 | THE SOFTWARE. 157 | -------------------------------------------------------------------------------- /declarations/index.d.ts: -------------------------------------------------------------------------------- 1 | import { IBaseModule, IPeripheral } from 'j5-io-types'; 2 | export declare function init(cb: () => void): void; 3 | export declare function getActivePeripherals(): { 4 | [pin: number]: IPeripheral; 5 | }; 6 | export declare function getActivePeripheral(pin: number): IPeripheral | undefined; 7 | export declare function setActivePeripheral(pin: number, peripheral: IPeripheral): void; 8 | export declare function getPinNumber(alias: string | number): number | null; 9 | export declare const module: IBaseModule; 10 | -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /* 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2014-2017 Bryan Hughes 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | Object.defineProperty(exports, "__esModule", { value: true }); 26 | const raspi_board_1 = require("raspi-board"); 27 | if (!global.raspiPinUsage) { 28 | global.raspiPinUsage = {}; 29 | } 30 | const registeredPins = global.raspiPinUsage; 31 | // We used to do some stuff here back when we used Wiring Pi, but now that we 32 | // use pigpio, there's nothing for us to do. We're keeping this module in place 33 | // though because some other OSes may require this initialization, and we may 34 | // even require it again someday in Raspbian. 35 | function init(cb) { 36 | process.nextTick(cb); 37 | } 38 | exports.init = init; 39 | function getActivePeripherals() { 40 | return registeredPins; 41 | } 42 | exports.getActivePeripherals = getActivePeripherals; 43 | function getActivePeripheral(pin) { 44 | return registeredPins[pin]; 45 | } 46 | exports.getActivePeripheral = getActivePeripheral; 47 | function setActivePeripheral(pin, peripheral) { 48 | if (registeredPins[pin]) { 49 | registeredPins[pin].destroy(); 50 | const peripheralPins = registeredPins[pin].pins; 51 | for (const peripheralPin of peripheralPins) { 52 | delete registeredPins[peripheralPin]; 53 | } 54 | } 55 | registeredPins[pin] = peripheral; 56 | } 57 | exports.setActivePeripheral = setActivePeripheral; 58 | function getPinNumber(alias) { 59 | return raspi_board_1.getPinNumber(alias); 60 | } 61 | exports.getPinNumber = getPinNumber; 62 | exports.module = { 63 | init, 64 | getActivePeripherals, 65 | getActivePeripheral, 66 | setActivePeripheral, 67 | getPinNumber 68 | }; 69 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;EAsBE;;AAGF,6CAAgE;AAEhE,IAAI,CAAE,MAAc,CAAC,aAAa,EAAE;IACjC,MAAc,CAAC,aAAa,GAAG,EAAE,CAAC;CACpC;AACD,MAAM,cAAc,GAA4C,MAAc,CAAC,aAAa,CAAC;AAE7F,6EAA6E;AAC7E,+EAA+E;AAC/E,6EAA6E;AAC7E,6CAA6C;AAC7C,SAAgB,IAAI,CAAC,EAAc;IACjC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AACvB,CAAC;AAFD,oBAEC;AAED,SAAgB,oBAAoB;IAClC,OAAO,cAAc,CAAC;AACxB,CAAC;AAFD,oDAEC;AAED,SAAgB,mBAAmB,CAAC,GAAW;IAC7C,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC;AAFD,kDAEC;AAED,SAAgB,mBAAmB,CAAC,GAAW,EAAE,UAAuB;IACtE,IAAI,cAAc,CAAC,GAAG,CAAC,EAAE;QACvB,cAAc,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;QAC9B,MAAM,cAAc,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;QAChD,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE;YAC1C,OAAO,cAAc,CAAC,aAAa,CAAC,CAAC;SACtC;KACF;IACD,cAAc,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC;AACnC,CAAC;AATD,kDASC;AAED,SAAgB,YAAY,CAAC,KAAsB;IACjD,OAAO,0BAAiB,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC;AAFD,oCAEC;AAEY,QAAA,MAAM,GAAgB;IACjC,IAAI;IACJ,oBAAoB;IACpB,mBAAmB;IACnB,mBAAmB;IACnB,YAAY;CACb,CAAC"} -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "raspi", 3 | "version": "6.0.1", 4 | "description": "Provides access to Raspberry Pi peripherals from Node.js", 5 | "main": "dist/index.js", 6 | "types": "./declarations/index.d.ts", 7 | "scripts": { 8 | "prebuild": "tslint 'src/**/*.ts'", 9 | "build": "tsc", 10 | "test": "echo \"Error: no test specified\" && exit 1" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/nebrius/raspi.git" 15 | }, 16 | "keywords": [ 17 | "raspberry pi", 18 | "robotics", 19 | "nodebots" 20 | ], 21 | "author": "Bryan Hughes ", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/nebrius/raspi/issues" 25 | }, 26 | "homepage": "https://github.com/nebrius/raspi", 27 | "dependencies": { 28 | "j5-io-types": "^2.4.0", 29 | "raspi-board": "^7.0.0" 30 | }, 31 | "devDependencies": { 32 | "@types/node": "^10.12.12", 33 | "tslint": "^5.11.0", 34 | "typescript": "^3.2.1" 35 | }, 36 | "engines": { 37 | "node": ">= 6.4.0" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2014-2017 Bryan Hughes 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | import { IBaseModule, IPeripheral } from 'j5-io-types'; 26 | import { getPinNumber as getRaspiPinNumber } from 'raspi-board'; 27 | 28 | if (!(global as any).raspiPinUsage) { 29 | (global as any).raspiPinUsage = {}; 30 | } 31 | const registeredPins: { [ pinNumber: string ]: IPeripheral } = (global as any).raspiPinUsage; 32 | 33 | // We used to do some stuff here back when we used Wiring Pi, but now that we 34 | // use pigpio, there's nothing for us to do. We're keeping this module in place 35 | // though because some other OSes may require this initialization, and we may 36 | // even require it again someday in Raspbian. 37 | export function init(cb: () => void): void { 38 | process.nextTick(cb); 39 | } 40 | 41 | export function getActivePeripherals(): { [ pin: number ]: IPeripheral } { 42 | return registeredPins; 43 | } 44 | 45 | export function getActivePeripheral(pin: number): IPeripheral | undefined { 46 | return registeredPins[pin]; 47 | } 48 | 49 | export function setActivePeripheral(pin: number, peripheral: IPeripheral): void { 50 | if (registeredPins[pin]) { 51 | registeredPins[pin].destroy(); 52 | const peripheralPins = registeredPins[pin].pins; 53 | for (const peripheralPin of peripheralPins) { 54 | delete registeredPins[peripheralPin]; 55 | } 56 | } 57 | registeredPins[pin] = peripheral; 58 | } 59 | 60 | export function getPinNumber(alias: string | number): number | null { 61 | return getRaspiPinNumber(alias); 62 | } 63 | 64 | export const module: IBaseModule = { 65 | init, 66 | getActivePeripherals, 67 | getActivePeripheral, 68 | setActivePeripheral, 69 | getPinNumber 70 | }; 71 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Basic Options */ 4 | "target": "ES2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ 5 | "module": "commonjs", /* Specify module code generation: 'none', commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ 6 | // "lib": [], /* Specify library files to be included in the compilation: */ 7 | // "allowJs": true, /* Allow javascript files to be compiled. */ 8 | // "checkJs": true, /* Report errors in .js files. */ 9 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 10 | "declaration": true, /* Generates corresponding '.d.ts' file. */ 11 | "declarationDir": "declarations", 12 | "sourceMap": true, /* Generates corresponding '.map' file. */ 13 | // "outFile": "./", /* Concatenate and emit output to single file. */ 14 | "outDir": "dist", /* Redirect output structure to the directory. */ 15 | "rootDir": "src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 16 | // "removeComments": true, /* Do not emit comments to output. */ 17 | // "noEmit": true, /* Do not emit outputs. */ 18 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 19 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 20 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 21 | 22 | /* Strict Type-Checking Options */ 23 | "strict": true, /* Enable all strict type-checking options. */ 24 | "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 25 | "strictNullChecks": true, /* Enable strict null checks. */ 26 | "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 27 | "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 28 | 29 | /* Additional Checks */ 30 | "noUnusedLocals": true, /* Report errors on unused locals. */ 31 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 32 | "noImplicitReturns": true /* Report error when not all code paths in function return a value. */ 33 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 34 | 35 | /* Module Resolution Options */ 36 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 37 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 38 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 39 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 40 | // "typeRoots": [], /* List of folders to include type definitions from. */ 41 | // "types": [], /* Type declaration files to be included in compilation. */ 42 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 43 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 44 | 45 | /* Source Map Options */ 46 | // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 47 | // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ 48 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 49 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 50 | 51 | /* Experimental Options */ 52 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 53 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 54 | }, 55 | "include": [ 56 | "src/**/*.ts" 57 | ] 58 | } -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "defaultSeverity": "error", 3 | "extends": [ 4 | "tslint:recommended" 5 | ], 6 | "jsRules": {}, 7 | "rules": { 8 | "indent": [ true, "spaces", 2 ], 9 | "no-console": false, 10 | "quotemark": [ true, "single" ], 11 | "semicolon": [ true, "always" ], 12 | "trailing-comma": false, 13 | "ordered-imports": false, 14 | "object-literal-sort-keys": false, 15 | "variable-name": [ true, "allow-leading-underscore", "allow-pascal-case" ], 16 | "max-classes-per-file": false 17 | }, 18 | "rulesDirectory": [] 19 | } 20 | --------------------------------------------------------------------------------