balena-dslr-js

A js tool to run on a pi zero w to control cameras via gphoto2
git clone git://archive.git.mtrnord.blog/balena-dslr/balena-dslr-js.git
Log | Files | Refs | README | LICENSE

commit 5fb5fa5f5b6ccbc20dda50a79043f15c1f5a23ae
parent 5bf3d40417d02c174bdedfb484d2842df793863b
Author: Giovanni Garufi <nazrhom@users.noreply.github.com>
Date:   Fri,  1 May 2020 13:02:18 +0100

Merge pull request #1 from balena-io-playground/sigle-service

Refactor to single service
Diffstat:
A.dockerignore | 1+
A.gitignore | 1+
ADockerfile.template | 21+++++++++++++++++++++
Abuild/.gitkeep | 0
Apackage.json | 24++++++++++++++++++++++++
Asrc/index.ts | 27+++++++++++++++++++++++++++
Atsconfig.json | 24++++++++++++++++++++++++
7 files changed, 98 insertions(+), 0 deletions(-)

diff --git a/.dockerignore b/.dockerignore @@ -0,0 +1 @@ +node_modules diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/Dockerfile.template b/Dockerfile.template @@ -0,0 +1,21 @@ +FROM balenalib/%%BALENA_MACHINE_NAME%%-node + +# Install dependencies +RUN install_packages libgphoto2-dev gphoto2 + +# Defines our working directory in container +WORKDIR /usr/src/app + +# Copies the package.json first for better cache on later pushes +COPY package.json ./ + +# This install npm dependencies on the balena build server, +# making sure to clean up the artifacts it creates in order to reduce the image size. +RUN JOBS=MAX npm install --production --unsafe-perm && npm cache verify + +# This will copy all files in our root to the working directory in the container +COPY . ./ + +RUN npm run build + +CMD ["npm", "start"] diff --git a/build/.gitkeep b/build/.gitkeep diff --git a/package.json b/package.json @@ -0,0 +1,24 @@ +{ + "name": "dslr-cam", + "version": "1.0.0", + "description": "Balena application to control a DSLR camera", + "repository": "https://github.com/balena-io-playground/balena-dslr", + "main": "index.js", + "scripts": { + "build": "tsc", + "start": "node ./build/index.js", + "prettify": "balena-lint --typescript --fix src/ test/", + "lint": "balena-lint --typescript src/ test/ && tsc --noEmit" + }, + "author": "", + "license": "ISC", + "dependencies": { + "@typedproject/gphoto2-driver": "^2.4.0", + "lodash": "^4.17.15", + "segfault-handler": "^1.3.0", + "typescript": "^3.6.4" + }, + "devDependencies": { + "@types/node": "^13.13.4" + } +} diff --git a/src/index.ts b/src/index.ts @@ -0,0 +1,27 @@ +import SegfaultHandler from 'segfault-handler'; +import path from 'path'; +import { CameraList, closeQuietly } from '@typedproject/gphoto2-driver'; + +SegfaultHandler.registerHandler('crash.log'); + +const cameraList = new CameraList().load(); + +console.log('Nb camera', cameraList.size); + +if (cameraList.size) { + const camera = cameraList.getCamera(0); + + + if (camera && !camera.isClosed()) { + console.log('Camera =>', camera); + + const cameraFile = camera.captureImage()!; + + cameraFile.save(path.join(__dirname, '../.tmp/capture.jpeg')); + + closeQuietly(cameraFile); + closeQuietly(camera); + } +} + +cameraList.close(); diff --git a/tsconfig.json b/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es2019", + "outDir": "./build", + + "strict": true, + "strictNullChecks": true, + "noUnusedParameters": true, + "noUnusedLocals": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + + "esModuleInterop": true, + "preserveConstEnums": true, + "removeComments": true, + "resolveJsonModule": true, + "sourceMap": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "moduleResolution": "node", + }, + "include": ["src/"] +}