Skip to content

Commit

Permalink
Add docs to camlib from camlib-docs repo
Browse files Browse the repository at this point in the history
  • Loading branch information
petabyt committed Oct 11, 2023
1 parent 1cb29ac commit 490a139
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: ci
on:
push:
branches:
- master
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.x
- run: pip install mkdocs-material
- run: pip install mkdocs-exclude
- run: pip install mkdocs-roamlinks-plugin
- run: mkdocs gh-deploy --force
26 changes: 26 additions & 0 deletions docs/c.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Camlib C API

Camlib uses *no macros*, so it's easy to use camlib from any language that has a basic C FFI. It would be trivial to
write a binding for Rust.

Camlib also uses a single-buffer design. This means that all data, whether it comes in or out, is read, written, packed, and unpacked in a *single multi-megabyte buffer*.
This is not done to reduce memory usage, but to decrease complexity and reduce the number of `malloc()` calls. It also helps prevent rogue memory leaks, which
is crucial for apps, which have a very low memory limit.

This means that functions processing or using this data *must* keep the operation mutex locked until processing is done, so long as
the caller isn't making the application thread-safe. In a single-threaded application, there is no need for it to be thread-safe.

Camlib was designed to run on a single thread, through a thread-safe server returning `bind` requests. This works well
in many applications, but I'm slowly working on making it thread-safe for higher speeds applications.

## `void ptp_generic_init(struct PtpRuntime *r);`
Initializes a `struct PtpRuntime`. The struct is pretty small. This allocates the a large buffer to `r.data`.
You may also set r.connection_type to one of `enum PtpConnType`.
## `int ptp_device_init(struct PtpRuntime *r);`
Attempts to connect to the first valid PTP device found, over USB. Returns `enum CamlibError`.
## `int ptp_open_session(struct PtpRuntime *r);`
Opens session
## `int ptp_close_session(struct PtpRuntime *r);`
Closes session, (typically shuts down camera)
## `int ptp_get_device_info(struct PtpRuntime *r, struct PtpDeviceInfo *di);`
Recieves device info into [`struct PtpDeviceInfo`](https://github.com/petabyt/camlib/blob/8291304dc94a00a57200e33a19a497f1a6ccc5b6/src/cl_data.h#L32).
33 changes: 33 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Examples
```
-- Timelapse script
TAKE_X_PICS = 10
MS_BETWEEN_PICS = 100
for i = 0,TAKE_X_PICS,1 do
rc = ptp.takePicture()
if rc == ptp.IO_ERR then
setStatusText("IO Error taking picture")
break
elseif rc == ptp.UNSUPPORTED then
setStatusText("Remote capture is unsupported")
break
elseif rc then
setStatusText("Error: " + tostring(rc))
break
else
setStatusText("Took " .. tostring(i) .. "picture(s)")
end
msleep(MS_BETWEEN_PICS);
end
```

```
-- Basic UI script
win = ui.popup("Astro Mode")
if win.addButton("Take pic") then
rc = ptp.takePicture()
endif
```
12 changes: 12 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Camlib

Camlib is still under heavy development. The API will change and break as I'm using it to develop
tools and apps for several different projects.

- [camlib source code on Github](https://github.com/petabyt/camlib)

## Current Applications
- [Cam, a better camera controller](https://cam.clutchlink.com/)
- [Fujihack Project](https://github.com/fujihack/fujihack/tree/master/ptp)
- [mlinstall, Installer for Magic Lantern](https://github.com/petabyt/mlinstall)
- [Fudge, alternative WiFi/Bluetooth app for Fujifilm cameras](https://github.com/petabyt/fudge)
65 changes: 65 additions & 0 deletions docs/js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Camlib.js

The user interface for CamControl is written entirely in HTML/CSS/JS. Requests are made through a JS 'mutex' and routed to camlib bindings.
Camlib.js is open-source, you can find it here: [https://github.com/clutchlink/camlibjs](https://github.com/clutchlink/camlibjs)

This is mostly used internally, as every one of these functions *require* `await` as they are async. This makes for a clunky and arkward API.

## `ptp.getDeviceInfo()`

Returns device info as JSON. Note that device info is stored in `ptp.info` when the device is connected.

## `ptp.disconnect()`

Disconnects the device abruptly. All tasks should die after this.

## `ptp.driveLens()`

Drives the lens, if possible. For EOS cameras, you can use range `-3`-`3`.

## `ptp.getLiveViewFrame()`

Internal function used by CamControl (Linux, Windows) to get JSON raw bytes from a liveview frame.
This is done internally on the backend.

## `ptp.getDeviceType()`

Returns the current device type - type enums are stored in `ptp.devs`:

```javascript
devs: {
EMPTY: 0,
EOS: 1,
CANON: 2,
NIKON: 3,
SONY: 4,
FUJI: 5,
PANASONIC: 6,
}
```


## `ptp.getRetCode()`
Gets the return code from the last operation.

## `ptp.getStorageIDs()`
Return a list of storage IDs (32 bit integers) from the camera.

## `getStorageInfo(id)`
Returns a JSON structure with information on the requested storage ID.

## `ptp.getObjectHandles(id, root)`
Returns a list of object handles from a storage ID. Root can either be 0 for the top directory, or a handle to a folder.

## `ptp.getObjectInfo()`
Gets information on a particular object. Could be a folder, file, or even an album.

## `ptp.getEvents()`
Used only by CamControl. Gets a list of changes the camera has made since the last call.

## `ptp.customCmd(opcode, params)`
(Not implemented in v0.1.0)
Sends a custom command opcode (with no data phase) to the camera.

## `ptp.getPartialObject(handle, offset, max)`
Data is returned in the same way that thumbnail JPEG data is returned.
24 changes: 24 additions & 0 deletions docs/lua.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Lua API

The Lua API for camlib is under development. You can view the current source code
for the bindings [here on Github](https://github.com/petabyt/camlib/blob/master/src/lua.c).

Currently, the Lua bindings take advantage of the fact that camlib already can convert almost
every PTP data structure to JSON - and is able to convert the JSON to Lua tables using `lua-cjson`.

## `ptp.getDeviceInfo()`
Returns a structure about the device:
```
{
model = "Canon Rebel Blah"
propsSupported = {12345, 12345, 12345}
...
}
```
## `ptp.takePicture()`
Triggers a complete capture.
## `ptp.sendOperation(opcode, params, payload)`
Send a custom opcode request to the camera. Have up to 5 parameters, and an optional
payload in bytes (0-255).
**Only use this if you know what you're doing.**
Sending bad data can easily brick cameras.
15 changes: 15 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
site_name: Camlib documetation
site_description: 'Docs for camlib, PTP/USB/IP library'
site_author: 'Daniel Cook'
docs_dir: docs/
repo_name: 'petabyt/camlib'
repo_url: 'http://github.com/petabyt/camlib'
nav:
- Home: index.md
- C API: c.md
- camlib.js: js.md
- Lua API: lua.md
theme:
name: 'material'
palette:
scheme: default

0 comments on commit 490a139

Please sign in to comment.