This repository has been archived by the owner on Nov 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from camphor-/develop
0.2.0
- Loading branch information
Showing
7 changed files
with
98 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"presets": ["es2015"] | ||
"presets": ["es2015-node5"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
# now-client-camera | ||
|
||
[![Build Status](https://travis-ci.org/camphor-/now-client-camera.svg?branch=master)](https://travis-ci.org/camphor-/now-client-camera) | ||
[![Dependency Status](https://david-dm.org/camphor-/now-client-camera.svg)](https://david-dm.org/camphor-/now-client-camera) | ||
[![devDependency Status](https://david-dm.org/camphor-/now-client-camera/dev-status.svg)](https://david-dm.org/camphor-/now-client-camera#info=devDependencies) | ||
|
||
## Run | ||
Examples: | ||
- `npm start -- --mode=raspistill http://192.168.1.128:3000` | ||
- `DEBUG=now-client-camera npm start -- --mode=sample http://192.168.1.128:3000` | ||
- `npm start -- --mode=sample --authorization='Basic <token>' http://192.168.1.128:3000` | ||
- `npm start -- --driver=raspistill http://192.168.1.128:3000` | ||
- `DEBUG=now-client-camera npm start -- --driver=sample http://192.168.1.128:3000` | ||
- `npm start -- --driver=sample --authorization='Basic <token>' http://192.168.1.128:3000` | ||
|
||
### Drivers | ||
Specify a driver with `--driver=` option. (default: `sample`) | ||
|
||
#### raspistill | ||
Raspberry Pi Camera Module | ||
|
||
Environment variables: | ||
- `RASPISTILL_WIDTH` - Width of a picture (default: 320) | ||
- `RASPISTILL_HEIGHT` - Height of a picture (default: 240) | ||
|
||
#### sample | ||
Sample JPEG image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {exec} from 'child_process'; | ||
|
||
const MAX_BUFFER = 1 * 1024 * 1024; // 1MiB | ||
|
||
const parseInteger = (string, defaultValue) => { | ||
const number = Number(string); | ||
if (Number.isInteger(number)) { | ||
return number; | ||
} else { | ||
return defaultValue; | ||
} | ||
}; | ||
|
||
const WIDTH = parseInteger(process.env.RASPISTILL_WIDTH, 320); | ||
const HEIGHT = parseInteger(process.env.RASPISTILL_HEIGHT, 240); | ||
|
||
export default () => new Promise((resolve, reject) => { | ||
exec(`raspistill -w ${WIDTH} -h ${HEIGHT} -n -e jpg -o -`, { | ||
encoding: 'buffer', | ||
maxBuffer: MAX_BUFFER | ||
}, (err, stdout, stderr) => { | ||
if (err === null) { | ||
resolve(stdout); | ||
} else { | ||
reject(err.toString()); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {readFile} from 'fs'; | ||
|
||
export default () => new Promise((resolve, reject) => { | ||
readFile('./test.jpg', (err, data) => { | ||
if (err) { | ||
reject(err.toString()); | ||
} else { | ||
resolve(data); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters